In order to decide on the proper ROI, fit a team center or make a mask, the first step is always to create an image that you would like to use as base. This is achieved using the following function
SDAna In: anaps.AvImage()
This will by default create an average image of 100 events of an area detector.
The full command with all its options and a examples is here:
AvImage
LDana In [1]: anaps.AvImage?
Type: instancemethod
String form: <bound method LittleDataAna_psana.AvImage of <LittleDataAna_psana.LittleDataAna_psana object at 0x7fd37fe03590>>
File: /reg/d/psdm/xpp/xpptut15/res/littleData/xppmodules/scripts/LittleDataAna_psana.py
Definition: anaps.AvImage(self, detname='None', numEvts=100, thresADU=0.0, thresRms=0.0, useLdat=False, nSkip=0, minIpm=-1.0, common_mode=True)
Docstring: <no docstring>
LDana In [2]: anaps.AvImage()
detectors in event:
cs140_rob
opal_1
Select detector to select ROI of?:
cs140_rob
try get detector info to make average image for: cs140_rob
try to make psana Detector with: cs140_rob
requested 100 used 100
LDana In [3]: anaps.plotAvImage()
plot AvImg_cs140_rob using the 5/99.5 percentiles as plot min/max: (1603.9, 1950.21)
If you would like to take a quick look at your average image before proceeding, use as seen above:
SDAna In: anaps.plotAvImage()
which will result in a figure like this popping up:
The following functions will all ask question on the ipython command line (mainly to check if you are happy with your selections and/or if you are done).
These functions require interaction with the plots and currently do not work with the notebooks. There is a automatic version of the center finding that would work in a notebook, but is still under testing.
SDAna In: anaps.SelectRegion()
This will by draw the image and let you select a rectangular area of interest with the mouse. At this point, you click on two corners of the ROI. Once you are happy with your selection, it will print the numbers you need to enter in the LittleDataProducer_userData.py file. Below both what the terminal session looks like (here with an optionla selection of different plot limits, by default 5% and 99.5% are used). Figure 2 will come up when you get asked if you are happy with the selection which appears on the right side of that figure. "n" means you can to click again until you are satisfied. "y" will print the ROI as it should be entered in the LittleDataProducer file. Figure 3 shows the ROI again, this time obtained from the raw data rather than the image (a technical detail). The more striking different is that the scaling/limit are now taken from only the ROI rather than the whole image.
Select ROI
LDana In [3]: anaps.SelectRegion(limits=[5,99.8])
plot AvImg_cs140_rob using the 5/99.8 percentiles as plot min/max: (1603.9, 1994.84)
Happy with this selection:
y
ROI: [[1,2], [55,76], [308,335]]
SDAna In: anaps.FitCircle()
This will by draw the image and let you either select points by clicking or define a threshold above which points are selected and fitted to a single circle. The azimuthal integration code needs a center point which the circle fitting will return.
Below are an example fit: first the image you created first will pop up. You can then either select points by hand or use a threshold (highest x% of pixels). The chosen pixel location will be shown and you are adjust your threshold until you are satisfied. In the last step, the fit is performed and overlaid on the image. The beam center and radius of the circle are printed. You will have to know about your sample to use the radius to extract the detector - sample distance. The latter will not affect she shape of the azimuthally integrated data (a wrong center will!), but the q-bin values will be wrong.
FitCircle has an optional argument (useMask=False/True) that defaults to False. If set to True, the mask stored in the calib directory will be applied.
FitCircle
LDana In [2]: anaps.FitCircle()
plot AvImg_cspad using the 5/99.5 percentiles as plot min/max: (0.199616, 263.383)
Select Circle Points by Mouse?:
n
Select Circle Points with threshold (y/n):
y
min percentile % of selected points:
99.2
thresP 248.786973755
Happy with this threshold (y/n):
y
x,y: 99652.2541599 87977.9162216 R 18603.6250138
LDAna In: anaPS.anaps.addAzInt?
Type: instancemethod
String form: <bound method LittleDataAna_psana.addAzInt of <LittleDataAna_psana.LittleDataAna_psana object at 0x7f7731f13f10>>
File: /reg/data/ana13/xpp/xppo6616/results/littleData/xppmodules/scripts/LittleDataAna_psana.py
Definition: anaps.addAzInt(self, detname=None, phiBins=1, qBin=0.01, eBeam=9.5, center=None, dis_to_sam=None)
This function will set up the azimuthal integration. It will also correct for the LCLS Xray polarization and the geometric acceptance. The center and distance to sample are needed. Then this code can be applied to any average image by:
LDana In [2]: anaps.AzInt?
Type: instancemethod
String form: <bound method LittleDataAna_psana.AzInt of <LittleDataAna_psana.LittleDataAna_psana object at 0x7f7731f13f10>>
File: /reg/data/ana13/xpp/xppo6616/results/littleData/xppmodules/scripts/LittleDataAna_psana.py
Definition: anaps.AzInt(self, detname=None, use_mask=False)
It returns the data arrays. The q-bins are stored as well in anaps.<detname>.azav_q
SDAna In: anaps.MakeMask()
This will by draw the image and let you define a mask using rectangles, circles and polygons defined by mouse clicks. You can add several of these shapes. This mask can be saved locally or in the calib directory where it will be available for the littleData creation. Masks are e.g. used for the azimuthal integration. A session where a mask consisting of the inner circle and a polygon was developed is shown below. For each part of the mask, you can either use a circle, rectangle or polygon. The mask will then be shown to you. Once you have defined all the sub-masks, the total mask is calculated and applied to the image. If so desired, the mask can then be stored either locally or in the calibdirectory (where the littleData creating will pick it up automatically).
Mask
LDana In [3]: anaps.MakeMask()
(32, 185, 388)
plot AvImg_cspad using the 5/99.5 percentiles as plot min/max: (0.199616, 263.383)
rectangle(r), circle(c) or polygon(p)?:
c
Select center by mouse?
y
/reg/g/psdm/sw/releases/ana-0.17.30/arch/x86_64-rhel7-gcc48-opt/python/matplotlib/backend_bases.py:2399: MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented
warnings.warn(str, mplDeprecation)
center: 98067.8500159 87780.7509265
Select outer radius by mouse?
y
Select inner radius by mouse?
n
radii: 6044.641774 0
mask from circle (shape): (32, 185, 388)
Done?
n
created a mask....
masked now: 9506.0
masked tot: 9506.0
rectangle(r), circle(c) or polygon(p)?:
p
Number of Points (-1 until right click)?
5
[[ 81561.33638984 90357.32502125]
[ 75822.06188735 95379.19021093]
[ 80126.51776422 101477.16936983]
[ 86941.90623593 100401.05540061]
[ 86583.20157952 92509.55295969]]
mask from polygon (shape): (32, 185, 388)
not implemented yet....
Done?
y
created a mask....
masked now: 5649.0
masked tot: 15155.0
Save to calibdir?
n
Save to local?
y
Invert?
n
LDana Out[3]:
array([[1, 1, 1, ..., 1, 1, 1],
[1, 1, 1, ..., 1, 1, 1],
[1, 1, 1, ..., 1, 1, 1],
...,
[1, 1, 1, ..., 1, 1, 1],
[1, 1, 1, ..., 1, 1, 1],
[1, 1, 1, ..., 1, 1, 1]])