Skip to content

Commit

Permalink
Update tc_tracks tests for new IBTrACS version
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisFairless committed Nov 12, 2024
1 parent 0bbc123 commit 1994104
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions climada/hazard/test/test_tc_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ def test_penv_rmax_penv_pass(self):
provider="usa", storm_id="1992230N11325"
)
penv_ref = np.ones(97) * 1010
penv_ref[26:36] = [1011, 1012, 1013, 1014, 1015, 1014, 1014, 1014, 1014, 1012]
penv_ref[26:36] = [1011, 1012, 1013, 1014, 1015, 1015, 1014, 1014, 1014, 1012]
rmax_ref = np.zeros(97)
rmax_ref[63:82] = [10., 10., 10.625, 11.25, 11.875, 12.5, 13.125, 13.75, 14.375, 15., 15.625, 16.25, 16.875, 17.5 , 18.125, 18.75, 19.375, 20., 20.]

self.assertTrue(
np.allclose(tc_track.get_track()["environmental_pressure"].values, penv_ref)
np.testing.assert_array_almost_equal(
tc_track.get_track()["environmental_pressure"].values, penv_ref, decimal=4
)
self.assertTrue(
np.allclose(tc_track.get_track()["radius_max_wind"].values, np.zeros(97))
np.testing.assert_array_almost_equal(
tc_track.get_track()["radius_max_wind"].values, rmax_ref, decimal=4
)

def test_ibtracs_raw_pass(self):
Expand Down Expand Up @@ -278,7 +280,7 @@ def test_ibtracs_correct_pass(self):
tc_try.data[0]["central_pressure"].values[0], 1013, places=0
)
self.assertAlmostEqual(
tc_try.data[0]["central_pressure"].values[5], 1008, places=0
tc_try.data[0]["central_pressure"].values[5], 1007, places=0
)
self.assertAlmostEqual(
tc_try.data[0]["central_pressure"].values[-1], 1012, places=0
Expand Down Expand Up @@ -701,14 +703,16 @@ def test_get_extent(self):
tc_track = tc.TCTracks.from_ibtracs_netcdf(
storm_id=storms, provider=["usa", "bom"]
)
bounds = (153.585022, -23.200001, 258.714996, 17.514986)
bounds_buf = (153.485022, -23.300001, 258.814996, 17.614986)
np.testing.assert_array_almost_equal(tc_track.bounds, bounds)
bounds = (153.6, -23.2, 258.7, 17.5)
bounds_buf = (153.5, -23.3, 258.8, 17.6)
np.testing.assert_array_almost_equal(
tc_track.bounds, bounds, decimal=4
)
np.testing.assert_array_almost_equal(
tc_track.get_bounds(deg_buffer=0.1), bounds_buf
tc_track.get_bounds(deg_buffer=0.1), bounds_buf, decimal=4
)
np.testing.assert_array_almost_equal(
tc_track.extent, u_coord.toggle_extent_bounds(bounds)
tc_track.extent, u_coord.toggle_extent_bounds(bounds), decimal=4
)

def test_generate_centroids(self):
Expand All @@ -718,13 +722,13 @@ def test_generate_centroids(self):
storm_id=storms, provider=["usa", "bom"]
)
cen = tc_track.generate_centroids(10, 1)
cen_bounds = (157.585022, -19.200001, 257.585022, 10.799999)
cen_bounds = (157.6, -19.2, 257.6, 10.8)
self.assertEqual(cen.size, 44)
self.assertEqual(np.unique(cen.lat).size, 4)
self.assertEqual(np.unique(cen.lon).size, 11)
np.testing.assert_array_equal(np.diff(np.unique(cen.lat)), 10)
np.testing.assert_array_equal(np.diff(np.unique(cen.lon)), 10)
np.testing.assert_array_almost_equal(cen.total_bounds, cen_bounds)
np.testing.assert_array_almost_equal(cen.total_bounds, cen_bounds, decimal=4)

def test_interp_track_pass(self):
"""Interpolate track to min_time_step. Compare to MATLAB reference."""
Expand Down

0 comments on commit 1994104

Please sign in to comment.