Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more numpy and improve naming #6

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/antares/tsgen/cluster_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def import_thermal_cluster(path: Path, days_per_year: int = 365) -> ThermalClust
return ThermalCluster(
unit_count=int(array[1][1]),
nominal_power=float(array[2][1]),
modulation=[float(i) for i in array[3][1 : 24 + 1]],
modulation=array[3][1 : 24 + 1].astype(int),
fo_law=law_dict[array[4][1]],
fo_volatility=float(array[5][1]),
po_law=law_dict[array[6][1]],
Expand Down
14 changes: 7 additions & 7 deletions src/antares/tsgen/cluster_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def resolve_thermal_cluster(
return ThermalCluster(
unit_count=parsed_yaml.unit_count,
nominal_power=parsed_yaml.nominal_power,
modulation=modulation["modulation"].to_list(),
modulation=modulation["modulation"].to_numpy(dtype=float),
fo_law=law_dict[parsed_yaml.fo_law],
fo_volatility=parsed_yaml.fo_volatility,
po_law=law_dict[parsed_yaml.po_law],
po_volatility=parsed_yaml.po_volatility,
fo_duration=parameters_ts["FOD"].to_list(),
fo_rate=parameters_ts["FOR"].to_list(),
po_duration=parameters_ts["POD"].to_list(),
po_rate=parameters_ts["POR"].to_list(),
npo_min=parameters_ts["POMax"].to_list(),
npo_max=parameters_ts["POMin"].to_list(),
fo_duration=parameters_ts["FOD"].to_numpy(dtype=int),
fo_rate=parameters_ts["FOR"].to_numpy(dtype=float),
po_duration=parameters_ts["POD"].to_numpy(dtype=int),
po_rate=parameters_ts["POR"].to_numpy(dtype=float),
npo_min=parameters_ts["POMax"].to_numpy(dtype=int),
npo_max=parameters_ts["POMin"].to_numpy(dtype=int),
)
17 changes: 12 additions & 5 deletions src/antares/tsgen/duration_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from abc import ABC, abstractmethod
from enum import Enum
from math import log, sqrt
from typing import List

import numpy as np
import numpy.typing as npt

from .random_generator import RNG

Expand All @@ -41,7 +41,10 @@ class GeneratorWrapper(DurationGenerator):
"""

def __init__(
self, delegate: DurationGenerator, volatility: float, expecs: List[int]
self,
delegate: DurationGenerator,
volatility: float,
expecs: npt.NDArray[np.int_],
) -> None:
self.volatility = volatility
self.expectations = expecs
Expand All @@ -59,7 +62,9 @@ def generate_duration(self, day: int) -> int:


class UniformDurationGenerator(DurationGenerator):
def __init__(self, rng: RNG, volatility: float, expecs: List[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 @@ -77,7 +82,9 @@ def generate_duration(self, day: int) -> int:


class GeometricDurationGenerator(DurationGenerator):
def __init__(self, rng: RNG, volatility: float, expecs: List[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 @@ -100,7 +107,7 @@ def generate_duration(self, day: int) -> int:


def make_duration_generator(
rng: RNG, law: ProbabilityLaw, volatility: float, expectations: List[int]
rng: RNG, law: ProbabilityLaw, volatility: float, expectations: npt.NDArray[np.int_]
) -> DurationGenerator:
"""
return a DurationGenerator for the given law
Expand Down
Loading
Loading