eelib.data.csv_reader.csv_reader_model

eElib csv-reader model for reading-in .csv-files to imitate different model types (e.g. PV, household or heatpump).

Author: elenia@TUBS
Copyright 2024 elenia
This file is part of eELib, which is free software under the terms of the GNU GPL Version 3.

Module Contents

Classes

CSVReader

Parent class for reading-in .csv-files.

GenericCSV

CSV-Reader for profiles. Sets each column of the csv file as attribute.

ConventionalCSV

Base class for all CSVReaders that expect specific column content.

PowerCSV

CSV-Data-Reader parent for power profiles.

RatedCSV

CSV-Reader for power profiles that can be associated with a rated power

RatedScalableCSV

Same as RatedCSV, but p and q exposed to simulation may be scaled using

HouseholdCSV

CSV-Data-Reader for household load profiles using individualy specified datafiles.

HouseholdWPuQCSV

CSV-Data-Reader for household load profiles in pre-defined format based on the WPuQ project.

PvCSV

CSV-Data-Reader marking pv-generation profiles.

HeatpumpCSV

CSV-Data-Reader for heatpump load profiles.

ChargingStationCSV

CSV-Data-Reader marking charging station load profiles.

HouseholdThermalCSV

CSV-Data-Reader for thermal demand profiles.

Attributes

_logger

