libera_utils.io.filenaming.LiberaVersionPartitionedDataProductFilename#

class libera_utils.io.filenaming.LiberaVersionPartitionedDataProductFilename(*args, **kwargs)#

Bases: AbstractDataProductFilename

Filename validation class for version-partitioned Libera SDC data products.

A version-partitioned product, such as an ADM, is valid over more than one day (indefinitely until the next version update). Its filename carries no time range, so it has no applicable date. The period it covers is recorded in the file’s variables and metadata. Only a DataProductIdentifier whose partition_scheme is PartitionScheme.VERSION is accepted. A daily product is named by LiberaDataProductFilename.

Version-partitioned data product filenames follow the convention:

LIBERA_{data_level}_{product_name}_{version}_{revision}.nc

e.g. LIBERA_AUX_ADM-CAM_V1-2-3_R20270103T080910123456.nc

  • data_level is the string value of the product’s DataLevel, which must be the data_level of its DataProductIdentifier.

  • product_name is the string value of a DataProductIdentifier whose partition_scheme is PartitionScheme.VERSION.

  • version is the algorithm semantic version in VM-m-p[RCn] form.

  • revision is the UTC creation time of the file, R followed by YYYYMMDDTHHMMSSffffff (microseconds).

__init__(*args, **kwargs)#

Methods

from_file_path(*args, **kwargs)

Factory method to produce an AbstractValidFilename from a valid Libera file path (str or Path)

from_filename_parts(*, product_name, version)

Create instance from filename parts.

generate_prefixed_path(parent_path)

Generates an absolute path of the form {parent_path}/{prefix_structure}/{file_basename} The parent_path can be an S3 bucket or an absolute local filepath (must start with /)

regex_match(path)

Parse and validate a given path against class-attribute defined regex

Attributes

archive_prefix

Property that contains the generated prefix for archiving, <product_name>/<version>

data_product_id

Property that contains the DataProductIdentifier for this file type

filename_parts

Property that contains a namespace of filename parts

path

Property containing the file path

processing_step_id

Property that contains the ProcessingStepIdentifier that generates this file

_fmt: str = 'LIBERA_{data_level}_{product_name}_{version}_{revision}.nc'#
classmethod _format_filename_parts(*, data_level: str, product_name: str, version: str, revision: datetime)#

Construct a filename from filename parts

Parameters:
  • data_level (str) – Data level of the product, e.g. AUX.

  • product_name (str) – Version-partitioned product type, e.g. ADM-CAM.

  • version (str) – Software version that the file was created with, as VM-m-p or a semantic version M.m.p.

  • revision (datetime.datetime) – Time when the file was created.

Returns:

Formatted filename

Return type:

str

classmethod _from_filename_parts(*, basepath: str | Path | S3Path | None = None, **parts: Any)#

Create instance from filename parts.

The part kwarg names are named according to the regex for the file type.

Parameters:
  • basepath (Union[str, Path, S3Path], Optional) – Allows prepending a basepath or prefix.

  • parts (Any) – Passed directly to _format_filename_parts. This is a dict of variable kwargs that will differ in each filename class based on the required parts for that particular filename type.

Return type:

AbstractValidFilename

_parse_filename_parts()#

Parse the filename parts into objects from regex matched strings

Returns:

namespace object containing filename parts as parsed objects

Return type:

types.SimpleNamespace

static _parse_match(d: dict[str, Any]) → SimpleNamespace#

Parse regex matched filename parts into objects

Parameters:

d (dict) – Named groups from matching the filename regex

Returns:

namespace object containing filename parts as parsed objects

Return type:

types.SimpleNamespace

Raises:

ValueError – If revision is not a real UTC time.

property archive_prefix: str#

Property that contains the generated prefix for archiving, <product_name>/<version>

Each file is archived once under this prefix, whatever period it covers.

property data_product_id: DataProductIdentifier#

Property that contains the DataProductIdentifier for this file type

property filename_parts#

Property that contains a namespace of filename parts

classmethod from_file_path(*args, **kwargs)#

Factory method to produce an AbstractValidFilename from a valid Libera file path (str or Path)

Parameters:
  • *args – Positional arguments passed unchanged to each candidate class, normally the single file path as a str, pathlib.Path, or cloudpathlib.S3Path.

  • **kwargs – Keyword arguments passed unchanged to each candidate class.

Returns:

An instance of the first class that accepts the path, trying in order L0Filename, LiberaGroundCcsdsFilename, LiberaDataProductFilename, LiberaVersionPartitionedDataProductFilename, and ManifestFilename.

Return type:

AbstractValidFilename

Raises:

ValueError – If none of the candidate classes accepts the path.

classmethod from_filename_parts(*, product_name: str | DataProductIdentifier, version: str, revision: datetime | None = None, basepath: str | Path | S3Path | None = None)#

Create instance from filename parts.

Parameters:
  • product_name (str | DataProductIdentifier) – Version-partitioned product type, e.g. ADM-CAM.

  • version (str) – Software version that the file was created with, as VM-m-p or a semantic version M.m.p. Corresponds to the algorithm version as determined by the algorithm software.

  • revision (datetime.datetime | None) – Time when the file was created. Default None uses the current UTC time.

  • basepath (str | Path | S3Path | None) – Allows prepending a basepath or prefix.

Return type:

LiberaVersionPartitionedDataProductFilename

Raises:

ValueError – If product_name is not a DataProductIdentifier, if it names a product whose partition scheme is not VERSION, or if version is not a valid version string.

generate_prefixed_path(parent_path: str | CloudPath | Path) → CloudPath | Path#

Generates an absolute path of the form {parent_path}/{prefix_structure}/{file_basename} The parent_path can be an S3 bucket or an absolute local filepath (must start with /)

Parameters:

parent_path (Union[str, Path, S3Path]) – Absolute path to the parent directory or S3 bucket prefix. The generated path prefix is appended to the parent path and followed by the file basename.

Return type:

pathlib.Path or cloudpathlib.s3.s3path.S3Path

property path: CloudPath | Path#

Property containing the file path

property processing_step_id: ProcessingStepIdentifier | None#

Property that contains the ProcessingStepIdentifier that generates this file

regex_match(path: CloudPath | Path)#

Parse and validate a given path against class-attribute defined regex

Parameters:

path (Union[Path, CloudPath]) – Path to validate

Returns:

Match group dict of filename parts

Return type:

dict