Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Acknowledgement: >
Prof. David J. McComas of Princeton University (Contract #80GSFC19C0027).
IMAP Rules-of-the-Road for data usage can be found in the IMAP CMAD.
Discipline: Solar Physics>Heliospheric Physics
File_naming_convention: source_descriptor_datatype_yyyyMMdd_vNNN
File_naming_convention: source_descriptor_datatype_yyyyMMdd_vMMM.mmmm
HTTP_LINK: https://imap.princeton.edu/
LINK_TITLE: IMAP The Interstellar Mapping and Acceleration Probe
Mission_group: IMAP
Expand Down
17 changes: 11 additions & 6 deletions imap_processing/cdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from cdflib.logging import logger as cdflib_logger
from cdflib.xarray import cdf_to_xarray, xarray_to_cdf
from cdflib.xarray.cdf_to_xarray import ISTP_TO_XARRAY_ATTRS
from imap_data_access.file_validation import Version

import imap_processing
from imap_processing._version import __version__, __version_tuple__ # noqa: F401
Expand Down Expand Up @@ -121,14 +122,18 @@ def write_cdf(
version = dataset.attrs.get("Data_version", None)
if version is None:
warnings.warn(
"No Data_version attribute found in dataset. Using default v999.",
"No Data_version attribute found in dataset. Using default v001.0001",
stacklevel=2,
)
version = "999"
version = "v001.0001"
dataset.attrs["Data_version"] = version
elif not re.match(r"\d{3}", version):

# Data_version may be stored without the leading 'v'; add it before validating.
version_string = version if str(version).startswith("v") else f"v{version}"
if not Version.is_valid_version(version_string):
raise ValueError(
f"The Data_version attribute {version} does not match expected format XXX."
rf"The Data_version attribute {version} does not match the expected "
"regex {Version.version_regex()}"
)

repointing = dataset.attrs.get("Repointing", None)
Expand All @@ -139,7 +144,7 @@ def write_cdf(
data_level=data_level,
descriptor=descriptor,
start_time=start_date,
version=f"v{version}", # Ensure version is prefixed with 'v'
version=version_string,
repointing=repointing_int,
)
file_path = Path(science_file.construct_path())
Expand Down Expand Up @@ -218,7 +223,7 @@ def parse_filename_like(filename_like: str) -> re.Match:
r"(?P<descriptor>[^_]+)" # Required descriptor
r"(_(?P<start_date>\d{8}))?" # Optional start date
r"(-repoint(?P<repointing>\d{5}))?" # Optional repointing field
r"(?:_(?P<version>v\d{3}))?" # Optional version
rf"(?:_(?P<version>{Version.version_regex()}))?" # Optional version
r"(?:\.(?P<extension>cdf|pkts))?$" # Optional extension
)
match = re.match(regex_str, filename_like)
Expand Down
Loading
Loading