extract_quantity_from_filepath

extract_quantity_from_filepath#

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

Extract the MAS/POT3D quantity name from a filename stem.

Matches the longest recognized quantity prefix at the start of the stem (before any digit or end-of-string). The match is case-insensitive.

Parameters:
ifilePath

File path whose stem is examined. Only the stem (filename without extension) is inspected.

defaultstr or None, optional

Value to return when no quantity prefix is found. Defaults to None.

Returns:
outstr or None

Lower-case quantity name (e.g. 'br'), or default if the stem does not begin with a recognized quantity prefix.

Examples

>>> from pathlib import Path
>>> from psi_io.mhd_io import extract_quantity_from_filepath
>>> extract_quantity_from_filepath(Path('br001001.h5'))
'br'
>>> extract_quantity_from_filepath(Path('heat001.h5'))
'heat'
>>> extract_quantity_from_filepath(Path('unknown.h5')) is None
True
>>> extract_quantity_from_filepath(Path('unknown.h5'), default='br')
'br'