Skip to content

Commit

Permalink
reformating imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdiwahada committed Oct 29, 2024
1 parent c4b1dee commit ab5c787
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 106 deletions.
14 changes: 7 additions & 7 deletions src/antares/tsgen/cluster_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import numpy as np

from .ts_generator import ProbabilityLaw, ThermalCluster, OutageGenerationParameters
from .ts_generator import OutageGenerationParameters, ProbabilityLaw, ThermalCluster


def import_thermal_cluster(path: Path, days_per_year: int = 365) -> ThermalCluster:
Expand All @@ -30,12 +30,12 @@ def import_thermal_cluster(path: Path, days_per_year: int = 365) -> ThermalClust
fo_volatility=float(array[5][1]),
po_law=law_dict[array[6][1]],
po_volatility=float(array[7][1]),
fo_duration=array[8][1: days_per_year + 1].astype(int),
fo_rate=array[9][1: days_per_year + 1].astype(float),
po_duration=array[10][1: days_per_year + 1].astype(int),
po_rate=array[11][1: days_per_year + 1].astype(float),
npo_min=array[12][1: days_per_year + 1].astype(int),
npo_max=array[13][1: days_per_year + 1].astype(int),
fo_duration=array[8][1 : days_per_year + 1].astype(int),
fo_rate=array[9][1 : days_per_year + 1].astype(float),
po_duration=array[10][1 : days_per_year + 1].astype(int),
po_rate=array[11][1 : days_per_year + 1].astype(float),
npo_min=array[12][1 : days_per_year + 1].astype(int),
npo_max=array[13][1 : days_per_year + 1].astype(int),
)
return ThermalCluster(
outage_gen_params,
Expand Down
3 changes: 1 addition & 2 deletions src/antares/tsgen/duration_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class DurationGenerator(ABC):
"""

@abstractmethod
def generate_duration(self, day: int) -> int:
...
def generate_duration(self, day: int) -> int: ...


class GeneratorWrapper(DurationGenerator):
Expand Down
3 changes: 1 addition & 2 deletions src/antares/tsgen/random_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class RNG(ABC):
"""

@abstractmethod
def next(self) -> float:
...
def next(self) -> float: ...


class PythonRNG(ABC):
Expand Down
105 changes: 56 additions & 49 deletions src/antares/tsgen/ts_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
# This file is part of the Antares project.

from dataclasses import dataclass
from typing import Tuple, Any
from typing import Any, Tuple

import numpy as np
import numpy.typing as npt
from numpy import ndarray, dtype
from numpy import dtype, ndarray

from antares.tsgen.duration_generator import ProbabilityLaw, make_duration_generator
from antares.tsgen.random_generator import RNG, MersenneTwisterRNG
Expand Down Expand Up @@ -55,7 +55,7 @@ def __post_init__(self) -> None:
@dataclass
class ThermalCluster:
# available units of the cluster
#unit_count: int
# unit_count: int
outage_gen_params: OutageGenerationParameters
# nominal power
nominal_power: float
Expand All @@ -64,33 +64,33 @@ class ThermalCluster:

# forced and planed outage parameters
# indexed by day of the year
#fo_duration: IntArray
#fo_rate: FloatArray
#po_duration: IntArray
#po_rate: FloatArray
#npo_min: IntArray # number of planed outage min in a day
#npo_max: IntArray # number of planed outage max in a day
# fo_duration: IntArray
# fo_rate: FloatArray
# po_duration: IntArray
# po_rate: FloatArray
# npo_min: IntArray # number of planed outage min in a day
# npo_max: IntArray # number of planed outage max in a day

# forced and planed outage probability law and volatility
# volatility characterizes the distance from the expect at which the value drawn can be
#fo_law: ProbabilityLaw
#fo_volatility: float
#po_law: ProbabilityLaw
#po_volatility: float
# fo_law: ProbabilityLaw
# fo_volatility: float
# po_law: ProbabilityLaw
# po_volatility: float

def __post_init__(self) -> None:
_check_cluster(self)


@dataclass
class LinkCapacity:
#outage generation parameters
# outage generation parameters
outage_gen_params: OutageGenerationParameters

#nominal capacity
# nominal capacity
nominal_capacity: float

#direct / indirect modulation of the nominal capacity
# direct / indirect modulation of the nominal capacity
modulation_direct: FloatArray
modulation_indirect: FloatArray

Expand Down Expand Up @@ -192,7 +192,8 @@ def _check_link_capacity(link_capacity: LinkCapacity):
if len(lengths) != 1:
raise ValueError(f"Not all daily arrays have same size, got {lengths}")

#OutputTimeseries ->

# OutputTimeseries ->
class OutputTimeseries:
def __init__(self, ts_count: int, days: int) -> None:
self.available_units = np.zeros(shape=(days, ts_count), dtype=int)
Expand Down Expand Up @@ -337,12 +338,7 @@ def __init__(self, rng: RNG = MersenneTwisterRNG(), days: int = 365) -> None:
self.rng = rng
self.days = days

def _compare_apparent_PO(
self,
current_available_units: int,
po_candidates: int,
stock: int
):
def _compare_apparent_PO(self, current_available_units: int, po_candidates: int, stock: int):
candidate = po_candidates + stock
if 0 <= candidate <= current_available_units:
po_candidates = candidate
Expand All @@ -356,13 +352,7 @@ def _compare_apparent_PO(
return po_candidates, stock

def _generate_outages(
self,
outage_gen_params: OutageGenerationParameters,
log,
log_size,
logp,
number_of_timeseries,
output
self, outage_gen_params: OutageGenerationParameters, log, log_size, logp, number_of_timeseries, output
):
daily_fo_rate = _compute_failure_rates(outage_gen_params.fo_rate, outage_gen_params.fo_duration)
daily_po_rate = _compute_failure_rates(outage_gen_params.po_rate, outage_gen_params.po_duration)
Expand All @@ -371,19 +361,28 @@ def _generate_outages(
fo_drawer = ForcedOutagesDrawer(self.rng, outage_gen_params.unit_count, daily_fo_rate)
po_drawer = PlannedOutagesDrawer(self.rng, outage_gen_params.unit_count, daily_po_rate)

fod_generator = make_duration_generator(self.rng, outage_gen_params.fo_law,
outage_gen_params.fo_volatility, outage_gen_params.fo_duration)
pod_generator = make_duration_generator(self.rng, outage_gen_params.po_law,
outage_gen_params.po_volatility, outage_gen_params.po_duration)

self.output_generation(outage_gen_params, fo_drawer, fod_generator,
log, log_size, logp,
number_of_timeseries, output, po_drawer, pod_generator)
fod_generator = make_duration_generator(
self.rng, outage_gen_params.fo_law, outage_gen_params.fo_volatility, outage_gen_params.fo_duration
)
pod_generator = make_duration_generator(
self.rng, outage_gen_params.po_law, outage_gen_params.po_volatility, outage_gen_params.po_duration
)

self.output_generation(
outage_gen_params,
fo_drawer,
fod_generator,
log,
log_size,
logp,
number_of_timeseries,
output,
po_drawer,
pod_generator,
)

def generate_time_series_for_links(
self,
link: LinkCapacity,
number_of_timeseries: int
self, link: LinkCapacity, number_of_timeseries: int
) -> tuple[ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]]]:
"""
generation of multiple timeseries for a given link capacity
Expand Down Expand Up @@ -414,9 +413,9 @@ def generate_time_series_for_links(
return direct_output, indirect_output

def generate_time_series_for_clusters(
self,
cluster: ThermalCluster,
number_of_timeseries: int,
self,
cluster: ThermalCluster,
number_of_timeseries: int,
) -> OutputTimeseries:
"""
generation of multiple timeseries for a given thermal cluster
Expand All @@ -434,8 +433,6 @@ def generate_time_series_for_clusters(
# failure rate means the probability to enter in outage each day
# its value is given by: OR / [OR + OD * (1 - OR)]



# --- calculation ---
# the two first generated time series will be dropped, necessary to make system stable and physically coherent
# as a consequence, N + 2 time series will be computed
Expand All @@ -451,9 +448,19 @@ def generate_time_series_for_clusters(
np.round(output.available_power)
return output

def output_generation(self, outage_gen_params, fo_drawer, fod_generator, log, log_size, logp, number_of_timeseries,
output,
po_drawer, pod_generator):
def output_generation(
self,
outage_gen_params,
fo_drawer,
fod_generator,
log,
log_size,
logp,
number_of_timeseries,
output,
po_drawer,
pod_generator,
):
# dates
now = 0
# current number of PO and AU (avlaible units)
Expand Down
Loading

0 comments on commit ab5c787

Please sign in to comment.