-
Notifications
You must be signed in to change notification settings - Fork 6
Ctrdata
- modules/ana/ctr_data.py
- modules/ana/scan_data.py
- modules/xtal
-
The CtrData class holds all the scandata and other parameters for a CTR data set. The class instance can be created via:
>>ctr = scandata.CtrData(scans=[],I='I',Inorm='io',Ierr='Ierr', Ibgr='Ibgr',corr_params={},scan_type='image')
-
scans = list of scan data instances
-
I is the string label corresponding to the intensity array, ie let y be the intensity, then y = scan[I]
- Inorm is the string label corresponding to the normalization intensity array, ie norm = scan[Inorm], where the normalized intensity is taken as ynorm = y/norm.
-
The parameter Ierr is a string label corresponding to the intensity error array, ie y_err = scan[Ierr]. We assume these are standard deviations of the intensities, y
Note when the data are normalized we assume the statistics of norm go as norm_err = sqrt(norm). Therefore the error of normalized data is ynorm_err = ynorm * sqrt( (y_err/y)^2 + (norm_err/(norm))^2 ) = ynorm * sqrt( (y_err/y)^2 + 1/norm ) If its assumed that y_err = sqrt(y) then the expression could be simplified futher, but we wont make that assumption since there may be other factors that determine how yerr was calculated.
-
Ibgr = string label corresponding to background intensity array
-
corr_params = a dictionary containing the necessary information for data corrections.
corr_params['geom'] = Type of goniometer geometry ('psic' is default) corr_params['beam_slits'] = dictionary describing the beam slits,e.g. {'horz':.6,'vert':.8} corr_params['det_slits'] = dictionary describing the beam slits,e.g. {'horz':.6,'vert':.8} corr_params['sample'] = a dictionary describing the sample shape. {'dia':0,'angles':{},'polygon':[]} if dia >=0 then assume a round sample. Otherwise use polygon/angles If all are None, then no sample correction is computed corr_params['scale'] = scale factor to multiply by all the intensity values. e.g. if Io ~ 1million cps then using 1e6 as the scale makes the normalized intensity close to cps. ie y = scale*y/norm
-
scan_type is the type of scans (e.g. 'image', 'phi', etc..)
- The following script reads several scans into a list of scandata objects
- Note that the images will be cached in an hdf file with the specified path (rather than cached in memory). See the note further below about editing the path if you move the files.
-
All the read in images will have the specified rois
######################################## # script to read spec files and images # into a list of scan objects ######################################## # create an instance of the reader object spec_file = specfile.reader.Reader(spec_path = '../',spec = 'caco3_feb09j.spc') spec_file.spec_params['image'] = True spec_file.image_params['archive'] = {'path':'d:\\tmp'} spec_file.image_params['rois'] = [180,70,277,126] print spec_file # Make a list of selected scans, and plot S = [] first_scan = 1 last_scan = 8 pyplot.clf() j = 0 for i in range(first_scan, last_scan+1): S.append(spec_file.spec_scan(i, image = True)) pyplot.plotter(S[j]['L'],S[j]['IROI']/S[j]['io'],ylog=True) j = j+1 #end of script
-
Now create a
CtrData
object>>corr_params = {} >>corr_params['geom'] = 'psic' >>corr_params['beam_slits'] = {'horz':.6,'vert':.8} >>corr_params['det_slits'] = None >>corr_params['sample'] = 10. >>corr_params['scale'] = 1.e6 >>ctr = ana.CtrData(S,I='I',Inorm='io',Ierr='Ierr',Ibgr='Ibgr',corr_params=corr_params)
-
make plots and write files
>>ctr.plot() >>ctr.plot_I() >>ctr.write_HKL(fname='data.lst')
-
If you want to add some new scan data (in this case from a new file - note all other parameters will stay as above)
-
Also note in the example, we are adding multiple scans as a list, you can also just add a single scan
>>S2 = [] >>S2.append(spec_file.spec_scan(23,file='caco3_feb09x.spc')) >>S2.append(spec_file.spec_scan(24)) >>S2.append(spec_file.spec_scan(25)) # >>ctr.append_scans(S2)
-
If you are working in pds you can save the ctr data set in a pickle using:
>>save ctr my_ctr_data.sav - to restore >>>restore my_ctr_data.sav
-
If you have archived your images and later move them you'll need to update the path. this can be done by editing the ctr object as:
>>for j in range(len(ctr.scan)): ... ctr.scan[j].image.image.path = 'c:\\my_path\\to\\images' >>
-
(this will be improved at a later date!)
-
Create a new reader
>>r = specfile.reader.Reader(spec_path='spec/')
-
Set image parameters - archive directory and integration params
>>r.image_params['archive'] = {'path':'d:\\tmp'} >>r.image_params['rois'] = [180,70,277,126]
-
Create some correction params, including a sample polygon
corr_params = {} corr_params['geom'] = 'psic' corr_params['beam_slits'] = {'horz':.6,'vert':.8} corr_params['det_slits'] = None polygon = [[1.,1.], [.5,1.5], [-1.,1.], [-1.,-1.],[0.,.5],[1.,-1.]] angles = {'phi':108.0007,'chi':0.4831} sample = {'polygon':polygon,'angles':angles} corr_params['sample'] = sample corr_params['scale'] = 1.e6
-
Now read some data
>>f = 'caco3_feb09f.spc' >>j = 'caco3_feb09j.spc' >>s1 = [] >># 00L >>s1.append(r.spec_scan(1, file=j, image = True)) >>s1.append(r.spec_scan(2)) >>s1.append(r.spec_scan(3))
-
Create a CtrData object ad plot it
>>ctr = ana.CtrData(s1,I='I_r',Inorm='io',Ierr='Ierr_r',Ibgr='Ibgr_r', corr_params=corr_params) >>ctr.plot(num_col=1)
-
Now add some more scans and plot
>># 21L >>s2 = [] >>s2.append(r.spec_scan(23,file=f)) >>s2.append(r.spec_scan(24)) >>s2.append(r.spec_scan(25)) >>ctr.append_scans(s2) >>ctr.plot(num_col=2)