quicknxs.utils package

QuickNXS utilities, such as filepath normalization.

Submodules

quicknxs.utils.filepath module

Classes to handle string representations of sets of run numbers and absolute paths to data files.

class quicknxs.utils.filepath.FilePath(file_path: str | list[str], sort: bool = True)[source]

Bases: object

Helper class to deal with string representation of one or more absolute file paths.

Example: file_path = ‘/SNS/REF_M/IPTS-25531/nexus/REF_M_38202.nxs.h5+/SNS/REF_M/IPTS-25531/nexus/REF_M_38201.nxs.h5’

NOTE: Paths are sorted

property basename
property dirname
property first_path
property is_composite
classmethod join(dirname: str, basename: str, sort: bool = True) str[source]

Create the file path for a single file or a set of files using one directory.

Example: u’/SNS/REF_M/IPTS-25531/nexus/REF_M_38198.nxs.h5+/SNS/REF_M/IPTS-25531/nexus/REF_M_38199.nxs.h5’

Parameters:
  • dirname – absolute path to a directory

  • basename – name of one or more files. If more than one file, they’re concatenated with the merge symbol ‘+’. Example: u’REF_M_38198.nxs.h5+REF_M_38199.nxs.h5’

  • sort – if True, sort the basenames according to increasing run number when more than one file.

Returns:

string representing the absolute path to the files.

Return type:

str

merge_symbol = '+'
property path
run_numbers(string_representation: str | None = None) list[int] | str[source]

Return the run number(s) associated to this file path.

This function assumes the basename of each single file path has the pattern “REF_M_XXXX.*” where ‘XXXX’ is the run number to extract, and * is some file extension

Parameters:

string_representation – One of [None, “long”, “short”, “statement”] to return the run numbers as a list of integers, a long string representation, a short string representation, or a human readable statement, respectively.

property single_paths
split()[source]
classmethod unique_dirname(file_path)[source]

For composite file paths, check that the dirname of the paths is the same for all files.

class quicknxs.utils.filepath.RunNumbers(numbers: list[int] | list[str] | int | str)[source]

Bases: object

A helper class to handle string representations of one or more run numbers.

Translates from a string representation to a list of run numbers, and viceversa

Initialize the RunNumbers object.

Parameters:

numbers – a list of numbers or a string containing one or more numbers. For instance, ‘1:3+5’ translates to [1, 2, 3, 5]

property long: str

Long string representation of the run numbers.

Example: [1, 2, 3, 6] becomes ‘1+2+3+6’

merge_symbol = '+'
property numbers: list[int]

List of run numbers as a list of integers.

range_symbol = ':'
property short: str

Short string representation of the run numbers.

Example: [1, 2, 3, 6] becomes ‘1:3+6’

property statement: str

Human readable string representation.

Examples: ‘12’, ‘12 and 13’, ‘12, 13, and 14’