modules
Top-level package for Volte Norway Grid Tariff Calculator.
analysis
¶
monthly_maximums(curve, top_n_averaged=1, single_max_per_day=False)
¶
Function to get the maximum value of each month in the consumption curve. top_n_averaged determines how many of the largest values are averaged per month. single_max_per_day determines if only the maximum value of each day is kept before finding the largest values of each month and averaging.
Expects a list of tuples containing datetimes and corresponding consumption values in kWH during the hour starting at the datetime, an integer for top_n_averaged and a boolean for single_max_per_day.
Source code in grid_tariff_calculator/analysis.py
def monthly_maximums(
curve: [(datetime.datetime, float)],
top_n_averaged: int = 1,
single_max_per_day: bool = False,
) -> pd.DataFrame:
"""Function to get the maximum value of each month in the consumption curve.
top_n_averaged determines how many of the largest values are averaged per month.
single_max_per_day determines if only the maximum value of each day is kept before
finding the largest values of each month and averaging.
Expects a list of tuples containing datetimes and corresponding consumption values in kWH during the hour starting at the datetime,
an integer for top_n_averaged and a boolean for single_max_per_day.
"""
# assert top_n_averaged >= 1
curve_df = pd.DataFrame(curve, columns=["start_time", "value"])
with_total_consumption = _get_monthly_totals(curve_df)
if single_max_per_day:
curve_df = _get_daily_maximums(curve_df)
curve_df = _get_top_n_values(curve_df, top_n_averaged)
curve_df = _average_groups(curve_df)
curve_df = curve_df.merge(with_total_consumption, on=["year", "month"])
return curve_df
app
¶
Main module.
grid_tariff_dataclasses
¶
AmsMeter
dataclass
¶
Class to create meter objects
Source code in grid_tariff_calculator/grid_tariff_dataclasses.py
@dataclass
class AmsMeter:
"""Class to create meter objects"""
identification: str
distributor_name: str
estimated_yearly_cons: float
ElFeeTariff
dataclass
¶
Class to create el-fee tariff objects Forbruksavgift/el-avgift in norwegian.
Source code in grid_tariff_calculator/grid_tariff_dataclasses.py
@dataclass
class ElFeeTariff:
""" Class to create el-fee tariff objects
Forbruksavgift/el-avgift in norwegian."""
distributor_name: str
price_NOK_per_kWh: float
start_time: datetime.datetime
end_time: datetime.datetime
EnergyTariff
dataclass
¶
Class to create energy tariff objects Energiledd in norwegian.
Source code in grid_tariff_calculator/grid_tariff_dataclasses.py
@dataclass
class EnergyTariff:
""" Class to create energy tariff objects
Energiledd in norwegian.
"""
distributor_name: str
price_NOK_per_kWh: float
start_time: datetime.datetime # TODO: implement day/night tariff
end_time: datetime.datetime
EnovaFee
dataclass
¶
Class to create objects for the Enova fee
Source code in grid_tariff_calculator/grid_tariff_dataclasses.py
@dataclass
class EnovaFee:
""" Class to create objects for the Enova fee"""
price_NOK_per_year: float
start_time: datetime.datetime
end_time: datetime.datetime
FixedTariff
dataclass
¶
Class to create objects for fixed yearly fees
Source code in grid_tariff_calculator/grid_tariff_dataclasses.py
@dataclass
class FixedTariff:
""" Class to create objects for fixed yearly fees"""
distributor_name: str
price_NOK_per_year: float
start_time: datetime.datetime
end_time: datetime.datetime
PeakTariffLargeConsumers
dataclass
¶
Class to create peak tariff objects for large consumers (above 100 MWh/year) Effektledd in norwegian.
Source code in grid_tariff_calculator/grid_tariff_dataclasses.py
@dataclass
class PeakTariffLargeConsumers:
""" Class to create peak tariff objects for large consumers (above 100 MWh/year)
Effektledd in norwegian.
"""
distributor_name: str
price_NOK_per_kWh: float
start_time: datetime.datetime
end_time: datetime.datetime
PeakTariffSmallConsumers
dataclass
¶
Class to create peak tariff objects for small consumers (below 100 MWh/year) Fastledd/kapasitetsledd in norwegian.
Source code in grid_tariff_calculator/grid_tariff_dataclasses.py
@dataclass
class PeakTariffSmallConsumers:
""" Class to create peak tariff objects for small consumers (below 100 MWh/year)
Fastledd/kapasitetsledd in norwegian.
"""
distributor_name: str
price_NOK: float
start_time: datetime.datetime
end_time: datetime.datetime
lower_limit: float
upper_limit: float
tariff_calculator
¶
calculate_costs_over_100k(curve, threshold, load_shifting=True, fixed_tariffs=[], peak_tariffs_large_consumers=[], el_fee=[])
¶
Function to calculate the grid rental costs of a consumption curve. Assumes estimated yearly consumption is over 100k kWh.
Returns a dataframe with columns "year", "month", "maximum", "total_consumption", "peak_cost" and "fixed_cost".
Source code in grid_tariff_calculator/tariff_calculator.py
def calculate_costs_over_100k(
curve: [(datetime.datetime, float)],
threshold: float,
load_shifting: bool = True,
fixed_tariffs: [FixedTariff] = [],
peak_tariffs_large_consumers: [PeakTariffLargeConsumers] = [],
el_fee: [ElFeeTariff] = [],
) -> pd.DataFrame:
"""Function to calculate the grid rental costs of a consumption curve.
Assumes estimated yearly consumption is over 100k kWh.
Returns a dataframe with columns "year", "month", "maximum", "total_consumption", "peak_cost" and "fixed_cost".
"""
monthly_max_df = monthly_maximums(
curve, top_n_averaged=1, single_max_per_day=False
)[["year", "month", "maximum", "total_consumption", "maximums_occured_on"]]
_set_to_threshold(curve, monthly_max_df, threshold, load_shifting)
if peak_tariffs_large_consumers:
monthly_max_df["peak_cost"] = _get_peak_costs_large_consumers(
monthly_max_df, peak_tariffs_large_consumers
)
else:
logger.warning(
"No peak tariffs for large consumers provided. Peak cost will not be calculated."
)
if fixed_tariffs:
monthly_max_df["fixed_cost"] = _get_fixed_tariff(monthly_max_df, fixed_tariffs)
monthly_max_df["fixed_cost"] = monthly_max_df.apply(
_weight_by_nr_days, axis=1, col_name="fixed_cost"
)
else:
logger.warning(
"No fixed tariffs provided. Fixed cost will not be calculated."
)
return monthly_max_df
calculate_costs_under_100k(curve, threshold, load_shifting=True, peak_tariffs_small_consumers=[], el_fee=[])
¶
Function to calculate the grid rental costs of a consumption curve. Assumes estimated yearly consumption is under 100k kWh.
Returns a dataframe with columns "year", "month", "maximum", "total_consumption" and "peak_cost".
Source code in grid_tariff_calculator/tariff_calculator.py
def calculate_costs_under_100k(
curve: [(datetime.datetime, float)],
threshold: float,
load_shifting: bool = True,
peak_tariffs_small_consumers: [PeakTariffSmallConsumers] = [],
el_fee: [ElFeeTariff] = [],
) -> pd.DataFrame:
"""Function to calculate the grid rental costs of a consumption curve.
Assumes estimated yearly consumption is under 100k kWh.
Returns a dataframe with columns "year", "month", "maximum", "total_consumption" and "peak_cost".
"""
monthly_max_df = monthly_maximums(curve, top_n_averaged=3, single_max_per_day=True)[
["year", "month", "maximum", "total_consumption", "maximums_occured_on"]
]
monthly_max_df = _set_to_threshold(curve, monthly_max_df, threshold, load_shifting)
if peak_tariffs_small_consumers:
monthly_max_df["peak_cost"] = _get_peak_tariff_small_consumers(
monthly_max_df, peak_tariffs_small_consumers
)
else:
logger.warning(
"No peak tariffs for small consumers provided. Peak cost will not be calculated."
)
return monthly_max_df
calculate_grid_rental(curve, load_shifting=True, estimated_yearly_cons=100000, energy_tariffs=[], enova_fee=[], fixed_tariffs=[], peak_tariffs_large_consumers=[], peak_tariffs_small_consumers=[], el_fee=[])
¶
Function to get the grid rental costs of the original consumption curve.
Source code in grid_tariff_calculator/tariff_calculator.py
def calculate_grid_rental(
curve: [(datetime.datetime, float)],
load_shifting: bool = True,
estimated_yearly_cons: float = 100000,
energy_tariffs: [EnergyTariff] = [],
enova_fee: [EnovaFee] = [],
fixed_tariffs: [FixedTariff] = [],
peak_tariffs_large_consumers: [PeakTariffLargeConsumers] = [],
peak_tariffs_small_consumers: [PeakTariffSmallConsumers] = [],
el_fee: [ElFeeTariff] = [],
) -> pd.DataFrame:
"""Function to get the grid rental costs of the original consumption curve."""
curve_CET = [(t[0].astimezone(pytz.timezone('Europe/Oslo')), t[1]) for t in curve]
monthly_grid_rental = _calculate_costs(
curve_CET,
estimated_yearly_cons,
threshold=1,
load_shifting=load_shifting,
energy_tariffs=energy_tariffs,
enova_fee=enova_fee,
fixed_tariffs=fixed_tariffs,
peak_tariffs_large_consumers=peak_tariffs_large_consumers,
peak_tariffs_small_consumers=peak_tariffs_small_consumers,
el_fee=el_fee,
)
return monthly_grid_rental
calculate_threshold_grid_rental(curve, threshold, load_shifting=True, estimated_yearly_cons=100000, energy_tariffs=[], enova_fee=[], fixed_tariffs=[], peak_tariffs_large_consumers=[], peak_tariffs_small_consumers=[], el_fee=[])
¶
Function to get the grid rental costs of a consumption curve that's lowered to a threshold.
Source code in grid_tariff_calculator/tariff_calculator.py
def calculate_threshold_grid_rental(
curve: [(datetime.datetime, float)],
threshold: float,
load_shifting: bool = True,
estimated_yearly_cons: float = 100000,
energy_tariffs: [EnergyTariff] = [],
enova_fee: [EnovaFee] = [],
fixed_tariffs: [FixedTariff] = [],
peak_tariffs_large_consumers: [PeakTariffLargeConsumers] = [],
peak_tariffs_small_consumers: [PeakTariffSmallConsumers] = [],
el_fee: [ElFeeTariff] = [],
) -> pd.DataFrame:
"""Function to get the grid rental costs of a consumption curve that's lowered to a threshold."""
curve_CET = [(t[0].astimezone(pytz.timezone('Europe/Oslo')), t[1]) for t in curve]
monthly_grid_rental = _calculate_costs(
curve_CET,
estimated_yearly_cons,
threshold=threshold,
load_shifting=load_shifting,
energy_tariffs=energy_tariffs,
enova_fee=enova_fee,
fixed_tariffs=fixed_tariffs,
peak_tariffs_large_consumers=peak_tariffs_large_consumers,
peak_tariffs_small_consumers=peak_tariffs_small_consumers,
el_fee=el_fee,
)
return monthly_grid_rental