Skip to content

Commit 4f86e46

Browse files
Merge branch 'develop' into feature/review_yearsets_tutorial
2 parents 1a0eadb + 8aea89b commit 4f86e46

40 files changed

+2294
-2060
lines changed

.github/pull_request_template.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ This PR fixes #
1919
### PR Reviewer Checklist
2020

2121
- [ ] Read the [Contribution Guide][contrib]
22-
- [ ] [CLIMADA Reviewer Checklist](https://climada-python.readthedocs.io/en/latest/guide/Guide_Reviewer_Checklist.html) passed
22+
- [ ] [CLIMADA Reviewer Checklist](https://climada-python.readthedocs.io/en/latest/development/Guide_Review.html) passed
2323
- [ ] [Tests][testing] passing
2424
- [ ] No new [linter issues][linter]
2525

2626
[contrib]: https://github.com/CLIMADA-project/climada_python/blob/main/CONTRIBUTING.md
27-
[testing]: https://climada-python.readthedocs.io/en/latest/guide/Guide_Continuous_Integration_and_Testing.html
28-
[linter]: https://climada-python.readthedocs.io/en/stable/guide/Guide_Continuous_Integration_and_Testing.html#3.C.--Static-Code-Analysis
27+
[testing]: https://climada-python.readthedocs.io/en/latest/development/Guide_continuous_integration_GitHub_actions.html
28+
[linter]: https://climada-python.readthedocs.io/en/latest/development/Guide_continuous_integration_GitHub_actions.html#static-code-analysis

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
-
4848
name: Install CLIMADA
4949
run: |
50-
python -m pip install ".[test]"
50+
python -m pip install "./[dev]"
5151
-
5252
name: Run Unit Tests
5353
run: |

.zenodo.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
},
120120
{
121121
"name": "Valentin Gebhart"
122+
},
123+
{
124+
"name": "Dahyann Araya"
122125
}
123126
]
124127
}

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636
* Luca Severino
3737
* Samuel Juhel
3838
* Valentin Gebhart
39+
* Dahyann Araya

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,36 @@ Code freeze date: YYYY-MM-DD
1010

1111
### Dependency Changes
1212

13+
Added:
14+
15+
- `fiona` >=1.10
16+
17+
Updated:
18+
19+
- `geopandas` >=0.14,<1.0 → >=0.14
20+
- `pandas` >=2.1,<2.2 → >=2.1
21+
1322
Removed:
1423

1524
- `pandas-datareader`
1625

