Skip to content

Commit 261d428

Browse files
authored
Add back vXXX version format to ScienceFilePath (#334)
* add back vXXX handling * fix test
1 parent a38c1a4 commit 261d428

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

imap_data_access/file_validation.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,9 @@ class ScienceFilePath(ImapFilePath):
312312
FILENAME_CONVENTION = (
313313
"<mission>_<instrument>_<datalevel>_<descriptor>_"
314314
"<startdate>(-<repointing>)_<version>.<extension>"
315-
" where version is vMMM.mmmm (legacy vXXX is deprecated and no longer "
316-
"supported.)"
315+
" where version is vMMM.mmmm or vXXX."
317316
)
318-
VALID_VERSION_PATTERN: typing.ClassVar[str] = Version.science_version_pattern
317+
VALID_VERSION_PATTERN: typing.ClassVar[str] = Version.valid_imap_version_pattern
319318
VALID_EXTENSIONS: typing.ClassVar[set[str]] = {"cdf", "pkts"}
320319
_dir_prefix = "imap"
321320

@@ -346,8 +345,8 @@ def __init__(self, filename: str | Path):
346345
repointing the data is from, format: repointXXXXX
347346
<cr>: This is an optional field describing the Carrington rotation.
348347
format: crXXXXX.
349-
<version>: This stores the data version for this product, format: vMMM.mmmm.
350-
vXXX format is deprecated and will raise an error.
348+
<version>: This stores the data version for this product, format: vMMM.mmmm or
349+
vXXX.
351350
352351
Parameters
353352
----------
@@ -397,7 +396,7 @@ def generate_from_inputs(
397396
This can be used instead of the __init__ method to make a new instance:
398397
```
399398
science_file_path = ScienceFilePath.generate_from_inputs("mag", "l0", "test",
400-
"20240213", "v001")
399+
"20240213", 1, 1)
401400
full_path = science_file_path.construct_path()
402401
```
403402
@@ -476,7 +475,6 @@ def validate_filename(self) -> str:
476475
self.descriptor,
477476
self.start_date,
478477
self.extension,
479-
self.major_version,
480478
self.minor_version,
481479
]
482480
):

imap_data_access/webpoda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def _get_latest_version_file_path(
560560
descriptor="raw",
561561
start_time=start_time.strftime("%Y%m%d"),
562562
repointing=repointing,
563-
major_version=0,
563+
major_version=1, # L0 files always use major version 1
564564
minor_version=max_minor_version,
565565
)
566566
return science_file.construct_path()

tests/test_file_validation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def test_extract_filename_components():
6666
ScienceFilePath.extract_filename_components(valid_filepath) == expected_output
6767
)
6868

69+
valid_filepath = Path("/test/imap_mag_l1a_burst_20210101_v001.cdf") # test with
70+
# vXXX format
71+
expected_output["extension"] = "cdf"
72+
expected_output["major_version"] = None
73+
assert (
74+
ScienceFilePath.extract_filename_components(valid_filepath) == expected_output
75+
)
76+
6977

7078
def test_construct_sciencefilepathmanager():
7179
"""Tests that the ``ScienceFilePath`` class constructs a valid filename."""
@@ -196,6 +204,13 @@ def test_generate_from_inputs():
196204
"glows", "l3a", "test", "20210101", 0, 1, cr=23, repointing=1
197205
)
198206

207+
sfm = ScienceFilePath.generate_from_inputs("mag", "l0", "raw", "20210101", None, 1)
208+
expected_output = imap_data_access.config["DATA_DIR"] / Path(
209+
"imap/mag/l0/2021/01/imap_mag_l0_raw_20210101_v001.pkts"
210+
)
211+
212+
assert sfm.construct_path() == expected_output
213+
199214

200215
def test_spice_file_path():
201216
"""Tests the ``SPICEFilePath`` class."""

tests/test_webpoda.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_download_daily_data(
125125
data_level="l0",
126126
descriptor="raw",
127127
start_time=day.strftime("%Y%m%d"),
128-
major_version=0,
128+
major_version=1,
129129
minor_version=1,
130130
).construct_path()
131131
# There are two swapi apids, so we download the same byte stream twice
@@ -209,7 +209,7 @@ def test_download_repointing_data(
209209
descriptor="raw",
210210
start_time=date,
211211
repointing=repoint_id,
212-
major_version=0,
212+
major_version=1,
213213
minor_version=1,
214214
).construct_path()
215215
# There are two hi apids, so we download the same byte stream twice
@@ -251,7 +251,7 @@ def test_file_versioning(
251251
data_level="l0",
252252
descriptor="raw",
253253
start_time=day.strftime("%Y%m%d"),
254-
major_version=0,
254+
major_version=1,
255255
minor_version=3,
256256
).construct_path()
257257
# There are two swapi apids, so we download the same byte stream twice

0 commit comments

Comments
 (0)