Changeset 1174


Ignore:
Timestamp:
Jan 5, 2022 9:45:25 PM (7 months ago)
Author:
ilavsky
Message:

Nika minor fix for errors and 12IDB support improvement

Location:
trunk/User Procedures/Nika
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/User Procedures/Nika/NI1_ConvProc.ipf

    r1169 r1174  
    227227        Multithread Error[1,numpnts(Error)-1] = sum(TempIntSqt,TempHistSum[p-1],TempHistSum[p])
    228228       
    229 //      //suggested by Wavemetrics another way... I am uinable to make this work at this time...
     229//      //suggested by Wavemetrics another way... I am unable to make this work at this time...
    230230//              //Yes, MatrixOP is a possible solution.
    231231//              //First notice that your indexWave needs to be converted into a matrix using the following rule:
     
    256256                //variance  = (Error - (Intensity^2 / Histogram)) / (Histogram - 1)
    257257                //st deviation = sqrt(variance)
    258                 MatrixOp/O  Error = sqrt(abs(Error - (TempSumXi*TempSumXi / HistogramWv)) / (HistogramWv - 1))
     258                MatrixOp/O  Error = sqrt(abs(Error - (TempSumXi*TempSumXi / HistogramWv)) / clip((HistogramWv - 1),1,inf))      //modified 2022-01-05, this clip shoudl avoid infs/Nans due to histrogramWv-1 being 0
    259259                if(ErrorCalculationsUseSEM)
    260260                        //error_mean=stdDev/sqrt(Histogram)                     use Standard error of mean...
     
    271271        endif
    272272       
    273         //this fix is same for all - if there is only 1 point in the bin, simply use sqrt of intensity... Of course, this can be really wrong, since by now this is fully calibrated and hecne sqrt is useless...
     273        //this fix is same for all - if there is only 1 point in the bin, simply use sqrt of intensity... Of course, this can be really wrong, since by now this is fully calibrated and hence sqrt is useless...
    274274        Error = (HistogramWv[p]>1)? Error[p] : sqrt(abs(Intensity[p]))          //for negative intensities this can give nan, so take abs(int)
    275275        //now handling of case where we have error=0, which is possible only if Intensity=0 for each point summed together. 
    276         Error = Error[p]>0 ? Error[p] : NaN                                                             //for Int=0 we could have error = 0 if all points ahve 0 intensity, which is degenerate case (bad masking).
     276        Error = Error[p]>0 ? Error[p] : NaN                                                             //for Int=0 we could have error = 0 if all points have 0 intensity, which is degenerate case (bad masking).
    277277        note Intensity, OldNote
    278278        note Error, OldNote
     
    430430        Wave/Z MaskWave=root:Packages:Convert2Dto1D:M_ROIMask
    431431        Wave/Z Pix2DSensitivity=root:Packages:Convert2Dto1D:Pixel2DSensitivity
     432        //Wave/Z SolAngCor2Dwave = root:Packages:Convert2Dto1D:SolAngCor2Dwave //2022-01 - this is not needed, 2D Solid angle correction is combination of SOlidAngle Correction AND geometry correction.
    432433        //little checking here...
    433434        if(UseMask)
     
    446447                endif
    447448        endif
    448         if(UsePixelSensitivity&&!UseCalib2DData)
     449        if(UsePixelSensitivity &&!UseCalib2DData)
    449450                if(!WaveExists(Pix2DSensitivity) || DimSize(Pix2DSensitivity, 0)!=DimSize(DataWave, 0) || DimSize(Pix2DSensitivity, 1)!=DimSize(DataWave, 1))
    450451                        abort "Pix2D Sensitivity problem - either does not exist or has differnet dimensions that data "
    451452                endif
    452453        endif
    453 
     454        //if(UseSolidAngle&&!UseCalib2DData)
     455        //      if(!WaveExists(SolAngCor2Dwave))
     456        //              abort "SOlid ANgle Correction wave does nto exist. Change some parameters to recalculate geometry and try again. "
     457        //      endif
     458        //endif
     459
     460        //MatrixOP/O/S   Calibrated2DDataSet = DataWave         // MatrixOP/O does NOT preserve wavenote... 
    454461        Duplicate/O DataWave,  Calibrated2DDataSet
    455462       
    456463        Wave Calibrated2DDataSet=root:Packages:Convert2Dto1D:Calibrated2DDataSet
    457         redimension/S Calibrated2DDataSet
     464        //redimension/S Calibrated2DDataSet             //2022-01 needed???
    458465        string OldNote=note(Calibrated2DDataSet)
    459466
     
    465472                        CalibrationPrefactor*=CorrectionFactor
    466473                endif
    467                 if(UseSolidAngle)
     474                if(UseSolidAngle)               //Combined with Gemoetry Correction this results in angle dependent solid angle correction. 
    468475                        variable solidAngle =PixelSizeX/SampleToCCDDistance * PixelSizeY/SampleToCCDDistance
    469                         //print solidANgle
     476                        //print solidAngle
    470477                        //fixed bug 10-13-2018, was multiplying by solid angle. not dividing.But we need to divide by solid angle - if the detector is further, we see less of area,
    471478                        //well, this is approximate, but should be just fine... my testing shows, that for 30mm far pixel with 0.3mm size the difference is less than 4e-4... Who cares?
     
    480487                endif
    481488       
    482                 Duplicate/O DataWave, tempDataWv, tempEmptyField
    483                 redimension/S tempDataWv, tempEmptyField
     489                MatrixOP/O   tempDataWv = DataWave
     490                MatrixOP/O   tempEmptyField = DataWave
     491                //redimension/S tempDataWv, tempEmptyField - needed???
     492                Wave tempDataWv
     493                Wave tempEmptyField
     494                tempEmptyField=0
    484495               
    485496                if(UsePixelSensitivity)
    486497                        MatrixOP/O  tempDataWv=tempDataWv/Pix2DSensitivity
    487498                endif
     499                //if(UseSolidAngle)             //2022-01 - this is not needed, 2D Solid angle correction is combination of SOlidAngle Correction AND geometry correction.
     500                //      MatrixOP/O  tempDataWv=tempDataWv/SolAngCor2Dwave
     501                //endif
     502
    488503                if(UseDarkField)
    489504                        if(UseSampleMeasTime && UseDarkMeasTime)
     
    538553                        endif
    539554                endif
    540                 tempEmptyField=0
    541555                variable ScalingConstEF=1
    542556       
     
    816830        //OK, we need to recalculate the GeometryCorrention, here is the procedure...
    817831        variable Ltemp = Wavelength / (4 * pi)
    818         //NI1A_Create2DQWave(DataWave)                  //creates 2-D Q wave - this must extsting by now...
     832        //NI1A_Create2DQWave(DataWave)                  //creates 2-D Q wave - this must exist by now...
    819833        wave Q2DWave = root:Packages:Convert2Dto1D:Q2DWave
    820834        MatrixOp/O  GeometryCorrection =  2 * asin(Q2DWave * Ltemp))
     
    857871//      wave/Z Radius2DWave=root:Packages:Convert2Dto1D:Radius2DWave
    858872        wave/Z Q2DWave=root:Packages:Convert2Dto1D:Q2DWave
     873        //wave/Z SolAngCor2Dwave=root:Packages:Convert2Dto1D:SolAngCor2Dwave                            //2022-01 - this is not needed, 2D Solid angle correction is combination of SOlidAngle Correction AND geometry correction.
    859874        wave/Z Rdistribution1D=$("root:Packages:Convert2Dto1D:Rdistribution1D_"+orientation)
    860875        wave/Z AnglesWave=root:Packages:Convert2Dto1D:AnglesWave
     
    866881        //Check that the waves exist at all...
    867882        if (!WaveExists(Qvector) || !WaveExists(HistogramWv) || !WaveExists(LUT))
    868                 NI1A_Create2DQWave(DataWave)                    //creates 2-D Q wave does not need to be run always...
     883                NI1A_Create2DQWave(DataWave)                                    //creates 2-D Q wave and SolAngCor2Dwave does not need to be run always...
    869884                NI1A_Create2DAngleWave(DataWave)                        //creates 2-D Azimuth Angle wave does not need to be run always...
    870885                NI1A_CreateLUT(orientation)                                     //creates 1D LUT, should not be run always....
     
    13521367                //print microSeconds/10000, "MatrixOP"
    13531368                //record for which geometry this Radius vector wave was created
     1369                //MatrixOp/O SolAngCor2Dwave = PixelSizeX*PixelSizeY/powR(SampleToCCDDistance*cos(Theta2DWave),2)
    13541370        else
    13551371                Theta2DWave[beamCenterX][beamCenterY] = NaN
  • trunk/User Procedures/Nika/NI1_InstrumentSupport.ipf

    r1169 r1174  
    18191819        NI1BC_InitCreateBmCntrFile()
    18201820        NI1_12IDBHowTo()
     1821
     1822        setDataFOlder root:Packages:Convert2Dto1D:
     1823        NI1A_ButtonProc("Select2DDataPath")
     1824        PathInfo Convert2Dto1DDataPath
     1825        string DataFilePath=S_path
     1826        NewPath/Q/O Convert2Dto1DEmptyDarkPath, S_path 
     1827        String DoingWhat= StringFromList(ItemsInList(DataFilePath,":")-1, DataFilePath,":")
     1828       
     1829        SVAR DataFileExtension=root:Packages:Convert2Dto1D:DataFileExtension
     1830        SVAR BlankFileExtension=root:Packages:Convert2Dto1D:BlankFileExtension
     1831        BlankFileExtension = "12IDB_tif"
     1832        //select the right type of data
     1833        DataFileExtension = "12IDB_tif"
     1834        PopupMenu Select2DDataType win=NI1A_Convert2Dto1DPanel, popmatch= "12IDB_tif"
     1835        //now load mask...
     1836        variable ProcessingMethod       //0 for beamline method (no background), 1 for Nika standard (with background).
     1837        ProcessingMethod = NI1_12IDBLoadGoodPixMask()                     
     1838
     1839       
    18211840        //setup configuration hwo this will be dome here:
    18221841        NVAR UseSampleTransmission = root:Packages:Convert2Dto1D:UseSampleTransmission
     
    18391858        NVAR BeamCenterX = root:Packages:Convert2Dto1D:BeamCenterX
    18401859        NVAR BeamCenterY = root:Packages:Convert2Dto1D:BeamCenterY
    1841        
    1842         UseSampleTransmission = 1
    1843         UseSampleThickness = 0
    1844         UseEmptyField = 1
    1845         UseI0ToCalibrate = 1
    1846         DoGeometryCorrection = 1
    1847         UseMonitorForEf = 1
    1848 
    1849         UseSampleThicknFnct  =1
    1850         UseSampleTransmFnct = 1
    1851 //      UseSampleThicknFnct =1
    1852         UseSampleMonitorFnct = 1
    1853         UseEmptyMonitorFnct = 1
     1860        NVAR UseCorrectionFactor = root:Packages:Convert2Dto1D:UseCorrectionFactor
     1861        NVAR CorrectionFactor = root:Packages:Convert2Dto1D:CorrectionFactor
     1862        NVAR UseSolidAngle = root:Packages:Convert2Dto1D:UseSolidAngle
    18541863        SVAR SampleTransmFnct = root:Packages:Convert2Dto1D:SampleTransmFnct
    18551864        SVAR SampleThicknFnct = root:Packages:Convert2Dto1D:SampleThicknFnct
     
    18571866        SVAR EmptyMonitorFnct = root:Packages:Convert2Dto1D:EmptyMonitorFnct
    18581867       
    1859         SampleTransmFnct = "NI1_12IDBGetTranmsission"
    1860         SampleMonitorFnct = "NI1_12IDBGetSampleI0"
    1861         EmptyMonitorFnct = "NI1_12IDBGetEmptyI0"
    1862 
    1863         setDataFOlder root:Packages:Convert2Dto1D:
    1864         NI1A_ButtonProc("Select2DDataPath")
    1865         PathInfo Convert2Dto1DDataPath
    1866         string DataFilePath=S_path
    1867         NewPath/Q/O Convert2Dto1DEmptyDarkPath, S_path 
    1868         String DoingWhat= StringFromList(ItemsInList(DataFilePath,":")-1, DataFilePath,":")
    1869        
    1870         SVAR DataFileExtension=root:Packages:Convert2Dto1D:DataFileExtension
    1871         SVAR BlankFileExtension=root:Packages:Convert2Dto1D:BlankFileExtension
    1872         BlankFileExtension = "12IDB_tif"
    1873         //select the right type of data
    1874         DataFileExtension = "12IDB_tif"
    1875         PopupMenu Select2DDataType win=NI1A_Convert2Dto1DPanel, popmatch= "12IDB_tif"
    1876         //now load mask...
    1877         NI1_12IDBLoadGoodPixMask()                       
     1868        NVAR ErrorCalculationsUseSEM = root:Packages:Convert2Dto1D:ErrorCalculationsUseSEM
     1869        NVAR ErrorCalculationsUseStdDev = root:Packages:Convert2Dto1D:ErrorCalculationsUseStdDev
     1870        NVAR ErrorCalculationsUseOld = root:Packages:Convert2Dto1D:ErrorCalculationsUseOld
     1871       
     1872        ErrorCalculationsUseOld = 0
     1873        ErrorCalculationsUseStdDev = 0
     1874        ErrorCalculationsUseSEM = 1
     1875       
     1876        if(ProcessingMethod)
     1877                UseSampleTransmission = 1
     1878                UseSampleThickness = 0
     1879                UseEmptyField = 1
     1880                UseI0ToCalibrate = 1
     1881                DoGeometryCorrection = 1
     1882                UseMonitorForEf = 1
     1883       
     1884                UseSampleThicknFnct  =1
     1885                UseSampleTransmFnct = 1
     1886        //      UseSampleThicknFnct =1
     1887                UseSampleMonitorFnct = 1
     1888                UseEmptyMonitorFnct = 1
     1889               
     1890                UseCorrectionFactor = 0
     1891                CorrectionFactor = 1
     1892                UseSolidAngle = 0
     1893               
     1894                SampleTransmFnct = "NI1_12IDBGetTranmsission"
     1895                SampleMonitorFnct = "NI1_12IDBGetSampleI0"
     1896                EmptyMonitorFnct = "NI1_12IDBGetEmptyI0"
     1897        else //no background subtraction
     1898                UseSampleTransmission = 0
     1899                UseSampleThickness = 0
     1900                UseEmptyField = 0
     1901                UseI0ToCalibrate = 1
     1902                DoGeometryCorrection = 1
     1903                UseMonitorForEf = 0
     1904       
     1905                UseSampleThicknFnct  = 0
     1906                UseSampleTransmFnct = 0
     1907        //      UseSampleThicknFnct =1
     1908                UseSampleMonitorFnct = 1
     1909                UseEmptyMonitorFnct = 0
     1910
     1911                UseCorrectionFactor = 1
     1912                CorrectionFactor = 2.4e-06                      //this should be fudge factor 12IDB is using to crrect data to 0.1-100 intensity range...
     1913                UseSolidAngle = 1                                               //thsi is needed for that fudge factor above.
     1914               
     1915                SampleTransmFnct = ""
     1916                SampleMonitorFnct = "NI1_12IDBGetSampleBS"
     1917                EmptyMonitorFnct = ""
     1918
     1919        endif
     1920
    18781921        //now configure Nika to produce some data...
    18791922        NVAR DisplayDataAfterProcessing = root:Packages:Convert2Dto1D:DisplayDataAfterProcessing
     
    19001943                QvectorMaxNumPnts=1
    19011944        endif
    1902         //send user to Empty/Dark tab
    1903         TabControl Convert2Dto1DTab win=NI1A_Convert2Dto1DPanel, value=3
    1904         NI1A_TabProc("NI1A_Convert2Dto1DPanel",3)       
     1945        if(ProcessingMethod)
     1946                //send user to Empty/Dark tab
     1947                TabControl Convert2Dto1DTab win=NI1A_Convert2Dto1DPanel, value=3
     1948                NI1A_TabProc("NI1A_Convert2Dto1DPanel",3)       
     1949        else
     1950                //send user to Empty/Dark tab
     1951                TabControl Convert2Dto1DTab win=NI1A_Convert2Dto1DPanel, value=0
     1952                NI1A_TabProc("NI1A_Convert2Dto1DPanel",0)       
     1953        endif
    19051954        setDataFolder OldDFf
    19061955
     
    19341983        print "Found transmission = "+num2str(transmission)
    19351984        return transmission
     1985end
     1986//*******************************************************************************************************************************************
     1987
     1988Function NI1_12IDBGetSampleBS(fileName)
     1989        string fileName
     1990        wave/Z CCDImageToConvert = root:Packages:Convert2Dto1D:CCDImageToConvert
     1991        //wave/Z EmptyData = root:Packages:Convert2Dto1D:EmptyData
     1992        if(!WaveExists(CCDImageToConvert))// || !WaveExists(EmptyData))
     1993                abort "Needed Image do not exist. Load Sample data before going further"
     1994        endif
     1995        string sampleNote=note(CCDImageToConvert)
     1996        sampleNote = ReplaceString(" ", sampleNote, "")
     1997        //string emptyNote=note(EmptyData)
     1998        //emptyNote = ReplaceString(" ", emptyNote, "")
     1999        //variable SampleBeamStopDiode=NumberByKey("Photodiode", sampleNote , ":" , ";")
     2000        //variable EmptyBeamStopDiode=NumberByKey("Photodiode", emptyNote , ":" , ";")
     2001        variable SampleBeamStopBS=NumberByKey("BS", sampleNote , ":" , ";")
     2002        //variable EmptyBeamStopI0=NumberByKey("I0", emptyNote , ":" , ";")
     2003        //variable I0Normalized = (SampleBeamStopDiode/SampleBeamStopI0)//(EmptyBeamStopDiode/EmptyBeamStopI0)
     2004        print "Found Sample BS = "+num2str(SampleBeamStopBS)
     2005        return SampleBeamStopBS
    19362006end
    19372007//*******************************************************************************************************************************************
     
    21382208        string OldDFf=GetDataFolder(1)
    21392209        NVAR UseMask = root:Packages:Convert2Dto1D:UseMask
     2210        variable ProcessingTypeVal=0            //Processing type is : 0 use beamline processing (just reduction) or 1 subtract empty/background and reduce.
     2211        string ProcessingTypeStr="No"
    21402212        setDataFOlder root:Packages:Convert2Dto1D:
    21412213        //get the path to SAXS_mask2M.bmp or WAXS_mask2M.bpm, it is one level up...
     
    21502222        if(strlen(ListOfBMPFiles)>0)
    21512223                Prompt SelectedMaskFile, "Select BMP Mask file", popup, ListOfBMPFiles+"---;"
    2152                 DoPrompt "Select Mask file", SelectedMaskFile
     2224                Prompt ProcessingTypeStr, "Subtract Empty/background", popup, "No;Yes;"
     2225                DoPrompt "Select Mask/Method", ProcessingTypeStr, SelectedMaskFile
    21532226                if(V_Flag || stringmatch(SelectedMaskFile,"---"))
    21542227                        print "User canceled mask file selection, continue without it"
    21552228                        UseMask = 0
    2156                         return 0
     2229                        if(stringMatch(ProcessingTypeStr,"Yes"))
     2230                                ProcessingTypeVal = 1
     2231                        endif
     2232                        return ProcessingTypeVal
     2233                endif
     2234                if(stringMatch(ProcessingTypeStr,"Yes"))
     2235                        ProcessingTypeVal = 1
    21572236                endif
    21582237                ImageLoad/T=bmp/Q/N=TMPBMPMask/Z/P=TempMaskUserPath SelectedMaskFile
     
    21622241                        DoALert/T="Could not load Mask file" 0, "Could not load selected file with mask, you need to create mask manually"
    21632242                        UseMask = 0
    2164                         return 0
     2243                        return ProcessingTypeVal
    21652244                endif
    21662245                Wave LoadedmaskImage = TMPBMPMask
     
    21792258        else            //no mask file found
    21802259                print "No BMP mask file found, continue without it"
     2260                Prompt ProcessingTypeStr, "Subtract Empty/background", popup, "No;Yes;"
     2261                DoPrompt "Select Method", SelectedMaskFile, ProcessingTypeStr
     2262                if(stringMatch(ProcessingTypeStr,"Yes"))
     2263                        ProcessingTypeVal = 1
     2264                endif
    21812265                UseMask = 0
    2182                 return 0
     2266                return ProcessingTypeVal
    21832267        endif
    21842268
     
    21872271
    21882272        setDataFolder OldDFf   
    2189         return 1
     2273        return ProcessingTypeVal
    21902274end
    21912275//*******************************************************************************************************************************************
     
    21992283        else
    22002284        String nb = "APS12IDB_Instructions"
    2201         NewNotebook/N=$nb/F=1/V=1/K=1/ENCG={1,1}/W=(1532,45,2246,823) as "APS12IDB_Instructions"
    2202         Notebook $nb defaultTab=36, magnification=125
     2285        NewNotebook/N=$nb/F=1/V=1/K=1/ENCG={1,1}/W=(930,427,1644,1205) as "APS12IDB_Instructions"
     2286        Notebook $nb defaultTab=10, magnification=125
    22032287        Notebook $nb showRuler=1, rulerUnits=2, updating={1, 1}
    22042288        Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Helvetica",11,0,(0,0,0)}
     
    22072291        Notebook $nb ruler=Normal, text="\r"
    22082292        Notebook $nb text="\r"
    2209         Notebook $nb text="1. Find path to your tif images\r"
     2293        Notebook $nb text="1. Find path to your tif images. Pick folder with raw tiff images, not the average folder. \r"
    22102294        Notebook $nb text="\r"
    2211         Notebook $nb text="2. Mask and all configuration and calibration shoudl be read from meta files with metadata for each file"
    2212         Notebook $nb text=" automatically. \r"
     2295        Notebook $nb text="2. Code will find available masks and present dialog to select:\r"
     2296        Notebook $nb text="\ta. Data reduction method (see below)\r"
     2297        Notebook $nb text="\tb. Proper (SAXS/WAXS mask)\r"
    22132298        Notebook $nb text="\r"
    2214         Notebook $nb text="This needs a lot more testing!!!! \r"
     2299        Notebook $nb text="3. Configuration and calibration should be read from meta files with metadata for each file automaticall"
     2300        Notebook $nb text="y. \r"
    22152301        Notebook $nb text="\r"
    22162302        Notebook $nb text="\r"
     2303        Notebook $nb text="*** Data reduction methods ***\r"
     2304        Notebook $nb text="1. Subtract Empty/Background NO: reduces each image separately, normalized by transmitted counts (flux an"
     2305        Notebook $nb text="d transmission normalization), masked. Solvent/background sutraction needs to be done later, for example"
     2306        Notebook $nb text=" in BioSAXS Irena tools, but you can average many data sets together. This is default beamline and bioSAXS setting.\r"
    22172307        Notebook $nb text="\r"
    2218         Notebook $nb text="Jan Ilavsky, 2/27/2020\r"
     2308        Notebook $nb text="2. Subtract Empty/Background : YES. This is typical Nika processing - solvent/background image is subtr"
     2309        Notebook $nb text="acted in Nika directly, with flux normalization for sample and background, transmission calculation etc."
     2310        Notebook $nb text=" In this case only ONE background image can be used at time, which may not be suitable if you have multiple images. \r"
     2311        Notebook $nb text="\r"
     2312        Notebook $nb text="\r"
     2313        Notebook $nb text="Jan Ilavsky, 1/5/2021\r"
    22192314        Notebook $nb text="\r"
    22202315        Notebook $nb fStyle=2, text="Hint: watch history area for notes on what Nika has found and done. \r"
     2316
    22212317        endif
    22222318end
Note: See TracChangeset for help on using the changeset viewer.