experiment
This file contains the Experiment class, which contains all of the information relating to your experiment.
Module Contents
Classes
The Experiment class specifies all experimental details necessary to process experimental data. This can be a list of file paths, a central pixel location, details of the experimental geometry, the desired output, etc. |
Functions
Removes a file if it exists. Doesn’t do anything if it doesn’t exist. |
|
Takes a list of paths to .npy files. Adds them all together. Returns this sum. |
|
save separate tiffs for all 2d image data in data |
|
save all 1d datasets to .dat files |
Data
API
- experiment.logger = 'getLogger(...)'
- experiment._remove_file(path: Union[str, pathlib.Path])
Removes a file if it exists. Doesn’t do anything if it doesn’t exist.
- experiment._sum_numpy_files(filenames: List[Union[pathlib.Path, str]])
Takes a list of paths to .npy files. Adds them all together. Returns this sum.
TODO: this could be parallelised.
- Args:
- filenames:
A list/tuple/iterable of strings/paths/np.load-able things.
- Returns:
Sum of the contents of all the files in the filenames list.
- experiment.histogram_xy(x, y, step_size)
- xarray
x dataset.
- yarray
y dataset.
- step_sizefloat
desired stepsize.
- bin_centersarray
value of centres for bin values.
- histarray
historgam output.
- hist_normalizedarray
normalised histogram output.
- countsarray
counts for each bin position.
- experiment._match_start_stop_to_step(step, user_bounds, auto_bounds, eps=1e-05)
- experiment.write_im_to_tiff(parainfo, perpinfo, hfname, out_filename, imdata)
- experiment.do_savetiffs(hf, data, axespara, axesperp)
save separate tiffs for all 2d image data in data
- experiment.write_qi_to_csv(qvals, intvals, tthetavals, out_filename, metadata)
- experiment.do_savedats(hf, intdata, qdata, tthdata)
save all 1d datasets to .dat files
- class experiment.Experiment(scans: List[fast_rsm.scan.Scan], setup: str)
The Experiment class specifies all experimental details necessary to process experimental data. This can be a list of file paths, a central pixel location, details of the experimental geometry, the desired output, etc.
Experiments contain lot of tools that can be used to work out what they are. For example, experiments can work out whether or not binning is required to reduce data volumes, and if so, generate finite difference volumes in which the data can be optimally stored.
- Attrs:
- scans:
A list of all of the scans explored in this experiment.
Initialization
- parse_dcd_angles(scan: fast_rsm.scan.Scan)
- load_incident_angle(scan: fast_rsm.scan.Scan)
- load_dps_offsets(scan: fast_rsm.scan.Scan)
- load_curve_values(scan: fast_rsm.scan.Scan)
set attributes of experiment for easier access to key variables
- _clean_temp_files() None
Removes all temporary files.
- add_processing_step(processing_step: callable) None
Adds a processing step to every scan in the experiment. The processing step is a function that takes a numpy array representing the input image, and outputs a numpy array representing the output image. A valid processing step could look something like
- def add_one(arr):
return arr + 1
If you, for some reason, wanted to add 1 to every raw image array, this function can be added to all the scans in this experiment using:
experiment.add_processing_step(add_one)
Note that this must currently (python 3.10) be a module-level named function. Because of the internals of how pythons serialization (pickling) works, anonymous (lambda) functions won’t work.
Processing steps are applied in the order in which they are added.
- mask_pixels(pixels: tuple) None
Masks the requested pixels. Note that the pixels argument will be used to directly affect arrays, i.e.
array[pixels] = np.nan
is going to be used at somencounterede point.
- Args:
- pixels:
The pixels to be masked.
- mask_regions(regions: List[diffraction_utils.Region])
Masks the requested regions defined as regions in setup file.
- mask_edf(edfmask)
apply any mask defined with a .edf file as created in pyFAI-calib GUI
- q_bounds(frame: diffraction_utils.Frame, spherical_bragg_vec: numpy.ndarray, oop: str = 'y') Tuple[numpy.ndarray]
Works out the region of reciprocal space sampled by every scan in this experiment. This is reasonably performant, but should really be parallelised at some point.
- Returns:
(start, stop)
- get_limitcalc_vars(axis, slitvertratio, slithorratio)
Calculates the pixel limits of the scan in either vertical or horizontal direction and returns dictionary with values relating to the limits calculated
- calcanglim(axis, slitvertratio=None, slithorratio=None)
Calculates limits in exit angle for either vertical or horizontal axis
- calcqlim(axis, slitvertratio=None, slithorratio=None)
Calculates limits in q for either vertical or horizontal axis
- binned_reciprocal_space_map_smm(num_threads: int, map_frame: diffraction_utils.Frame, process_config: types.SimpleNamespace, output_file_name: str = 'mapped', min_intensity_mask: float = None, output_file_size: float = 100, save_vtk: bool = True, save_npy: bool = True, oop: str = 'y', volume_start: numpy.ndarray = None, volume_stop: numpy.ndarray = None, volume_step: numpy.ndarray = None, map_each_image: bool = False)
Carries out a binned reciprocal space map for this experimental data. New version using SharedMemoryManager
- Args:
- num_threads:
How many threads should be used to carry out this map? You should probably set this to however many threads are available on your machine.
- map_frame:
An instance of diffraction_utils.Frame that specifies what frame of reference and coordinate system you’d like your map to be carried out in.
- output_file_name:
What should the final file be saved as?
- output_file_size:
The desired output file size, in units of MB. Defaults to 100 MB.
- save_vtk:
Should we save a vtk file for this map? Defaults to True.
- save_npy:
Should we save a numpy file for this map? Defaults to True.
- oop:
Which synchrotron axis should become the out-of-plane (001) direction. Defaults to ‘y’; can be ‘x’, ‘y’ or ‘z’.
- classmethod from_i07_nxs(nexus_paths: List[Union[str, pathlib.Path]], beam_centre: Tuple[int], detector_distance: float, setup: str, path_to_data: str = '', using_dps: bool = False, experimental_hutch=0)
Generates an instance of Experiment from paths to nexus files obtained from the i07 beamline. Also requires a few other essential pieces of information to uniquely specify the experimental setup (because you could be doing basically anything on i07…)
- Args:
- nexus_paths:
Path to the nexus files containing all of the scans’ metadata. If the experiment consists of only one scan, then you can pass a single string/Path in place of a list of strings/paths.
- 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 Experiment.