1726
### Added
27+
1828
- Added optional parameter to `geo_im_from_array`, `plot_from_gdf`, `plot_rp_imp`, `plot_rp_intensity`,
1929
`plot_intensity`, `plot_fraction`, `_event_plot` to mask plotting when regions are too far from data points [#1047](https://github.com/CLIMADA-project/climada_python/pull/1047). To recreate previous plots (no masking), the parameter can be set to None.
2030
- Added instructions to install Climada petals on Euler cluster in `doc.guide.Guide_Euler.ipynb` [#1029](https://github.com/CLIMADA-project/climada_python/pull/1029)
2131

2232
- `ImpactFunc` and `ImpactFuncSet` now support equality comparisons via `==` [#1027](https://github.com/CLIMADA-project/climada_python/pull/1027)
2333

2434
### Changed
35+
2536
- Changed the default mask_distance in `util.plot.geo_im_from_array` to 0.03 to avoid white gaps in gridded hazard data with comparably low resolution (>80 centroids per axis) [#1073](https://github.com/CLIMADA-project/climada_python/pull/1073)
2637
- Increased speed of `util.plot.add_shapes` by avoiding for loops, substantially speeding up `Hazard.plot_intensity` and other functions. [#1073](https://github.com/CLIMADA-project/climada_python/pull/1073)
2738
- `Hazard.local_exceedance_intensity`, `Hazard.local_return_period` and `Impact.local_exceedance_impact`, `Impact.local_return_period`, using the `climada.util.interpolation` module: New default (no binning), binning on decimals, and faster implementation [#1012](https://github.com/CLIMADA-project/climada_python/pull/1012)
2839
- World Bank indicator data is now downloaded directly from their API via the function `download_world_bank_indicator`, instead of relying on the `pandas-datareader` package [#1033](https://github.com/CLIMADA-project/climada_python/pull/1033)
2940
- `Exposures.write_hdf5` pickles geometry data in WKB format, which is faster and more sustainable. [#1051](https://github.com/CLIMADA-project/climada_python/pull/1051)
3041
- The online documentation has been completely overhauled, now uses PyData theme: [#977](https://github.com/CLIMADA-project/climada_python/pull/977)
42+
- Add `climada.hazard.xarray` module with helper structures for reading Hazard objects from `xarray` data [#1063](https://github.com/CLIMADA-project/climada_python/pull/1063)
3143
- The output of the `impact_yearset` was changed to only contain attributes corresponding to the yearly impact set. The default parameters of `impact_yearset`, `sample_events`, and `impact_yearset_from_sampling_vect` functions of the `climada.util.yearsets` module have been changed to sampling with replacement and not applying the correction factor to the impact yearsets. The application of the correction factor and the frequency of the resulting yearly impact object are corrected. [#1075](https://github.com/CLIMADA-project/climada_python/pull/1075)
3244

3345
### Fixed
@@ -37,9 +49,13 @@ Removed:
3749

3850
### Deprecated
3951

52+
- `Hazard.from_xarray_raster_file`. Use `Hazard.from_xarray_raster` and pass the file path as `data` argument [#1063](https://github.com/CLIMADA-project/climada_python/pull/1063)
53+
4054
### Removed
4155

4256
- `climada.util.interpolation.round_to_sig_digits` [#1012](https://github.com/CLIMADA-project/climada_python/pull/1012)
57+
- `intensity_thres` of `Hazard`, `StormEurope`, and `TropCyclones` object [#1065](https://github.com/CLIMADA-project/climada_python/pull/1065)
58+
- Deprecated method `climada.hazard.trop_cyclone.trop_cyclone.TropCyclone.set_from_tracks` [#1065](https://github.com/CLIMADA-project/climada_python/pull/1065)
4359

4460
## 6.0.1
4561

@@ -90,6 +106,7 @@ Removed:
90106

91107
### Added
92108

109+
- `climada.entity.impact_funcs.trop_cyclone.ImpfSetTropCyclone.get_impf_id_regions_per_countries` function [#1034](https://github.com/CLIMADA-project/climada_python/pull/1034)
93110
- `climada.hazard.tc_tracks.TCTracks.subset_years` function [#1023](https://github.com/CLIMADA-project/climada_python/pull/1023)
94111
- `climada.hazard.tc_tracks.TCTracks.from_FAST` function, add Australia basin (AU) [#993](https://github.com/CLIMADA-project/climada_python/pull/993)
95112
- Add `osm-flex` package to CLIMADA core [#981](https://github.com/CLIMADA-project/climada_python/pull/981)
@@ -209,6 +226,7 @@ CLIMADA tutorials. [#872](https://github.com/CLIMADA-project/climada_python/pull
209226
- `Impact.write_hdf5` now throws an error if `event_name` is does not contain strings exclusively [#894](https://github.com/CLIMADA-project/climada_python/pull/894)
210227
- Split `climada.hazard.trop_cyclone` module into smaller submodules without affecting module usage [#911](https://github.com/CLIMADA-project/climada_python/pull/911)
211228
- `yearly_steps` parameter of `TropCyclone.apply_climate_scenario_knu` has been made explicit [#991](https://github.com/CLIMADA-project/climada_python/pull/991)
229+
- `Hazard.write_hdf5` writes centroids as x,y columns (or as wkb in case of polygons) at a compression level of 9, not as pickled `Shapely` objects anymore, which reduces the size of the files significantly.
212230

213231
### Fixed
214232

climada/engine/impact_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def clean_emdat_df(
774774
df_data["Start Day"] = np.array(day_list, dtype="int")
775775
df_data["Start Year"] = np.array(year_list, dtype="int")
776776
for var in ["Disaster Subtype", "Disaster Type", "Country"]:
777-
df_data[VARNAMES_EMDAT[target_version][var]].fillna("None", inplace=True)
777+
df_data.fillna({VARNAMES_EMDAT[target_version][var]: "None"}, inplace=True)
778778

779779
# (3) Filter by countries, year range, and disaster type
780780
# (3.1) Countries:

climada/engine/unsequa/calc_cost_benefit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _map_costben_calc(
398398
ent_future=ent_fut,
399399
save_imp=False,
400400
assign_centroids=False,
401-
**cost_benefit_kwargs
401+
**cost_benefit_kwargs,
402402
)
403403
# Extract from climada.impact the chosen metrics
404404
uncertainty_values.append(

climada/engine/unsequa/test/test_unsequa.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ def test_calc_sensitivity_all_pass(self):
650650
}
651651

652652
def test_sensitivity_method(
653-
exp_unc, impf_unc, haz_unc, sensitivity_method, param_dict
653+
exp_unc, impf_unc, haz_unc, sensitivity_method, param_dict, places
654654
):
655655
"""Function to test each seaprate sensitivity method"""
656656
unc_calc = CalcImpact(exp_unc, impf_unc, haz_unc)
@@ -681,7 +681,7 @@ def test_sensitivity_method(
681681
self.assertAlmostEqual(
682682
param_dict["test_si_value"][0],
683683
unc_data.aai_agg_sens_df["aai_agg"][param_dict["test_si_value"][1]],
684-
places=5,
684+
places=places,
685685
)
686686

687687
self.assertEqual(unc_data.aai_agg_unc_df.size, unc_data.n_samples)
@@ -695,7 +695,12 @@ def test_sensitivity_method(
695695
# loop over each method and do test
696696
for sensitivity_method, method_params in test_dict.items():
697697
test_sensitivity_method(
698-
exp_unc, impf_unc, haz_unc, sensitivity_method, method_params
698+
exp_unc,
699+
impf_unc,
700+
haz_unc,
701+
sensitivity_method,
702+
method_params,
703+
places=2 if sensitivity_method == "rbd_fast" else 5,
699704
)
700705

701706

climada/entity/exposures/litpop/litpop.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"""
2020

2121
import logging
22+
import numbers
2223
from pathlib import Path
2324

2425
import geopandas
@@ -820,12 +821,12 @@ def _from_country(
820821
total_value = _get_total_value_per_country(iso3a, fin_mode, reference_year)
821822

822823
# disaggregate total value proportional to LitPop values:
823-
if isinstance(total_value, (float, int)):
824+
if isinstance(total_value, numbers.Number):
824825
litpop_gdf["value"] = (
825826
np.divide(litpop_gdf["value"], litpop_gdf["value"].sum()) * total_value
826827
)
827828
elif total_value is not None:
828-
raise TypeError("total_value must be int or float.")
829+
raise TypeError(f"total_value ({total_value}) must be a number.")
829830

830831
exp = LitPop()
831832
exp.set_gdf(litpop_gdf)

climada/entity/impact_funcs/test/test_tc.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_default_values_pass(self):
115115
self.assertEqual(impfs.size(), 10)
116116
self.assertEqual(impfs.get_ids()["TC"], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
117117
self.assertEqual(impf_wp4.intensity_unit, "m/s")
118-
self.assertEqual(impf_wp4.name, "North West Pacific (WP4)")
118+
self.assertEqual(impf_wp4.name, "North West Pacific")
119119
self.assertAlmostEqual(v_halfs["WP2"], 188.4, places=7)
120120
self.assertAlmostEqual(v_halfs["ROW"], 110.1, places=7)
121121
self.assertListEqual(list(impf_wp4.intensity), list(np.arange(0, 121, 5)))
@@ -135,7 +135,7 @@ def test_RMSF_pass(self):
135135
self.assertEqual(impfs.size(), 10)
136136
self.assertEqual(impfs.get_ids()["TC"], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
137137
self.assertEqual(impf_na1.intensity_unit, "m/s")
138-
self.assertEqual(impf_na1.name, "Caribbean and Mexico (NA1)")
138+
self.assertEqual(impf_na1.name, "Caribbean and Mexico")
139139
self.assertAlmostEqual(v_halfs["NA1"], 59.6, places=7)
140140
self.assertAlmostEqual(v_halfs["ROW"], 73.4, places=7)
141141
self.assertListEqual(list(impf_na1.intensity), list(np.arange(0, 121, 5)))
@@ -153,7 +153,7 @@ def test_quantile_pass(self):
153153
self.assertEqual(impfs.size(), 10)
154154
self.assertEqual(impfs_p10.size(), 10)
155155
self.assertEqual(impf_si.intensity_unit, "m/s")
156-
self.assertEqual(impf_si_p10.name, "South Indian (SI)")
156+
self.assertEqual(impf_si_p10.name, "South Indian")
157157
self.assertAlmostEqual(impf_si_p10.mdd.max(), 0.99999999880, places=5)
158158
self.assertAlmostEqual(impf_si.calc_mdr(30), 0.01620503041, places=5)
159159
intensity = np.random.randint(26, impf_si.intensity.max())
@@ -168,6 +168,35 @@ def test_get_countries_per_region(self):
168168
self.assertListEqual(out[2], [124, 840])
169169
self.assertListEqual(out[3], ["CAN", "USA"])
170170

171+
def test_get_imf_id_regions_per_countries(self):
172+
"""Test get_impf_id_regions_per_countries()"""
173+
ifs = ImpfSetTropCyclone()
174+
impf_id_reg_id_reg_name = ifs.get_impf_id_regions_per_countries(
175+
countries=["CHE"]
176+
)
177+
178+
# the first element of impf_id_reg_id_reg_name [0] is the impact function id,
179+
# the second [1] is the region id, the third [2] is the region name.
180+
self.assertEqual(impf_id_reg_id_reg_name[0][0], 10)
181+
self.assertEqual(impf_id_reg_id_reg_name[1][0], "ROW")
182+
self.assertEqual(impf_id_reg_id_reg_name[2][0], "Rest of The World")
183+
impf_id_reg_id_reg_name = ifs.get_impf_id_regions_per_countries(countries=[756])
184+
self.assertEqual(impf_id_reg_id_reg_name[0][0], 10)
185+
self.assertEqual(impf_id_reg_id_reg_name[1][0], "ROW")
186+
self.assertEqual(impf_id_reg_id_reg_name[2][0], "Rest of The World")
187+
188+
impf_id_reg_id_reg_name = ifs.get_impf_id_regions_per_countries(
189+
countries=["CHE", 268]
190+
)
191+
# CHE
192+
self.assertEqual(impf_id_reg_id_reg_name[0][0], 10)
193+
self.assertEqual(impf_id_reg_id_reg_name[1][0], "ROW")
194+
self.assertEqual(impf_id_reg_id_reg_name[2][0], "Rest of The World")
195+
# GEO (georgia, 268)
196+
self.assertEqual(impf_id_reg_id_reg_name[0][1], 3)
197+
self.assertEqual(impf_id_reg_id_reg_name[1][1], "NI")
198+
self.assertEqual(impf_id_reg_id_reg_name[2][1], "North Indian")
199+
171200

172201
# Execute Tests
173202
if __name__ == "__main__":

0 commit comments

Comments
 (0)