Skip to content

Commit 00de6ab

Browse files
merge develop-white
2 parents 9717c85 + aa0615f commit 00de6ab

31 files changed

+1733
-1048
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
build-and-test:
1313
name: 'Core / Unit Test Pipeline'
1414
runs-on: ubuntu-latest
15+
timeout-minutes: 20
1516
permissions:
1617
# For publishing results
1718
checks: write

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,10 @@ data/ISIMIP_crop/
176176

177177
# climada data results folder:
178178
results/
179+
180+
# Hidden files we want to track
181+
!.gitignore
182+
!.pre-commit-config.yaml
183+
!.pylintrc
184+
!.readthedocs.yml
185+
!.github

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://pre-commit.com for more information
2+
default_language_version:
3+
python: python3
4+
5+
# See https://pre-commit.com/hooks.html for more hooks
6+
repos:
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v3.2.0
9+
hooks:
10+
- id: end-of-file-fixer
11+
- id: trailing-whitespace
12+
13+
- repo: https://github.com/pycqa/isort
14+
rev: '5.13.2'
15+
hooks:
16+
- id: isort
17+
args: ["--profile", "black", "--filter-files"]
18+
19+
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
20+
- repo: https://github.com/psf/black-pre-commit-mirror
21+
rev: '24.4.2'
22+
hooks:
23+
- id: black-jupyter

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ Code freeze date: YYYY-MM-DD
1313
### Added
1414

1515
- `climada.util.interpolation` module for inter- and extrapolation util functions used in local exceedance intensity and return period functions [#930](https://github.com/CLIMADA-project/climada_python/pull/930)
16-
16+
1717
### Changed
1818

19+
- 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)
1920
- 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)
2021
- Renamed `climada.util.plot.subplots_from_gdf` to `climada.util.plot.plot_from_gdf` [#929](https://github.com/CLIMADA-project/climada_python/pull/929)
2122

2223
### Fixed
2324

24-
- Broken ECMWF links in pydoc of `climada.hazard.storm_europe` relocated.
25+
- Broken ECMWF links in pydoc of `climada.hazard.storm_europe` relocated. [#944](https://github.com/CLIMADA-project/climada_python/pull/944)
26+
- File handles are being closed after reading netcdf files with `climada.hazard` modules [#953](https://github.com/CLIMADA-project/climada_python/pull/953)
27+
- 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)
2528

2629
### Deprecated
2730

@@ -471,4 +474,3 @@ updated:
471474

472475
- `climada.enginge.impact.Impact.calc()` and `climada.enginge.impact.Impact.calc_impact_yearset()`
473476
[#436](https://github.com/CLIMADA-project/climada_python/pull/436).
474-

climada/engine/cost_benefit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from tabulate import tabulate
3333

3434
from climada.engine.impact_calc import ImpactCalc
35-
from climada.engine import Impact, ImpactFreqCurve
35+
from climada.engine.impact import Impact, ImpactFreqCurve
3636

3737
LOGGER = logging.getLogger(__name__)
3838

climada/engine/impact_calc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import geopandas as gpd
2828

2929
from climada import CONFIG
30-
from climada.engine import Impact
30+
from climada.engine.impact import Impact
3131

3232
LOGGER = logging.getLogger(__name__)
3333

climada/engine/test/test_impact_calc.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
from climada import CONFIG
3030
from climada.entity.entity_def import Entity
31-
from climada.entity import Exposures, ImpactFuncSet, ImpactFunc
32-
from climada.hazard.base import Hazard
31+
from climada.entity import Exposures, ImpactFuncSet, ImpactFunc, ImpfTropCyclone
32+
from climada.hazard.base import Hazard, Centroids
3333
from climada.engine import ImpactCalc, Impact
3434
from climada.engine.impact_calc import LOGGER as ILOG
3535
from climada.util.constants import ENT_DEMO_TODAY, DEMO_DIR
@@ -471,6 +471,34 @@ def test_stitch_risk_metrics(self):
471471
np.testing.assert_array_equal(eai_exp, [2.25, 1.25, 4.5])
472472
self.assertEqual(aai_agg, 8.0) # Sum of eai_exp
473473

474+
def test_single_exp_zero_mdr(self):
475+
"""Test for case where exposure has a single value and MDR or fraction contains zeros"""
476+
centroids = Centroids.from_lat_lon([-26.16], [28.20])
477+
haz = Hazard(
478+
intensity=sparse.csr_matrix(np.array([[31.5], [19.0]])),
479+
event_id=np.arange(2),
480+
event_name=[0,1],
481+
frequency=np.ones(2) / 2,
482+
fraction=sparse.csr_matrix(np.zeros((2,1))),
483+
date=np.array([0, 1]),
484+
centroids=centroids,
485+
haz_type='TC'
486+
)
487+
exp = Exposures({'value': [1.],
488+
'longitude': 28.22,
489+
'latitude': -26.17,
490+
'impf_TC': 1},
491+
crs="EPSG:4326")
492+
imp_evt = 0.00250988804927603
493+
aai_agg = imp_evt/2
494+
eai_exp = np.array([aai_agg])
495+
at_event = np.array([imp_evt, 0])
496+
exp.set_geometry_points()
497+
impf_tc = ImpfTropCyclone.from_emanuel_usa()
498+
impf_set = ImpactFuncSet([impf_tc])
499+
impf_set.check()
500+
imp = ImpactCalc(exp, impf_set, haz).impact(save_mat=True)
501+
check_impact(self, imp, haz, exp, aai_agg, eai_exp, at_event, at_event)
474502

475503
class TestImpactMatrixCalc(unittest.TestCase):
476504
"""Verify the computation of the impact matrix"""

climada/engine/unsequa/calc_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import numpy as np
3030

3131
from climada.util.value_representation import sig_dig as u_sig_dig
32-
from climada.engine.unsequa import UncOutput
32+
from climada.engine.unsequa.unc_output import UncOutput
3333

3434
LOGGER = logging.getLogger(__name__)
3535

climada/engine/unsequa/calc_cost_benefit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727

2828
from typing import Optional, Union
2929
import pandas as pd
30-
import numpy as np
3130
import pathos.multiprocessing as mp
3231
# use pathos.multiprocess fork of multiprocessing for compatibility
3332
# wiht notebooks and other environments https://stackoverflow.com/a/65001152/12454103
3433

3534
from climada.engine.cost_benefit import CostBenefit
36-
from climada.engine.unsequa import Calc, InputVar, UncCostBenefitOutput
37-
from climada.engine.unsequa.calc_base import _sample_parallel_iterator, _multiprocess_chunksize, _transpose_chunked_data
35+
from climada.engine.unsequa.input_var import InputVar
36+
from climada.engine.unsequa.unc_output import UncCostBenefitOutput
37+
from climada.engine.unsequa.calc_base import Calc, _sample_parallel_iterator, _multiprocess_chunksize, _transpose_chunked_data
3838
from climada.util import log_level
3939
from climada.hazard import Hazard
4040
from climada.entity import Entity

climada/engine/unsequa/calc_delta_climate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
# wiht notebooks and other environments https://stackoverflow.com/a/65001152/12454103
3535

3636
from climada.engine import ImpactCalc
37-
from climada.engine.unsequa import Calc, InputVar, UncImpactOutput
37+
from climada.engine.unsequa.input_var import InputVar
38+
from climada.engine.unsequa.unc_output import UncImpactOutput
3839
from climada.engine.unsequa.calc_base import (
40+
Calc,
3941
_sample_parallel_iterator,
4042
_multiprocess_chunksize,
4143
_transpose_chunked_data,

0 commit comments

Comments
 (0)