Skip to content

Commit

Permalink
update some type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerle committed Nov 22, 2024
1 parent 03e69b1 commit 32445b0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
4 changes: 3 additions & 1 deletion assume/common/forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,9 @@ def __init__(
*args,
**kwargs,
):
super().__init__(index, powerplants_units, demand_units, market_configs, *args, **kwargs)
super().__init__(

Check warning on line 469 in assume/common/forecasts.py

View check run for this annotation

Codecov / codecov/patch

assume/common/forecasts.py#L469

Added line #L469 was not covered by tests
index, powerplants_units, demand_units, market_configs, *args, **kwargs
)

self.index = FastIndex(start=index[0], end=index[-1], freq=pd.infer_freq(index))

Check warning on line 473 in assume/common/forecasts.py

View check run for this annotation

Codecov / codecov/patch

assume/common/forecasts.py#L473

Added line #L473 was not covered by tests
self.sigma = sigma
Expand Down
5 changes: 2 additions & 3 deletions assume/common/units_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from itertools import groupby
from operator import itemgetter

import pandas as pd
from mango import Role, create_acl, sender_addr
from mango.messages.message import Performatives

Expand Down Expand Up @@ -294,7 +293,7 @@ def set_unit_dispatch(

def get_actual_dispatch(
self, product_type: str, last: datetime
) -> tuple[pd.DataFrame, list[pd.DataFrame]]:
) -> tuple[list[tuple[datetime, float, str, str]], list[dict]]:
"""
Retrieves the actual dispatch and commits it in the unit.
We calculate the series of the actual market results dataframe with accepted bids.
Expand All @@ -305,7 +304,7 @@ def get_actual_dispatch(
last (datetime): the last date until which the dispatch was already sent
Returns:
tuple[pd.DataFrame, list[pd.DataFrame]]: market_dispatch and unit_dispatch dataframes
tuple[list[tuple[datetime, float, str, str]], list[dict]]: market_dispatch and unit_dispatch dataframes
"""
now = timestamp2datetime(self.context.current_timestamp)
start = timestamp2datetime(last + 1)
Expand Down
17 changes: 8 additions & 9 deletions assume/units/demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later

import numbers

import pandas as pd
from datetime import datetime

from assume.common.base import SupportsMinMax
from assume.common.fast_pandas import FastSeries
Expand Down Expand Up @@ -41,7 +40,7 @@ def __init__(
min_power: float,
forecaster: Forecaster,
node: str = "node0",
price: float | pd.Series = 3000.0,
price: float | FastSeries = 3000.0,
location: tuple[float, float] = (0.0, 0.0),
**kwargs,
):
Expand Down Expand Up @@ -71,8 +70,8 @@ def __init__(

def execute_current_dispatch(
self,
start: pd.Timestamp,
end: pd.Timestamp,
start: datetime,
end: datetime,
):
"""
Execute the current dispatch of the unit.
Expand All @@ -83,14 +82,14 @@ def execute_current_dispatch(
end (pandas.Timestamp): The end time of the dispatch.
Returns:
pd.Series: The volume of the unit within the gicen time range.
FastSeries: The volume of the unit within the gicen time range.
"""

return self.volume[start:end]

def calculate_min_max_power(
self, start: pd.Timestamp, end: pd.Timestamp, product_type="energy"
) -> tuple[pd.Series, pd.Series]:
self, start: datetime, end: datetime, product_type="energy"
) -> tuple[FastSeries, FastSeries]:
"""
Calculates the minimum and maximum power output of the unit and returns the bid volume as both the minimum and maximum power output of the unit.
Expand All @@ -105,7 +104,7 @@ def calculate_min_max_power(
bid_volume = (self.volume - self.outputs[product_type]).loc[start:end_excl]
return bid_volume, bid_volume

def calculate_marginal_cost(self, start: pd.Timestamp, power: float) -> float:
def calculate_marginal_cost(self, start: datetime, power: float) -> float:
"""
Calculate the marginal cost of the unit returns the marginal cost of the unit based on the provided time and power.
Expand Down
27 changes: 13 additions & 14 deletions assume/units/powerplant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from datetime import datetime, timedelta
from functools import lru_cache

import pandas as pd

