Search code examples
dm-script

DM shows calibration is invalid when loading EDX line scan CSV by dm scripting


I used one DM script to load line scan profiles to DM, it was useful well with line scan csv profiles from Esprit. But when I tried it with a python based line scan CSV file, it always shows some error"the calibration is invalid; check that the scale is non-zero and both scale and origin are representable as 32-bit floats." My cali srcirpt is as below and the screenshot of the error and CSV file were also attached. Any suggesions really appreciated.

string path
number filereference
number counter
number dobreak=0

number colcounter=1
image dataarray
documentwindow win
string unitstring

number cltest


// Select the file

if(!opendialog(win,"Select Bruker Line Profile export file (.csv).","",path)) exit(0)
string filename=pathextractbasename(path,0)
string extension=pathextractextension(path, 0)


// Check to see if the file is a text file - extension .txt

if(extension!="csv")
    {
        if(!twobuttondialog("The selected file does not appear to be a csv (.csv) file.", "Continue", "Cancel")) exit(0)
    }


// Remove any previous temporary information in the Global info

deletepersistentnote("Bruker Import")



try
    {
        filereference=openfileforreading(path)
        number readok=1
        string thisline
        
        
        // While ever the end of file has not been reached (readok=0) continue reading lines from the file
        
        while(readok==1)
            {
                readok=readfileline(filereference, thisline)
                number linelen=len(thisline)
                
                // Check the first line contains the word 'Index'. Note, this checking is kept deliberately
                // loose because the Bruker export format has varied over the years, so the aim is to keep
                // it compatible.
                
                if(counter==0) 
                    {
                        string indexstring
                        number foundstring=find(thisline, "Index")
                        number foundstring1=find(thisline, "x")
                        number cl
                        
                        

                        if(foundstring1<0)
                         
                         { cl=23; }
                         
                        else 
                         
                        { 
                           if(foundstring<0)
                         
                             { cl=2; }
                         
                         else
                           {cl=15;
                             } 
                              }
                             
                                                  
                          

                            
                    // Find the tabs - which are the delimiters

                    number i
                            
                    
                    string tempstring
                    for(i=cl; i<linelen; i++)
                        {
                            string thischar=mid(thisline, i, 1)
                            
                            if(thischar==",")
                            {
                                thischar="" // nb i+1 because a space follows immediately after the comma
                                // and +3 to deal with the carriage return at the end of the line
                                
                            //}
                            
                                                        
                            //if(asc(thischar)==44) // tab found*/
                                //{
                                    setpersistentstringnote("Bruker Import:Element "+colcounter, tempstring)
                                    colcounter=colcounter+1
                                    tempstring=""
                                }
                            if(asc(thischar)==13) // Carriage return found
                                {
                                    setpersistentstringnote("Bruker Import:Element "+colcounter, tempstring)
                                    break
                                }
                            
                            tempstring=tempstring+thischar  
                        }

                    }
                    
                counter=counter+1
            }
    }
catch // there was an error - close the file
    {
        closefile(filereference)
        showalert("the file was opened by other process",2)
        exit(0)
    }

number nooflines=counter-1 // ignore the headeer line
counter=0
number i
closefile(filereference)

number noofcolumns=colcounter+2 


try

{

  filereference=openfileforreading(path)
        number readok=1
        string thisline
                
        readok=readfileline(filereference, thisline)
        
        dataarray=realimage("",4, (nooflines-1), noofcolumns)
        
        number linecounter=0
        while(readok==1)
            {
                        string tempstring
                        number columncounter=0

number xsize, ysize, reallines
getsize(dataarray, xsize, ysize)
for(i=0; i<xsize; i++)
    {
        number thisval=getpixel(dataarray, i,0)
        if(thisval!=0) reallines=reallines+1
    }


number totallength=getpixel(dataarray, xsize-1, 1)

number calib

  if (totallength<1)

  {calib=totallength*1000/(xsize);}
  
  else
   {calib=totallength/(xsize);}
     
result("calib :"+ calib+"\n" )

enter image description here enter image description here


Solution

  • As the updated script excerpt currently stands, please note that it never transfers any numeric values into the dataarray image. So all the values in the image will be zero and your calculated value of calib will be zero.

    PLEASE NOTE: this forum is for questions about DM scripting, in general, and is meant for those who have some experience writing and debugging code. It is NOT a code troubleshooting and debugging service. The script, as shown above, has numerous deficiencies and looks like a work in progress, rather than a functioning piece of code. If it works correctly on some other CSV file, then the arrangement of values in that file is quite different than in your current file and the script needs to be rewritten accordingly. If you are not familiar with the internal design and logic of the original script, then I highly recommend that you ask the original author to revise it appropriately. No simple change of one line of code will get it working properly.

    As indicated in the comment, the part of your script shown in your question is not at all involved with the error message. However, I'm going to guess that the calculated calib value is ultimately passed to the ImageSetDimensionScale function. If that is true, then please check the logic of your script for determining the value of calib. Currently, it seems to derive it from the last entry in the second row of dataarray (via totallength = GetPixel(dataarray, xsize-1, 1)). If that value is zero, then your calibration value will be zero and the call to ImageSetDimensionScale will result in the error that is posted.