Added methods to run insel and write output files
This commit is contained in:
parent
102e6ae2d4
commit
c7d569b688
|
@ -3,10 +3,11 @@ HeatPumpExport exports heatpump coefficient into several formats
|
|||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2021 Project Author Peter Yefi peteryefi@gmail.com
|
||||
"""
|
||||
import subprocess
|
||||
from typing import List, Tuple, Union
|
||||
import os
|
||||
from typing import List, Tuple, Union, Dict
|
||||
import yaml
|
||||
from string import Template
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class HeatPumpExport:
|
||||
|
@ -24,7 +25,7 @@ class HeatPumpExport:
|
|||
self._input_data = None
|
||||
self._base_path = base_path
|
||||
|
||||
def run_insel(self, user_input, hp_model, data_type) -> None:
|
||||
def run_insel(self, user_input: Dict, hp_model: str, data_type: str) -> None:
|
||||
"""
|
||||
Runs insel and write the necessary files
|
||||
:param user_input: a dictionary containing the user
|
||||
|
@ -55,17 +56,50 @@ class HeatPumpExport:
|
|||
insel_file_handler = open(insel_file, "w")
|
||||
insel_file_handler.write(insel_template)
|
||||
# Now run insel
|
||||
subprocess.call('insel', insel_file)
|
||||
os.system('insel {}'.format(insel_file))
|
||||
# Writer headers to csv output files generated by insel
|
||||
self._write_insel_output_headers()
|
||||
except IOError as err:
|
||||
print("I/O exception: {}".format(err))
|
||||
except subprocess.CalledProcessError as err:
|
||||
print("Insel command error {}".format(err))
|
||||
else:
|
||||
print("Insel executed successfully")
|
||||
finally:
|
||||
insel_file_handler.close()
|
||||
insel_template_handler.close()
|
||||
|
||||
def _write_insel_output_headers(self):
|
||||
"""
|
||||
Write headers to the various csv file generated by insel
|
||||
:return:
|
||||
"""
|
||||
header_data = {
|
||||
self._input_data['fileOut1']: ['Year', ' Month', ' Day', 'Hour', 'Minute', 'HP Heat Output (kW)',
|
||||
'HP Electricity Consumption (kW)', 'HP COP', 'TES Charging Rate (kg/s)',
|
||||
'TES Discharging Rate (kg/s)', 'TES Node 1 Temperature', 'TES Node 2 Temperature',
|
||||
'TES Node 3 Temperature', 'TES Node 4 Temperature', 'TES Energy Content (J)',
|
||||
'TES Energy Content (kWh)', 'TES Energy Content Variation (kWh)',
|
||||
'Auxiliary Heater Fuel Flow Rate (kg/s)', 'Auxiliary Heater Energy Input (kW)',
|
||||
'HP Operational Cost (CAD)', 'Auxiliary Heater Operational Cost (CAD)',
|
||||
'Operational CO2 Emissions of HP (g)',
|
||||
'Operational CO2 Emissions of Auxiliary Heater (g)',
|
||||
'Return Temperature', 'Demand (kW)'],
|
||||
self._input_data['fileOut2']: ['Day', 'Operational Daily Emissions from Heat Pumps (g)',
|
||||
'Operational Daily Emissions from Auxiliary Heater (g)'],
|
||||
self._input_data['fileOut3']: ['Month', 'Monthly Operational Costs of Heat Pumps (CAD)',
|
||||
'Monthly Operational Costs of Auxiliary Heater (CAD)'],
|
||||
self._input_data['fileOut4']: ['Month', 'Monthly Fuel Consumption of Auxiliary Heater (m3)'],
|
||||
self._input_data['fileOut5']: ['Month', 'Operational Monthly Emissions from Heat Pumps (g)',
|
||||
'Operational Monthly Emissions from Auxiliary Heater (g)'],
|
||||
self._input_data['fileOut6']: ['Day', 'Daily HP Electricity Demand (kWh)'],
|
||||
self._input_data['fileOut7']: ['Day', 'Daily Operational Costs of Heat Pumps (CAD)',
|
||||
'Daily Operational Costs of Auxiliary Heater (CAD)'],
|
||||
self._input_data['fileOut8']: ['Month', 'Monthly HP Electricity Demand (kWh)'],
|
||||
self._input_data['fileOut9']: ['Day', 'Daily Fuel Consumption of Auxiliary Heater (m3)'],
|
||||
self._input_data['fileOut10']: ['Year', 'Month', 'Day', 'Hour', 'HP Electricity Demand (kWh)']
|
||||
}
|
||||
for file_path, header in header_data.items():
|
||||
file_path = file_path.strip("'")
|
||||
df = pd.read_csv(file_path, sep='\s+')
|
||||
df.to_csv(file_path, header=header)
|
||||
|
||||
def _update_input_data_with_files(self):
|
||||
"""
|
||||
Updates input data for insel with some files that will
|
||||
|
@ -73,17 +107,17 @@ class HeatPumpExport:
|
|||
which is the Heating Demand (demand.txt) file
|
||||
:return:
|
||||
"""
|
||||
self._input_data["HeatingDemand"] = self._demand_path
|
||||
self._input_data["fileOut1"] = (self._base_path / 'heat_pumps/technical_performance.csv')
|
||||
self._input_data["fileOut2"] = (self._base_path / 'heat_pumps/system_daily_emissions.cs')
|
||||
self._input_data["fileOut3"] = (self._base_path / 'heat_pumps/monthly_operational_costs.csv')
|
||||
self._input_data["fileOut4"] = (self._base_path / 'heat_pumps/monthly_fossil_fuel_consumptions.csv')
|
||||
self._input_data["fileOut5"] = (self._base_path / 'heat_pumps/system_monthly_emissions.csv')
|
||||
self._input_data["fileOut6"] = (self._base_path / 'heat_pumps/daily_hp_electricity_demand.csv')
|
||||
self._input_data["fileOut7"] = (self._base_path / 'heat_pumps/daily_operational_costs.csv')
|
||||
self._input_data["fileOut8"] = (self._base_path / 'heat_pumps/monthly_hp_electricity_demand.csv')
|
||||
self._input_data["fileOut9"] = (self._base_path / 'heat_pumps/daily_fossil_fuel_consumption.csv')
|
||||
self._input_data["fileOut10"] = (self._base_path / 'heat_pumps/hp_hourly_electricity_demand.csv')
|
||||
self._input_data["HeatingDemand"] = f"'{str(self._demand_path)}'"
|
||||
self._input_data["fileOut1"] = f"'{str((self._base_path / 'heat_pumps/technical_performance.csv'))}'"
|
||||
self._input_data["fileOut2"] = f"'{str((self._base_path / 'heat_pumps/system_daily_emissions.csv'))}'"
|
||||
self._input_data["fileOut3"] = f"'{str((self._base_path / 'heat_pumps/monthly_operational_costs.csv'))}'"
|
||||
self._input_data["fileOut4"] = f"'{str((self._base_path / 'heat_pumps/monthly_fossil_fuel_consumptions.csv'))}'"
|
||||
self._input_data["fileOut5"] = f"'{str((self._base_path / 'heat_pumps/system_monthly_emissions.csv'))}'"
|
||||
self._input_data["fileOut6"] = f"'{str((self._base_path / 'heat_pumps/daily_hp_electricity_demand.csv'))}'"
|
||||
self._input_data["fileOut7"] = f"'{str((self._base_path / 'heat_pumps/daily_operational_costs.csv'))}'"
|
||||
self._input_data["fileOut8"] = f"'{str((self._base_path / 'heat_pumps/monthly_hp_electricity_demand.csv'))}'"
|
||||
self._input_data["fileOut9"] = f"'{str((self._base_path / 'heat_pumps/daily_fossil_fuel_consumption.csv'))}'"
|
||||
self._input_data["fileOut10"] = f"'{str((self._base_path / 'heat_pumps/hp_hourly_electricity_demand.csv'))}'"
|
||||
|
||||
def _compute_max_demand(self):
|
||||
"""
|
||||
|
@ -109,7 +143,7 @@ class HeatPumpExport:
|
|||
self._input_data["TESCapacity"] = self._input_data["HoursOfStorageAtMaxDemand"] * (max_demand * 3.6) / (
|
||||
(self._input_data["Cp"] / 1000) * self._input_data["TemperatureDifference"])
|
||||
|
||||
def _update_input_data_with_coff(self, capacity_coff, comp_power_coff):
|
||||
def _update_input_data_with_coff(self, capacity_coff: List, comp_power_coff: List):
|
||||
"""
|
||||
Updates the user data with coefficients derived from imports
|
||||
:param capacity_coff: heat or cooling capacity coefficients
|
||||
|
@ -129,7 +163,7 @@ class HeatPumpExport:
|
|||
self._input_data["b5"] = comp_power_coff[4]
|
||||
self._input_data["b6"] = comp_power_coff[5]
|
||||
|
||||
def _extract_model_coff(self, hp_model, data_type='heat') -> Union[Tuple[List, List], None]:
|
||||
def _extract_model_coff(self, hp_model: str, data_type='heat') -> Union[Tuple[List, List], None]:
|
||||
"""
|
||||
Extracts heat pump coefficient data for a specific
|
||||
model. e.g 012, 140
|
||||
|
|
Loading…
Reference in New Issue
Block a user