Skip to content

Commit

Permalink
Merge branch 'develop' into feature/add-missing-JRC-flood-impact-func…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
aleeciu committed Aug 7, 2024
2 parents a1dac9b + b020a69 commit bc9e612
Show file tree
Hide file tree
Showing 56 changed files with 7,903 additions and 521 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[report]
omit =
*/climada/*
*/test*/*
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: GitHub CI

on: [push]

jobs:
ci:
name: Petals
uses: ./.github/workflows/testing.yml
with:
petals_branch: ${{ github.ref }}
permissions:
# For publishing results
checks: write
99 changes: 99 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Petals Testing

# 'Reusable workflow', can be triggered from other workflows
on:
workflow_call:
inputs:
petals_branch:
description: Branch of CLIMADA Petals to check out
type: string
default: develop
required: false
core_branch:
description: Branch of CLIMADA Core to test against
type: string
default: develop
required: false


# Use bash explicitly for being able to enter the conda environment
defaults:
run:
shell: bash -el {0}

jobs:
build-and-test:
name: Unit Test Pipeline
runs-on: ubuntu-latest
permissions:
# For publishing results
checks: write

# Run this test for different Python versions
strategy:
# Do not abort other tests if only a single one fails
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
-
name: Checkout Petals
uses: actions/checkout@v4
with:
repository: CLIMADA-project/climada_petals
path: climada_petals
ref: ${{ inputs.petals_branch }}
-
name: Checkout Core
uses: actions/checkout@v4
with:
repository: CLIMADA-project/climada_python
path: climada_python
ref: ${{ inputs.core_branch }}
-
# Store the current date to use it as cache key for the environment
name: Get current date
id: date
run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}"
-
name: Create Environment with Mamba
uses: mamba-org/setup-micromamba@v1
with:
environment-name: climada_env_${{ matrix.python-version }}
environment-file: climada_python/requirements/env_climada.yml
# NOTE: Might be able to give second spec file in create-args in future
# micromamba version
create-args: >-
python=${{ matrix.python-version }}
make
# Persist environment for branch, Python version, single day
cache-environment-key: env-${{ github.ref }}-${{ matrix.python-version }}-${{ steps.date.outputs.date }}
-
name: Update Environment for Petals
run: |
micromamba update -n climada_env_${{ matrix.python-version }} -f climada_petals/requirements/env_climada.yml
-
name: Install CLIMADA Core and Petals
run: |
python -m pip install "./climada_python[test]" "./climada_petals"
-
name: Run Unit Tests
working-directory: climada_petals/
run: |
make unit_test
-
name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
junit_files: climada_petals/tests_xml/tests.xml
check_name: "Petals / Unit Test Results (${{ matrix.python-version }})"
comment_mode: "off"
-
name: Upload Coverage Reports
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report-petals-unittests-py${{ matrix.python-version }}
path: climada_petals/coverage/
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
* Chris Fairless
* Jan Wüthrich
* Zélie Standhanske
* Lukas Riedel
62 changes: 51 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,66 @@ Code freeze date: YYYY-MM-DD

### Dependency Changes

Added dependencies:

- `pymrio` >=5.2.0
- `overpy`
- `osm-flex` >=1.1.1

### Added

### Changed

- Restructured `Supplychain` module, which now uses `pymrio` to download and handle multi-regional input output tables [#66](https://github.com/CLIMADA-project/climada_petals/pull/66)
- Restructured `openstreetmap` module to draw functionalities from external package osm-flex [#103](https://github.com/CLIMADA-project/climada_petals/pull/103)
- As part of `climada_petals.hazard.tc_rainfield`, implement a new, physics-based TC rain model ("TCR") in addition to the existing implementation of the purely statistical R-CLIPER model ([#85](https://github.com/CLIMADA-project/climada_petals/pull/85))

### Fixed

### Deprecated

### Removed

## 5.0.0

Release date: 2024-07-19

### Dependency Changes

Added:

- `cdsapi` >=0.7
- `importlib-metadata` <8.0
- `meson-python` >=0.15,<0.16
- `rioxarray` >=0.13
- `ruamel.yaml` >=0.18
- `seaborn` >=0.13
- `xesmf` >=0.8

### Changed

- Adaptations to refactoring of the `climada.hazard.Centroids` class, to be compatible with `climada>=5.0` [#122](https://github.com/CLIMADA-project/climada_petals/pull/122)
- Always assign `csr_matrix` to `Hazard.intensity` [#129](https://github.com/CLIMADA-project/climada_petals/pull/129) [#131](https://github.com/CLIMADA-project/climada_petals/pull/131)

### Fixed

- Fix `climada.hazard.tc_rainfield` for TC tracks crossing the antimeridian [#105](https://github.com/CLIMADA-project/climada_petals/pull/105)
- Update the table of content for the tutorials [#125](https://github.com/CLIMADA-project/climada_petals/pull/125)
- Store all-zero fraction matrices in `LowFlow` and `WildFire` hazards [#129](https://github.com/CLIMADA-project/climada_petals/pull/129) [#131](https://github.com/CLIMADA-project/climada_petals/pull/131)

## 4.1.0

Release date: 2024-02-19

### Dependency Changes

Updated:

- `climada` >=4.0 &rarr; ==4.1

Added:

- `overpy` >=0.7
- `osm-flex` >=1.1.1
- `pymrio` >=0.5

### Changed

- Restructured `Supplychain` module, which now uses `pymrio` to download and handle multi-regional input output tables [#66](https://github.com/CLIMADA-project/climada_petals/pull/66)
- Restructured `openstreetmap` module to draw functionalities from external package osm-flex [#103](https://github.com/CLIMADA-project/climada_petals/pull/103)
- As part of `climada_petals.hazard.tc_rainfield`, implement a new, physics-based TC rain model ("TCR") in addition to the existing implementation of the purely statistical R-CLIPER model ([#85](https://github.com/CLIMADA-project/climada_petals/pull/85))
- Conda environment now avoids `default` channel packages, as these are incompatible to conda-forge [#110](https://github.com/CLIMADA-project/climada_petals/pull/110)

## 4.0.2

Release date: 2023-09-27
Expand Down Expand Up @@ -103,7 +143,7 @@ Release aligned with climada (core) 3.3.

### Changed

- Rework docs and switch to Book theme [#63](ttps://github.com/CLIMADA-project/climada_petals/pull/63)
- Rework docs and switch to Book theme [#63](https://github.com/CLIMADA-project/climada_petals/pull/63)

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
PYTEST_JUNIT_ARGS = --junitxml=tests_xml/tests.xml

PYTEST_COV_ARGS = \
--cov --cov-config=.coveragerc --cov-report html --cov-report xml \
--cov-report term:skip-covered
--cov --cov-config=.coveragerc --cov-report html:coverage \
--cov-report xml:coverage.xml --cov-report term:skip-covered

PYTEST_ARGS = $(PYTEST_JUNIT_ARGS) $(PYTEST_COV_ARGS)

Expand Down
3 changes: 3 additions & 0 deletions climada_petals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
DEMO_DIR.joinpath('pepic_miroc5_ewembi_historical_2005soc_co2_yield-whe-noirr_global_annual_DEMO_TJANJIN_1861_2005.nc'),
DEMO_DIR.joinpath('lpjml_ipsl-cm5a-lr_ewembi_historical_2005soc_co2_yield-whe-noirr_annual_FR_DE_DEMO_1861_2005.nc'),
],
'climada_petals/data/tc_surge_bathtub': [
DEMO_DIR.joinpath('SRTM15+V2.0_sample.tiff'),
],
'climada_petals/data/wildfire': [
DEMO_DIR.joinpath('Portugal_firms_June_2017.csv'),
DEMO_DIR.joinpath('Portugal_firms_2016_17_18_MODIS.csv'),
Expand Down
2 changes: 1 addition & 1 deletion climada_petals/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '4.0.3-dev'
__version__ = '5.0.1-dev'
Binary file not shown.
5 changes: 3 additions & 2 deletions climada_petals/hazard/emulator/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from shapely.geometry import Polygon

from climada.hazard import Centroids
from climada.util.constants import NATEARTH_CENTROIDS
import climada.util.coordinates as u_coord
import climada_petals.hazard.emulator.const as const

Expand Down Expand Up @@ -102,8 +103,8 @@ def centroids(self, latlon=None, res_as=360):
centroids : climada.hazard.Centroids object
"""
if latlon is None:
centroids = Centroids.from_base_grid(res_as=res_as)
centroids.set_meta_to_lat_lon()
# default centroids: Natural Earth data at given resolution
centroids = Centroids.from_hdf5(NATEARTH_CENTROIDS[res_as])
else:
centroids = Centroids.from_lat_lon(*latlon)
msk = shapely.vectorized.contains(self.shape, centroids.lon, centroids.lat)
Expand Down
8 changes: 2 additions & 6 deletions climada_petals/hazard/landslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ def from_prob(cls, bbox, path_sourcefile, corr_fact=10e6, n_years=500,

haz = cls()
# raster with occurrence probs
haz.centroids.meta, prob_matrix = \
meta, prob_matrix = \
u_coord.read_raster(path_sourcefile, geometry=[shapely.geometry.box(*bbox, ccw=True)])
haz.centroids = Centroids.from_meta(meta)
prob_matrix = prob_matrix.squeeze()/corr_fact

# sample events from probabilities
Expand All @@ -314,11 +315,6 @@ def from_prob(cls, bbox, path_sourcefile, corr_fact=10e6, n_years=500,
haz.event_name = np.array(range(n_years))
haz.event_id = np.array(range(n_years))

if not haz.centroids.meta['crs'].is_epsg_code:
haz.centroids.meta['crs'] = haz.centroids.meta['crs'
].from_user_input(DEF_CRS)
haz.centroids.set_geometry_points()

haz.check()

return haz
Expand Down
14 changes: 4 additions & 10 deletions climada_petals/hazard/low_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,11 @@ def events_from_clusters(self, centroids):
self.orig = np.ones(uniq_ev.size)
self.set_frequency()

self.intensity = self._intensity_loop(uniq_ev, centroids.coord, res_centr, num_centr)
intensity = self._intensity_loop(uniq_ev, centroids.coord, res_centr, num_centr)

# Following values are defined for each event and centroid
self.intensity = self.intensity.tocsr()
self.fraction = self.intensity.copy()
self.fraction.data.fill(1.0)
self.intensity = intensity.tocsr()
self.fraction = sparse.csr_matrix(self.intensity.shape)

def identify_clusters(self, clus_thresh_xy=None, clus_thresh_t=None, min_samples=None):
"""call clustering functions to identify the clusters inside the dataframe
Expand Down Expand Up @@ -539,11 +538,7 @@ def _centroids_resolution(centroids):
-------
float
"""
if centroids.meta:
res_centr = abs(centroids.meta['transform'][4]), \
centroids.meta['transform'][0]
else:
res_centr = np.abs(u_coord.get_resolution(centroids.lat, centroids.lon))
res_centr = np.abs(u_coord.get_resolution(centroids.lat, centroids.lon))
if np.abs(res_centr[0] - res_centr[1]) > 1.0e-6:
LOGGER.warning('Centroids do not represent regular pixels %s.', str(res_centr))
return (res_centr[0] + res_centr[1]) / 2
Expand Down Expand Up @@ -645,7 +640,6 @@ def _init_centroids(dis_xarray, centr_res_factor=1):
(dis_xarray.lon.values.min(), dis_xarray.lat.values.min(),
dis_xarray.lon.values.max(), dis_xarray.lat.values.max()),
res=res_data / centr_res_factor)
centroids.set_meta_to_lat_lon()
centroids.set_area_approx()
centroids.set_on_land()
centroids.empty_geometry_points()
Expand Down
5 changes: 1 addition & 4 deletions climada_petals/hazard/relative_cropyield.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ def from_isimip_netcdf(cls, input_dir=None, filename=None, bbox=None,
haz.units = 't / y / ha'
haz.date = np.array(dt.str_to_date(
[event_ + '-01-01' for event_ in haz.event_name]))
haz.centroids.set_meta_to_lat_lon()
haz.centroids.region_id = (
haz.centroids.gdf['region_id'] = (
coord.coord_on_land(haz.centroids.lat, haz.centroids.lon)).astype(dtype=int)
haz.check()
return haz
Expand Down Expand Up @@ -371,8 +370,6 @@ def plot_time_series(self, event=None):
else:
event = [str(n) for n in range(event[0], event[1] + 1)]

self.centroids.set_meta_to_lat_lon()

# definition of plot extents
len_lat = abs(self.centroids.lat[0] - self.centroids.lat[-1]) * (2.5 / 13.5)
len_lon = abs(self.centroids.lon[0] - self.centroids.lon[-1]) * (5 / 26)
Expand Down
25 changes: 25 additions & 0 deletions climada_petals/hazard/rf_glofas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
This file is part of CLIMADA.
Copyright (C) 2017 ETH Zurich, CLIMADA contributors listed in AUTHORS.
CLIMADA is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free
Software Foundation, version 3.
CLIMADA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with CLIMADA. If not, see <https://www.gnu.org/licenses/>.
---
Export functions of the GloFAS River Flood Module
"""

from .setup import setup_all
from .river_flood_computation import RiverFloodInundation
from .rf_glofas import hazard_series_from_dataset
from .transform_ops import save_file
Loading

0 comments on commit bc9e612

Please sign in to comment.