Utilities

API Reference

csxtools.utils.calculate_flatfield(image, limits=(0.6, 1.4))[source]

Calculate a flatfield from fluo data

This routine calculates the flatfield correction from fluorescence data The image is thresholded by limits from the median value of the image. The flatfield is then constructed from the mean of the image divided by the masked (by NaN) image resulting in a true flatfield correction

Parameters:
  • image (array_like) – This is the 2D image to convert to a flatfield correction.
  • limits (tuple) – Pixels outwith the median value multiplied by these limits will be excluded by setting to NaN.
Returns:

Return type:

Array of flatfield correction.

csxtools.utils.fccd_mask()[source]

Return the initial flatfield mask for the FastCCD

Returns:
Return type:np.array of flatfield
csxtools.utils.get_fastccd_flatfield(light, dark, flat=None, limits=(0.6, 1.4))[source]

Calculate a flatfield from two headers

This routine calculates the flatfield using the :func:calculate_flatfield() function after obtaining the images from the headers.

Parameters:
  • light (databroker header) – The header containing the light images
  • dark (databroker header) – The header from the run containin the dark images
  • flat (flatfield image (optional)) – The array to be used for the initial flatfield
Returns:

Flatfield correction

Return type:

array_like

csxtools.utils.get_fastccd_images(light_header, dark_headers=None, flat=None, gain=(1, 4, 8), tag=None, roi=None)[source]

Retreive and correct FastCCD Images from associated headers

Retrieve FastCCD Images from databroker and correct for:

  • Bad Pixels (converted to np.nan)
  • Backgorund.
  • Multigain bits.
  • Flatfield correction.
  • Rotation (returned images are rotated 90 deg cw)
Parameters:
  • light_header (databorker header) – This header defines the images to convert
  • dark_headers (tuple of 3 databroker headers , optional) – These headers are the dark images. The tuple should be formed from the dark image sets for the Gain 8, Gain 2 and Gain 1 (most sensitive to least sensitive) settings. If a set is not avaliable then None can be entered.
  • flat (array_like) – Array to use for the flatfield correction. This should be a 2D array sized as the last two dimensions of the image stack.
  • gain (tuple) – Gain multipliers for the 3 gain settings (most sensitive to least sensitive)
  • tag (string) – Data tag used to retrieve images. Used in the call to databroker.get_images(). If None, use the defualt from the settings.
  • roi (tuple) – coordinates of the upper-left corner and width and height of the ROI: e.g., (x, y, w, h)
Returns:

Return type:

A corrected pims.pipeline of the data

csxtools.utils.get_fastccd_timestamps(header, tag='fccd_image')[source]

Return the FastCCD timestamps from the Areadetector Data File

Return a list of numpy arrays of the timestamps for the images as recorded in the datafile.

Parameters:
  • header (databorker header) – This header defines the run
  • tag (string) – This is the tag or name of the fastccd.
Returns:

Return type:

list of arrays of the timestamps

csxtools.utils.get_images_to_3D(images, dtype=None)[source]

Convert image stack to 3D numpy array

This function converts an image stack from :func: get_images() into a 3D numpy ndarray of a given datatype. This is useful to just get a simple array from detector data

Parameters:
  • images (the result of get_images()) –
  • dtype (the datatype to use for the conversion) –

Example

>>> header = DataBroker[-1]
>>> images = get_images(header, "my_detector')
>>> a = get_images_to_3D(images, dtype=np.float32)
csxtools.utils.get_images_to_4D(images, dtype=None)[source]

Convert image stack to 4D numpy array

This function converts an image stack from :func: get_images() into a 4D numpy ndarray of a given datatype. This is useful to just get a simple array from detector data

Parameters:
  • images (the result of get_images()) –
  • dtype (the datatype to use for the conversion) –

Example

>>> header = DataBroker[-1]
>>> images = get_images(header, "my_detector')
>>> a = get_images_to_4D(images, dtype=np.float32)