Skip to content

Commit 11a599c

Browse files
author
Simona Meiler
committed
Refactor test_from_FAST: extend fixture to 2 years, remove separate regression test
The test fixture FAST_test_tracks.nc now has year=[2025,2026] (only seeds_per_month is extended; track variables retain their n_trk dim). The existing len(tc_track.data)==5 assertion now acts as the regression check: the buggy year-loop code would return 5x2=10 tracks. The separate test_from_FAST_not_multiplied_by_year_dim (with its temporary-file scaffolding) is removed.
1 parent f8a35ce commit 11a599c

2 files changed

Lines changed: 7 additions & 67 deletions

File tree

1.59 KB
Binary file not shown.

climada/hazard/test/test_tc_tracks.py

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
Test tc_tracks module.
2020
"""
2121

22-
import tempfile
2322
import unittest
2423
from datetime import datetime as dt
2524

@@ -661,8 +660,13 @@ def test_from_simulations_storm(self):
661660
self.assertEqual(len(tc_track.data), 0)
662661

663662
def test_from_FAST(self):
664-
"""test the correct import of netcdf files from FAST model and the conversion to a
665-
different xr.array structure compatible with CLIMADA."""
663+
"""Test the correct import of netcdf files from FAST model and the conversion to a
664+
different xr.array structure compatible with CLIMADA.
665+
666+
The test fixture contains 5 tracks across 2 years. The regression check
667+
``len(tc_track.data) == 5`` ensures that tracks are not multiplied by the
668+
``year`` dimension (the bug would produce 5 × 2 = 10 tracks instead).
669+
"""
666670

667671
tc_track = tc.TCTracks.from_FAST(TEST_TRACK_FAST)
668672

@@ -705,70 +709,6 @@ def test_from_FAST(self):
705709
self.assertEqual(tc_track.data[0].environmental_pressure.data[0], 1010)
706710
self.assertEqual(tc_track.data[0].basin[0], "NA")
707711

708-
def test_from_FAST_not_multiplied_by_year_dim(self):
709-
"""Regression test: FAST tracks must not be repeated across `year` dimension."""
710-
with tempfile.TemporaryDirectory() as tmpdir:
711-
ds = xr.Dataset(
712-
{
713-
"lon_trks": (
714-
("n_trk", "time"),
715-
np.array(
716-
[
717-
[290.0, 291.0, 292.0],
718-
[300.0, 301.0, 302.0],
719-
],
720-
dtype=float,
721-
),
722-
),
723-
"lat_trks": (
724-
("n_trk", "time"),
725-
np.array(
726-
[
727-
[10.0, 10.5, 11.0],
728-
[15.0, 15.5, 16.0],
729-
],
730-
dtype=float,
731-
),
732-
),
733-
"vmax_trks": (
734-
("n_trk", "time"),
735-
np.array(
736-
[
737-
[20.0, 21.0, 22.0],
738-
[25.0, 26.0, 27.0],
739-
],
740-
dtype=float,
741-
),
742-
),
743-
"tc_month": ("n_trk", np.array([8, 9], dtype=np.int64)),
744-
"tc_basins": ("n_trk", np.array(["NA", "NA"], dtype="<U2")),
745-
"tc_years": ("n_trk", np.array([1998, 1999], dtype=np.int64)),
746-
"seeds_per_month": (
747-
("year", "basin", "month"),
748-
np.zeros((4, 1, 12), dtype=float),
749-
),
750-
},
751-
coords={
752-
"n_trk": ("n_trk", np.array([0, 1], dtype=np.int64)),
753-
"time": ("time", np.array([0, 10800, 21600], dtype=float)),
754-
"year": (
755-
"year",
756-
np.array([1998, 1999, 2000, 2001], dtype=np.int64),
757-
),
758-
"basin": ("basin", np.array(["NA"], dtype="<U2")),
759-
"month": ("month", np.arange(1, 13, dtype=np.int64)),
760-
},
761-
)
762-
763-
path = DATA_DIR.joinpath(tmpdir, "fast_regression.nc")
764-
ds.to_netcdf(path)
765-
766-
tc_track = tc.TCTracks.from_FAST(DATA_DIR.joinpath(tmpdir))
767-
768-
self.assertEqual(tc_track.size, 2)
769-
self.assertEqual(tc_track.data[0].time.dt.year.values[0], 1998)
770-
self.assertEqual(tc_track.data[1].time.dt.year.values[0], 1999)
771-
772712
def test_to_geodataframe_points(self):
773713
"""Conversion of TCTracks to GeoDataFrame using Points."""
774714
tc_track = tc.TCTracks.from_processed_ibtracs_csv(TEST_TRACK)

0 commit comments

Comments
 (0)