Skip to content

Commit

Permalink
v0.1.4 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle authored Aug 9, 2024
1 parent 156f1b3 commit 651d85b
Show file tree
Hide file tree
Showing 13 changed files with 8,939 additions and 194 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Changelog
=========

v0.1.4 (2023-08-09)
-------------------

### Bug fixes
* various code fixes inside module `ts_generator.py` to match with the existing C++ code

### Checkstyle
* add line-length limit of 120 for black and isort


v0.1.3 (2023-08-05)
-------------------

Expand Down
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "antares-timeseries-generation"
version = "0.1.3"
version = "0.1.4"
license = {text="MPL-2.0"}
description = 'Timeseries generation library aiming at creating input data for Antares simulator studies.'
readme = "README.md"
Expand All @@ -10,3 +10,13 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)"
]

[tool.black]
target-version = ["py38"]
line-length = 120

[tool.isort]
profile = "black"
line_length = 120
src_paths = ["src", "tests"]
skip_gitignore = true
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sonar.projectVersion=0.1.3
sonar.projectVersion=0.1.4
sonar.organization=antaressimulatorteam
sonar.projectKey=AntaresSimulatorTeam_antares-timeseries-generation
sonar.sources=src
Expand Down
4 changes: 1 addition & 3 deletions src/antares/tsgen/cluster_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def parse_yaml_cluster(input_cluster: TextIO) -> InputCluster:
return InputCluster.model_validate(tree["cluster"])


def parse_cluster_ts(
file: Path, shape: Optional[Tuple[int, int]] = None
) -> pd.core.frame.DataFrame:
def parse_cluster_ts(file: Path, shape: Optional[Tuple[int, int]] = None) -> pd.core.frame.DataFrame:
ts = pd.read_csv(file)
assert shape is None or ts.shape == shape
return ts
14 changes: 5 additions & 9 deletions src/antares/tsgen/duration_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def generate_duration(self, day: int) -> int:


class UniformDurationGenerator(DurationGenerator):
def __init__(
self, rng: RNG, volatility: float, expecs: npt.NDArray[np.int_]
) -> None:
def __init__(self, rng: RNG, volatility: float, expecs: npt.NDArray[np.int_]) -> None:
self.rng = rng
self.a = np.empty(len(expecs), dtype=float)
self.b = np.empty(len(expecs), dtype=float)
Expand All @@ -82,9 +80,7 @@ def generate_duration(self, day: int) -> int:


class GeometricDurationGenerator(DurationGenerator):
def __init__(
self, rng: RNG, volatility: float, expecs: npt.NDArray[np.int_]
) -> None:
def __init__(self, rng: RNG, volatility: float, expecs: npt.NDArray[np.int_]) -> None:
self.rng = rng
self.a = np.empty(len(expecs), dtype=float)
self.b = np.empty(len(expecs), dtype=float)
Expand All @@ -95,15 +91,15 @@ def __init__(
self.a[day] = expec - 1 / ytemp
self.b[day] = 1 / log(1 - ytemp)
else:
self.a[day] = expec - 1
self.b[day] = 0
self.a[day] = 1
self.b[day] = 1

def generate_duration(self, day: int) -> int:
"""
generation of random outage duration
"""
rnd_nb = self.rng.next()
return min(int(1 + self.a[day] + self.b[day] * log(rnd_nb)), 1999)
return min(1 + int(self.a[day] + self.b[day] * log(rnd_nb)), 1999)


def make_duration_generator(
Expand Down
24 changes: 6 additions & 18 deletions src/antares/tsgen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,12 @@

def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--study", type=Path, help="path to the root directory of the study"
)
parser.add_argument(
"--models", nargs="+", type=Path, help="list of path to model file, *.yml"
)
parser.add_argument(
"--component", type=Path, help="path to the component file, *.yml"
)
parser.add_argument(
"--timeseries", type=Path, help="path to the timeseries directory"
)
parser.add_argument(
"--duration", type=int, help="duration of the simulation", default=1
)
parser.add_argument(
"--scenario", type=int, help="number of scenario of the simulation", default=1
)
parser.add_argument("--study", type=Path, help="path to the root directory of the study")
parser.add_argument("--models", nargs="+", type=Path, help="list of path to model file, *.yml")
parser.add_argument("--component", type=Path, help="path to the component file, *.yml")
parser.add_argument("--timeseries", type=Path, help="path to the timeseries directory")
parser.add_argument("--duration", type=int, help="duration of the simulation", default=1)
parser.add_argument("--scenario", type=int, help="number of scenario of the simulation", default=1)

parser.parse_args()

Expand Down
14 changes: 3 additions & 11 deletions src/antares/tsgen/mersenne_twister.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,10 @@ def next(self) -> float:

for j in range(self.periodN - self.periodM, self.periodN - 1):
y = (self.mt[j] & self.UPPER_MASK) | (self.mt[j + 1] & self.LOWER_MASK)
self.mt[j] = (
self.mt[j + self.periodM - self.periodN]
^ (y >> 1)
^ self.MAG[y & 1]
)
self.mt[j] = self.mt[j + self.periodM - self.periodN] ^ (y >> 1) ^ self.MAG[y & 1]

y = (self.mt[self.periodN - 1] & self.UPPER_MASK) | (
self.mt[0] & self.LOWER_MASK
)
self.mt[self.periodN - 1] = (
self.mt[self.periodM - 1] ^ (y >> 1) ^ self.MAG[y & 1]
)
y = (self.mt[self.periodN - 1] & self.UPPER_MASK) | (self.mt[0] & self.LOWER_MASK)
self.mt[self.periodN - 1] = self.mt[self.periodM - 1] ^ (y >> 1) ^ self.MAG[y & 1]

self.mti = 0

Expand Down
Loading

0 comments on commit 651d85b

Please sign in to comment.