extract_sequence_from_filepath

extract_sequence_from_filepath#

extract_sequence_from_filepath(ifile, default=None)[source]#

Extract the sequence number from a filename stem.

Searches for the first 3- or 6-digit decimal token in the stem that is not immediately preceded or followed by another digit. A 6-digit run is always preferred over a 3-digit run at the same position.

Parameters:
ifilePath

File path whose stem is examined.

defaultint or None, optional

Value to return when no 3- or 6-digit token is found. Defaults to None.

Returns:
outint or None

Integer sequence number, or default if no match is found.

See also

extract_quantity_from_filepath

Extract the quantity name from a filepath stem.

parse_psi_filename_schema

Strict parser requiring both quantity and sequence.

Examples

>>> from pathlib import Path
>>> from psi_io.models import extract_sequence_from_filepath
>>> extract_sequence_from_filepath(Path('br001001.h5'))
1001
>>> extract_sequence_from_filepath(Path('vr001.h5'))
1
>>> extract_sequence_from_filepath(Path('nosequence.h5')) is None
True