rsm_metadata
This module contains the metadata class, which provides a python interface for the .nxs file written for the scan .
Module Contents
Classes
This class contains a diffraction_utils DiffractometerBase implementation, which contains all of the information that it’s possible to extract about the experiment automatically. Generally, the poni (here called beam_centre) has to be given by a user at run-time since this is usually experiment specific, so we take it as an explicit argument here. |
API
- class rsm_metadata.RSMMetadata(diffractometer: diffraction_utils.DiffractometerBase, beam_centre: Tuple[int, int], mask_pixels: tuple | None = None, mask_regions: List[diffraction_utils.Region] | None = None)
This class contains a diffraction_utils DiffractometerBase implementation, which contains all of the information that it’s possible to extract about the experiment automatically. Generally, the poni (here called beam_centre) has to be given by a user at run-time since this is usually experiment specific, so we take it as an explicit argument here.
This class contains some reciprocal space map specific stuff that doesn’t belong in diffraction_utils, such as relative polar coordinate angle calculations, solid angle calculations and the like.
- Attrs:
- diffractometer:
An implementation of DiffractometerBase that can be used to change reference frames, map vectors etc. The diffractometer also has a data_file attribute that can be used to access additional metadata from the .nxs file, such as detector_distance, probe_energy etc.
- data_file:
A reference to the diffractometer’s data file.
- beam_centre:
The centre of the beam.
- mask_pixels:
A tuple representing pixels that should be masked from the image. This tuple will be used to directly index a numpy array. In other words, at some point:
array[mask_pixels] = np.nan
is going to be executed. For more information on how to index many elements of a numpy array simultaneously: google it.
Initialization
- swap_beam_centre()
- check_beam_centre_rot()
- beam_centre_range_check()
- _correct_beam_centre()
Correct the beam centre, if necessary. We can use the metadata to work out where the data was acquired. Some data sources might report the beam_centre using a different convention; this is where we correct for that to make sure that that data[0, 0] is the top left pixel, data[-1, 0] is the bottom left pixel.
This means that, if the beam was centered at the top left pixel, the user should enter that the beam_centre=[0, 0]. This seems unlikely; this would probably be given as [0, -1] in typical software!
- update_i07_nx(motors: Dict[str, numpy.ndarray], metadata: dict)
Updates an underlying I07Nexus data_file attribute from new motor positions and new metadata values. This significantly decreases synchronization time between threads.
- get_detector_distance(index: int) float
The detector distance should be written into the data_file object. However, I07Nexus.detector_distance should return a float, which is understood to be the distance between sample and detector with the dps system zeroed. If the dps system is being used, things get a bit more complicated.
This method aims to provide a universal interface to the detector distance.
- Args:
- index:
The index of the scan for which we want to find the detector distance. This should correspond to Image.index, for example.
- Returns:
The distance between sample and detector, in m, at this particular image index in your setup.
- property solid_angles
Returns a 2D array whose elements are proportional to the solid angle covered by each pixel in the camera. Divide by this to correct for variation in solid angle.
- property vertical_pixel_offsets
The offsets between each pixel and the central pixel.
- property horizontal_pixel_offsets
The offsets between each pixel and the central pixel.
- get_vertical_pixel_distances(idx: int) numpy.ndarray
The vertical distances (in m) between each pixel and the central vertical pixel. This method accounts for e.g. detector displacement systems moving the detector during a scan, which is why the index argument is needed.
- Args:
- index:
The scan index at which these distances should be calculated.
- Returns:
Numpy array containing the vertical displacement of each pixel from the central pixel.
- get_horizontal_pixel_distances(index: int) numpy.ndarray
The horizontal pixel distances (in m) between each pixel and the central horizontal pixel. This method accounts for e.g. detector displacement systems moving the detector during a scan, which is why the index argument is needed.
- Args:
- index:
The scan index at which these distances should be calculated.
- Returns:
Numpy array containing the horizontal displacement of each pixel from the central pixel.
- property relative_polar
This property makes accessing the detector’s relative theta from the beam centre for each pixel, when all detector rotation motors have been zeroed.
- property relative_azimuth
This property makes accessing the detector’s relative phi from the beam centre for each pixel, when all detector rotation motors have been zeroed.
- property incident_wavelength
Returns the wavelength of the incident light in Å.
- property k_incident_length
Returns the wavevector of the incident beam in Å^-1.
- _init_solid_angles()
Initialize the solid angles property. Note that this is not an exact calculation, but all the values should be almost correct (since small angle approximations are likely to hold nicely).
The following are low priority because the solid angle correction is pretty damn minor/unimportant. TODO: This implementation is wrong by half a pixel. Fix this. TODO: This implementation is approximate and should be replaced by an
exact treatment.
- get_pixel_index_offsets(index, image_shape)
- _init_vertical_pixel_offsets(image_shape: int = None)
Initializes the array of relative pixel offsets.
- _init_horizontal_pixel_offsets(image_shape: int = None)
Initializes the array of relative horizontal pixel offsets, i.e. the distance (in units of pixels) between each pixel and the horizontal beam centre.
- _init_relative_polar(image_shape: int = None)
Initializes the relative_polar array.
- _init_relative_azimuth(image_shape: int = None)
Initializes the relative_azimuth array.