from assume.common.base import SupportsMinMax
from assume.common.fast_pandas import FastSeries
from assume.common.forecasts import Forecaster
from assume.common.market_objects import MarketConfig, Orderbook
from assume.common.utils import get_products_index
Expand All @@ -29,7 +28,7 @@ class PowerPlant(SupportsMinMax):
max_power (float): The maximum power output capacity of the power plant in MW.
min_power (float, optional): The minimum power output capacity of the power plant in MW. Defaults to 0.0 MW.
efficiency (float, optional): The efficiency of the power plant in converting fuel to electricity. Defaults to 1.0.
additional_cost (Union[float, pd.Series], optional): Additional costs associated with power generation, in EUR/MWh. Defaults to 0.
additional_cost (Union[float, FastSeries], optional): Additional costs associated with power generation, in EUR/MWh. Defaults to 0.
partial_load_eff (bool, optional): Does the efficiency vary at part loads? Defaults to False.
fuel_type (str, optional): The type of fuel used by the power plant for power generation. Defaults to "others".
emission_factor (float, optional): The emission factor associated with the power plant's fuel type (CO2 emissions per unit of energy produced). Defaults to 0.0.
Expand Down Expand Up @@ -59,7 +58,7 @@ def __init__(
max_power: float,
min_power: float = 0.0,
efficiency: float = 1.0,
additional_cost: float | pd.Series = 0.0,
additional_cost: float | FastSeries = 0.0,
partial_load_eff: bool = False,
fuel_type: str = "others",
emission_factor: float = 0.0,
Expand Down Expand Up @@ -127,8 +126,8 @@ def init_marginal_cost(self):

def execute_current_dispatch(
self,
start: pd.Timestamp,
end: pd.Timestamp,
start: datetime,
end: datetime,
):
"""
Executes the current dispatch of the unit based on the provided timestamps.
Expand All @@ -141,7 +140,7 @@ def execute_current_dispatch(
end (pandas.Timestamp): The end time of the dispatch.
Returns:
pd.Series: The volume of the unit within the given time range.
FastSeries: The volume of the unit within the given time range.
"""
start = max(start, self.index[0])

Expand Down Expand Up @@ -242,18 +241,18 @@ def calc_simple_marginal_cost(
def calc_marginal_cost_with_partial_eff(
self,
power_output: float,
timestep: pd.Timestamp = None,
) -> float | pd.Series:
timestep: datetime = None,
) -> float | FastSeries:
"""
Calculates the marginal cost of the unit based on power output and timestamp, considering partial efficiency.
Returns the marginal cost of the unit.
Args:
power_output (float): The power output of the unit.
timestep (pd.Timestamp, optional): The timestamp of the unit. Defaults to None.
timestep (datetime, optional): The timestamp of the unit. Defaults to None.
Returns:
float | pd.Series: The marginal cost of the unit.
float | FastSeries: The marginal cost of the unit.
"""
fuel_price = self.forecaster.get_price(self.fuel_type).at[timestep]

Expand Down Expand Up @@ -294,7 +293,7 @@ def calc_marginal_cost_with_partial_eff(

additional_cost = (
self.additional_cost.at[timestep]
if isinstance(self.additional_cost, pd.Series)
if isinstance(self.additional_cost, FastSeries)
else self.additional_cost
)

Expand All @@ -307,8 +306,8 @@ def calc_marginal_cost_with_partial_eff(
return marginal_cost

def calculate_min_max_power(
self, start: pd.Timestamp, end: pd.Timestamp, product_type="energy"
) -> tuple[pd.Series, pd.Series]:
self, start: datetime, end: datetime, product_type="energy"
) -> tuple[FastSeries, FastSeries]:
"""
Calculates the minimum and maximum power output of the unit and returns it.
Expand Down
18 changes: 9 additions & 9 deletions assume/units/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later

import logging
from datetime import timedelta
from datetime import datetime, timedelta
from functools import lru_cache

import numpy as np
Expand Down Expand Up @@ -160,7 +160,7 @@ def __init__(
self.warm_start_cost = warm_start_cost * max_power_discharge
self.cold_start_cost = cold_start_cost * max_power_discharge

def execute_current_dispatch(self, start: pd.Timestamp, end: pd.Timestamp):
def execute_current_dispatch(self, start: datetime, end: datetime):
"""
Executes the current dispatch of the unit based on the provided timestamps.
Expand Down Expand Up @@ -286,7 +286,7 @@ def set_dispatch_plan(
@lru_cache(maxsize=256)
def calculate_marginal_cost(
self,
start: pd.Timestamp,
start: datetime,
power: float,
) -> float:
"""
Expand Down Expand Up @@ -359,8 +359,8 @@ def calculate_soc_max_charge(
return power

def calculate_min_max_charge(
self, start: pd.Timestamp, end: pd.Timestamp, product_type="energy"
) -> tuple[pd.Series]:
self, start: datetime, end: datetime, product_type="energy"
) -> tuple[FastSeries, FastSeries]:
"""
Calculates the min and max charging power for the given time period.
This is relative to the already sold output on other markets for the same period.
Expand All @@ -372,7 +372,7 @@ def calculate_min_max_charge(
product_type (str): The product type of the storage unit.
Returns:
tuple[pd.Series]: The minimum and maximum charge power levels of the storage unit in MW.
tuple[FastSeries, FastSeries]: The minimum and maximum charge power levels of the storage unit in MW.
"""
end_excl = end - self.index.freq

Expand Down Expand Up @@ -408,8 +408,8 @@ def calculate_min_max_charge(
return min_power_charge, max_power_charge

def calculate_min_max_discharge(
self, start: pd.Timestamp, end: pd.Timestamp, product_type="energy"
) -> tuple[pd.Series]:
self, start: datetime, end: datetime, product_type="energy"
) -> tuple[FastSeries, FastSeries]:
"""
Calculates the min and max discharging power for the given time period.
This is relative to the already sold output on other markets for the same period.
Expand All @@ -421,7 +421,7 @@ def calculate_min_max_discharge(
product_type (str): The product type of the storage unit.
Returns:
tuple[pd.Series]: The minimum and maximum discharge power levels of the storage unit in MW.
tuple[FastSeries, FastSeries]: The minimum and maximum discharge power levels of the storage unit in MW.
"""
end_excl = end - self.index.freq

Expand Down

0 comments on commit 32445b0

Please sign in to comment.