Skip to content

Commit 595b31f

Browse files
ChrisFairlessChahan Kropfemanuel-schmidchahank
authored
Update IBTrACS to version 4.1 (#976)
* Update IBTrACS version * Update CHANGELOG * Update tc_tracks tests for new IBTrACS version * Fix deprecation notice for datasets.dims -> datasets.sizes * Fix pool problem for concatenating hazards after pool computations * Update changelog * Apply black * Update CHANGELOG.md --------- Co-authored-by: Chahan Kropf <[email protected]> Co-authored-by: emanuel-schmid <[email protected]> Co-authored-by: Chahan M. Kropf <[email protected]>
1 parent ec3ce59 commit 595b31f

File tree

6 files changed

+51
-27
lines changed

6 files changed

+51
-27
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Code freeze date: YYYY-MM-DD
3737
- latitude and longitude column are no longer present there (the according arrays can be retrieved as properties of the Exposures object: `exp.latitude` instead of `exp.gdf.latitude.values`).
3838
- `Exposures.gdf` has been renamed to `Exposures.data` (it still works though, as it is a property now pointing to the latter)
3939
- the `check` method does not add a default "IMPF_" column to the GeoDataFrame anymore
40+
- Updated IBTrACS version from v4.0 to v4.1 ([#976](https://github.com/CLIMADA-project/climada_python/pull/976)
41+
- Fix xarray future warning in TCTracks for .dims to .sizes
42+
- Fix hazard.concatenate type test for pathos pools
4043

4144
### Fixed
4245

climada/hazard/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,7 @@ def append(self, *others):
936936
"The hazards are incompatible and cannot be concatenated."
937937
)
938938
self.haz_type = haz_types.pop()
939-
940-
haz_classes = {type(haz) for haz in haz_list}
939+
haz_classes = {haz.__class__.__name__ for haz in haz_list}
941940
if len(haz_classes) > 1:
942941
raise TypeError(
943942
f"The given hazards are of different classes: {haz_classes}. "

climada/hazard/tc_tracks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@
8484
IBTRACS_URL = (
8585
"https://www.ncei.noaa.gov/data/"
8686
"international-best-track-archive-for-climate-stewardship-ibtracs/"
87-
"v04r00/access/netcdf"
87+
"v04r01/access/netcdf"
8888
)
8989
"""Site of IBTrACS netcdf file containing all tracks v4.0,
9090
s. https://www.ncdc.noaa.gov/ibtracs/index.php?name=ib-v4-access"""
9191

92-
IBTRACS_FILE = "IBTrACS.ALL.v04r00.nc"
93-
"""IBTrACS v4.0 file all"""
92+
IBTRACS_FILE = "IBTrACS.ALL.v04r01.nc"
93+
"""IBTrACS v4.1 file all"""
9494

9595
IBTRACS_AGENCIES = [
9696
"usa",
@@ -376,7 +376,7 @@ def from_ibtracs_netcdf(
376376
correct_pres=False,
377377
discard_single_points=True,
378378
additional_variables=None,
379-
file_name="IBTrACS.ALL.v04r00.nc",
379+
file_name=IBTRACS_FILE,
380380
):
381381
"""Create new TCTracks object from IBTrACS databse.
382382
@@ -485,7 +485,7 @@ def from_ibtracs_netcdf(
485485
compatiblity with other functions such as `equal_timesteps`. Default: True.
486486
file_name : str, optional
487487
Name of NetCDF file to be dowloaded or located at climada/data/system.
488-
Default: 'IBTrACS.ALL.v04r00.nc'
488+
Default: 'IBTrACS.ALL.v04r01.nc'
489489
additional_variables : list of str, optional
490490
If specified, additional IBTrACS data variables are extracted, such as "nature" or
491491
"storm_speed". Only variables that are not agency-specific are supported.
@@ -731,7 +731,7 @@ def from_ibtracs_netcdf(
731731
)
732732
ibtracs_ds = ibtracs_ds.sel(storm=valid_storms_mask)
733733

734-
if ibtracs_ds.dims["storm"] == 0:
734+
if ibtracs_ds.sizes["storm"] == 0:
735735
LOGGER.info(
736736
"After discarding IBTrACS events without valid values by the selected "
737737
"reporting agencies, there are no tracks left that match the specified "
@@ -2576,7 +2576,7 @@ def ibtracs_fit_param(explained, explanatory, year_range=(1980, 2019), order=1):
25762576
raise KeyError("Unknown ibtracs variable: %s" % var)
25772577

25782578
# load ibtracs dataset
2579-
fn_nc = SYSTEM_DIR.joinpath("IBTrACS.ALL.v04r00.nc")
2579+
fn_nc = SYSTEM_DIR.joinpath(IBTRACS_FILE)
25802580
with xr.open_dataset(fn_nc) as ibtracs_ds:
25812581
# choose specified year range
25822582
years = ibtracs_ds.sid.str.slice(0, 4).astype(int)

climada/hazard/test/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
def download_ibtracs():
31-
"""This makes sure a IBTrACS.ALL.v04r00.nc file is present in SYSTEM_DIR
31+
"""This makes sure a IBTrACS.ALL.v04r01.nc file is present in SYSTEM_DIR
3232
First, downloading from the original sources is attempted. If that fails an old version
3333
is downloaded from the CLIMADA Data API
3434
"""
@@ -44,9 +44,9 @@ def download_ibtracs():
4444
): # plan b: download an old version of that file from the climada api
4545
client = Client()
4646
dsinfo = client.get_dataset_info(
47-
name="IBTrACS", version="v04r00", status="external"
47+
name="IBTrACS", version="v04r01", status="external"
4848
)
4949
[fileinfo] = [
50-
fi for fi in dsinfo.files if fi.file_name == "IBTrACS.ALL.v04r00.nc"
50+
fi for fi in dsinfo.files if fi.file_name == "IBTrACS.ALL.v04r01.nc"
5151
]
5252
client._download_file(local_path=SYSTEM_DIR, fileinfo=fileinfo)

climada/hazard/test/test_tc_tracks.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,35 @@ def test_penv_rmax_penv_pass(self):
8282
provider="usa", storm_id="1992230N11325"
8383
)
8484
penv_ref = np.ones(97) * 1010
85-
penv_ref[26:36] = [1011, 1012, 1013, 1014, 1015, 1014, 1014, 1014, 1014, 1012]
85+
penv_ref[26:36] = [1011, 1012, 1013, 1014, 1015, 1015, 1014, 1014, 1014, 1012]
86+
rmax_ref = np.zeros(97)
87+
rmax_ref[63:82] = [
88+
10.0,
89+
10.0,
90+
10.625,
91+
11.25,
92+
11.875,
93+
12.5,
94+
13.125,
95+
13.75,
96+
14.375,
97+
15.0,
98+
15.625,
99+
16.25,
100+
16.875,
101+
17.5,
102+
18.125,
103+
18.75,
104+
19.375,
105+
20.0,
106+
20.0,
107+
]
86108

87-
self.assertTrue(
88-
np.allclose(tc_track.get_track()["environmental_pressure"].values, penv_ref)
109+
np.testing.assert_array_almost_equal(
110+
tc_track.get_track()["environmental_pressure"].values, penv_ref, decimal=4
89111
)
90-
self.assertTrue(
91-
np.allclose(tc_track.get_track()["radius_max_wind"].values, np.zeros(97))
112+
np.testing.assert_array_almost_equal(
113+
tc_track.get_track()["radius_max_wind"].values, rmax_ref, decimal=4
92114
)
93115

94116
def test_ibtracs_raw_pass(self):
@@ -278,7 +300,7 @@ def test_ibtracs_correct_pass(self):
278300
tc_try.data[0]["central_pressure"].values[0], 1013, places=0
279301
)
280302
self.assertAlmostEqual(
281-
tc_try.data[0]["central_pressure"].values[5], 1008, places=0
303+
tc_try.data[0]["central_pressure"].values[5], 1007, places=0
282304
)
283305
self.assertAlmostEqual(
284306
tc_try.data[0]["central_pressure"].values[-1], 1012, places=0
@@ -701,14 +723,14 @@ def test_get_extent(self):
701723
tc_track = tc.TCTracks.from_ibtracs_netcdf(
702724
storm_id=storms, provider=["usa", "bom"]
703725
)
704-
bounds = (153.585022, -23.200001, 258.714996, 17.514986)
705-
bounds_buf = (153.485022, -23.300001, 258.814996, 17.614986)
706-
np.testing.assert_array_almost_equal(tc_track.bounds, bounds)
726+
bounds = (153.6, -23.2, 258.7, 17.5)
727+
bounds_buf = (153.5, -23.3, 258.8, 17.6)
728+
np.testing.assert_array_almost_equal(tc_track.bounds, bounds, decimal=4)
707729
np.testing.assert_array_almost_equal(
708-
tc_track.get_bounds(deg_buffer=0.1), bounds_buf
730+
tc_track.get_bounds(deg_buffer=0.1), bounds_buf, decimal=4
709731
)
710732
np.testing.assert_array_almost_equal(
711-
tc_track.extent, u_coord.toggle_extent_bounds(bounds)
733+
tc_track.extent, u_coord.toggle_extent_bounds(bounds), decimal=4
712734
)
713735

714736
def test_generate_centroids(self):
@@ -718,13 +740,13 @@ def test_generate_centroids(self):
718740
storm_id=storms, provider=["usa", "bom"]
719741
)
720742
cen = tc_track.generate_centroids(10, 1)
721-
cen_bounds = (157.585022, -19.200001, 257.585022, 10.799999)
743+
cen_bounds = (157.6, -19.2, 257.6, 10.8)
722744
self.assertEqual(cen.size, 44)
723745
self.assertEqual(np.unique(cen.lat).size, 4)
724746
self.assertEqual(np.unique(cen.lon).size, 11)
725747
np.testing.assert_array_equal(np.diff(np.unique(cen.lat)), 10)
726748
np.testing.assert_array_equal(np.diff(np.unique(cen.lon)), 10)
727-
np.testing.assert_array_almost_equal(cen.total_bounds, cen_bounds)
749+
np.testing.assert_array_almost_equal(cen.total_bounds, cen_bounds, decimal=4)
728750

729751
def test_interp_track_pass(self):
730752
"""Interpolate track to min_time_step. Compare to MATLAB reference."""

doc/tutorial/climada_hazard_TropCyclone.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
"<a id='Part1.a'></a> \n",
6565
"### a) Load TC tracks from historical records\n",
6666
"\n",
67-
"The best-track historical data from the International Best Track Archive for Climate Stewardship ([IBTrACS](https://www.ncdc.noaa.gov/ibtracs/)) can easily be loaded into CLIMADA to study the historical records of TC events. The constructor `from_ibtracs_netcdf()` generates the `Datasets` for tracks selected by [IBTrACS](https://www.ncdc.noaa.gov/ibtracs/) id, or by basin and year range. To achieve this, it downloads the first time the [IBTrACS data v4 in netcdf format](https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r00/access/netcdf/) and stores it in `~/climada/data/`. The tracks can be accessed later either using the attribute `data` or using `get_track()`, which allows to select tracks by its name or id. Use the method `append()` to extend the `data` list.\n",
67+
"The best-track historical data from the International Best Track Archive for Climate Stewardship ([IBTrACS](https://www.ncdc.noaa.gov/ibtracs/)) can easily be loaded into CLIMADA to study the historical records of TC events. The constructor `from_ibtracs_netcdf()` generates the `Datasets` for tracks selected by [IBTrACS](https://www.ncdc.noaa.gov/ibtracs/) id, or by basin and year range. To achieve this, it downloads the first time the [IBTrACS data v4 in netcdf format](https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r01/access/netcdf/) and stores it in `~/climada/data/`. The tracks can be accessed later either using the attribute `data` or using `get_track()`, which allows to select tracks by its name or id. Use the method `append()` to extend the `data` list.\n",
6868
"\n",
69-
"If you get an error downloading the IBTrACS data, try to manually access [https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r00/access/netcdf/](https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r00/access/netcdf/), click on the file `IBTrACS.ALL.v04r00.nc` and copy it to `~/climada/data/`.\n",
69+
"If you get an error downloading the IBTrACS data, try to manually access [https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r01/access/netcdf/](https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r01/access/netcdf/), click on the file `IBTrACS.ALL.v04r01.nc` and copy it to `~/climada/data/`.\n",
7070
"\n",
7171
"To visualize the tracks use `plot()`.\n"
7272
]

0 commit comments

Comments
 (0)