Skip to content

Grating¤

extra.applications.Grating1DCalibration ¤

Grating1DCalibration(offset: Optional[int] = None, min_pixel: int = 0, max_pixel: int = 1280, sigma: float = 2.0)

Bases: SerializableMixin

Calibrate a 1D grating spectrometer.

Parameters:

Name Type Description Default
offset Optional[int]

Offset of the first pulse.

None
sigma float

Smoothing factor to apply to data to reduce noise in pixels.

2.0

Example:

bkg_run = open_run(proposal=900485, run=590)
calib_run = open_run(proposal=900485, run=611)
scan = Scan(calib_run["SA3_XTD10_MONO/MDL/PHOTON_ENERGY", "actualEnergy"])
grating_signal = calib_run["SQS_EXP_GH2-2/CORR/RECEIVER:daqOutput", "data.adc"]
pulses = XrayPulses(calib_run)
grating_calib = Grating1DCalibration()
grating_calib.setup(grating_signal, scan, pulses)

# apply it in new data
new_run = open_run(...)
grating_calib.apply(new_run)

to_file ¤

to_file(filename: str)

Dump all data needed for applying the calibration into an h5 file.

Parameters:

Name Type Description Default
filename str

The output file name.

required

from_file classmethod ¤

from_file(filename: str)

Load setup saved with save previously.

setup ¤

setup(grating_signal: KeyData, scan: Scan, pulses: XrayPulses, grating_mask: Optional[KeyData] = None)

Setup calibration.

Parameters:

Name Type Description Default
grating_signal KeyData

Where to read the grating data from. Example: signal_run["SQS_EXP_GH2-2/CORR/RECEIVER:daqOutput", "data.adc"]

required
scan Scan

Scan object identfying where to read the undulator energy from. Example: Scan(run["SA3_XTD10_MONO/MDL/PHOTON_ENERGY", "actualEnergy"])

required
pulses XrayPulses

Object with bunch pattern table. Example: XrayPulses(run)

required
grating_mask Optional[KeyData]

Grating mask from the calibration system. Example: signal_run["SQS_EXP_GH2-2/CORR/RECEIVER:daqOutput", "data.mask"]

None

guess_offset ¤

guess_offset()

Guess offset.

get_pulse_period ¤

get_pulse_period(pulses: XrayPulses)

Estimate difference between samples in neighbour pulses.

Parameters:

Name Type Description Default
pulses XrayPulses

XrayPulses element for the run.

required

Returns: Sample difference between neighbour pulses.

apply_mask ¤

apply_mask(arr)

Interpolate nans.

load_data ¤

load_data()

Load calibration data.

mask_calibration_point ¤

mask_calibration_point(energy: float, mask: bool = False, tol: float = 1.0)

If mask is False, the point at a given energy is ignored when performing the fit. A call to fit must be redone after this.

Parameters:

Name Type Description Default
energy float

Energy value, in the same units as provided in scan.

required
mask bool

If True, keep the point. If False, remove it.

False
tol float

Tolerance for energy matching.

1.0

fit ¤

fit()

Fit line.

plot ¤

plot()

Plot fit.

apply ¤

apply(run: DataCollection, load_all: bool = True) -> xr.Dataset

Apply calibration to a new analysis run. It is assumed it contains the same settings.

Parameters:

Name Type Description Default
run DataCollection

Input run.

required
load_all bool

If True, load all data in memory at once. This is faster, but uses more memory. Disable if not enough memory is available.

True

extra.applications.Grating2DCalibration ¤

Grating2DCalibration(angle: float = 0.0)

Bases: SerializableMixin

Calibrate a 2D grating spectrometer.

Parameters:

Name Type Description Default
angle float

The rotation angle in degrees if the camera is not aligned.

0.0

to_file ¤

to_file(filename: str)

Dump all data needed for applying the calibration into an h5 file.

Parameters:

Name Type Description Default
filename str

The output file name.

required

from_file classmethod ¤

from_file(filename: str)

Load setup saved with save previously.

setup ¤

setup(grating_signal: KeyData, scan: Scan, grating_bkg: Optional[KeyData] = None, grating_motor: Optional[KeyData] = None)

Setup calibration.

Parameters:

Name Type Description Default
grating_signal KeyData

Where to read the grating data from. Example: signal_run["SQS_DIAG3_BIU/CAM/CAM_6:daqOutput, "data.image.pixels"]

required
scan Scan

Scan object identfying where to read the undulator energy from. Example: Scan(run["SA3_XTD10_MONO/MDL/PHOTON_ENERGY", "actualEnergy"])

required
grating_bkg Optional[KeyData]

Where to read the grating background data from. Example: bkg_run["SQS_DIAG3_BIU/CAM/CAM_6:daqOutput, "data.image.pixels"]

None
grating_motor Optional[KeyData]

KeyData corresponding to the motor position. Example: signal_run['SQS_DIAG3_SCAM/MOTOR/ST_AXIS_X', 'encoderPosition.value']

None

get_background_template ¤

get_background_template()

Get the background template.

estimate_crop_roi ¤

estimate_crop_roi(nrows: int, ncols: int)

Calculate rectangle to be selected to crop the image and avoid edge effects.

Parameters:

Name Type Description Default
nrows int

Number of pixel rows.

required
ncols int

Number of pixel columns.

required

load_data ¤

load_data()

Load calibration data.

crop ¤

crop(data: ndarray) -> np.ndarray

Crop picture after rotation to avoid edges.

Parameters:

Name Type Description Default
data ndarray

The input data.

required

Returns: Cropped data.

fit ¤

fit()

Fit line.

plot ¤

plot()

Plot fit.

apply ¤

apply(run: DataCollection, load_all: bool = True) -> xr.Dataset

Apply calibration to a new analysis run. It is assumed it contains the same settings.

Parameters:

Name Type Description Default
run DataCollection

Input run.

required
load_all bool

If True, load all data in memory at once. This is faster, but uses more memory. Disable if not enugh memory is available.

True