chess_scanparsers.scanparsers
¶
Parsing data from certain CHESS SPEC scans is supported by a family
of classes derived from the base class, ScanParser
(defined
below). An instance of ScanParser
represents a single SPEC scan –
each instance is initialized with the name of a specific spec file and
integer scan number. Access to certain data collected by that scan
(counter data, positioner values, scan shape, detector data, etc.) are
made available through the properties and methods of that object.
ScanParser
is just an incomplete abstraction – one should not
declare or work with an instance of ScanParser
directly. Instead,
one must find the appropriate concrete subclass to use for the
particular type of scan one wishes to parse, then declare an instance
of that specific class to begin accessing data from that scan.
Basic usage examples:
Print out the position of a the SPEC positioner motor with mnemonic
'mne0'
for a SAXS/WAXS scan collected at FMB:from chess_scanparsers import FMBSAXSWAXSScanParser sp = FMBSAXSWAXSScanParser('/path/to/fmb/saxswaxs/spec/file', 1) print(sp.get_spec_positioner_value('mne0'))
Store all the detector data collected by the detector with prefix
'det'
over a rotation series collected at SMB in the variabledata
:from chess_scanparsers import SMBRotationScanParser sp = SMBRotationScanParser('/path/to/smb/rotation/spec/file', 1) data = sp.get_detector_data('det')
Module Contents¶
Classes¶
Partial implementation of a class representing a SPEC scan and some of its metadata. |
|
Partial implementation of a class representing a SPEC scan collected at FMB. |
|
Partial implementation of a class representing a SPEC scan collected at SMB or FAST. |
|
Partial implementation of a class representing a typical line or mesh scan in SPEC. |
|
Concrete implementation of a class representing a scan taken with the typical SAXS/WAXS setup at FMB. |
|
Concrete implementation of a class representing a scan taken with the typical XRF setup at FMB. |
|
Concrete implementation of a class representing a scan taken with the typical powder diffraction setup at SMB. |
|
Partial implementation of a class representing a rotation scan. |
|
Concrete implementation of a class representing a scan taken with the typical tomography setup at FMB. |
|
Concrete implementation of a class representing a scan taken with the typical tomography setup at SMB. |
|
Partial implementation of a class representing a scan taken while collecting SPEC MCA data. |
|
Concrete implementation of a class representing a scan taken with the typical EDD setup at SMB or FAST. |
|
Parser for SPEC scans taken at QM2 (ID4B) |
Functions¶
Return a sorted list of all data files for the given detector in the given directory. This function is cached to improve performace for carrying our full FAMB SAXS/WAXS data-processing workflows. |
|
Return a sorted list of all *.hdf5 files in a directory |
|
Return all data from all elements from an MCA data file |
|
Return a sorted list of all data files for the given detector in the given directory. |
API¶
- chess_scanparsers.scanparsers.filespec(spec_file_name)¶
- class chess_scanparsers.scanparsers.ScanParser(spec_file_name: str, scan_number: int)¶
Partial implementation of a class representing a SPEC scan and some of its metadata.
- Parameters:
spec_file_name (str) – path to a SPEC file on the CLASSE DAQ
scan_number (int) – the number of a scan in the SPEC file provided with
spec_file_name
Initialization
Constructor method
- __repr__()¶
- property spec_file¶
- property scan_path¶
- property scan_name¶
- property scan_title¶
- property spec_scan¶
- property spec_command¶
- property spec_macro¶
- property spec_args¶
- property spec_scan_npts¶
- property spec_scan_data¶
- property spec_positioner_values¶
- property detector_data_path¶
- get_scan_path()¶
Return the name of the directory containining the SPEC file for this scan.
- Return type:
str
- abstract get_scan_name()¶
Return the name of this SPEC scan (not unique to scans within a single spec file).
- Return type:
str
- abstract get_scan_title()¶
Return the title of this spec scan (unique to each scan within a spec file).
- Return type:
str
- get_spec_scan()¶
Return the
pyspec.file.spec.Scan
object parsed from the spec file and scan number provided to the constructor.- Return type:
pyspec.file.spec.Scan
- get_spec_command()¶
Return the string command of this SPEC scan.
- Return type:
str
- get_spec_macro()¶
Return the macro used in this scan’s SPEC command.
- Return type:
str
- get_spec_args()¶
Return a list of the arguments provided to the macro for this SPEC scan.
- Return type:
list[str]
- abstract get_spec_scan_npts()¶
Return the number of points collected in this SPEC scan
- Return type:
int
- get_spec_scan_data()¶
Return a dictionary of all the counter data collected by this SPEC scan.
- Return type:
dict[str, numpy.ndarray]
- get_spec_positioner_values()¶
Return a dictionary of all the SPEC positioner values recorded by SPEC just before the scan began.
- Return type:
dict[str,str]
- abstract get_detector_data_path()¶
Return the name of the directory containing detector data collected by this scan.
- Return type:
str
- abstract get_detector_data_file(detector_prefix, scan_step_index: int)¶
Return the name of the file containing detector data collected at a certain step of this scan.
- Parameters:
detector_prefix (str) – the prefix used in filenames for the detector
scan_step_index (int) – the index of the point in this scan whose detector file name should be returned.
- Return type:
str
- get_detector_data(detector_prefix, scan_step_index: int)¶
Return the detector data collected at a certain step of this scan.
- Parameters:
detector_prefix (str) – the prefix used in filenames for the detector
scan_step_index (int) – the index of the point in this scan whose detector data should be returned.
- Return type:
numpy.ndarray
- get_spec_positioner_value(positioner_name)¶
Return the value of a spec positioner recorded before this scan began.
- Parameters:
positioner_name – the name or mnemonic of a SPEC motor whose position should be returned.
- Raises:
KeyError – if
positioner_name
is not the name or mnemonic of a SPEC motor recorded for this scan.ValueError – if the recorded string value of the positioner in the SPEC file cannot be converted to a float.
- Return type:
float
- class chess_scanparsers.scanparsers.FMBScanParser(spec_file_name: str, scan_number: int)¶
Bases:
chess_scanparsers.scanparsers.ScanParser
Partial implementation of a class representing a SPEC scan collected at FMB.
Initialization
Constructor method
- get_scan_name()¶
- get_scan_title()¶
- class chess_scanparsers.scanparsers.SMBScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.ScanParser
Partial implementation of a class representing a SPEC scan collected at SMB or FAST.
Initialization
Constructor method
- get_scan_name()¶
- get_scan_title()¶
- property pars¶
- get_pars()¶
Return a dictionary of values recorded in the .par file associated with this SPEC scan.
- Return type:
dict[str,object]
- get_counter_gain(counter_name)¶
Return the gain of a counter as recorded in the comments or user lines of a scan in a SPEC file converted to nA/V.
- Parameters:
counter_name (str) – the name of the counter
- Return type:
str
- class chess_scanparsers.scanparsers.LinearScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.ScanParser
Partial implementation of a class representing a typical line or mesh scan in SPEC.
Initialization
Constructor method
- property spec_scan_motor_mnes¶
- property spec_scan_motor_vals¶
- property spec_scan_motor_vals_relative¶
- property spec_scan_shape¶
- property spec_scan_dwell¶
- get_spec_scan_motor_mnes()¶
Return the mnemonics of the SPEC motor(s) provided to the macro for this scan. If there is more than one motor scanned (in a “flymesh” scan, for example), the order of motors in the returned tuple will go from the fastest moving motor first to the slowest moving motor last.
- Return type:
tuple
- get_spec_scan_motor_vals(relative=False)¶
Return the values visited by each of the scanned motors. If there is more than one motor scanned (in a “flymesh” scan, for example), the order of motor values in the returned tuple will go from the fastest moving motor’s values first to the slowest moving motor’s values last.
- Return type:
tuple
- get_spec_scan_shape()¶
Return the number of points visited by each of the scanned motors. If there is more than one motor scanned (in a “flymesh” scan, for example), the order of number of motor values in the returned tuple will go from the number of points visited by the fastest moving motor first to the the number of points visited by the slowest moving motor last.
- Return type:
tuple
- get_spec_scan_dwell()¶
Return the dwell time for each point in the scan as it appears in the command string.
- Return type:
float
- get_spec_scan_npts()¶
Return the number of points collected in this SPEC scan.
- Return type:
int
- get_scan_step(scan_step_index: int)¶
Return the index of each motor coordinate corresponding to the index of a single point in the scan. If there is more than one motor scanned (in a “flymesh” scan, for example), the order of indices in the returned tuple will go from the index of the value of the fastest moving motor first to the index of the value of the slowest moving motor last.
- Parameters:
scan_step_index (int) – the index of a single point in the scan.
- Return type:
tuple
- get_scan_step_index(scan_step: tuple)¶
Return the index of a single scan point corresponding to a tuple of indices for each scanned motor coordinate.
- Parameters:
scan_step (tuple) – a tuple of the indices of each scanned motor coordinate. If there is more than one motor scanned (in a “flymesh” scan, for example), the order of indices should go from the index of the value of the fastest moving motor first to the index of the value of the slowest moving motor last.
- Trype:
int
- chess_scanparsers.scanparsers.list_fmb_saxswaxs_detector_files(detector_data_path, detector_prefix)¶
Return a sorted list of all data files for the given detector in the given directory. This function is cached to improve performace for carrying our full FAMB SAXS/WAXS data-processing workflows.
- Parameters:
detector_data_path (str) – directory in which to look for detector data files
detector_prefix (str) – detector name to list files for
- Returns:
list of detector filenames
- Return type:
list[str]
- class chess_scanparsers.scanparsers.FMBSAXSWAXSScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.LinearScanParser
,chess_scanparsers.scanparsers.FMBScanParser
Concrete implementation of a class representing a scan taken with the typical SAXS/WAXS setup at FMB.
Initialization
Constructor method
- get_scan_title()¶
- get_detector_data_path()¶
- get_detector_data_file(detector_prefix, scan_step_index: int)¶
- class chess_scanparsers.scanparsers.FMBXRFScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.LinearScanParser
,chess_scanparsers.scanparsers.FMBScanParser
Concrete implementation of a class representing a scan taken with the typical XRF setup at FMB.
Initialization
Constructor method
- get_scan_title()¶
- get_detector_data_path()¶
- get_detector_data_file(detector_prefix, scan_step_index: int)¶
- get_detector_data(detector_prefix, scan_step_index: int)¶
- class chess_scanparsers.scanparsers.SMBLinearScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.LinearScanParser
,chess_scanparsers.scanparsers.SMBScanParser
Concrete implementation of a class representing a scan taken with the typical powder diffraction setup at SMB.
Initialization
Constructor method
- get_detector_data_path()¶
- get_detector_data_file(detector_prefix, scan_step_index: int)¶
- class chess_scanparsers.scanparsers.RotationScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.ScanParser
Partial implementation of a class representing a rotation scan.
Initialization
Constructor method
- property starting_image_index¶
- property starting_image_offset¶
- abstract get_starting_image_index()¶
Return the first frame of the detector data collected by this scan from the index of the first frame of detector data collected by this scan.
- Return type:
int
- abstract get_starting_image_offset()¶
Return the offset of the index of the first “good” frame of detector data collected by this scan from the index of the first frame of detector data collected by this scan.
- Return type:
int
- class chess_scanparsers.scanparsers.FMBRotationScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.RotationScanParser
,chess_scanparsers.scanparsers.FMBScanParser
Concrete implementation of a class representing a scan taken with the typical tomography setup at FMB.
Initialization
Constructor method
- get_spec_scan_data()¶
- get_spec_scan_npts()¶
- get_starting_image_index()¶
- get_starting_image_offset()¶
- get_detector_data_path()¶
- get_detector_data_file(detector_prefix)¶
- get_all_detector_data_in_file(detector_prefix, scan_step_index=None)¶
- get_detector_data(detector_prefix, scan_step_index=None)¶
- _get_detector_tiff_file(detector_prefix, scan_step_index)¶
- class chess_scanparsers.scanparsers.SMBRotationScanParser(spec_file_name, scan_number, par_file=None)¶
Bases:
chess_scanparsers.scanparsers.RotationScanParser
,chess_scanparsers.scanparsers.SMBScanParser
Concrete implementation of a class representing a scan taken with the typical tomography setup at SMB.
Initialization
Constructor method
- property scan_type¶
- get_spec_scan_data()¶
- get_spec_scan_npts()¶
- get_scan_type()¶
- get_starting_image_index()¶
- get_starting_image_offset()¶
- get_detector_data_path()¶
- get_detector_data_file(scan_step_index: int)¶
- get_detector_data(detector_prefix, scan_step_index=None)¶
- class chess_scanparsers.scanparsers.MCAScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.ScanParser
Partial implementation of a class representing a scan taken while collecting SPEC MCA data.
Initialization
Constructor method
- abstract get_detector_num_bins(detector_prefix)¶
Return the number of bins for the detector with the given prefix.
- Parameters:
detector_prefix (str) – the detector prefix as used in SPEC MCA data files
- Return type:
int
- class chess_scanparsers.scanparsers.SMBMCAScanParser(spec_file_name, scan_number, detector_data_format=None)¶
Bases:
chess_scanparsers.scanparsers.MCAScanParser
,chess_scanparsers.scanparsers.SMBLinearScanParser
Concrete implementation of a class representing a scan taken with the typical EDD setup at SMB or FAST.
Initialization
Constructor for SMBMCAScnaParser.
- Parameters:
spec_file (str) – Path to scan’s SPEC file
scan_number (int) – Number of the SPEC scan
detector_data_format (Optional[Literal["spec", "h5"]]) – Format of the MCA data collected, defaults to None
- detector_data_formats¶
(‘spec’, ‘h5’)
- get_spec_scan_motor_vals(relative=True)¶
- init_detector_data_format()¶
Determine and set a value for the instance variable
detector_data_format
based on the presence / absence of detector data files of different formats conventionally associated with this scan. Also set the corresponding appropriate value for_detector_data_path
.
- abstract get_detector_data_path()¶
- get_detector_num_bins(element_index=0)¶
- get_detector_num_bins_spec()¶
- get_detector_num_bins_h5(element_index)¶
- get_detector_data_file(scan_step_index=0)¶
- get_detector_data_file_spec()¶
Return the filename (full absolute path) to the file containing spec-formatted MCA data for this scan.
- get_detector_data_file_h5(scan_step_index=0)¶
Return the filename (full absolute path) to the file containing h5-formatted MCA data for this scan.
- Parameters:
scan_step_index
- get_all_detector_data(detector)¶
Return a 2D array of all MCA spectra collected in this scan by the detector element indicated with
detector
.- Parameters:
detector (Union[str, int]) – For detector data collected in SPEC format, this is the detector prefix as it appears in the spec MCA data file. For detector data collected in H5 format, this is the index of a particular detector element.
- Return type:
numpy.ndarray
- get_all_detector_data_spec(detector_prefix)¶
Return a 2D array of all MCA spectra collected by a detector in the spec MCA file format during the scan.
- Parameters:
detector_prefix (str) – Detector name at is appears in the spec MCA file.
- Returns:
2D array of MCA spectra
- Return type:
numpy.ndarray
- get_all_detector_data_h5(element_index)¶
Return a 2D array of all MCA spectra collected by a detector in the h5 file format during the scan.
- Parameters:
element_index (int) – The index of a particular MCA element to return data for.
- Returns:
2D array of MCA spectra
- Return type:
numpy.ndarray
- get_detector_data(detector, scan_step_index: int)¶
Return a single MCA spectrum for the detector indicated.
- Parameters:
detector – If this scan collected MCA data in “spec” format, this is the detector prefix as it appears in the spec MCA data file. If this scan collected data in .h5 format, this is the index of the detector element of interest.:type detector: typing.Union[str, int]
scan_step_index (int) – Index of the scan step to return the spectrum from.
- Returns:
A single MCA spectrum
- Return type:
numpy.ndarray
- chess_scanparsers.scanparsers.list_smb_mca_detector_files_h5(detector_data_path)¶
Return a sorted list of all *.hdf5 files in a directory
- Parameters:
detector_data_path (str) – Directory to return *.hdf5 files from
- Returns:
Sorted list of detector data filenames
- Return type:
list[str]
- chess_scanparsers.scanparsers.get_all_mca_data_h5(filename)¶
Return all data from all elements from an MCA data file
- Parameters:
filename (str) – Name of the MCA h5 data file
- Returns:
3D array of MCA spectra where the first axis is scan step, second index is detector element, third index is channel energy.
- Return type:
numpy.ndarray
- chess_scanparsers.scanparsers.list_qm2_detector_files(detector_data_path, detector_prefix)¶
Return a sorted list of all data files for the given detector in the given directory.
- Parameters:
detector_data_path (str) – directory in which to look for detector data files
detector_prefix (str) – detector name to list files for
- Returns:
list of detector filenames
- Return type:
list[str]
- class chess_scanparsers.scanparsers.QM2ScanParser(spec_file_name, scan_number)¶
Bases:
chess_scanparsers.scanparsers.LinearScanParser
Parser for SPEC scans taken at QM2 (ID4B)
Initialization
Constructor method
- get_scan_name()¶
- get_scan_title()¶
- get_detector_data_path()¶
- get_detector_data_file(detector_prefix, scan_step_index)¶
- property sample_id¶
- get_sample_id()¶
Return the sample is used for this scan
- Return type:
str
- property temperature¶
- get_temperature()¶
Go through comment lines from previous scans in the file to find the most comment added most recently before this scan was run that has the format “Temperature Setpoint at
.” Parse and return the value of from this line. - Raises:
RuntimeError – If no value for temperature can be found
- Return type:
float