Skip to content
Snippets Groups Projects
Commit 44795c5a authored by Shavers, Nicholas H's avatar Shavers, Nicholas H
Browse files

Better mapping of publication level to imag or imf. Compression and Fill Value...

Better mapping of publication level to imag or imf. Compression and Fill Value constants. Code simplified.
parent ba081cc4
No related branches found
No related tags found
1 merge request!368Imagcdf factory mvp
...@@ -501,6 +501,7 @@ def get_input_factory(args): ...@@ -501,6 +501,7 @@ def get_input_factory(args):
input_factory_args["observatory"] = args.observatory input_factory_args["observatory"] = args.observatory
input_factory_args["type"] = args.type input_factory_args["type"] = args.type
input_type = args.input input_type = args.input
input_factory_args["output"] = args.output
# stream/url arguments # stream/url arguments
if args.input_file is not None: if args.input_file is not None:
if input_type in ["netcdf", "miniseed", "imagcdf"]: if input_type in ["netcdf", "miniseed", "imagcdf"]:
......
from typing import Optional, Union
class IMCDFPublicationLevel:
"""Handles publication levels and mapping between data types and levels.
The ImagCDF format uses publication levels to describe the processing
level of the data. This class maps data types (e.g., 'variation', 'definitive')
to their corresponding publication levels as defined in the ImagCDF documentation.
Publication Levels:
1: Raw data with no processing.
2: Edited data with preliminary baselines.
3: Data suitable for initial bulletins or quasi-definitive publication.
4: Definitive data with no further changes expected.
Reference:
- ImagCDF Technical Documentation: Attributes that Uniquely Identify the Data
"""
class PublicationLevel:
LEVEL_1 = "1"
LEVEL_2 = "2"
LEVEL_3 = "3"
LEVEL_4 = "4"
TYPE_TO_LEVEL = {
"none": PublicationLevel.LEVEL_1,
"variation": PublicationLevel.LEVEL_1,
"reported": PublicationLevel.LEVEL_1,
"provisional": PublicationLevel.LEVEL_2,
"adjusted": PublicationLevel.LEVEL_2,
"quasi-definitive": PublicationLevel.LEVEL_3,
"quasidefinitive": PublicationLevel.LEVEL_3,
"definitive": PublicationLevel.LEVEL_4,
}
def __init__(self, value: Union[str, int]):
"""Initialize with a data type or publication level to determine the publication level.
Args:
value (Union[str, int]): The data type (str) or publication level (int).
Raises:
ValueError: If the value is not provided or is unsupported.
"""
if isinstance(value, int) or (isinstance(value, str) and value.isdigit()):
self.level = str(value)
if self.level not in self.PublicationLevel.__dict__.values():
raise ValueError(f"Unsupported level: {value}")
elif isinstance(value, str):
self.level = self.TYPE_TO_LEVEL.get(value.lower())
if not self.level:
raise ValueError(f"Unsupported data_type: {value}")
else:
raise ValueError(
"value must be a string or an integer representing data_type or level."
)
def get_level(self) -> str:
"""Return the publication level as a string.
Returns:
str: The publication level.
"""
return self.level
def get_imf_data_type(self, long_form: Optional[bool] = True) -> str:
"""Get the IMF data type based on the publication level.
Args:
long_form (bool): If True, return the full description; otherwise, return the abbreviated form.
Returns:
str: The IMF data type.
Reference:
https://tech-man.intermagnet.org/latest/appendices/dataformats.html#intermagnet-satellite-transmission-format-imfv2-83
"""
if self.level == self.PublicationLevel.LEVEL_4:
return "Definitive" if long_form else "D"
elif self.level == self.PublicationLevel.LEVEL_3:
return "Quasi-definitive" if long_form else "Q"
elif self.level == self.PublicationLevel.LEVEL_2:
return "Adjusted" if long_form else "A"
else:
return "Reported" if long_form else "R"
def get_iaga2002_data_type(self, long_form: Optional[bool] = True) -> str:
"""Get the IAGA-2002 data type based on the publication level.
Args:
long_form (bool): If True, return the full description; otherwise, return the abbreviated form.
Returns:
str: The IAGA-2002 data type.
Reference:
https://tech-man.intermagnet.org/latest/appendices/dataformats.html#iaga2002-intermagnet-exchange-format-spreadsheet-compatible
"""
if self.level == self.PublicationLevel.LEVEL_4:
return "Definitive" if long_form else "D"
elif self.level == self.PublicationLevel.LEVEL_3:
return "Quasi-definitive" if long_form else "Q"
elif self.level == self.PublicationLevel.LEVEL_2:
return "Provisional" if long_form else "P"
else:
return "Variation" if long_form else "V"
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment