libera_utils.io.filenaming.LiberaDataProductFilename#

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

Bases: AbstractValidFilename

Filename validation class for L1B and L2 science products

Attributes:
archive_prefix

Property that contains the generated prefix for L1B and L2 archiving

filename_parts

Property that contains a namespace of filename parts

path

Property containing the file path

Methods

from_filename_parts([basepath, data_level, ...])

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

__init__(*args, **kwargs)#

Methods

from_filename_parts([basepath, data_level, ...])

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 L1B and L2 archiving

filename_parts

Property that contains a namespace of filename parts

path

Property containing the file path

static _calculate_applicable_time(start: datetime, end: datetime)#

Based on the start time and end time of a file, returns the applicable time (date)

Parameters:
Returns:

The date of the mean time between start and end

Return type:

datetime.date

classmethod _check_required_parts(local_vars: dict)#

Checks for the presence of required filename parts

Parameters:

local_vars (dict) – Dictionary of variables passed, created by a call to locals()

classmethod _format_filename_parts(data_level: str, product_name: str, version: str, utc_start: datetime, utc_end: datetime, revision: datetime, extension: str)#

Construct a path from filename parts

Parameters:
  • data_level (str) – L1B or L2

  • product_name (str) – Libera instrument, cam or rad for L1B and cloud-fraction etc. for L2. May contain anything except for underscores.

  • version (str) – Software version that the file was created with. Corresponds to the algorithm version as determined by the algorithm software.

  • utc_start (datetime.datetime) – First timestamp in the SPK

  • utc_end (datetime.datetime) – Last timestamp in the SPK

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

  • extension (str) – File extension (.nc or .h5)

Returns:

Formatted filename

Return type:

str

classmethod _from_filename_parts(basepath: str = None, **parts)#

Create instance from filename parts.

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

Parameters:
  • basepath (str or pathlib.Path, Optional) – Allows prepending a basepath or prefix.

  • parts (dict) – Passed directly to _format_filename_parts

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

property archive_prefix#

Property that contains the generated prefix for L1B and L2 archiving

property filename_parts#

Property that contains a namespace of filename parts

classmethod from_filename_parts(basepath: str = None, data_level: str = None, product_name: str = None, version: str = None, utc_start: datetime = None, utc_end: datetime = None, revision: datetime = None, extension: str = 'nc')#

Create instance from filename parts. All keyword arguments other than basepath are required!

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

Parameters:
  • basepath (str or pathlib.Path, Optional) – Allows prepending a basepath or prefix.

  • data_level (str) – L1B or L2 identifying the level of the data product

  • product_name (str) – Product type. e.g. cloud-fraction for L2 or cam for L1B. May contain anything except for underscores.

  • version (str) – Software version that the file was created with. Corresponds to the algorithm version as determined by the algorithm software.

  • utc_start (datetime.datetime) – First timestamp in the SPK

  • utc_end (datetime.datetime) – Last timestamp in the SPK

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

  • extension (str) – File extension (.nc or .h5)

Return type:

LiberaDataProductFilename

generate_prefixed_path(parent_path: str | Path | S3Path) Path | S3Path#

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 (str or pathlib.Path or cloudpathlib.s3.s3path.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#

Property containing the file path

regex_match(path: str)#

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

Returns:

Match group dict of filename parts

Return type:

dict