Added method to write user output

This commit is contained in:
Peter Yefi 2021-11-10 16:58:01 +00:00
parent ebe5439f02
commit b7d1197a2b

View File

@ -56,9 +56,12 @@ class HeatPumpExport:
insel_file_handler = open(insel_file, "w") insel_file_handler = open(insel_file, "w")
insel_file_handler.write(insel_template) insel_file_handler.write(insel_template)
# Now run insel # Now run insel
self._delete_existing_output_files()
os.system('insel {}'.format(insel_file)) os.system('insel {}'.format(insel_file))
# Writer headers to csv output files generated by insel # Writer headers to csv output files generated by insel
self._write_insel_output_headers() self._write_insel_output_headers()
# User output
self._get_user_out_put()
except IOError as err: except IOError as err:
print("I/O exception: {}".format(err)) print("I/O exception: {}".format(err))
finally: finally:
@ -97,7 +100,7 @@ class HeatPumpExport:
} }
for file_path, header in header_data.items(): for file_path, header in header_data.items():
file_path = file_path.strip("'") file_path = file_path.strip("'")
df = pd.read_csv(file_path, sep='\s+') df = pd.read_csv(file_path, header=None, sep='\s+')
df.to_csv(file_path, header=header) df.to_csv(file_path, header=header)
def _update_input_data_with_files(self): def _update_input_data_with_files(self):
@ -119,6 +122,20 @@ class HeatPumpExport:
self._input_data["fileOut9"] = f"'{str((self._base_path / 'heat_pumps/daily_fossil_fuel_consumption.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'))}'" self._input_data["fileOut10"] = f"'{str((self._base_path / 'heat_pumps/hp_hourly_electricity_demand.csv'))}'"
def _delete_existing_output_files(self):
"""
Remove existing out files generated by insel before
running insel
:return:
"""
for key, file_path in self._input_data.items():
if 'fileOut' in key:
file_path = file_path.strip("'")
try:
os.remove(file_path)
except OSError:
pass
def _compute_max_demand(self): def _compute_max_demand(self):
""" """
Retrieves the maximum demand value from Retrieves the maximum demand value from
@ -178,3 +195,20 @@ class HeatPumpExport:
return energy_system.heat_pump.heating_capacity_coff, energy_system.heat_pump.heating_comp_power_coff return energy_system.heat_pump.heating_capacity_coff, energy_system.heat_pump.heating_comp_power_coff
return energy_system.heat_pump.cooling_capacity_coff, energy_system.heat_pump.cooling_comp_power_coff return energy_system.heat_pump.cooling_capacity_coff, energy_system.heat_pump.cooling_comp_power_coff
return None return None
def _get_user_out_put(self):
"""
Extracts monthly electricity demand and fossil fuel consumption
from output files generated by insel
:return:
"""
electricity_df = pd.read_csv(self._input_data['fileOut8'].strip("'")).iloc[:, 2]
fossil_df = pd.read_csv(self._input_data['fileOut4'].strip("'")).iloc[:, 2]
data = [electricity_df, fossil_df]
df = pd.concat(data, axis=1)
df = df.append(df.agg(['sum']))
s = pd.Series(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec", "Total"])
df = df.set_index([s])
print(df)