_logger
class CSVReader(eid: str, datafile: str, start_time: str, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', step_size: int = 60 * 15)

Parent class for reading-in .csv-files.

property attrs: set

Contains data attrs of this model derived from col names of self.data.

VALID_PARAMETERS
eid
datafile: pathlib.Path
date_format = "'YYYY-MM-DD HH:mm:ss'"
start_date
delimiter = "','"
header_rows = '1'
step_size = '900'
timestep = 'None'
values: dict[str, object]
date: str
classmethod get_valid_parameters() dict

Returns dictionary containing valid parameter types and values.

Returns:

valid parameters for this model

Return type:

dict

_open_csv() None

Opens the .csv-file and loads data set.

Raises:

FileNotFoundError – when .csv-file cannot be read

_check_data() None

Checks if row in opened .csv-file contains the simulation start date.

Raises:

ValueError – Start date is not in .csv-file

_resample_data() None

Resamples the data to the target resolution.

_apply_scaling(start: float, end: float, col: str | None = None) None

Apply scaling factor (end/start).

Parameters:
  • start (float) – e.g. The rated power of original profile (.csv file).

  • end (float) – e.g. The rated power of profile exposed to eELib.

  • col (str | None, optional) – Name of the column to be scaled. Leave empty to scale all columns.

step(timestep: int) None

Performs simulation step of eELib csv_reader model, which is returning the averaged read values in the .csv-file.

Parameters:

timestep (int) – (in s) Index of current simulation step. The length of a step is defined in self.step_size.

class GenericCSV(datafile: str, start_time: str, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', **kwargs)

Bases: CSVReader

CSV-Reader for profiles. Sets each column of the csv file as attribute.

step(timestep: int) None

Performs simulation step of generic csv reader model, which is setting the attr according to the columns in .csv file.

Parameters:

timestep (int) – Index of current simulation step. The length of a step is defined in self.step_size (in s).

class ConventionalCSV(datafile: str, start_time: str, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', **kwargs)

Bases: CSVReader

Base class for all CSVReaders that expect specific column content. E.g. a PowerCSV would expect “P in W” for it’s simulation. This class would search for “P in” in every column name, retrieve that column and possibly convert, if the name was “P in kW”.

Only cols specified in symbols_and_units remain in self.data and an error is raised, if none is found. Known conversions are stored in self._conversions.

class SymbolUnit

Represents an expected data series for this CSV-Reader via symbol and unit.

symbol: str
unit: str
optional: bool = 'False'
SYMBOLS: list[ConventionalCSV.SymbolUnit] = '[]'
_conversions: dict
_apply_unit_conversion(col_name: str, target_unit: str)
_filter_expected_cols() None

The input expected symbols and their units are used in simulation. This method retrieves them from self.data and retrieves no others.

class PowerCSV(datafile: str, start_time: str, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', cos_phi: float | None = None, **kwargs)

Bases: ConventionalCSV

CSV-Data-Reader parent for power profiles.

Exposes the annual energy from active power as self.e_annual.

Your .csv is expected to contain a column with the name “P in W” or “P in kW”, …

There are options for reactive power:
1. add a second column “Q in VAr” in the .csv-file.
2. or input a cos_phi to let this model calculate self.q from the active power.
- if representing thermal power, do neither 1. or 2. and the model will store self.q=0.0.
property e_annual

Annual energy based on all values in “P” column in .csv.

VALID_PARAMETERS
SYMBOLS: list[ConventionalCSV]
p: float = '0.0'
q: float = '0.0'
_calc_reactive_power() None

Calculate reactive power if not given in csv file and if cos_phi is set.

step(timestep: int)

Performs simulation step of eELib load model, which is returning the read reactive power value of the .csv-file.

Parameters:

timestep (int) – Current simulation time in seconds.

class RatedCSV(datafile: str, start_time: str, p_rated: float, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', cos_phi: float | None = None, **kwargs)

Bases: PowerCSV

CSV-Reader for power profiles that can be associated with a rated power (PV, HP, Thermal Power, … - not Households). Can NOT be scaled. Always represents the original .csv profile.

VALID_PARAMETERS
p_rated
class RatedScalableCSV(datafile: str, start_time: str, p_rated: float, p_rated_sim: float | None = None, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', cos_phi: float | None = None, **kwargs)

Bases: RatedCSV

Same as RatedCSV, but p and q exposed to simulation may be scaled using p_rated_sim/p_rated.

VALID_PARAMETERS
class HouseholdCSV(datafile: str, start_time: str, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', cos_phi: float | None = None, e_annual_sim: float | None = None, **kwargs)

Bases: PowerCSV

CSV-Data-Reader for household load profiles using individualy specified datafiles. Similar functionality as PowerCSV, but marking Household load. In that, can (only) be scaled by annual load (in Wh).

e_annual_sim defines the annual energy of the Household in simulation. If defined, the profile is scaled to fit the new e_annual. If undefined, the original profile is used in Sim.

VALID_PARAMETERS
class HouseholdWPuQCSV(eid: str, cos_phi: float | None = None, e_annual_sim: float | None = None, incl_hp: bool = False, **kwargs)

Bases: HouseholdCSV

CSV-Data-Reader for household load profiles in pre-defined format based on the WPuQ project. Similar functionality as HouseholdCSV, meaing it can be scaled using e_annual_sim, but additionally…

Exposes active (p) and reactive power (q) for household loads, as profiles from the WPuQ project provide both. incl_hp defines whether to add the heatpump of the original WPuQ profile to p and q.

File path (datafile is not a parameter, as the model automatically selects unique files from the wpuq folder. If all profiles from that folder are already placed in sim, the selection starts anew from the first profile and shifts start time by 7 days, avoding simultaneity of any profiles in sim.

VALID_PARAMETERS
SYMBOLS: list[ConventionalCSV]
incl_hp: bool = 'False'
static _select_datafile(eid: str, incl_hp: bool) tuple[str, datetime.timedelta]

From the eid, expected to end with an ascending index, select a wpuq profile from the dir_list. Warn if reached end -> start from first profile shifted.

static _first_date_in_profile(datafile: str | pathlib.Path)
class PvCSV(datafile: str, start_time: str, p_rated: float, p_rated_sim: float | None = None, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', cos_phi: float | None = None, **kwargs)

Bases: RatedScalableCSV

CSV-Data-Reader marking pv-generation profiles.

step(timestep: int)

Performs simulation step of eELib load model, which is returning the read active/reactive power value of the .csv-file.

Parameters:

timestep (int) – Index of current simulation step. The length of a step is defined in self.step_size (in s).

class HeatpumpCSV(datafile: str, start_time: str, p_rated: float, p_rated_sim: float | None = None, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', cos_phi: float | None = None, **kwargs)

Bases: RatedScalableCSV

CSV-Data-Reader for heatpump load profiles. Expected input data is the electrical power. No thermal power is calculated and exposed.

class ChargingStationCSV(datafile: str, start_time: str, p_rated: float, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', cos_phi: float | None = None, **kwargs)

Bases: RatedCSV

CSV-Data-Reader marking charging station load profiles.

class HouseholdThermalCSV(datafile: str, start_time: str, header_rows: int = 1, date_format: str = 'YYYY-MM-DD HH:mm:ss', delimiter: str = ',', e_th_annual_sim: float | None = None, **kwargs)

Bases: ConventionalCSV

CSV-Data-Reader for thermal demand profiles.

Two columns are mandatory in the .csv: | - “P_th_room in W” or “P_th_room in kW”, … | - “P_th_water in W” or “P_th_water in kW”, …

Can be scaled by annual thermal energy (in Wh). e_th_annual defines the annual thermal energy in simulation. If defined, the profile is scaled to fit the new e_th_annual. If undefined, the original profile is used in Sim.

property e_th_annual

Calculate the annual thermal energy from the sum of power values, scaling up/down to 1 year. NOTE: Expecting second column to be power in Watt at this point!

VALID_PARAMETERS
SYMBOLS: list[ConventionalCSV]
p_th_room: int | float = '0'
p_th_water: int | float = '0'
step(timestep: int)

Performs simulation step of eELib charging_station model, which is returning the read active power value of the .csv-file.

Parameters:

timestep (int) – Index of current simulation step. The length of a step is defined in self.step_size (in s).