Skip to content

Commit

Permalink
Merge branch 'develop' into DahyannAraya-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
DahyannAraya committed May 2, 2024
2 parents bac6402 + a34a488 commit 464627e
Show file tree
Hide file tree
Showing 105 changed files with 8,235 additions and 6,271 deletions.
14 changes: 3 additions & 11 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# .coveragerc to control coverage.py

[run]
# Also report branch coverage
branch = True
# skip test files
omit =
*/test*/*
# Set concurrency type for correct coverage of multi-processing code
concurrency = multiprocessing

Expand All @@ -14,12 +15,3 @@ source = climada/
exclude_also =
# Main code is not run
if __name__ == .__main__.:

# Abtract methods are not run
@(abc\.)?abstractmethod

# Never fail when reporting
ignore_errors = True

[html]
directory = coverage
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior/error:
1.

Code example:
```python
# Your code here
```

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Climada Version:** [Version or branch]

**System Information (please complete the following information):**
- Operating system and version: [e.g. Ubuntu 22.04, macOS 14.3.1, Windows 10]
- Python version: [e.g. 3.10]
(to obtain this information execute > import sys >print(sys.version))

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/code-feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Code feature request
about: Suggest an idea to improve the code
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
steps:
-
name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
-
# Store the current date to use it as cache key for the environment
name: Get current date
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
-
name: Upload Coverage Reports
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-report-unittests-py${{ matrix.python-version }}
path: coverage/
7 changes: 6 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ build:
tools:
python: "mambaforge-4.10"

# Append fixed Python version to requirements
jobs:
pre_create_environment:
- echo " - python=3.9" >> requirements/env_climada.yml

conda:
environment: requirements/env_docs.yml
environment: requirements/env_climada.yml

python:
install:
Expand Down
5 changes: 5 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@
* Raphael Portmann
* Nicolas Colombi
* Leonie Villiger
* Kam Lam Yeung
* Sarah Hülsen
* Timo Schmid
* Luca Severino
* Samuel Juhel
121 changes: 117 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,133 @@ Code freeze date: YYYY-MM-DD

### Dependency Changes

### Changed

- Remove content tables and make minor improvements (fix typos and readability) in
CLIMADA tutorials. [#872](https://github.com/CLIMADA-project/climada_python/pull/872)
- Centroids complete overhaul. Most function should be backward compatible. Internal data is stored in a geodataframe attribute. Raster are now stored as points, and the meta attribute is removed. Several methds were deprecated or removed. [#787](https://github.com/CLIMADA-project/climada_python/pull/787)
- Improved error messages produced by `ImpactCalc.impact()` in case impact function in the exposures is not found in impf_set [#863](https://github.com/CLIMADA-project/climada_python/pull/863)

### Fixed

- Avoid an issue where a Hazard subselection would have a fraction matrix with only zeros as entries by throwing an error [#866](https://github.com/CLIMADA-project/climada_python/pull/866)

### Added

- climada.hazard.centroids.centr.Centroids.get_area_pixel
- climada.hazard.centroids.centr.Centroids.get_dist_coast
- climada.hazard.centroids.centr.Centroids.get_elevation
- climada.hazard.centroids.centr.Centroids.get_meta
- climada.hazard.centroids.centr.Centroids.get_pixel_shapes
- climada.hazard.centroids.centr.Centroids.to_crs
- climada.hazard.centroids.centr.Centroids.to_default_crs
- climada.hazard.centroids.centr.Centroids.write_csv
- climada.hazard.centroids.centr.Centroids.write_excel

### Deprecated

- climada.hazard.centroids.centr.Centroids.from_lat_lon
- climada.hazard.centroids.centr.Centroids.def set_area_pixel
- climada.hazard.centroids.centr.Centroids.def set_area_approx
- climada.hazard.centroids.centr.Centroids.set_dist_coast
- climada.hazard.centroids.centr.Centroids.empty_geometry_points
- climada.hazard.centroids.centr.Centroids.set_meta_to_lat_lon
- climada.hazard.centroids.centr.Centroids.set_lat_lon_to_meta

### Removed

- climada.hazard.base.Hazard.clear
- climada.hazard.base.Hazard.raster_to_vector
- climada.hazard.base.Hazard.read_mat
- climada.hazard.base.Hazard.reproject_raster
- climada.hazard.base.Hazard.set_vector
- climada.hazard.base.Hazard.vector_to_raster
- climada.hazard.centroids.centr.Centroids.calc_pixels_polygons
- climada.hazard.centroids.centr.Centroids.check
- climada.hazard.centroids.centr.Centroids.clear
- climada.hazard.centroids.centr.Centroids.equal
- climada.hazard.centroids.centr.Centroids.from_mat
- climada.hazard.centroids.centr.Centroids.from_base_grid
- climada.hazard.centroids.centr.Centroids.read_excel
- climada.hazard.centroids.centr.Centroids.read_hdf5
- climada.hazard.centroids.centr.Centroids.read_mat
- climada.hazard.centroids.centr.Centroids.set_elevation
- climada.hazard.centroids.centr.Centroids.set_geometry_points
- climada.hazard.centroids.centr.Centroids.set_lat_lon
- climada.hazard.centroids.centr.Centroids.set_raster_file
- climada.hazard.centroids.centr.Centroids.set_raster_from_pnt_bounds
- climada.hazard.centroids.centr.Centroids.set_vector_file
- climada.hazard.centroids.centr.Centroids.values_from_raster_files
- climada.hazard.centroids.centr.Centroids.values_from_vector_files
- climada.hazard.centroids.centr.generate_nat_earth_centroids
- `requirements/env_docs.yml`. The regular environment specs are now used to build the online documentation [#687](https://github.com/CLIMADA-project/climada_python/pull/687)

## 4.1.1

Release date: 2024-02-21

### Fixed

- Fix `util.coordinates.latlon_bounds` for cases where the specified buffer is very large so that the bounds cover more than the full longitudinal range `[-180, 180]` [#839](https://github.com/CLIMADA-project/climada_python/pull/839)
- Fix `climada.hazard.trop_cyclone` for TC tracks crossing the antimeridian [#839](https://github.com/CLIMADA-project/climada_python/pull/839)

## 4.1.0

Release date: 2024-02-14

### Dependency Changes

Added:

- `pyproj` >=3.5
- `numexpr` >=2.9

Updated:

- `contextily` >=1.3 → >=1.5
- `dask` >=2023 → >=2024
- `numba` >=0.57 → >=0.59
- `pandas` >=2.1 &rarr; >=2.1,<2.2
- `pint` >=0.22 &rarr; >=0.23
- `scikit-learn` >=1.3 &rarr; >=1.4
- `scipy` >=1.11 &rarr; >=1.12
- `sparse` >=0.14 &rarr; >=0.15
- `xarray` >=2023.8 &rarr; >=2024.1
- `overpy` =0.6 &rarr; =0.7
- `peewee` =3.16.3 &rarr; =3.17.1

Removed:

- `proj` (in favor of `pyproj`)

### Added

- Convenience method `api_client.Client.get_dataset_file`, combining `get_dataset_info` and `download_dataset`, returning a single file objet. [#821](https://github.com/CLIMADA-project/climada_python/pull/821)
- Read and Write methods to and from csv files for the `DiscRates` class. [#818](ttps://github.com/CLIMADA-project/climada_python/pull/818)
- Add `CalcDeltaClimate` to unsequa module to allow uncertainty and sensitivity analysis of impact change calculations [#844](https://github.com/CLIMADA-project/climada_python/pull/844)
- Add function `safe_divide` in util which handles division by zero and NaN values in the numerator or denominator [#844](https://github.com/CLIMADA-project/climada_python/pull/844)
- Add reset_frequency option for the impact.select() function. [#847](https://github.com/CLIMADA-project/climada_python/pull/847)

### Changed

- Update Developer and Installation Guides for easier accessibility by new developers. [808](https://github.com/CLIMADA-project/climada_python/pull/808)
- Add `shapes` argument to `geo_im_from_array` to allow flexible turning on/off of plotting coastline in `plot_intensity`. [#805](https://github.com/CLIMADA-project/climada_python/pull/805)
- Update `CONTRIBUTING.md` to better explain types of contributions to this repository [#797](https://github.com/CLIMADA-project/climada_python/pull/797)
- The default tile layer in Exposures maps is not Stamen Terrain anymore, but [CartoDB Positron](https://github.com/CartoDB/basemap-styles). Affected methods are `climada.engine.Impact.plot_basemap_eai_exposure`,`climada.engine.Impact.plot_basemap_impact_exposure` and `climada.entity.Exposures.plot_basemap`. [#798](https://github.com/CLIMADA-project/climada_python/pull/798)
- Recommend using Mamba instead of Conda for installing CLIMADA [#809](https://github.com/CLIMADA-project/climada_python/pull/809)
- `Hazard.from_xarray_raster` now allows arbitrary values as 'event' coordinates [#837](https://github.com/CLIMADA-project/climada_python/pull/837)
- `climada.test.get_test_file` now compares the version of the requested test dataset with the version of climada itself and selects the most appropriate dataset. In this way a test file can be updated without the need of changing the code of the unittest. [#822](https://github.com/CLIMADA-project/climada_python/pull/822)
- Explicitly require `pyproj` instead of `proj` (the latter is now implicitly required) [#845](https://github.com/CLIMADA-project/climada_python/pull/845)

### Fixed

- `Hazard.from_xarray_raster` now stores strings as default values for `Hazard.event_name` [#795](https://github.com/CLIMADA-project/climada_python/pull/795)
- Fix the dist_approx util function when used with method="geosphere" and log=True and points that are very close. [#792](https://github.com/CLIMADA-project/climada_python/pull/792)

### Deprecated

### Removed
- `climada.util.yearsets.sample_from_poisson`: fix a bug ([#819](https://github.com/CLIMADA-project/climada_python/issues/819)) and inconsistency that occurs when lambda events per year (`lam`) are set to 1. [[#823](https://github.com/CLIMADA-project/climada_python/pull/823)]
- In the TropCyclone class in the Holland model 2008 and 2010 implementation, a doublecounting of translational velocity is removed [#833](https://github.com/CLIMADA-project/climada_python/pull/833)
- `climada.util.test.test_finance` and `climada.test.test_engine` updated to recent input data from worldbank [#841](https://github.com/CLIMADA-project/climada_python/pull/841)
- Set `nodefaults` in Conda environment specs because `defaults` are not compatible with conda-forge [#845](https://github.com/CLIMADA-project/climada_python/pull/845)
- Avoid redundant calls to `np.unique` in `Impact.impact_at_reg` [#848](https://github.com/CLIMADA-project/climada_python/pull/848)

## 4.0.1

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ This is the Python (3.9+) version of CLIMADA - please see [here](https://github.
## Getting started

CLIMADA runs on Windows, macOS and Linux.
The released versions of the CLIMADA core can be installed directly through Anaconda:
The released versions of CLIMADA are available from [conda-forge](https://anaconda.org/conda-forge/climada).
Use the [Mamba](https://mamba.readthedocs.io/en/latest/) package manager to install it:

```shell
conda install -c conda-forge climada
mamba install -c conda-forge climada
```

It is **highly recommended** to install CLIMADA into a **separate** Anaconda environment.
It is **highly recommended** to install CLIMADA into a **separate** Conda environment.
See the [installation guide](https://climada-python.readthedocs.io/en/latest/guide/install.html) for further information.

Follow the [tutorials](https://climada-python.readthedocs.io/en/stable/tutorial/1_main_climada.html) in a Jupyter Notebook to see what can be done with CLIMADA and how.
Expand Down
2 changes: 1 addition & 1 deletion climada/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '4.0.2-dev'
__version__ = '4.1.2-dev'
4 changes: 2 additions & 2 deletions climada/conf/climada.conf
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"cache_db": "{local_data.system}/.downloads.db",
"cache_enabled": true,
"cache_dir": "{local_data.system}/.apicache",
"supported_hazard_types": ["river_flood", "tropical_cyclone", "storm_europe", "relative_cropyield", "wildfire", "earthquake", "flood"],
"supported_exposures_types": ["litpop", "crop_production", "ssp_population"]
"supported_hazard_types": ["river_flood", "tropical_cyclone", "storm_europe", "relative_cropyield", "wildfire", "earthquake", "flood", "hail"],
"supported_exposures_types": ["litpop", "crop_production", "ssp_population", "crops"]
}
}
3 changes: 2 additions & 1 deletion climada/engine/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from matplotlib.ticker import PercentFormatter, ScalarFormatter
from matplotlib.colors import ListedColormap, BoundaryNorm
import cartopy.crs as ccrs
from matplotlib import colormaps as cm
import pyproj
import shapely
from cartopy.io import shapereader
Expand Down Expand Up @@ -88,7 +89,7 @@
warnprob_colors_extended = np.repeat(warnprob_colors, 10, axis=0)
CMAP_WARNPROB = ListedColormap(warnprob_colors_extended)
# colors for impact forecast
color_map_pre = plt.get_cmap("plasma", 90)
color_map_pre = cm.get_cmap("plasma").resampled(90)
impact_colors = color_map_pre(np.linspace(0, 1, 90))
white_extended = np.repeat([[255 / 255, 255 / 255, 255 / 255, 1]], 10, axis=0)
impact_colors_extended = np.append(white_extended, impact_colors, axis=0)
Expand Down
31 changes: 26 additions & 5 deletions climada/engine/impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,12 @@ def impact_at_reg(self, agg_regions=None):
at_reg_event = np.hstack(
[
self.imp_mat[:, np.where(agg_regions == reg)[0]].sum(1)
for reg in np.unique(agg_reg_unique)
for reg in agg_reg_unique
]
)

at_reg_event = pd.DataFrame(
at_reg_event, columns=np.unique(agg_reg_unique), index=self.event_id
at_reg_event, columns=agg_reg_unique, index=self.event_id
)

return at_reg_event
Expand Down Expand Up @@ -1475,9 +1475,14 @@ def _cen_return_imp(imp, freq, imp_th, return_periods):

return imp_fit

def select(self,
event_ids=None, event_names=None, dates=None,
coord_exp=None):
def select(
self,
event_ids=None,
event_names=None,
dates=None,
coord_exp=None,
reset_frequency=False
):
"""
Select a subset of events and/or exposure points from the impact.
If multiple input variables are not None, it returns all the impacts
Expand Down Expand Up @@ -1509,6 +1514,9 @@ def select(self,
coord_exp : np.array, optional
Selection of exposures coordinates [lat, lon] (in degrees)
The default is None.
reset_frequency : bool, optional
Change frequency of events proportional to difference between first and last
year (old and new). Assumes annual frequency values. Default: False.
Raises
------
Expand Down Expand Up @@ -1580,6 +1588,19 @@ def select(self,
LOGGER.info("The total value cannot be re-computed for a "
"subset of exposures and is set to None.")

# reset frequency if date span has changed (optional):
if reset_frequency:
if self.frequency_unit not in ['1/year', 'annual', '1/y', '1/a']:
LOGGER.warning("Resetting the frequency is based on the calendar year of given"
" dates but the frequency unit here is %s. Consider setting the frequency"
" manually for the selection or changing the frequency unit to %s.",
self.frequency_unit, DEF_FREQ_UNIT)
year_span_old = np.abs(dt.datetime.fromordinal(self.date.max()).year -
dt.datetime.fromordinal(self.date.min()).year) + 1
year_span_new = np.abs(dt.datetime.fromordinal(imp.date.max()).year -
dt.datetime.fromordinal(imp.date.min()).year) + 1
imp.frequency = imp.frequency * year_span_old / year_span_new

# cast frequency vector into 2d array for sparse matrix multiplication
freq_mat = imp.frequency.reshape(len(imp.frequency), 1)
# .A1 reduce 1d matrix to 1d array
Expand Down
Loading

0 comments on commit 464627e

Please sign in to comment.