Skip to content

Commit

Permalink
Merge pull request #112 from spjuhel/develop
Browse files Browse the repository at this point in the history
Version 0.5.9
  • Loading branch information
spjuhel authored Apr 23, 2024
2 parents 04a30e5 + fe0a719 commit 32d2ada
Show file tree
Hide file tree
Showing 8 changed files with 504 additions and 92 deletions.
69 changes: 49 additions & 20 deletions boario/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import numpy as np
import numpy.typing as npt
import pandas as pd
from pandas.api.types import is_numeric_dtype


from boario import logger
from boario.utils.recovery_functions import (
Expand Down Expand Up @@ -190,6 +192,7 @@ def _instantiate(
occurrence: int = 1,
duration: int = 1,
name: Optional[str] = None,
**_,
):
return cls(impact=impact, occurrence=occurrence, duration=duration, name=name)

Expand All @@ -201,7 +204,7 @@ def from_series(
occurrence: int = 1,
duration: int = 1,
name: Optional[str] = None,
**kwarg,
**kwargs,
) -> Event:
"""Create an event for an impact given as a pd.Series.
Expand All @@ -215,7 +218,7 @@ def from_series(
The duration of the event (entire impact applied during this number of steps). Defaults to 1.
name : Optional[str]
A possible name for the event, for convenience. Defaults to None.
**kwarg :
**kwargs :
Keyword arguments keyword arguments to pass to the instantiating method
(depends on the type of event).
Expand Down Expand Up @@ -260,7 +263,7 @@ def from_series(
occurrence=occurrence,
duration=duration,
name=name,
**kwarg,
**kwargs,
)

@classmethod
Expand All @@ -271,7 +274,7 @@ def from_dataframe(
occurrence: int = 1,
duration: int = 1,
name: Optional[str] = None,
**kwarg,
**kwargs,
) -> Event:
"""Convenience function for DataFrames. See :meth:`~boario.event.Event.from_series`. This constructor only apply ``.squeeze()`` to the given DataFrame.
Expand All @@ -285,7 +288,7 @@ def from_dataframe(
The duration of the event (entire impact applied during this number of steps). Defaults to 1.
name : Optional[str]
A possible name for the event, for convenience. Defaults to None.
**kwarg :
**kwargs :
Keyword arguments
Other keyword arguments to pass to the instantiate method (depends on the type of event)
Expand All @@ -308,7 +311,7 @@ def from_dataframe(
occurrence=occurrence,
duration=duration,
name=name,
**kwarg,
**kwargs,
)

@classmethod
Expand Down Expand Up @@ -365,7 +368,7 @@ def from_scalar_industries(
occurrence: Optional[int] = 1,
duration: Optional[int] = 1,
name: Optional[str] = None,
**kwarg,
**kwargs,
) -> Event:
"""Creates an Event from a scalar and a list of industries affected.
Expand All @@ -390,7 +393,7 @@ def from_scalar_industries(
The duration of the event (entire impact applied during this number of steps). Defaults to 1.
name : Optional[str]
A possible name for the event, for convenience. Defaults to None.
**kwarg :
**kwargs :
Keyword arguments
Other keyword arguments to pass to the instantiate method (depends on the type of event)
Expand Down Expand Up @@ -435,7 +438,7 @@ def from_scalar_industries(
occurrence=occurrence,
duration=duration,
name=name,
**kwarg,
**kwargs,
)

@classmethod
Expand All @@ -450,7 +453,7 @@ def from_scalar_regions_sectors(
occurrence: int = 1,
duration: int = 1,
name: Optional[str] = None,
**kwarg,
**kwargs,
) -> Event:
"""Creates an Event from a scalar, a list of regions and a list of sectors affected.
Expand All @@ -477,7 +480,7 @@ def from_scalar_regions_sectors(
The duration of the event (entire impact applied during this number of steps). Defaults to 1.
name : Optional[str], optional
A possible name for the event, for convenience. Defaults to None.
**kwarg :
**kwargs :
Keyword arguments
Other keyword arguments to pass to the instantiate method (depends on the type of event)
Expand Down Expand Up @@ -592,7 +595,7 @@ def from_scalar_regions_sectors(
occurrence=occurrence,
duration=duration,
name=name,
**kwarg,
**kwargs,
)

@property
Expand Down Expand Up @@ -847,6 +850,7 @@ def _instantiate(
occurrence: int = 1,
duration: int = 1,
name: Optional[str] = None,
**_,
):
return cls(
impact=impact,
Expand Down Expand Up @@ -1178,6 +1182,7 @@ def __init__(

industrial_rebuilding_demand = np.zeros(shape=self.z_shape)
tmp = np.zeros(self.z_shape, dtype="float")

mask = np.ix_(
np.union1d(
self._rebuilding_industries_RoW_idx, self._rebuilding_industries_idx
Expand Down Expand Up @@ -1236,6 +1241,7 @@ def _instantiate(
rebuild_tau: int,
rebuilding_sectors: dict[str, float] | pd.Series,
rebuilding_factor: float = 1.0,
**_,
):
return cls(
impact=impact,
Expand All @@ -1249,6 +1255,20 @@ def _instantiate(
rebuilding_factor=rebuilding_factor,
)

@property
def rebuild_tau(self) -> int:
r"""The characteristic time for rebuilding."""
return self._rebuild_tau

@rebuild_tau.setter
def rebuild_tau(self, value: int):
if not isinstance(value, int) or value < 1:
raise ValueError(
f"``rebuild_tau`` should be a strictly positive integer. Value given is {value}."
)
else:
self._rebuild_tau = value

@property
def rebuilding_sectors(self) -> pd.Index:
r"""The (optional) array of rebuilding sectors"""
Expand All @@ -1270,7 +1290,12 @@ def rebuilding_sectors(self, value: dict[str, float] | pd.Series):
reb_sectors = pd.Series(value)
else:
reb_sectors = value
assert np.isclose(reb_sectors.sum(), 1.0)
if not is_numeric_dtype(reb_sectors):
raise TypeError(
"Rebuilding sectors should be given as ``dict[str, float] | pd.Series``."
)
if not np.isclose(reb_sectors.sum(), 1.0):
raise ValueError(f"Reconstruction shares among sectors do not sum up to 1.")
impossible_sectors = np.setdiff1d(reb_sectors.index, self.possible_sectors)
if impossible_sectors.size > 0:
raise ValueError(
Expand All @@ -1288,25 +1313,28 @@ def rebuilding_sectors(self, value: dict[str, float] | pd.Series):
np.size(self.possible_sectors) * ri + si
for ri in self._aff_regions_idx
for si in self._rebuilding_sectors_idx
]
],
dtype="int64",
)
self._rebuilding_industries_RoW_idx = np.array(
[
np.size(self.possible_sectors) * ri + si
for ri in range(np.size(self.possible_regions))
if ri not in self._aff_regions_idx
for si in self._rebuilding_sectors_idx
]
],
dtype="int64",
)
self._rebuilding_sectors_shares[self._rebuilding_industries_idx] = np.tile(
np.array(reb_sectors.values), np.size(self.aff_regions)
)
self._rebuilding_sectors_shares[self._rebuilding_industries_RoW_idx] = (
np.tile(
np.array(reb_sectors.values),
(np.size(self.possible_regions) - np.size(self.aff_regions)),
if self._rebuilding_industries_RoW_idx.size != 0:
self._rebuilding_sectors_shares[self._rebuilding_industries_RoW_idx] = (
np.tile(
np.array(reb_sectors.values),
(np.size(self.possible_regions) - np.size(self.aff_regions)),
)
)
)

@property
def rebuilding_demand_house(self) -> npt.NDArray:
Expand Down Expand Up @@ -1415,6 +1443,7 @@ def _instantiate(
event_monetary_factor: Optional[int] = None,
recovery_time: int,
recovery_function: str = "linear",
**_,
):
return cls(
impact=impact,
Expand Down
7 changes: 6 additions & 1 deletion docs/source/_static/switcher.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
[
{
"name": "latest",
"version": "v0.5.8",
"version": "v0.5.9",
"url": "https://spjuhel.github.io/BoARIO/",
"preferred": true
},
{
"name": "v0.5.8",
"version": "v0.5.8",
"url": "https://spjuhel.github.io/BoARIO/v0.5.8/en"
},
{
"name": "develop",
"version": "develop",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def move_dir(src, dst):
os.environ["build_all_docs"] = str(True)
os.environ["pages_root"] = "https://spjuhel.github.io/BoARIO"
# manually the main branch build in the current supported languages
build_doc("latest", "en", "main")
build_doc("latest", "en", "origin/main")
move_dir("./build/html/", "./pages/")
#build_doc("latest", "de", "main")
#move_dir("./_build/html/", "../pages/de/")
Expand Down
91 changes: 87 additions & 4 deletions docs/source/release-note.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,93 @@
Release notes
================

0.5.9 (04/2024)
----------------

Changes:

* event: added kwargs in instantiate methods by @spjuhel in https://github.com/spjuhel/BoARIO/pull/103

Dependencies updates:

* Bump numpy from 1.23.5 to 1.26.4 by @dependabot in https://github.com/spjuhel/BoARIO/pull/109
* Bump pytest from 7.4.4 to 8.1.1 by @dependabot in https://github.com/spjuhel/BoARIO/pull/108
* Bump pytest-cov from 4.1.0 to 5.0.0 by @dependabot in https://github.com/spjuhel/BoARIO/pull/107
* Bump sphinx-autodoc-typehints from 2.0.1 to 2.1.0 by @dependabot in https://github.com/spjuhel/BoARIO/pull/106
* Bump dask from 2024.4.1 to 2024.4.2 by @dependabot in https://github.com/spjuhel/BoARIO/pull/105

**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.8...v0.5.9

0.5.8 (04/2024)
----------------

* Bump actions/configure-pages from 4 to 5 by @dependabot in https://github.com/spjuhel/BoARIO/pull/94
* v0.5.8 by @spjuhel in https://github.com/spjuhel/BoARIO/pull/102

- Fixed badge in README
- Integrated dependabot in the CI/CD
- Documentation retrofit
- Version switch in documentation
- Multiple dependencies version update

**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.7...v0.5.8

0.5.7 (03/2024)
----------------

* Trying to fix dependencies for conda forge by @spjuhel in https://github.com/spjuhel/BoARIO/pull/86

**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.6...v0.5.7

0.5.6 (03/2024)
----------------

* Removed the requirement to record in memmaps (variables evolution can be recorder directly in arrays)
* Update to V0.5.6 by @spjuhel in https://github.com/spjuhel/BoARIO/pull/85

**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.5...v0.5.6

0.5.5 (02/2024)
----------------

* 📦 🚑 Fixed a problem with multi-events + pandas version by @spjuhel in https://github.com/spjuhel/BoARIO/pull/66
* Create draft-pdf.yml by @spjuhel in https://github.com/spjuhel/BoARIO/pull/71
* V0.5.5 and learning correct workflow ;) by @spjuhel in https://github.com/spjuhel/BoARIO/pull/78

**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.3...v0.5.5

0.5.4
------

There is no version 0.5.4

0.5.3 (10/2023)
----------------

Fixed a bug with household rebuilding demand

**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.2...v0.5.3


0.5.2 (09/2023)
----------------

**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.1...v0.5.2

0.5.1 (08/2023)
----------------

* hotfix for the use of pygit2

0.5.0 (06/2023)
---------------
----------------

* Putting in master the nice changes we made when coupling with climada by @spjuhel in https://github.com/spjuhel/BoARIO/pull/30
* Proper merge and Black Formatting (actually working) by @spjuhel in https://github.com/spjuhel/BoARIO/pull/34
* Doc testing merge: master testing by @spjuhel in https://github.com/spjuhel/BoARIO/pull/41
* Master testing by @spjuhel in https://github.com/spjuhel/BoARIO/pull/43
* Update issue templates by @spjuhel in https://github.com/spjuhel/BoARIO/pull/50
* v0.5.0 by @spjuhel in https://github.com/spjuhel/BoARIO/pull/58

Features
*********

* WIP
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.4.1b...v0.5.0b
2 changes: 1 addition & 1 deletion docs/source/versions.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"latest":
"v0.5.8":
tag: 'v0.5.8'
languages:
- "en"
Expand Down
Loading

0 comments on commit 32d2ada

Please sign in to comment.