From 6a28387e6b21fe608efd3519b327981428a21db8 Mon Sep 17 00:00:00 2001 From: Chris Fairless Date: Mon, 11 Nov 2024 16:03:59 +0100 Subject: [PATCH 1/8] Update IBTrACS version --- climada/hazard/tc_tracks.py | 12 ++++++------ climada/hazard/test/__init__.py | 6 +++--- doc/tutorial/climada_hazard_TropCyclone.ipynb | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/climada/hazard/tc_tracks.py b/climada/hazard/tc_tracks.py index 963d282cd..3270e45d0 100644 --- a/climada/hazard/tc_tracks.py +++ b/climada/hazard/tc_tracks.py @@ -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", @@ -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. @@ -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. @@ -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) with xr.open_dataset(fn_nc) as ibtracs_ds: # choose specified year range years = ibtracs_ds.sid.str.slice(0, 4).astype(int) diff --git a/climada/hazard/test/__init__.py b/climada/hazard/test/__init__.py index 10a572415..5aa865705 100755 --- a/climada/hazard/test/__init__.py +++ b/climada/hazard/test/__init__.py @@ -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 """ @@ -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) diff --git a/doc/tutorial/climada_hazard_TropCyclone.ipynb b/doc/tutorial/climada_hazard_TropCyclone.ipynb index 47df87fb7..0613fa7fd 100644 --- a/doc/tutorial/climada_hazard_TropCyclone.ipynb +++ b/doc/tutorial/climada_hazard_TropCyclone.ipynb @@ -64,9 +64,9 @@ " \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" ] From 0bbc12308b2cd29dbfb1b0b240a8149353179237 Mon Sep 17 00:00:00 2001 From: Chris Fairless Date: Mon, 11 Nov 2024 16:09:18 +0100 Subject: [PATCH 2/8] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28a5e2d31..0d15ff586 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ 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 ### Fixed From 1994104e769b1814680d1b9db7673825258ccf28 Mon Sep 17 00:00:00 2001 From: Chris Fairless Date: Tue, 12 Nov 2024 11:23:34 +0100 Subject: [PATCH 3/8] Update tc_tracks tests for new IBTrACS version --- climada/hazard/test/test_tc_tracks.py | 30 +++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/climada/hazard/test/test_tc_tracks.py b/climada/hazard/test/test_tc_tracks.py index c42d5a7a1..f5611eb77 100644 --- a/climada/hazard/test/test_tc_tracks.py +++ b/climada/hazard/test/test_tc_tracks.py @@ -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): @@ -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 @@ -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): @@ -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.""" From e66254a2ae7e89cb8a230ee07a13a21408036cc4 Mon Sep 17 00:00:00 2001 From: Chahan Kropf Date: Mon, 9 Dec 2024 15:14:10 +0100 Subject: [PATCH 4/8] Fix deprecation notice for datasets.dims -> datasets.sizes --- climada/hazard/tc_tracks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/climada/hazard/tc_tracks.py b/climada/hazard/tc_tracks.py index 3270e45d0..fce41053a 100644 --- a/climada/hazard/tc_tracks.py +++ b/climada/hazard/tc_tracks.py @@ -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 " From eec5a65043c4bb642cee77a1f685f5bb0c2d92c8 Mon Sep 17 00:00:00 2001 From: Chahan Kropf Date: Mon, 9 Dec 2024 16:21:25 +0100 Subject: [PATCH 5/8] Fix pool problem for concatenating hazards after pool computations --- climada/hazard/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/climada/hazard/base.py b/climada/hazard/base.py index 51d90cbbf..838c0b160 100644 --- a/climada/hazard/base.py +++ b/climada/hazard/base.py @@ -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}. " From fe1bb2a69d8fa60ddba9412669c9f6fa54bf66e6 Mon Sep 17 00:00:00 2001 From: Chahan Kropf Date: Mon, 9 Dec 2024 16:42:41 +0100 Subject: [PATCH 6/8] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d15ff586..68176ae17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ Code freeze date: YYYY-MM-DD - `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 +- Fix xarray future warning in TCTracks for .dims to .sizes +- Fix hazard.concatenate type test for pathos pools ### Fixed From 9e529f2e4f0bfe4197cdd8f4d5627507d5b26a61 Mon Sep 17 00:00:00 2001 From: Chahan Kropf Date: Mon, 9 Dec 2024 17:41:04 +0100 Subject: [PATCH 7/8] Apply black --- climada/hazard/test/test_tc_tracks.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/climada/hazard/test/test_tc_tracks.py b/climada/hazard/test/test_tc_tracks.py index f5611eb77..56005b51a 100644 --- a/climada/hazard/test/test_tc_tracks.py +++ b/climada/hazard/test/test_tc_tracks.py @@ -84,7 +84,27 @@ def test_penv_rmax_penv_pass(self): penv_ref = np.ones(97) * 1010 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.] + 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, + ] np.testing.assert_array_almost_equal( tc_track.get_track()["environmental_pressure"].values, penv_ref, decimal=4 @@ -705,9 +725,7 @@ def test_get_extent(self): ) 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.bounds, bounds, decimal=4) np.testing.assert_array_almost_equal( tc_track.get_bounds(deg_buffer=0.1), bounds_buf, decimal=4 ) From a5e4adc0ff265fb9b7c6f51f105739a0cb606ee7 Mon Sep 17 00:00:00 2001 From: "Chahan M. Kropf" Date: Wed, 11 Dec 2024 19:10:57 +0100 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8846a79eb..ee2d3bdf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,9 +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 -- Fix xarray future warning in TCTracks for .dims to .sizes -- Fix hazard.concatenate type test for pathos pools +- 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