(partial) tests update #43
10 fail, 639 pass in 10m 31s
Annotations
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestReader
github-actions / Unit Test Results Python 3.9
test_memory_limit (climada.hazard.test.test_trop_cyclone.TestReader) failed
tests_xml/tests.xml [took 0s]
Raw output
NameError: name '_compute_windfields_sparse' is not defined
self = <climada.hazard.test.test_trop_cyclone.TestReader testMethod=test_memory_limit>
def test_memory_limit(self):
"""Test from_tracks when memory is (very) limited"""
tc_track = TCTracks.from_processed_ibtracs_csv(TEST_TRACK)
tc_track.equal_timestep()
tc_track.data = tc_track.data[:1]
# A very low memory constraint forces the algorithm to split the track into chunks.
# This should not affect the results. In practice, chunking is not applied due to limited
# memory, but due to very high spatial/temporal resolution of the centroids/tracks. We
# simulate this situation by artificially reducing the available memory.
> tc_haz = TropCyclone.from_tracks(tc_track, centroids=CENTR_TEST_BRB, max_memory_gb=0.001)
climada/hazard/test/test_trop_cyclone.py:60:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:321: in from_tracks
cls.from_single_track(track, centroids, coastal_idx,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'climada.hazard.trop_cyclone.TropCyclone'>
track = <xarray.Dataset>
Dimensions: (time: 223)
Coordinates:
* time (time) datetime64[ns...
data_provider: hurdat_atl
id_no: 1951239012334.0
category: 1
centroids = <climada.hazard.centroids.centr.Centroids object at 0x7f51af9a01c0>
coastal_idx = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20,..., 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295])
model = 'H08', store_windfields = False, metric = 'equirect'
intensity_thres = 17.5, max_dist_eye_km = 300, max_memory_gb = 0.001
@classmethod
def from_single_track(
cls,
track: xr.Dataset,
centroids: Centroids,
coastal_idx: np.ndarray,
model: str = 'H08',
store_windfields: bool = False,
metric: str = "equirect",
intensity_thres: float = DEF_INTENSITY_THRES,
max_dist_eye_km: float = DEF_MAX_DIST_EYE_KM,
max_memory_gb: float = DEF_MAX_MEMORY_GB,
):
"""
Generate windfield hazard from a single track dataset
Parameters
----------
track : xr.Dataset
Single tropical cyclone track.
centroids : Centroids
Centroids instance.
coastal_idx : np.ndarray
Indices of centroids close to coast.
model : str, optional
Parametric wind field model, one of "H1980" (the prominent Holland 1980 model),
"H08" (Holland 1980 with b-value from Holland 2008), "H10" (Holland et al. 2010), or
"ER11" (Emanuel and Rotunno 2011).
Default: "H08".
store_windfields : boolean, optional
If True, store windfields. Default: False.
metric : str, optional
Specify an approximation method to use for earth distances: "equirect" (faster) or
"geosphere" (more accurate). See `dist_approx` function in `climada.util.coordinates`.
Default: "equirect".
intensity_thres : float, optional
Wind speeds (in m/s) below this threshold are stored as 0. Default: 17.5
max_dist_eye_km : float, optional
No wind speed calculation is done for centroids with a distance (in km) to the TC
center ("eye") larger than this parameter. Default: 300
max_memory_gb : float, optional
To avoid memory issues, the computation is done for chunks of the track sequentially.
The chunk size is determined depending on the available memory (in GB). Default: 8
Raises
------
ValueError, KeyError
Returns
-------
haz : TropCyclone
"""
> intensity_sparse, windfields_sparse = _compute_windfields_sparse(
track=track,
centroids=centroids,
coastal_idx=coastal_idx,
model=model,
store_windfields=store_windfields,
metric=metric,
intensity_thres=intensity_thres,
max_dist_eye_km=max_dist_eye_km,
max_memory_gb=max_memory_gb,
)
E NameError: name '_compute_windfields_sparse' is not defined
climada/hazard/trop_cyclone.py:604: NameError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestReader
github-actions / Unit Test Results Python 3.9
test_set_one_file_pass (climada.hazard.test.test_trop_cyclone.TestReader) failed
tests_xml/tests.xml [took 0s]
Raw output
NameError: name '_compute_windfields_sparse' is not defined
self = <climada.hazard.test.test_trop_cyclone.TestReader testMethod=test_set_one_file_pass>
def test_set_one_file_pass(self):
"""Test from_tracks with one input."""
tc_track = TCTracks.from_processed_ibtracs_csv(TEST_TRACK_SHORT)
> tc_haz = TropCyclone.from_tracks(tc_track, centroids=CENTR_TEST_BRB)
climada/hazard/test/test_trop_cyclone.py:201:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:321: in from_tracks
cls.from_single_track(track, centroids, coastal_idx,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'climada.hazard.trop_cyclone.TropCyclone'>
track = <xarray.Dataset>
Dimensions: (time: 9)
Coordinates:
* time (time) datetime64[ns] ... data_provider: hurdat_atl
id_no: 1951239012334.0
category: -1
centroids = <climada.hazard.centroids.centr.Centroids object at 0x7f51af9a01c0>
coastal_idx = array([], dtype=int64), model = 'H08', store_windfields = False
metric = 'equirect', intensity_thres = 17.5, max_dist_eye_km = 300
max_memory_gb = 8
@classmethod
def from_single_track(
cls,
track: xr.Dataset,
centroids: Centroids,
coastal_idx: np.ndarray,
model: str = 'H08',
store_windfields: bool = False,
metric: str = "equirect",
intensity_thres: float = DEF_INTENSITY_THRES,
max_dist_eye_km: float = DEF_MAX_DIST_EYE_KM,
max_memory_gb: float = DEF_MAX_MEMORY_GB,
):
"""
Generate windfield hazard from a single track dataset
Parameters
----------
track : xr.Dataset
Single tropical cyclone track.
centroids : Centroids
Centroids instance.
coastal_idx : np.ndarray
Indices of centroids close to coast.
model : str, optional
Parametric wind field model, one of "H1980" (the prominent Holland 1980 model),
"H08" (Holland 1980 with b-value from Holland 2008), "H10" (Holland et al. 2010), or
"ER11" (Emanuel and Rotunno 2011).
Default: "H08".
store_windfields : boolean, optional
If True, store windfields. Default: False.
metric : str, optional
Specify an approximation method to use for earth distances: "equirect" (faster) or
"geosphere" (more accurate). See `dist_approx` function in `climada.util.coordinates`.
Default: "equirect".
intensity_thres : float, optional
Wind speeds (in m/s) below this threshold are stored as 0. Default: 17.5
max_dist_eye_km : float, optional
No wind speed calculation is done for centroids with a distance (in km) to the TC
center ("eye") larger than this parameter. Default: 300
max_memory_gb : float, optional
To avoid memory issues, the computation is done for chunks of the track sequentially.
The chunk size is determined depending on the available memory (in GB). Default: 8
Raises
------
ValueError, KeyError
Returns
-------
haz : TropCyclone
"""
> intensity_sparse, windfields_sparse = _compute_windfields_sparse(
track=track,
centroids=centroids,
coastal_idx=coastal_idx,
model=model,
store_windfields=store_windfields,
metric=metric,
intensity_thres=intensity_thres,
max_dist_eye_km=max_dist_eye_km,
max_memory_gb=max_memory_gb,
)
E NameError: name '_compute_windfields_sparse' is not defined
climada/hazard/trop_cyclone.py:604: NameError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestReader
github-actions / Unit Test Results Python 3.9
test_set_one_pass (climada.hazard.test.test_trop_cyclone.TestReader) failed
tests_xml/tests.xml [took 0s]
Raw output
NameError: name '_compute_windfields_sparse' is not defined
self = <climada.hazard.test.test_trop_cyclone.TestReader testMethod=test_set_one_pass>
def test_set_one_pass(self):
"""Test _tc_from_track function."""
intensity_idx = [0, 1, 2, 3, 80, 100, 120, 200, 220, 250, 260, 295]
intensity_values = {
"geosphere": [25.60794285, 26.90906280, 28.26649026, 25.54076797, 31.21986961,
36.17171808, 21.11408573, 28.01457948, 32.65349378, 31.34027741, 0,
40.27362679],
"equirect": [25.60778909, 26.90887264, 28.26624642, 25.54092386, 31.21941738,
36.16596567, 21.11399856, 28.01452136, 32.65076804, 31.33884098, 0,
40.27002104]
}
# the values for the two metrics should agree up to first digit at least
for i, val in enumerate(intensity_values["geosphere"]):
self.assertAlmostEqual(intensity_values["equirect"][i], val, 1)
tc_track = TCTracks.from_processed_ibtracs_csv(TEST_TRACK)
tc_track.equal_timestep()
tc_track.data = tc_track.data[:1]
for metric in ["equirect", "geosphere"]:
> tc_haz = TropCyclone.from_tracks(tc_track, centroids=CENTR_TEST_BRB, model='H08',
store_windfields=True, metric=metric)
climada/hazard/test/test_trop_cyclone.py:91:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:321: in from_tracks
cls.from_single_track(track, centroids, coastal_idx,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'climada.hazard.trop_cyclone.TropCyclone'>
track = <xarray.Dataset>
Dimensions: (time: 223)
Coordinates:
* time (time) datetime64[ns...
data_provider: hurdat_atl
id_no: 1951239012334.0
category: 1
centroids = <climada.hazard.centroids.centr.Centroids object at 0x7f51af9a01c0>
coastal_idx = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20,..., 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295])
model = 'H08', store_windfields = True, metric = 'equirect'
intensity_thres = 17.5, max_dist_eye_km = 300, max_memory_gb = 8
@classmethod
def from_single_track(
cls,
track: xr.Dataset,
centroids: Centroids,
coastal_idx: np.ndarray,
model: str = 'H08',
store_windfields: bool = False,
metric: str = "equirect",
intensity_thres: float = DEF_INTENSITY_THRES,
max_dist_eye_km: float = DEF_MAX_DIST_EYE_KM,
max_memory_gb: float = DEF_MAX_MEMORY_GB,
):
"""
Generate windfield hazard from a single track dataset
Parameters
----------
track : xr.Dataset
Single tropical cyclone track.
centroids : Centroids
Centroids instance.
coastal_idx : np.ndarray
Indices of centroids close to coast.
model : str, optional
Parametric wind field model, one of "H1980" (the prominent Holland 1980 model),
"H08" (Holland 1980 with b-value from Holland 2008), "H10" (Holland et al. 2010), or
"ER11" (Emanuel and Rotunno 2011).
Default: "H08".
store_windfields : boolean, optional
If True, store windfields. Default: False.
metric : str, optional
Specify an approximation method to use for earth distances: "equirect" (faster) or
"geosphere" (more accurate). See `dist_approx` function in `climada.util.coordinates`.
Default: "equirect".
intensity_thres : float, optional
Wind speeds (in m/s) below this threshold are stored as 0. Default: 17.5
max_dist_eye_km : float, optional
No wind speed calculation is done for centroids with a distance (in km) to the TC
center ("eye") larger than this parameter. Default: 300
max_memory_gb : float, optional
To avoid memory issues, the computation is done for chunks of the track sequentially.
The chunk size is determined depending on the available memory (in GB). Default: 8
Raises
------
ValueError, KeyError
Returns
-------
haz : TropCyclone
"""
> intensity_sparse, windfields_sparse = _compute_windfields_sparse(
track=track,
centroids=centroids,
coastal_idx=coastal_idx,
model=model,
store_windfields=store_windfields,
metric=metric,
intensity_thres=intensity_thres,
max_dist_eye_km=max_dist_eye_km,
max_memory_gb=max_memory_gb,
)
E NameError: name '_compute_windfields_sparse' is not defined
climada/hazard/trop_cyclone.py:604: NameError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestReader
github-actions / Unit Test Results Python 3.9
test_two_files_pass (climada.hazard.test.test_trop_cyclone.TestReader) failed
tests_xml/tests.xml [took 0s]
Raw output
NameError: name '_compute_windfields_sparse' is not defined
self = <climada.hazard.test.test_trop_cyclone.TestReader testMethod=test_two_files_pass>
def test_two_files_pass(self):
"""Test from_tracks with two ibtracs."""
tc_track = TCTracks.from_processed_ibtracs_csv([TEST_TRACK_SHORT, TEST_TRACK_SHORT])
> tc_haz = TropCyclone.from_tracks(tc_track, centroids=CENTR_TEST_BRB)
climada/hazard/test/test_trop_cyclone.py:226:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:321: in from_tracks
cls.from_single_track(track, centroids, coastal_idx,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'climada.hazard.trop_cyclone.TropCyclone'>
track = <xarray.Dataset>
Dimensions: (time: 9)
Coordinates:
* time (time) datetime64[ns] ... data_provider: hurdat_atl
id_no: 1951239012334.0
category: -1
centroids = <climada.hazard.centroids.centr.Centroids object at 0x7f51af9a01c0>
coastal_idx = array([], dtype=int64), model = 'H08', store_windfields = False
metric = 'equirect', intensity_thres = 17.5, max_dist_eye_km = 300
max_memory_gb = 8
@classmethod
def from_single_track(
cls,
track: xr.Dataset,
centroids: Centroids,
coastal_idx: np.ndarray,
model: str = 'H08',
store_windfields: bool = False,
metric: str = "equirect",
intensity_thres: float = DEF_INTENSITY_THRES,
max_dist_eye_km: float = DEF_MAX_DIST_EYE_KM,
max_memory_gb: float = DEF_MAX_MEMORY_GB,
):
"""
Generate windfield hazard from a single track dataset
Parameters
----------
track : xr.Dataset
Single tropical cyclone track.
centroids : Centroids
Centroids instance.
coastal_idx : np.ndarray
Indices of centroids close to coast.
model : str, optional
Parametric wind field model, one of "H1980" (the prominent Holland 1980 model),
"H08" (Holland 1980 with b-value from Holland 2008), "H10" (Holland et al. 2010), or
"ER11" (Emanuel and Rotunno 2011).
Default: "H08".
store_windfields : boolean, optional
If True, store windfields. Default: False.
metric : str, optional
Specify an approximation method to use for earth distances: "equirect" (faster) or
"geosphere" (more accurate). See `dist_approx` function in `climada.util.coordinates`.
Default: "equirect".
intensity_thres : float, optional
Wind speeds (in m/s) below this threshold are stored as 0. Default: 17.5
max_dist_eye_km : float, optional
No wind speed calculation is done for centroids with a distance (in km) to the TC
center ("eye") larger than this parameter. Default: 300
max_memory_gb : float, optional
To avoid memory issues, the computation is done for chunks of the track sequentially.
The chunk size is determined depending on the available memory (in GB). Default: 8
Raises
------
ValueError, KeyError
Returns
-------
haz : TropCyclone
"""
> intensity_sparse, windfields_sparse = _compute_windfields_sparse(
track=track,
centroids=centroids,
coastal_idx=coastal_idx,
model=model,
store_windfields=store_windfields,
metric=metric,
intensity_thres=intensity_thres,
max_dist_eye_km=max_dist_eye_km,
max_memory_gb=max_memory_gb,
)
E NameError: name '_compute_windfields_sparse' is not defined
climada/hazard/trop_cyclone.py:604: NameError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestReader
github-actions / Unit Test Results Python 3.9
test_windfield_models (climada.hazard.test.test_trop_cyclone.TestReader) failed
tests_xml/tests.xml [took 0s]
Raw output
NameError: name '_compute_windfields_sparse' is not defined
self = <climada.hazard.test.test_trop_cyclone.TestReader testMethod=test_windfield_models>
def test_windfield_models(self):
"""Test _tc_from_track function with different wind field models."""
intensity_idx = [0, 1, 2, 3, 80, 100, 120, 200, 220, 250, 260, 295]
intensity_values = {
"H08": [25.60778909, 26.90887264, 28.26624642, 25.54092386, 31.21941738, 36.16596567,
21.11399856, 28.01452136, 32.65076804, 31.33884098, 0, 40.27002104],
"H10": [27.604317, 28.720708, 29.894993, 27.52234 , 32.512395, 37.114355,
23.848917, 29.614752, 33.775593, 32.545347, 19.957627, 41.014578],
# Holland 1980 and Emanuel & Rotunno 2011 use recorded wind speeds, while the above use
# pressure values only. That's why the results are so different:
"H1980": [21.376807, 21.957217, 22.569568, 21.284351, 24.254226, 26.971303,
19.220149, 21.984516, 24.196388, 23.449116, 0, 31.550207],
"ER11": [23.565332, 24.931413, 26.360758, 23.490333, 29.601171, 34.522795,
18.996389, 26.102109, 30.780737, 29.498453, 0, 38.368805],
}
tc_track = TCTracks.from_processed_ibtracs_csv(TEST_TRACK)
tc_track.equal_timestep()
tc_track.data = tc_track.data[:1]
for model in ["H08", "H10", "H1980", "ER11"]:
> tc_haz = TropCyclone.from_tracks(tc_track, centroids=CENTR_TEST_BRB, model=model)
climada/hazard/test/test_trop_cyclone.py:147:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:321: in from_tracks
cls.from_single_track(track, centroids, coastal_idx,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'climada.hazard.trop_cyclone.TropCyclone'>
track = <xarray.Dataset>
Dimensions: (time: 223)
Coordinates:
* time (time) datetime64[ns...
data_provider: hurdat_atl
id_no: 1951239012334.0
category: 1
centroids = <climada.hazard.centroids.centr.Centroids object at 0x7f51af9a01c0>
coastal_idx = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20,..., 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295])
model = 'H08', store_windfields = False, metric = 'equirect'
intensity_thres = 17.5, max_dist_eye_km = 300, max_memory_gb = 8
@classmethod
def from_single_track(
cls,
track: xr.Dataset,
centroids: Centroids,
coastal_idx: np.ndarray,
model: str = 'H08',
store_windfields: bool = False,
metric: str = "equirect",
intensity_thres: float = DEF_INTENSITY_THRES,
max_dist_eye_km: float = DEF_MAX_DIST_EYE_KM,
max_memory_gb: float = DEF_MAX_MEMORY_GB,
):
"""
Generate windfield hazard from a single track dataset
Parameters
----------
track : xr.Dataset
Single tropical cyclone track.
centroids : Centroids
Centroids instance.
coastal_idx : np.ndarray
Indices of centroids close to coast.
model : str, optional
Parametric wind field model, one of "H1980" (the prominent Holland 1980 model),
"H08" (Holland 1980 with b-value from Holland 2008), "H10" (Holland et al. 2010), or
"ER11" (Emanuel and Rotunno 2011).
Default: "H08".
store_windfields : boolean, optional
If True, store windfields. Default: False.
metric : str, optional
Specify an approximation method to use for earth distances: "equirect" (faster) or
"geosphere" (more accurate). See `dist_approx` function in `climada.util.coordinates`.
Default: "equirect".
intensity_thres : float, optional
Wind speeds (in m/s) below this threshold are stored as 0. Default: 17.5
max_dist_eye_km : float, optional
No wind speed calculation is done for centroids with a distance (in km) to the TC
center ("eye") larger than this parameter. Default: 300
max_memory_gb : float, optional
To avoid memory issues, the computation is done for chunks of the track sequentially.
The chunk size is determined depending on the available memory (in GB). Default: 8
Raises
------
ValueError, KeyError
Returns
-------
haz : TropCyclone
"""
> intensity_sparse, windfields_sparse = _compute_windfields_sparse(
track=track,
centroids=centroids,
coastal_idx=coastal_idx,
model=model,
store_windfields=store_windfields,
metric=metric,
intensity_thres=intensity_thres,
max_dist_eye_km=max_dist_eye_km,
max_memory_gb=max_memory_gb,
)
E NameError: name '_compute_windfields_sparse' is not defined
climada/hazard/trop_cyclone.py:604: NameError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestReader
github-actions / Unit Test Results Python 3.9
test_windfield_models_different_windunits (climada.hazard.test.test_trop_cyclone.TestReader) failed
tests_xml/tests.xml [took 0s]
Raw output
NameError: name '_compute_windfields_sparse' is not defined
self = <climada.hazard.test.test_trop_cyclone.TestReader testMethod=test_windfield_models_different_windunits>
def test_windfield_models_different_windunits(self):
"""
Test _tc_from_track function should calculate the same results or raise ValueError
with different windspeed units.
"""
intensity_idx = [0, 1, 2, 3, 80, 100, 120, 200, 220, 250, 260, 295]
intensity_values = {
# Holland 1980 and Emanuel & Rotunno 2011 use recorded wind speeds, that is why checking them for different
# windspeed units is so important:
"H1980": [21.376807, 21.957217, 22.569568, 21.284351, 24.254226, 26.971303,
19.220149, 21.984516, 24.196388, 23.449116, 0, 31.550207],
"ER11": [23.565332, 24.931413, 26.360758, 23.490333, 29.601171, 34.522795,
18.996389, 26.102109, 30.780737, 29.498453, 0, 38.368805],
}
tc_track = TCTracks.from_processed_ibtracs_csv(TEST_TRACK)
tc_track.equal_timestep()
tc_track.data = tc_track.data[:1]
tc_track_kmph = TCTracks(data=[ds.copy(deep=True) for ds in tc_track.data])
tc_track_kmph.data[0]['max_sustained_wind'] *= (
(1.0 * ureg.knot).to(ureg.km / ureg.hour).magnitude
)
tc_track_kmph.data[0].attrs['max_sustained_wind_unit'] = 'km/h'
tc_track_mps = TCTracks(data=[ds.copy(deep=True) for ds in tc_track.data])
tc_track_mps.data[0]['max_sustained_wind'] *= (
(1.0 * ureg.knot).to(ureg.meter / ureg.second).magnitude
)
tc_track_mps.data[0].attrs['max_sustained_wind_unit'] = 'm/s'
for model in ["H1980", "ER11"]:
for tc_track_i in [tc_track_kmph, tc_track_mps]:
> tc_haz = TropCyclone.from_tracks(tc_track_i, centroids=CENTR_TEST_BRB, model=model)
climada/hazard/test/test_trop_cyclone.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:321: in from_tracks
cls.from_single_track(track, centroids, coastal_idx,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'climada.hazard.trop_cyclone.TropCyclone'>
track = <xarray.Dataset>
Dimensions: (time: 223)
Coordinates:
* time (time) datetime64[ns...
data_provider: hurdat_atl
id_no: 1951239012334.0
category: 1
centroids = <climada.hazard.centroids.centr.Centroids object at 0x7f51af9a01c0>
coastal_idx = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20,..., 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295])
model = 'H1980', store_windfields = False, metric = 'equirect'
intensity_thres = 17.5, max_dist_eye_km = 300, max_memory_gb = 8
@classmethod
def from_single_track(
cls,
track: xr.Dataset,
centroids: Centroids,
coastal_idx: np.ndarray,
model: str = 'H08',
store_windfields: bool = False,
metric: str = "equirect",
intensity_thres: float = DEF_INTENSITY_THRES,
max_dist_eye_km: float = DEF_MAX_DIST_EYE_KM,
max_memory_gb: float = DEF_MAX_MEMORY_GB,
):
"""
Generate windfield hazard from a single track dataset
Parameters
----------
track : xr.Dataset
Single tropical cyclone track.
centroids : Centroids
Centroids instance.
coastal_idx : np.ndarray
Indices of centroids close to coast.
model : str, optional
Parametric wind field model, one of "H1980" (the prominent Holland 1980 model),
"H08" (Holland 1980 with b-value from Holland 2008), "H10" (Holland et al. 2010), or
"ER11" (Emanuel and Rotunno 2011).
Default: "H08".
store_windfields : boolean, optional
If True, store windfields. Default: False.
metric : str, optional
Specify an approximation method to use for earth distances: "equirect" (faster) or
"geosphere" (more accurate). See `dist_approx` function in `climada.util.coordinates`.
Default: "equirect".
intensity_thres : float, optional
Wind speeds (in m/s) below this threshold are stored as 0. Default: 17.5
max_dist_eye_km : float, optional
No wind speed calculation is done for centroids with a distance (in km) to the TC
center ("eye") larger than this parameter. Default: 300
max_memory_gb : float, optional
To avoid memory issues, the computation is done for chunks of the track sequentially.
The chunk size is determined depending on the available memory (in GB). Default: 8
Raises
------
ValueError, KeyError
Returns
-------
haz : TropCyclone
"""
> intensity_sparse, windfields_sparse = _compute_windfields_sparse(
track=track,
centroids=centroids,
coastal_idx=coastal_idx,
model=model,
store_windfields=store_windfields,
metric=metric,
intensity_thres=intensity_thres,
max_dist_eye_km=max_dist_eye_km,
max_memory_gb=max_memory_gb,
)
E NameError: name '_compute_windfields_sparse' is not defined
climada/hazard/trop_cyclone.py:604: NameError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestClimateSce
github-actions / Unit Test Results Python 3.9
test_apply_criterion_track (climada.hazard.test.test_trop_cyclone.TestClimateSce) failed
tests_xml/tests.xml [took 0s]
Raw output
AssertionError:
Arrays are not equal
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 0.0039708
Max relative difference: 0.14556134
x: array(0.03125)
y: array(0.027279)
self = <climada.hazard.test.test_trop_cyclone.TestClimateSce testMethod=test_apply_criterion_track>
def test_apply_criterion_track(self):
"""Test _apply_criterion function."""
criterion = [
{'basin': 'NA', 'category': [1, 2, 3, 4, 5],
'year': 2100, 'change': 1.045}
]
scale = 0.75
# artificially increase the size of
# the hazard by repeating (tiling) the data:
ntiles = 8
intensity = np.zeros((4, 10))
intensity[0, :] = np.arange(10)
intensity[1, 5] = 10
intensity[2, :] = np.arange(10, 20)
intensity[3, 3] = 3
intensity = np.tile(intensity, (ntiles, 1))
tc = TropCyclone(
intensity=sparse.csr_matrix(intensity),
basin=ntiles * ['NA', 'NA', 'NA', 'WP'],
frequency=np.repeat(1/(4*ntiles), 4*ntiles),
category=np.array(ntiles * [2, 0, 4, 1]),
event_id=np.arange(intensity.shape[0]),
)
tc_cc = tc.apply_climate_scenario_knu()
for i_tile in range(ntiles):
offset = i_tile * 4
# no factor applied because of category 0
> np.testing.assert_array_equal(
tc.frequency[offset + 1], tc_cc.frequency[offset + 1]
)
climada/hazard/test/test_trop_cyclone.py:466:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
args = (<built-in function eq>, 0.03125, 0.027279202818889382)
kwds = {'err_msg': '', 'header': 'Arrays are not equal', 'strict': False, 'verbose': True}
@wraps(func)
def inner(*args, **kwds):
with self._recreate_cm():
> return func(*args, **kwds)
E AssertionError:
E Arrays are not equal
E
E Mismatched elements: 1 / 1 (100%)
E Max absolute difference: 0.0039708
E Max relative difference: 0.14556134
E x: array(0.03125)
E y: array(0.027279)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/contextlib.py:79: AssertionError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestClimateSce
github-actions / Unit Test Results Python 3.9
test_no_negative_freq (climada.hazard.test.test_trop_cyclone.TestClimateSce) failed
tests_xml/tests.xml [took 0s]
Raw output
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
self = <climada.hazard.test.test_trop_cyclone.TestClimateSce testMethod=test_no_negative_freq>
def test_no_negative_freq(self):
"""Test apply_climate_scenario_knu with too high changes and check
that no negative frequencies are returned."""
criterion = [{'basin': 'SP', 'category': [0, 1],
'year': 2100, 'change': 0.5}
]
tc = TropCyclone(
frequency=np.ones(2),
basin=['SP', 'SP'],
category=np.array([0, 1]),
)
> tc_cc = tc.apply_climate_scenario_knu(criterion, 3)
climada/hazard/test/test_trop_cyclone.py:533:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:398: in apply_climate_scenario_knu
scale_year_rcp_05, scale_year_rcp_45 = [
climada/hazard/trop_cyclone.py:399: in <listcomp>
get_knutson_scaling_factor(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pct = [{'basin': 'SP', 'category': [0, 1], 'change': 0.5, 'year': 2100}]
basin = 'SP', variable = 'cat05', baseline = (1982, 2022)
def get_knutson_scaling_factor(
pct=0,
basin='NA',
variable='cat05',
baseline=(1950, 2018)
):
"""
This code combines data in Knutson et al. (2020) and GMST data
(historical and CMIP5 simulated) to produce TC projections for
4 RCPs and any historical baseline. The code uses GMST data
implements to interpolate and extrapolate the Knutson data
relative to the specified baseline time period for various RCPs
with a log-linear model. The methodology was developed and explained
in Jewson et al., (2021).
Related publications:
- Knutson et al., (2020): Tropical cyclones and climate
change assessment. Part II: Projected response to anthropogenic warming.
Bull. Amer. Meteor. Soc., 101 (3), E303–E322,
https://doi.org/10.1175/BAMS-D-18-0194.1.
- Jewson (2021): Conversion of the Knutson et al. (2020) Tropical Cyclone
Climate Change Projections to Risk Model Baselines,
https://doi.org/10.1175/JAMC-D-21-0102.1
Parameters
----------
pct: int
percentile of interest:
0 = 5% or 10%
1 = 25%
2 = 50%
3 = 75%
4 = 95% or 90%
basin : str
region of interest, possible choices are:
'NA', 'WP', 'EP', 'NI', 'SI', 'SP'
variable: int
variable of interest, possible choices are
'cat05', 'cat45', 'intensity'
baseline : tuple of int
the starting and ending years that define the historical
baseline. The historical baseline period must fall within
the GSMT data period, i.e., 1880-2100.
"""
# this could become an input variable in the future
windows_props = {
'windows': 21, 'start' : 2000,
'interval' : 5, 'smoothing' : 5
}
base_start_year, base_end_year = baseline
gmst_data, gmst_start_year, gmst_end_year, rcps = get_gmst_info()
knutson_data = get_knutson_data()
nrcps, gmst_years = gmst_data.shape
if ((base_start_year <= gmst_start_year) or (base_start_year >= gmst_end_year) or
(base_end_year <= gmst_start_year) or (base_end_year >= gmst_end_year)):
raise ValueError("The selected historical baseline falls outside"
"the GMST data period 1880-2100")
# calculate beta and annual values from this knutson_value
# (these annual values correspond to y in the paper)
var_id = MAP_VARS_NAMES[variable]
try:
basin_id = MAP_BASINS_NAMES[basin]
> knutson_value = knutson_data[var_id, basin_id, pct]
E IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
climada/hazard/tc_clim_change.py:109: IndexError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestClimateSce
github-actions / Unit Test Results Python 3.9
test_two_criterion_track (climada.hazard.test.test_trop_cyclone.TestClimateSce) failed
tests_xml/tests.xml [took 0s]
Raw output
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
self = <climada.hazard.test.test_trop_cyclone.TestClimateSce testMethod=test_two_criterion_track>
def test_two_criterion_track(self):
"""Test apply_climate_scenario_knu function with two criteria"""
criterion = [
{'basin': 'WP', 'category': [1, 2, 3, 4, 5],
'year': 2100, 'change': 1.025},
{'basin': 'NA', 'category': [0, 1, 2, 3, 4, 5],
'year': 2100, 'change': 0.7},
{'basin': 'NA', 'category': [1, 2, 3, 4, 5],
'year': 2100, 'change': 1},
{'basin': 'NA', 'category': [3, 4, 5],
'year': 2100, 'change': 1},
{'basin': 'NA', 'category': [4, 5],
'year': 2100, 'change': 2}
]
scale = 0.75
intensity = np.zeros((4, 10))
intensity[0, :] = np.arange(10)
intensity[1, 5] = 10
intensity[2, :] = np.arange(10, 20)
intensity[3, 3] = 3
tc = TropCyclone(
intensity=sparse.csr_matrix(intensity),
frequency=np.ones(4) * 0.5,
basin=['NA', 'NA', 'NA', 'WP'],
category=np.array([2, 0, 4, 1]),
event_id=np.arange(4),
)
> tc_cc = tc.apply_climate_scenario_knu(criterion, scale)
climada/hazard/test/test_trop_cyclone.py:512:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:398: in apply_climate_scenario_knu
scale_year_rcp_05, scale_year_rcp_45 = [
climada/hazard/trop_cyclone.py:399: in <listcomp>
get_knutson_scaling_factor(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pct = [{'basin': 'WP', 'category': [1, 2, 3, 4, 5], 'change': 1.025, 'year': 2100}, {'basin': 'NA', 'category': [0, 1, 2, 3,...NA', 'category': [3, 4, 5], 'change': 1, 'year': 2100}, {'basin': 'NA', 'category': [4, 5], 'change': 2, 'year': 2100}]
basin = 'NA', variable = 'cat05', baseline = (1982, 2022)
def get_knutson_scaling_factor(
pct=0,
basin='NA',
variable='cat05',
baseline=(1950, 2018)
):
"""
This code combines data in Knutson et al. (2020) and GMST data
(historical and CMIP5 simulated) to produce TC projections for
4 RCPs and any historical baseline. The code uses GMST data
implements to interpolate and extrapolate the Knutson data
relative to the specified baseline time period for various RCPs
with a log-linear model. The methodology was developed and explained
in Jewson et al., (2021).
Related publications:
- Knutson et al., (2020): Tropical cyclones and climate
change assessment. Part II: Projected response to anthropogenic warming.
Bull. Amer. Meteor. Soc., 101 (3), E303–E322,
https://doi.org/10.1175/BAMS-D-18-0194.1.
- Jewson (2021): Conversion of the Knutson et al. (2020) Tropical Cyclone
Climate Change Projections to Risk Model Baselines,
https://doi.org/10.1175/JAMC-D-21-0102.1
Parameters
----------
pct: int
percentile of interest:
0 = 5% or 10%
1 = 25%
2 = 50%
3 = 75%
4 = 95% or 90%
basin : str
region of interest, possible choices are:
'NA', 'WP', 'EP', 'NI', 'SI', 'SP'
variable: int
variable of interest, possible choices are
'cat05', 'cat45', 'intensity'
baseline : tuple of int
the starting and ending years that define the historical
baseline. The historical baseline period must fall within
the GSMT data period, i.e., 1880-2100.
"""
# this could become an input variable in the future
windows_props = {
'windows': 21, 'start' : 2000,
'interval' : 5, 'smoothing' : 5
}
base_start_year, base_end_year = baseline
gmst_data, gmst_start_year, gmst_end_year, rcps = get_gmst_info()
knutson_data = get_knutson_data()
nrcps, gmst_years = gmst_data.shape
if ((base_start_year <= gmst_start_year) or (base_start_year >= gmst_end_year) or
(base_end_year <= gmst_start_year) or (base_end_year >= gmst_end_year)):
raise ValueError("The selected historical baseline falls outside"
"the GMST data period 1880-2100")
# calculate beta and annual values from this knutson_value
# (these annual values correspond to y in the paper)
var_id = MAP_VARS_NAMES[variable]
try:
basin_id = MAP_BASINS_NAMES[basin]
> knutson_value = knutson_data[var_id, basin_id, pct]
E IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
climada/hazard/tc_clim_change.py:109: IndexError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestDumpReloadCycle
github-actions / Unit Test Results Python 3.9
test_dump_reload_hdf5 (climada.hazard.test.test_trop_cyclone.TestDumpReloadCycle) failed
tests_xml/tests.xml [took 0s]
Raw output
NameError: name '_compute_windfields_sparse' is not defined
self = <climada.hazard.test.test_trop_cyclone.TestDumpReloadCycle testMethod=test_dump_reload_hdf5>
def setUp(self):
"""Create a TropCyclone object and a temporary directory"""
self.tempdir = TemporaryDirectory()
tc_track = TCTracks.from_processed_ibtracs_csv(TEST_TRACK_SHORT)
> self.tc_hazard = TropCyclone.from_tracks(tc_track, centroids=CENTR_TEST_BRB)
climada/hazard/test/test_trop_cyclone.py:541:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone.py:321: in from_tracks
cls.from_single_track(track, centroids, coastal_idx,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'climada.hazard.trop_cyclone.TropCyclone'>
track = <xarray.Dataset>
Dimensions: (time: 9)
Coordinates:
* time (time) datetime64[ns] ... data_provider: hurdat_atl
id_no: 1951239012334.0
category: -1
centroids = <climada.hazard.centroids.centr.Centroids object at 0x7f51af9a01c0>
coastal_idx = array([], dtype=int64), model = 'H08', store_windfields = False
metric = 'equirect', intensity_thres = 17.5, max_dist_eye_km = 300
max_memory_gb = 8
@classmethod
def from_single_track(
cls,
track: xr.Dataset,
centroids: Centroids,
coastal_idx: np.ndarray,
model: str = 'H08',
store_windfields: bool = False,
metric: str = "equirect",
intensity_thres: float = DEF_INTENSITY_THRES,
max_dist_eye_km: float = DEF_MAX_DIST_EYE_KM,
max_memory_gb: float = DEF_MAX_MEMORY_GB,
):
"""
Generate windfield hazard from a single track dataset
Parameters
----------
track : xr.Dataset
Single tropical cyclone track.
centroids : Centroids
Centroids instance.
coastal_idx : np.ndarray
Indices of centroids close to coast.
model : str, optional
Parametric wind field model, one of "H1980" (the prominent Holland 1980 model),
"H08" (Holland 1980 with b-value from Holland 2008), "H10" (Holland et al. 2010), or
"ER11" (Emanuel and Rotunno 2011).
Default: "H08".
store_windfields : boolean, optional
If True, store windfields. Default: False.
metric : str, optional
Specify an approximation method to use for earth distances: "equirect" (faster) or
"geosphere" (more accurate). See `dist_approx` function in `climada.util.coordinates`.
Default: "equirect".
intensity_thres : float, optional
Wind speeds (in m/s) below this threshold are stored as 0. Default: 17.5
max_dist_eye_km : float, optional
No wind speed calculation is done for centroids with a distance (in km) to the TC
center ("eye") larger than this parameter. Default: 300
max_memory_gb : float, optional
To avoid memory issues, the computation is done for chunks of the track sequentially.
The chunk size is determined depending on the available memory (in GB). Default: 8
Raises
------
ValueError, KeyError
Returns
-------
haz : TropCyclone
"""
> intensity_sparse, windfields_sparse = _compute_windfields_sparse(
track=track,
centroids=centroids,
coastal_idx=coastal_idx,
model=model,
store_windfields=store_windfields,
metric=metric,
intensity_thres=intensity_thres,
max_dist_eye_km=max_dist_eye_km,
max_memory_gb=max_memory_gb,
)
E NameError: name '_compute_windfields_sparse' is not defined
climada/hazard/trop_cyclone.py:604: NameError