Skip to content

Commit 0cb3655

Browse files
ThomasRoosliThomas Rooslipeanutfun
authored
TC track forecast missing time period handling (#91)
* continue reading messages from a multimessage file in case a track is missing timeperiods * Apply suggestions from code review * Update CHANGELOG.md --------- Co-authored-by: Thomas Roosli <thomas.roeoesli@meteoswiss.ch> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
1 parent b57686b commit 0cb3655

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Code freeze date: YYYY-MM-DD
1616

1717
### Fixed
1818

19+
- `TCForecast` now skips "untrackable" TCs when reading multi-message `.bufr` files [#91](https://github.com/CLIMADA-project/climada_petals/pull/91)
20+
1921
### Deprecated
2022

2123
### Removed

climada_petals/hazard/tc_tracks_forecast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def read_one_bufr_tc(self, file, id_no=None):
277277
n_timestep = ec.codes_get_size(bufr, 'timePeriod') + 1
278278
except ec.CodesInternalError:
279279
LOGGER.warning("Track %s has no defined timePeriod. Track is discarded.", sid)
280-
return None
280+
continue
281281

282282
# get number of ensemble members
283283
ens_no = ec.codes_get_array(bufr, "ensembleMemberNumber")
68 KB
Binary file not shown.

climada_petals/hazard/test/test_tc_tracks_forecast.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
https://confluence.ecmwf.int/display/FCST/New+Tropical+Cyclone+Wind+Radii+product
3939
"""
4040

41+
TEST_BUFR_FILE_MULTIMESSAGE_MISSING_TIMEPERIOD = DATA_DIR.joinpath('test202308220000.bufr')
42+
"""TC tracks in four BUFR formats as provided by ECMWF. Sourced from
43+
https://confluence.ecmwf.int/display/FCST/New+Tropical+Cyclone+Wind+Radii+product
44+
"""
45+
4146
TEST_CXML_FILE = DATA_DIR.joinpath("cxml_sample_track.xml")
4247
"""A sample CXML file holding forecast data, subset from the ECMWF archive at
4348
https://confluence.ecmwf.int/display/TIGGE/Tools#Tools-ECMWFTropicalCycloneTrackData(XMLformat)
@@ -80,7 +85,6 @@ def test_fetch_ecmwf(self):
8085
np.datetime64('2020-03-19T12:00:00.000000'))
8186
self.assertEqual(forecast.data[1].is_ensemble, True)
8287

83-
8488
def test_ecmwf_multimessage(self):
8589
"""Test ECMWF reader in multimessage format"""
8690
forecast = TCForecast()
@@ -100,6 +104,22 @@ def test_ecmwf_multimessage(self):
100104
np.array(['70E', '70W', '71E', '71W', '72W'], dtype=str)
101105
)
102106

107+
def test_ecmwf_multimessage_missing_timeperiod(self):
108+
"""Test ECMWF reader should continue reading messages if one track misses timePeriod"""
109+
with self.assertLogs('climada_petals.hazard.tc_tracks_forecast', level='INFO') as cm:
110+
forecast = TCForecast()
111+
forecast.fetch_ecmwf(files=TEST_BUFR_FILE_MULTIMESSAGE_MISSING_TIMEPERIOD)
112+
self.assertIn(
113+
"Track 07L has no defined timePeriod. Track is discarded.", cm.output[0]
114+
)
115+
self.assertEqual(forecast.size, 125)
116+
np.testing.assert_array_equal(
117+
np.unique(
118+
[forecast.data[ind_i].name
119+
for ind_i in np.arange(122)]
120+
),
121+
np.array(['09L', 'FRANKLIN', 'GERT'], dtype=str)
122+
)
103123

104124
def test_equal_timestep(self):
105125
"""Test equal timestep"""

0 commit comments

Comments
 (0)