Newer
Older
Shavers, Nicholas H
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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"