Skip to content

Commit 37da530

Browse files
Merge branch 'develop' into feature/cyclostrophic-as-parameter
2 parents 5044b73 + 86061e2 commit 37da530

File tree

9 files changed

+153
-166
lines changed

9 files changed

+153
-166
lines changed

.readthedocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
version: 2
22

3+
sphinx:
4+
configuration: doc/conf.py
5+
36
build:
47
os: "ubuntu-22.04"
58
tools:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Code freeze date: YYYY-MM-DD
3131

3232
### Changed
3333

34+
- `Centroids.append` now takes multiple arguments and provides a performance boost when doing so [#989](https://github.com/CLIMADA-project/climada_python/pull/989)
3435
- `climada.util.coordinates.get_country_geometries` function: Now throwing a ValueError if unregognized ISO country code is given (before, the invalid ISO code was ignored) [#980](https://github.com/CLIMADA-project/climada_python/pull/980)
3536
- Improved scaling factors implemented in `climada.hazard.trop_cyclone.apply_climate_scenario_knu` to model the impact of climate changes to tropical cyclones [#734](https://github.com/CLIMADA-project/climada_python/pull/734)
3637
- In `climada.util.plot.geo_im_from_array`, NaNs are plotted in gray while cells with no centroid are not plotted [#929](https://github.com/CLIMADA-project/climada_python/pull/929)
@@ -47,6 +48,7 @@ Code freeze date: YYYY-MM-DD
4748

4849
### Fixed
4950

51+
- Resolved an issue where windspeed computation was much slower than in Climada v3 [#989](https://github.com/CLIMADA-project/climada_python/pull/989)
5052
- File handles are being closed after reading netcdf files with `climada.hazard` modules [#953](https://github.com/CLIMADA-project/climada_python/pull/953)
5153
- Avoids a ValueError in the impact calculation for cases with a single exposure point and MDR values of 0, by explicitly removing zeros in `climada.hazard.Hazard.get_mdr` [#933](https://github.com/CLIMADA-project/climada_python/pull/948)
5254

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ install_test : ## Test installation was successful
2929

3030
.PHONY : data_test
3131
data_test : ## Test data APIs
32-
python script/jenkins/test_data_api.py
32+
pytest $(PYTEST_JUNIT_ARGS) script/jenkins/test_data_api.py
3333

3434
.PHONY : notebook_test
3535
notebook_test : ## Test notebooks in doc/tutorial
36-
python script/jenkins/test_notebooks.py report
36+
pytest $(PYTEST_JUNIT_ARGS) script/jenkins/test_notebooks.py
3737

3838
.PHONY : integ_test
3939
integ_test : ## Integration tests execution with xml reports

climada/hazard/centroids/centr.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,16 @@ def from_pnt_bounds(cls, points_bounds, res, crs=DEF_CRS):
331331
}
332332
)
333333

334-
def append(self, centr):
335-
"""Append Centroids
334+
def append(self, *centr):
335+
"""Append Centroids to the current centroid object for concatenation.
336+
337+
This method checks that all centroids use the same CRS, appends the list of centroids to
338+
the initial Centroid object and eventually concatenates them to create a single centroid
339+
object with the union of all centroids.
336340
337341
Note that the result might contain duplicate points if the object to append has an overlap
338-
with the current object.
342+
with the current object. Remove duplicates by either using :py:meth:`union`
343+
or calling :py:meth:`remove_duplicate_points` after appending.
339344
340345
Parameters
341346
----------
@@ -351,22 +356,25 @@ def append(self, centr):
351356
union : Union of Centroid objects.
352357
remove_duplicate_points : Remove duplicate points in a Centroids object.
353358
"""
354-
if not u_coord.equal_crs(self.crs, centr.crs):
355-
raise ValueError(
356-
f"The given centroids use different CRS: {self.crs}, {centr.crs}. "
357-
"The centroids are incompatible and cannot be concatenated."
358-
)
359-
self.gdf = pd.concat([self.gdf, centr.gdf])
359+
for other in centr:
360+
if not u_coord.equal_crs(self.crs, other.crs):
361+
raise ValueError(
362+
f"The given centroids use different CRS: {self.crs}, {other.crs}. "
363+
"The centroids are incompatible and cannot be concatenated."
364+
)
365+
self.gdf = pd.concat([self.gdf] + [other.gdf for other in centr])
360366

361367
def union(self, *others):
362-
"""Create the union of Centroids objects
368+
"""Create the union of the current Centroids object with one or more other centroids
369+
objects by passing the list of centroids to :py:meth:`append` for concatenation and then
370+
removes duplicates.
363371
364372
All centroids must have the same CRS. Points that are contained in more than one of the
365373
Centroids objects will only be contained once (i.e. duplicates are removed).
366374
367375
Parameters
368376
----------
369-
others : list of Centroids
377+
others : Centroids
370378
Centroids contributing to the union.
371379
372380
Returns
@@ -375,8 +383,8 @@ def union(self, *others):
375383
Centroids object containing the union of all Centroids.
376384
"""
377385
centroids = copy.deepcopy(self)
378-
for cent in others:
379-
centroids.append(cent)
386+
centroids.append(*others)
387+
380388
return centroids.remove_duplicate_points()
381389

382390
def remove_duplicate_points(self):

climada/hazard/centroids/test/test_centr.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,20 @@ def test_append_dif_crs(self):
816816
with self.assertRaises(ValueError):
817817
self.centr.append(centr2)
818818

819+
def test_append_multiple_arguments(self):
820+
"""Test passing append() multiple arguments in the form of a list of Centroids."""
821+
# create a single centroid
822+
lat, lon = np.array([1, 2]), np.array([1, 2])
823+
centr = Centroids(lat=lat, lon=lon)
824+
# create a list of centroids
825+
coords = [(np.array([3, 4]), np.array([3, 4]))]
826+
centroids_list = [Centroids(lat=lat, lon=lon) for lat, lon in coords]
827+
828+
centr.append(*centroids_list)
829+
830+
np.testing.assert_array_equal(centr.lat, [1, 2, 3, 4])
831+
np.testing.assert_array_equal(centr.lon, [1, 2, 3, 4])
832+
819833
def test_remove_duplicate_pass(self):
820834
"""Test remove_duplicate_points"""
821835
centr = Centroids(

requirements/env_climada.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ dependencies:
2424
- pint>=0.24
2525
- pip
2626
- pycountry>=24.6
27-
- pyepsg>=0.4
2827
- pyproj>=3.5
2928
- pytables>=3.7
3029
- pyxlsb>=1.0
@@ -33,7 +32,7 @@ dependencies:
3332
- salib>=1.5
3433
- seaborn>=0.13
3534
- scikit-learn>=1.5
36-
- scipy>=1.13
35+
- scipy>=1.13,<1.15 # 1.15 is not compatible with climada_petals, climada_petals.engine.test.test_supplychain fails with "'Series' has no attribute 'nonzero'"
3736
- sparse>=0.15
3837
- statsmodels>=0.14
3938
- tabulate>=0.9

script/jenkins/test_data_api.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
import datetime as dt
2323
import unittest
2424
from pathlib import Path
25-
from sys import dont_write_bytecode
2625

2726
import numpy as np
28-
import pandas as pd
29-
import xmlrunner
27+
import pytest
3028
from pandas_datareader import wb
3129

3230
from climada import CONFIG
@@ -125,8 +123,7 @@ def test_icon_centroids_download(self):
125123

126124
# Execute Tests
127125
if __name__ == "__main__":
128-
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestDataAvail)
129126
from sys import argv
130127

131128
outputdir = argv[1] if len(argv) > 1 else str(Path.cwd().joinpath("tests_xml"))
132-
xmlrunner.XMLTestRunner(output=outputdir).run(TESTS)
129+
pytest.main([f"--junitxml={outputdir}/tests.xml", __file__])

0 commit comments

Comments
 (0)