Skip to content

Commit

Permalink
Accept uppercase within filename and convert to lowercase for vptstoo…
Browse files Browse the repository at this point in the history
…ls parsing (#53)

* Accept also uppercase radar-landcode

* Return radarcode as lowercase when parsing filenames
  • Loading branch information
stijnvanhoey authored Aug 21, 2023
1 parent 108fc15 commit a7e4032
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/vptstools/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ def parse_file_name(file_name):
"""

name_regex = re.compile(
r".*([a-z]{2})([a-z]{3})_([a-z]*)_(\d\d\d\d)(\d\d)(\d\d)T?"
r".*([a-zA-Z]{2})([a-zA-Z]{3})_([a-z]*)_(\d\d\d\d)(\d\d)(\d\d)T?"
r"(\d\d)(\d\d)(?:Z|00)?.*\.h5"
)
match = re.match(name_regex, file_name)
if match:
file_name = Path(file_name).name
country, radar, data_type, year, month, day, hour, minute = match.groups()
radar_code = country + radar
return radar_code, data_type, year, month, day, hour, minute, file_name
return radar_code.lower(), data_type, year, month, day, hour, minute, file_name
else:
raise ValueError("File name is not a valid ODIM h5 file.")

Expand Down
13 changes: 13 additions & 0 deletions tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ class TestOdimFilePath:
"plrze_vp_20201027T172000Z_0x9.h5",
),
),
(
"uva/hdf5/2008/02/15/NLDBL_vp_20080215T0000_NL50_v0-3-20.h5",
(
"nldbl",
"vp",
"2008",
"02",
"15",
"00",
"00",
"NLDBL_vp_20080215T0000_NL50_v0-3-20.h5",
),
),
],
)
def test_parse_file_name(self, file_path, components):
Expand Down

0 comments on commit a7e4032

Please sign in to comment.