From 175d772c24854ae7d4ed1a8aa9c4d0b71f096096 Mon Sep 17 00:00:00 2001 From: Peter Yefi Date: Thu, 18 Aug 2022 16:45:55 -0400 Subject: [PATCH] Included an option for return dictionary when output file is None --- .../air_source_hp_export.cpython-38.pyc | Bin 2806 -> 0 bytes .../heat_pump_export.cpython-38.pyc | Bin 8851 -> 0 bytes .../water_to_water_hp_export.cpython-38.pyc | Bin 2632 -> 0 bytes .../energy_systems/air_source_hp_export.py | 8 ++--- exports/energy_systems/heat_pump_export.py | 31 ++++++++++++++---- .../water_to_water_hp_export.py | 6 ++-- exports/energy_systems_factory.py | 4 +-- .../test_energy_systems_air_source_hp.py | 10 +++--- 8 files changed, 37 insertions(+), 22 deletions(-) delete mode 100644 exports/energy_systems/__pycache__/air_source_hp_export.cpython-38.pyc delete mode 100644 exports/energy_systems/__pycache__/heat_pump_export.cpython-38.pyc delete mode 100644 exports/energy_systems/__pycache__/water_to_water_hp_export.cpython-38.pyc diff --git a/exports/energy_systems/__pycache__/air_source_hp_export.cpython-38.pyc b/exports/energy_systems/__pycache__/air_source_hp_export.cpython-38.pyc deleted file mode 100644 index 839a9bb9a1fd02a2c91a3fbdf38af3ab1974398d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2806 zcmZuzTaVjB6dvCaCz~uSZ6zoOM%=21Hc1zdP=u800&`Z04L1=5X_wHEy!T z5$QGae_?z3+fW>(xd`~);r*vsDir1VBdH$>D)kcm)sJ!xGZV!Htn(mOVKSv*B6-wr z|By#2%py)FVT4kG(h|Z zMFv(Law;N=HOA` zJWN733x(^CQw`)EbT}CskOh+&V~cG)Clkm3v(H*%n{~Lu8@$QPiTN&Jjo(eyWbTp8K>xD6TU7MCw%W3kt!w6smq8Q4lQF!nqllExds2jMp+3FZ%iM$H8m z`b~H(c;yh9rOk{-rsyy;F`0GRSQ^X5d*rmK$TRZ7fRVYhmd&N}(gBRwV6EeSYyf^h zGo_=<7k*5SeaXGdSF;htma3E@4yJP|=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sy;{xX zE(~~O2od>Gk^nE|q!3YlJ2vPlA~qmqtWvn$X*A?_bD_6rhx`i^&}Kri43efw5qUIu zkzrF}mp>*%86n*K2~8Q$VHW!K@C5W>3Iu5s{|W885U2@NmX@fWM>($N;1*AO6U_~Z z+A)^oU^6(itOH3#cE3v0>;9-t6kfs;{0ar#>3}CFkW1w( z!5_GeFm(vU9r86jxT{#Yi5ycS5YDdSad^2MUUkJCskn+0D~SsNk-)X;;*)?`LJ@W6osdlYLUU72TPi z+b1@s+I&fqCYgp%7haB!`XIYfiua%K1XC!KJek_$uNS&CHM;bz*%RzY-`D-orcdAz z?D$WpgmkGyK^mBHS7-2L_EeYz1ZsbyF{7qUD`cA!7%=BCFdD9?v^oq&s65XgEs9hz zjEaGo8C+-@yC%!kfw@k86ZK|~Pb1ey0E1b(x$O+i5!X^=E(+vl32$m5`fG9CE3ZQi z9T$K(gokgX9MP`XC!UaQEiPe^<0FYpJb8gbuq)g!3a5l$c!Vb=*|;y1AqQGITY_6S zscOMMaA8+ahl|^3#`-;{73;U%XR-dk;jwAWFGsW(8xYh7l z%ze!t&?GwVM2A+2DGJ%FR>>zGKdT|1fnbua6LK{eWJ|IXzr`bOL9-Xc%|a0x^a3<$ zB(j3(^ugf0N=aK?EsfHJDqVWoHZC=62y_SDksS})_KS|wNJg@@&HSoua}oef#*UK? z(Dje=1A_x2Q(4!)d3f-3x0lNqr=yWls;}S>zKXAd(umAu6 diff --git a/exports/energy_systems/__pycache__/water_to_water_hp_export.cpython-38.pyc b/exports/energy_systems/__pycache__/water_to_water_hp_export.cpython-38.pyc deleted file mode 100644 index 2661ec4763b56b1f432455567c8811dbfe7039f8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2632 zcmZuzOK;pZ5T;(cvixY$q>msiO5~7si)7b!kfJbxB7hwv1svDN18Em11X<*IW$P7^ zs=W*OloUDj+EWk7F@K{!L)V^qE_&%DogsJawPP9LQk>y%9^ZWQ)5XPr!1L?B|Llx>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!EWq+%$_5 zx{7(4g7OK5wbKY>9XXPl2Ci?p-onzS3wm{{>d;Rgt`RsOw)oE hh2j}kFm&S?W_ZSdlZ5$qOpM>*g(6YSh4#7Z{13Mb3?Bdh diff --git a/exports/energy_systems/air_source_hp_export.py b/exports/energy_systems/air_source_hp_export.py index 3ee1dbd9..5d8c1971 100644 --- a/exports/energy_systems/air_source_hp_export.py +++ b/exports/energy_systems/air_source_hp_export.py @@ -6,7 +6,7 @@ Copyright © 2022 Concordia CERC group Project Coder Peter Yefi peteryefi@gmail.com """ from exports.energy_systems.heat_pump_export import HeatPumpExport -from typing import List, Tuple, Union +from typing import List, Dict, Union class AirSourceHPExport(HeatPumpExport): @@ -28,7 +28,6 @@ class AirSourceHPExport(HeatPumpExport): template_path = (base_path / tmp_file) super().__init__(base_path, city, output_path, template_path, demand_path) - def _extract_model_coff(self, hp_model: str, data_type='heat') -> Union[List, None]: """ Extracts heat pump coefficient data for a specific @@ -45,7 +44,7 @@ class AirSourceHPExport(HeatPumpExport): return energy_system.air_source_hp.cooling_capacity_coff return None - def execute_insel(self, user_input, hp_model, data_type): + def execute_insel(self, user_input, hp_model, data_type) -> Union[Dict, None]: """ Runs insel and produces output files Runs insel and write the necessary files @@ -56,7 +55,6 @@ class AirSourceHPExport(HeatPumpExport): :param data_type: a string that indicates whether insel should run for heat or cooling performance :return: - :return: """ capacity_coeff = self._extract_model_coff(hp_model, data_type) - super(AirSourceHPExport, self)._run_insel(user_input, capacity_coeff, 'air_source.insel') + return super(AirSourceHPExport, self)._run_insel(user_input, capacity_coeff, 'air_source.insel') diff --git a/exports/energy_systems/heat_pump_export.py b/exports/energy_systems/heat_pump_export.py index 0c644777..208772ad 100644 --- a/exports/energy_systems/heat_pump_export.py +++ b/exports/energy_systems/heat_pump_export.py @@ -5,7 +5,7 @@ Copyright © 2022 Concordia CERC group Project Coder Peter Yefi peteryefi@gmail.com """ import os -from typing import List, Tuple, Union, Dict +from typing import List, Union, Dict import yaml from string import Template import pandas as pd @@ -28,7 +28,7 @@ class HeatPumpExport: self._base_path = base_path self._output_path = output_path - def _run_insel(self, user_input: Dict, capacity_coeff: List, filename: str) -> None: + def _run_insel(self, user_input: Dict, capacity_coeff: List, filename: str) -> Union[Dict, None]: """ Runs insel and write the necessary files :param user_input: a dictionary containing the user @@ -60,7 +60,7 @@ class HeatPumpExport: # Writer headers to csv output files generated by insel self._write_insel_output_headers() # User output - self._get_user_out_put() + return self._get_user_out_put() except IOError as err: print("I/O exception: {}".format(err)) finally: @@ -224,15 +224,30 @@ class HeatPumpExport: self._input_data["a10"] = a_coeff[9] self._input_data["a11"] = a_coeff[10] - def _get_user_out_put(self): + def _get_user_out_put(self) -> Union[Dict, None]: """ Extracts monthly electricity demand and fossil fuel consumption from output files generated by insel - :return: + :return: Dict for json output """ + demand_data = 'fileOut8' + fossil_data = 'fileOut4' + fossil_index = 2 + demand_index = 2 - electricity_df = pd.read_csv(self._input_data['fileOut8'].strip("'")).iloc[:, 2] - fossil_df = pd.read_csv(self._input_data['fileOut4'].strip("'")).iloc[:, 2] + if self._output_path is None: + demand_data = 'fileOut10' + fossil_data = 'fileOut9' + demand_index = 5 + + electricity_df = pd.read_csv(self._input_data[demand_data].strip("'")).iloc[:, demand_index] + fossil_df = pd.read_csv(self._input_data[fossil_data].strip("'")).iloc[:, fossil_index] + + if self._output_path is None: + return { + 'hourly_electricity_demand': electricity_df.values.tolist(), + 'daily_fossil_consumption': fossil_df.values.tolist() + } data = [electricity_df, fossil_df] df = pd.concat(data, axis=1) @@ -240,3 +255,5 @@ class HeatPumpExport: s = pd.Series(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec", "Total"]) df = df.set_index([s]) df.to_csv(self._output_path) + + diff --git a/exports/energy_systems/water_to_water_hp_export.py b/exports/energy_systems/water_to_water_hp_export.py index 3acf4d45..b2d98e05 100644 --- a/exports/energy_systems/water_to_water_hp_export.py +++ b/exports/energy_systems/water_to_water_hp_export.py @@ -6,7 +6,7 @@ Copyright © 2022 Concordia CERC group Project Coder Peter Yefi peteryefi@gmail.com """ from exports.energy_systems.heat_pump_export import HeatPumpExport -from typing import List, Tuple, Union +from typing import List, Dict, Union class WaterToWaterHPExport(HeatPumpExport): @@ -41,7 +41,7 @@ class WaterToWaterHPExport(HeatPumpExport): return energy_system.water_to_water_hp.power_demand_coff return None - def execute_insel(self, user_input, hp_model): + def execute_insel(self, user_input, hp_model) -> Union[Dict, None]: """ Runs insel and produces output files Runs insel and write the necessary files @@ -52,4 +52,4 @@ class WaterToWaterHPExport(HeatPumpExport): :return: """ pow_demand_coeff = self._extract_model_coff(hp_model) - super(WaterToWaterHPExport, self)._run_insel(user_input, pow_demand_coeff, 'w2w.insel') + return super(WaterToWaterHPExport, self)._run_insel(user_input, pow_demand_coeff, 'w2w.insel') diff --git a/exports/energy_systems_factory.py b/exports/energy_systems_factory.py index 9003b21a..29a3c3c4 100644 --- a/exports/energy_systems_factory.py +++ b/exports/energy_systems_factory.py @@ -48,10 +48,10 @@ class EnergySystemsExportFactory: :return: None """ if source == 'air': - AirSourceHPExport(self._base_path, self._city, self._output_path, self._sim_type, self._demand_path)\ + return AirSourceHPExport(self._base_path, self._city, self._output_path, self._sim_type, self._demand_path)\ .execute_insel(self._user_input, self._hp_model, self._data_type) elif source == 'water': - WaterToWaterHPExport(self._base_path, self._city, self._output_path, self._sim_type, self._demand_path)\ + return WaterToWaterHPExport(self._base_path, self._city, self._output_path, self._sim_type, self._demand_path)\ .execute_insel(self._user_input, self._hp_model) def export(self, source='air'): diff --git a/unittests/test_energy_systems_air_source_hp.py b/unittests/test_energy_systems_air_source_hp.py index c9711cce..294028e6 100644 --- a/unittests/test_energy_systems_air_source_hp.py +++ b/unittests/test_energy_systems_air_source_hp.py @@ -57,11 +57,11 @@ class TestEnergySystemsFactory(TestCase): self.assertEqual(df.iloc[0, 1], 1867715.88) def test_air_source_parallel_heat_pump_export(self): - EnergySystemsExportFactory(city=self._city, user_input=user_input, hp_model='018', - output_path=self._output_path, sim_type=1).export() - df = pd.read_csv(self._output_path) - self.assertEqual(df.shape, (13, 3)) - self.assertEqual(df.iloc[0, 1], 22155602.0) + output = EnergySystemsExportFactory(city=self._city, user_input=user_input, hp_model='018', + output_path=None, sim_type=1).export() + self.assertEqual(output["hourly_electricity_demand"][0], 38748.5625) + self.assertIsNotNone(output["daily_fossil_consumption"]) + self.assertEqual(len(output["hourly_electricity_demand"]), 8760) def tearDown(self) -> None: try: