scan
This module contains the scan class, that is used to store all of the information relating to a reciprocal space scan .
Module Contents
Classes
This class stores all of the data and metadata relating to a reciprocal space map. |
Functions
Make sure that a shared memory array is not open. Clear the shared memory and print a warning if it is open. |
|
Initializes a processing pool to have a global shared lock. |
|
Can be used with the atexit module. Makes sure that the shared memory is cleaned when called. |
|
Split lst into num_chunks almost evenly sized chunks. Algorithm lifted from stackoverflow almost without change (but isn’t everything, in the end…) |
|
Yield num_chunks (N) tuples of incides (a, b) such that array[a0:b0], array[a1:b1], …, array[aN:bN] spans the entire array. |
|
Bins all of the maps with indices in indices. The purpose of this intermediate function call is to decrease the amount of context switching/ serialization that the interpreter has to do. |
|
Calculates and bins the reciprocal space map with index idx. Saves the result to the shared memory buffer. |
|
initialiser for reciprocal space mapping |
Data
API
- scan.logger = 'getLogger(...)'
- scan.lock = None
- scan.RSM_ARRAY = None
- scan.COUNT_ARRAY = None
- scan.SHM_RSM = None
- scan.SHM_COUNT = None
- scan.METADATA = None
- scan.NUM_THREADS = None
- scan.FRAME = None
- scan.OUTPUT_FILE_NAME = None
- scan.SHM_INTENSITY = None
- scan.INTENSITY_ARRAY = None
Make sure that a shared memory array is not open. Clear the shared memory and print a warning if it is open.
- Args:
- shared_mem_name:
Name of the shared memory array to check.
- scan.init_process_pool(locks: List, num_threads: int, metadata: fast_rsm.rsm_metadata.RSMMetadata, frame: diffraction_utils.Frame, shape: tuple, output_file_name: str = None) None
Initializes a processing pool to have a global shared lock.
- Args:
- locks:
A list of the locks that will be shared between spawned processes.
- num_threads:
The total number of processes that are being spawned in the pool.
- shape:
Passed if you want to make RSM and count arrays global.
- scan._on_exit(shared_mem: multiprocessing.shared_memory.SharedMemory) None
Can be used with the atexit module. Makes sure that the shared memory is cleaned when called.
- Args:
- shared_mem:
The shared memory to close/unlink.
- scan.chunk(lst, num_chunks)
Split lst into num_chunks almost evenly sized chunks. Algorithm lifted from stackoverflow almost without change (but isn’t everything, in the end…)
- Args:
- lst:
The iterable to split up.
- num_chunks:
The number of almost-evenly-sized chunks to split lst into. Note that the last chunk can be decently smaller.
- Yields:
the chunks. Note that this yields as a generator, it does not return.
- scan._chunk_indices(array: numpy.ndarray, num_chunks: int) Generator[tuple[int, int], None, None]
Yield num_chunks (N) tuples of incides (a, b) such that array[a0:b0], array[a1:b1], …, array[aN:bN] spans the entire array.
- scan.bin_maps_with_indices_smm(indices: List[int], start: numpy.ndarray, stop: numpy.ndarray, step: numpy.ndarray, min_intensity: float, processing_steps: list, skip_images: List[int], oop: str, spherical_bragg_vec: numpy.array, map_each_image: bool = False, previous_images: int = 0) None
Bins all of the maps with indices in indices. The purpose of this intermediate function call is to decrease the amount of context switching/ serialization that the interpreter has to do.
- scan._bin_one_map_smm(start: numpy.ndarray, stop: numpy.ndarray, step: numpy.ndarray, min_intensity: float, idx: int, processing_steps: list, oop: str, spherical_bragg_vec: numpy.array, map_each_image: bool = False, previous_images: int = 0) numpy.ndarray
Calculates and bins the reciprocal space map with index idx. Saves the result to the shared memory buffer.
- scan.rsm_init_worker(smmlock, shm_rsm_name: str, shm_counts_name: str, shmshape: numpy.ndarray, metadata: fast_rsm.rsm_metadata.RSMMetadata, newmetadata: dict, motors: Dict[str, numpy.ndarray], num_threads: int, frame: diffraction_utils.Frame, output_file_name: str = None)
initialiser for reciprocal space mapping
- class scan.Scan(metadata: fast_rsm.rsm_metadata.RSMMetadata, skip_images: List[int] = None)
This class stores all of the data and metadata relating to a reciprocal space map.
- Attrs:
- metadata:
Scan metadata.
- skip_images:
Image indices to be skipped in a reciprocal space map.
- load_image:
A Callable that takes an index as an argument and returns an instance of Image with that corresponding index.
Initialization
- property processing_steps
Left as a property to give the option to deepcopy in the future.
- add_processing_step(function) None
Adds the processing step to the processing pipeline.
- Args:
- function:
A function that takes a numpy array as an argument, and returns a numpy array.
- load_image(idx: int, load_data=True)
Convenience method for loading a single image. This is unpicklable.
- q_bounds(frame: diffraction_utils.Frame, spherical_bragg_vec: numpy.array, oop: str = 'y') Tuple[numpy.ndarray]
Works out the region of reciprocal space sampled by this scan.
- Args:
- frame:
The frame of reference in which we want to calculate the bounds.
- Returns:
(start, stop), where start and stop are numpy arrays with shape (3,)
- static from_i10(path_to_nx: Union[str, pathlib.Path], beam_centre: Tuple[int], detector_distance: float, setup: str, path_to_data: str = '')
Aliases to io.from_i10.
- Args:
- path_to_nx:
Path to the nexus file containing the scan metadata.
- beam_centre:
A (y, x) tuple of the beam centre, measured in the usual image coordinate system, in units of pixels.
- detector_distance:
The distance between the sample and the detector.
- setup:
What was the experimental setup? Can be “vertical”, “horizontal” or “DCD”.
- path_to_data:
Path to the directory in which the images are stored. Defaults to ‘’, in which case a bunch of reasonable directories will be searched for the images.
- Returns:
Corresponding instance of Scan.
- static from_i07(path_to_nx: Union[str, pathlib.Path], beam_centre: Tuple[int], detector_distance: float, setup: str, path_to_data: str = '')
Aliases to io.from_i07.
- Args:
- path_to_nx:
Path to the nexus file containing the scan metadata.
- beam_centre:
A (y, x) tuple of the beam centre, measured in the usual image coordinate system, in units of pixels.
- detector_distance:
The distance between the sample and the detector.
- setup:
What was the experimental setup? Can be “vertical”, “horizontal” or “DCD”.
- path_to_data:
Path to the directory in which the images are stored. Defaults to ‘’, in which case a bunch of reasonable directories will be searched for the images.
- Returns:
Corresponding instance of Scan.