Home Forums Imaging Export Cellspace Images to XYZ Matrix

This topic contains 7 replies, has 6 voices, and was last updated by  Dr Tephy Marillo-Sialer 3 months, 3 weeks ago.

  • Creator
    Topic
  • #7236

    Manuel Roman
    Participant

    Hi all,

    Sorry to disturb again. After all my problems solved I’m getting good results with CellSpace but I was wondering If could be possible to export the data map for each wave (or element) in XYZ format, I mean, XY (coordinates) and Z (concentration).

    Thanks a lot

    Manuel

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #7241

    Dr Bence Paul
    Keymaster

    Hi Manuel,

    There is no built-in way to export x,y,z data, but below is a bit of code that you can copy and paste into a procedure window within iolite, after you have created your CellSpace image. It will create a text wave of x,y,z data for your currently displayed image. Depending on the size of your image, it may take a couple of minutes to process.

    Once it is finished, you can save the result using the Data menu -> Save Waves.

    Best regards,
    Bence

    Function ExtractXYZvalues()
    	
    	DFREF dfSav = GetDataFolderDFR()
    	
    	SetDataFolder root:Packages:iolite:CellSpaceImages
    	
    	Wave CellSpace_Sample
    	
    	If(!WaveExists(CellSpace_Sample))
    		DoAlert 0, "Could not find the CellSpace_Sample image. Process aborted."
    		Abort
    	EndIf
    	
    	Variable NoOfRows = dimsize(CellSpace_Sample, 0)
    	Variable NoOfCols = dimsize(CellSpace_Sample, 1)
    	
    	Make /O /T /N=(NoOfRows * NoOfCols + 1) ImageXYZ
    	ImageXYZ[0] = "x,y,z"
    	
    	Variable RowCounter, ColCounter
    	For(RowCounter = 0; RowCounter < NoOfRows; RowCounter += 1)
    		Print "Processing Row " + num2str(RowCounter + 1)
    		For(ColCounter = 0;ColCounter < NoOfCols;ColCounter += 1)
    			ImageXYZ[RowCounter * NoOfCols + ColCounter + 1] = num2str(RowCounter) + "," + num2str(ColCounter) + "," + num2str(CellSpace_Sample[RowCounter][ColCounter])
    		EndFor
    	EndFor
    
    	Edit ImageXYZ
    
    	SetDataFolder dfSav
    
    End
    #7256

    Manuel Roman
    Participant

    Many, many thanks, Vence

    It’s working great, I can export now the data to make further treatment and combine with other images…

    Thanks a lot for your help

    Best Regards

    Manuel

    #7257

    Manuel Roman
    Participant

    Sorry…my automatic corrector didn’t understand “Bence” and he wrote “Vence” instead… sorry…

    #7692

    Freya George
    Participant

    Hi all,
    I am trying to do exactly this, create an XY (coordinates) and Z (concentration) datafile of a range of trace elements that can be exported from the CellSpace image. However, when I copy the above code into the procedure window and execute the code, I receive a CommandError: “expected wave name, variable name, or operation.”

    Any advice on what to do? Do i first need to save the CellSpaceImage that is displayed on the screen in some way?

    Thanks a lot!

    Best regards,
    Freya

    • This reply was modified 1 year, 9 months ago by  Freya George.
    #12142

    Ian Moffat
    Participant

    Hi Bence,
    Thanks for this very useful bit of code. Is it possible to do a similar XYZ data export if you have created an Image from Selections? If so, could you post the code please?

    Cheers,
    Ian

    #12337

    Riia Chmielowski
    Participant

    Thank you for that code, I just found it today (Thanks Tephy!), and have successfully compiled it and have made an attempt at exporting the data. However, I strongly suspect there is a better approach than what I am doing in my attempt to get the CPS data and its XY coordinates out of iolite and into iogas. My work flow so far:

    * used the “save wave” option to create a text file with the default name of “StageX_Itnerped++.txt” containing quite a variety of different bits of information on X-Y values

    * use the “save wave” option to create a text file with the default name of “TotalBeam++.txt” containing the raw CPS data

    * combine information from both files into a single file (using the row and column labels that I had chosen to “write” in the above step to confirm that they line up with one another

    * Add 1 new columns each next to the X and Y values and add formulas to say “true” if the adjacent value is the same as the above cell, and “false if it is different.

    * Add three new columns and name them (e.g. “name”, the second “laser spot #”, and “jump here”)

    * Starting at the top of the file, for the first set of data for which both the X and Y text results are “true” (e.g. the stage was not moving) enter the name of the first laser spot (e.g. “blank”) in the name column, and a “1” in the laser spot column . Page down till you reach the first row where those test resuts are “false (e.g. the stage was moving) and enter “move” in both of those columns. Use the cntrl-arrow to jump back to where you had entered the name, and use the automatic fill down option to copy the name and number down to the start of the move. Jump back to the bottom, enter a 1 in that third column.
    * Repeat this procedure for all of the other laser spots and moving between them (use that third column to jump to the last one to double check that you are about to enter the correct number).
    Note that when you get to the map you will be looking for the next place where X is false but Y is true, as the stage is moving from left to right, but not in the Y direction. (if you had run standards as lines as well then, of course, this would have been the case from the beginning).

    Doing this by hand like this is kinds of tedious, but, in theory, when I am done, I will be able to open the data in iogas, where I can look at one type of data at a time and used differences in range of values for the various channels to be able to tell which phase is which and assign a colour/size/shape attributes for the different phases till I am confidant that I have them all correct.

    It is my hope that once I have done that I will be able use the automatic selection from beam intensity to assign everything to their phases based on the upper and lower limits revealed by iogas. If that works, it is my hope that I could then apply the X_Trace_Elements_IS to the various phases, and then make a new cellspace map, with units in ppm or wt% (as appropriate).

    While I would, of course, welcome advice on any stage in this plan, I am specifically asking for easier ways to get the X-Y data and the CPS data out of iolite and to assign the names and laser numbers. Did I miss some obvious choice in the export window? Would it be possible to write a script to do the assignment of names and numbers automatically, instead of needing to to them by hand?

    Thank you for any thought you can share

    #12360

    Hi,

    To run the code, copy and paste it into the Procedure window which you can open using the top menu bar: Windows > Procedure Windows > Procedure Window. Then copy and paste the function name (e.g. ExtractXYZvalues()) into the bottom line of the Command Window (Windows>Command Window) and hit the return key.

    For CellSpace, the code will create a wave called ImageXYZ which corresponds to the currently plotted image in the CellSpace window. The code will append this wave to a Table which you can save by going to File > Save Table copy… after selecting the required file format (csv, txt, etc). You can also save the new wave using the Save Waves option (Data > Save Waves) and selecting ImageXYZ from the wave list.
    If you want to export a different CellSpace map (channel) you have to close the table, then plot the other channel from the CellSpace Window and re-run the code.

    Ian, below is the code to export XYZ data from Image from Selections maps. In this case, the code will generate a XYZImage wave for each existing map and will append each to separate table.

    Function ExtractXYZvaluesImgSel()
    	
    	DFREF dfSav = GetDataFolderDFR()
    	
    	SetDataFolder root:Packages:iolite:images
    	
    	String ListOfMapWaves = WaveList("*Map", ";", "")
    	Variable NoOfMaps = ItemsInList(ListOfMapWaves)
    	
    	Variable MapCounter
    	For(MapCounter = 0; MapCounter < NoOfMaps; MapCounter += 1)
    		String NameOfMap = StringFromList(MapCounter, ListOfMapWaves)
    	
    		Wave ThisMap = $NameOfMap
    		
    		If(!WaveExists(ThisMap))
    			DoAlert 0, "Could not find the map image. Process aborted."
    			Abort
    		EndIf
    		
    		Variable NoOfRows = dimsize(ThisMap, 0)
    		Variable NoOfCols = dimsize(ThisMap, 1)
    		
    		String ThisXYZImage = "ImageXYZ_" + NameOfMap 
    		Make /O /T /N=(NoOfRows * NoOfCols + 1) ImageXYZ
    		Rename ImageXYZ, $ThisXYZImage
    		Wave/T XYZImage = $ThisXYZImage
    		XYZImage[0] = "x,y,z"
    		
    		Variable RowCounter, ColCounter
    		For(RowCounter = 0; RowCounter < NoOfRows; RowCounter += 1)
    			//Print "Processing Row " + num2str(RowCounter + 1)
    			For(ColCounter = 0;ColCounter < NoOfCols;ColCounter += 1)
    				XYZImage[RowCounter * NoOfCols + ColCounter + 1] = num2str(RowCounter) + "," + num2str(ColCounter) + "," + num2str(ThisMap[RowCounter][ColCounter])
    			EndFor
    		EndFor
    	
    		Edit XYZImage
    	
    	EndFor
    	
    	SetDataFolder dfSav
    
    End
Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.