Skip to content

Commit

Permalink
Update IBTrACS to version 4.1 (#976)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Dec 12, 2024
1 parent ec3ce59 commit 595b31f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Code freeze date: YYYY-MM-DD
- 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`).
- `Exposures.gdf` has been renamed to `Exposures.data` (it still works though, as it is a property now pointing to the latter)
- the `check` method does not add a default "IMPF_" column to the GeoDataFrame anymore
- Updated IBTrACS version from v4.0 to v4.1 ([#976](https://github.com/CLIMADA-project/climada_python/pull/976)
- Fix xarray future warning in TCTracks for .dims to .sizes
- Fix hazard.concatenate type test for pathos pools

### Fixed

Expand Down
3 changes: 1 addition & 2 deletions climada/hazard/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,7 @@ def append(self, *others):
"The hazards are incompatible and cannot be concatenated."
)
self.haz_type = haz_types.pop()

haz_classes = {type(haz) for haz in haz_list}
haz_classes = {haz.__class__.__name__ for haz in haz_list}
if len(haz_classes) > 1:
raise TypeError(
f"The given hazards are of different classes: {haz_classes}. "
Expand Down
14 changes: 7 additions & 7 deletions climada/hazard/tc_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@
IBTRACS_URL = (
"https://www.ncei.noaa.gov/data/"
"international-best-track-archive-for-climate-stewardship-ibtracs/"
"v04r00/access/netcdf"
"v04r01/access/netcdf"
)
"""Site of IBTrACS netcdf file containing all tracks v4.0,
s. https://www.ncdc.noaa.gov/ibtracs/index.php?name=ib-v4-access"""

IBTRACS_FILE = "IBTrACS.ALL.v04r00.nc"
"""IBTrACS v4.0 file all"""
IBTRACS_FILE = "IBTrACS.ALL.v04r01.nc"
"""IBTrACS v4.1 file all"""

IBTRACS_AGENCIES = [
"usa",
Expand Down Expand Up @@ -376,7 +376,7 @@ def from_ibtracs_netcdf(
correct_pres=False,
discard_single_points=True,
additional_variables=None,
file_name="IBTrACS.ALL.v04r00.nc",
file_name=IBTRACS_FILE,
):
"""Create new TCTracks object from IBTrACS databse.
Expand Down Expand Up @@ -485,7 +485,7 @@ def from_ibtracs_netcdf(
compatiblity with other functions such as `equal_timesteps`. Default: True.
file_name : str, optional
Name of NetCDF file to be dowloaded or located at climada/data/system.
Default: 'IBTrACS.ALL.v04r00.nc'
Default: 'IBTrACS.ALL.v04r01.nc'
additional_variables : list of str, optional
If specified, additional IBTrACS data variables are extracted, such as "nature" or
"storm_speed". Only variables that are not agency-specific are supported.
Expand Down Expand Up @@ -731,7 +731,7 @@ def from_ibtracs_netcdf(
)
ibtracs_ds = ibtracs_ds.sel(storm=valid_storms_mask)

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

# load ibtracs dataset
fn_nc = SYSTEM_DIR.joinpath("IBTrACS.ALL.v04r00.nc")
fn_nc = SYSTEM_DIR.joinpath(IBTRACS_FILE)

Check warning on line 2579 in climada/hazard/tc_tracks.py

View check run for this annotation

Jenkins - WCR / Code Coverage

Not covered line

Line 2579 is not covered by tests
with xr.open_dataset(fn_nc) as ibtracs_ds:
# choose specified year range
years = ibtracs_ds.sid.str.slice(0, 4).astype(int)
Expand Down
6 changes: 3 additions & 3 deletions climada/hazard/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def download_ibtracs():
"""This makes sure a IBTrACS.ALL.v04r00.nc file is present in SYSTEM_DIR
"""This makes sure a IBTrACS.ALL.v04r01.nc file is present in SYSTEM_DIR
First, downloading from the original sources is attempted. If that fails an old version
is downloaded from the CLIMADA Data API
"""
Expand All @@ -44,9 +44,9 @@ def download_ibtracs():
): # plan b: download an old version of that file from the climada api
client = Client()
dsinfo = client.get_dataset_info(
name="IBTrACS", version="v04r00", status="external"
name="IBTrACS", version="v04r01", status="external"
)
[fileinfo] = [
fi for fi in dsinfo.files if fi.file_name == "IBTrACS.ALL.v04r00.nc"
fi for fi in dsinfo.files if fi.file_name == "IBTrACS.ALL.v04r01.nc"
]
client._download_file(local_path=SYSTEM_DIR, fileinfo=fileinfo)
48 changes: 35 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,35 @@ 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.0,
10.0,
10.625,
11.25,
11.875,
12.5,
13.125,
13.75,
14.375,
15.0,
15.625,
16.25,
16.875,
17.5,
18.125,
18.75,
19.375,
20.0,
20.0,
]

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 +300,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 +723,14 @@ 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 +740,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
4 changes: 2 additions & 2 deletions doc/tutorial/climada_hazard_TropCyclone.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
"<a id='Part1.a'></a> \n",
"### a) Load TC tracks from historical records\n",
"\n",
"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",
"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",
"\n",
"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",
"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",
"\n",
"To visualize the tracks use `plot()`.\n"
]
Expand Down

0 comments on commit 595b31f

Please sign in to comment.