ebm.model.file_handler module

class FileHandler(directory: str | Path | None = None)[source]

Bases: object

Handles file operations.

BUILDING_CONDITIONS = 'building_conditions.csv'
BUILDING_CODE_PARAMS = 'building_code_parameters.csv'
S_CURVE = 's_curve.csv'
POPULATION_FORECAST = 'population_forecast.csv'
NEW_BUILDINGS_RESIDENTIAL = 'new_buildings_residential.csv'
AREA_NEW_RESIDENTIAL_BUILDINGS = 'area_new_residential_buildings.csv'
AREA = 'area.csv'
BEHAVIOUR_FACTOR = 'energy_need_behaviour_factor.csv'
ENERGY_NEED_ORIGINAL_CONDITION = 'energy_need_original_condition.csv'
IMPROVEMENT_BUILDING_UPGRADE = 'improvement_building_upgrade.csv'
ENERGY_NEED_YEARLY_IMPROVEMENTS = 'energy_need_improvements.csv'
HOLIDAY_HOME_STOCK = 'holiday_home_stock.csv'
HOLIDAY_HOME_ENERGY_CONSUMPTION = 'holiday_home_energy_consumption.csv'
AREA_PER_PERSON = 'area_per_person.csv'
HEATING_SYSTEM_INITIAL_SHARES = 'heating_system_initial_shares.csv'
HEATING_SYSTEM_EFFICIENCIES = 'heating_system_efficiencies.csv'
HEATING_SYSTEM_FORECAST = 'heating_system_forecast.csv'
CALIBRATE_ENERGY_REQUIREMENT = 'calibrate_heating_rv.xlsx'
CALIBRATE_ENERGY_CONSUMPTION = 'calibrate_energy_consumption.xlsx'
__init__(directory: str | Path | None = None)[source]

Constructor for FileHandler Object. Sets FileHandler.input_directory.

Parameters

directorypathlib.Path | None | (str)
When directory is None the constructor will attempt to read directory location from

environment variable EBM_INPUT_DIRECTORY

input_directory: Path
static default_data_directory() Path[source]

Returns the path for ebm default data. The function is used when content is needed for a new input directory

Not to be confused with FileHandler.input_directory.

Returns

pathlib.Path

See Also

create_missing_input_files

get_file(file_name: str) DataFrame[source]

Finds and returns a file by searching in the folder defined by self.input_folder

Parameters: - file_name (str): Name of the file to retrieve.

Returns: - file_df (pd.DataFrame): DataFrame containing file data.

get_building_code() DataFrame[source]

Get TEK parameters DataFrame.

Returns: - building_code_params (pd.DataFrame): DataFrame containing TEK parameters.

get_s_curve() DataFrame[source]

Get S-curve parameters DataFrame.

Returns: - scurve_params (pd.DataFrame): DataFrame containing S-curve parameters.

get_construction_population() DataFrame[source]

Get population and household size DataFrame from a file.

Returns: - construction_population (pd.DataFrame): Dataframe containing population numbers

year population household_size

get_population() DataFrame[source]

Loads population data from population.csv as float64

Should probably be merged with get_construction_population

Returns populationpd.DataFrame

dataframe with population


get_construction_building_category_share() DataFrame[source]

Get building category share by year DataFrame from a file.

The number can be used in conjunction with number of households to calculate total number of buildings of category house and apartment block

Returns: - construction_population (pd.DataFrame): Dataframe containing population numbers

“year”, “Andel nye småhus”, “Andel nye leiligheter”, “Areal nye småhus”, “Areal nye leiligheter”

get_building_category_area() DataFrame[source]

Get population and household size DataFrame from a file.

Returns: - construction_population (pd.DataFrame): Dataframe containing population numbers

“area”,”type of building”,”2010”,”2011”

get_area_parameters() DataFrame[source]

Get dataframe with area parameters.

Returns: - area_parameters (pd.DataFrame): Dataframe containing total area (m^2) per

building category and TEK.

get_energy_req_original_condition() DataFrame[source]

Get dataframe with energy requirement (kWh/m^2) for floor area in original condition.

Returns

pd.DataFrame

Dataframe containing energy requirement (kWh/m^2) for floor area in original condition, per building category and purpose.

get_energy_req_reduction_per_condition() DataFrame[source]

Get dataframe with shares for reducing the energy requirement of the different building conditions.

Returns

pd.DataFrame

Dataframe containing energy requirement reduction shares for the different building conditions, per building category, TEK and purpose.

get_energy_need_yearly_improvements() DataFrame[source]

Get dataframe with yearly efficiency rates for energy requirement improvements.

Returns

pd.DataFrame

Dataframe containing yearly efficiency rates (%) for energy requirement improvements, per building category, tek and purpose.

get_holiday_home_energy_consumption() DataFrame[source]
get_holiday_home_by_year() DataFrame[source]
get_area_per_person()[source]
get_calibrate_heating_rv() DataFrame[source]

Retrieve the calibrated heating requirement values

This method attempts to load the energy requirement calibration file from the input directory. It first checks for a file without extension, then for a .csv version. If neither is found, it returns a default DataFrame.

Returns

pd.DataFrame

A DataFrame containing the calibrated heating requirement values. If no file is found, a default DataFrame is returned.

get_calibrate_heating_systems() DataFrame[source]

Retrieve the calibrated energy consumption values for heating systems

This method attempts to load the energy consumption calibration file from the input directory. It first checks for a file without extension, then for a .csv version. If neither is found, it returns a default DataFrame.

Returns

pd.DataFrame

A DataFrame containing the calibrated energy consumption values. If no file is found, a default DataFrame is returned.

get_heating_systems_shares_start_year() DataFrame[source]
get_heating_system_efficiencies() DataFrame[source]

Load heating_system_efficiencies.csv from file into a dataframe

Returns

heating_system_efficienciespd.DataFrame

pandas DataFrame with heating system efficiencies

get_heating_system_forecast() DataFrame[source]
check_for_missing_files() List[str][source]

Returns a list of required files that are not present in self.input_folder

Returns

missing_files : List[str]

Raises

FileNotFoundError

If FileHandler::input_directory not found

NotADirectoryError

If FileHandler::input_directory is not a directory

create_missing_input_files(source_directory: Path | None = None) None[source]

Creates any input files missing in self.input_directory. When source is omitted FileHandler

Parameters

source_directorypathlib.Path, optional

Optional directory for sourcing files to copy.

Returns

None

See Also

default_data_directory : default source for data files

create_input_file(file, source_directory=None)[source]
validate_input_files()[source]

Validates the input files for correct formatting and content using the validators module

Raises

pa.errors.SchemaErrors

If any invalid data for formatting is found when validating files. The validation is lazy, meaning multiple errors may be listed in the exception.

is_calibrated() bool[source]

Check if calibration files exist in the input directory.

This method verifies the presence of both energy consumption and energy requirement files in either .xlsx or .csv format within the specified input directory.

Returns

bool

True if both required files exist with the same extension (.xlsx or .csv), otherwise False.