extract_quantity_from_filepath#
- extract_quantity_from_filepath(ifile, default=None)[source]#
Extract the MAS/POT3D quantity name from a filename stem.
Searches for the first recognized quantity token anywhere in the stem. A match is accepted only when the token is not immediately preceded or followed by another ASCII letter, so partial matches inside longer words are rejected. The match is case-insensitive.
- Parameters:
- Returns:
Examples
>>> from psi_io.models import extract_quantity_from_filepath >>> from pathlib import Path >>> extract_quantity_from_filepath(Path('br001001.h5')) 'br' >>> extract_quantity_from_filepath(Path('heat001.h5')) 'heat' >>> extract_quantity_from_filepath(Path('run_br_001.h5')) 'br' >>> extract_quantity_from_filepath(Path('unknown.h5')) is None True >>> extract_quantity_from_filepath(Path('unknown.h5'), default='br') 'br'