stems.io.utils module

IO utilities

stems.io.utils.parse_filename_attrs(paths, index=None, sep=None)[source]

Parse filenames into an array of dates

Parameters
  • paths (str or Sequence) – Glob style search pattern, or a list of filenames

  • index (slice or int) – Either a slice used to index on the stem of the filenames in paths, or together with sep an int used to index on the filename stem split by sep (e.g., filename.split(sep)[index])

  • sep (str, optional) – String field seperator

Returns

Attribute extracted from each filename path

Return type

list[str]

stems.io.utils.parse_filename_dates(paths, index=None, sep=None, date_format='%Y%m%d')[source]

Parse filenames into an array of dates

Parameters
  • paths (str or Sequence) – Glob style search pattern, or a list of filenames

  • index (slice or int) – Either a slice used to index on the stem of the filenames in paths, or together with sep an int used to index on the filename stem split by sep (e.g., filename.split(sep)[index])

  • sep (str, optional) – String field seperator

  • date_format (str) – Date format used by datetime.datetime.strptime()

Returns

Array of datetime64

Return type

np.ndarray

stems.io.utils.parse_paths(paths)[source]

Return a list of path(s)

Parameters

paths (str or Sequence) – Either a string glob in the form “path/to/my/files/*.nc” or an explicit list of files to open.

Returns

Paths determined from paths

Return type

list[Path]