Modified heat pump import to compute coefficient of performance data

This commit is contained in:
Peter Yefi 2021-11-01 14:53:51 +00:00
parent c221c9876f
commit 545c58a5f1

View File

@ -7,9 +7,12 @@ Contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
import pandas as pd import pandas as pd
from typing import Dict from typing import Dict
from typing import List
from city_model_structure.energy_systems.heat_pump import HeatPump from city_model_structure.energy_systems.heat_pump import HeatPump
from city_model_structure.energy_system import EnergySystem from city_model_structure.energy_system import EnergySystem
from scipy.optimize import curve_fit
import numpy as np
from typing import List
import itertools
class XlsxHeatPumpParameters: class XlsxHeatPumpParameters:
@ -71,16 +74,19 @@ class XlsxHeatPumpParameters:
c_data = self._extract_heat_pump_data(v_cool) c_data = self._extract_heat_pump_data(v_cool)
heat_pump.cooling_capacity = c_data[0] heat_pump.cooling_capacity = c_data[0]
heat_pump.cooling_comp_power = c_data[1] heat_pump.cooling_comp_power = c_data[1]
heat_pump.cooling_water_flow = c_data[2] heat_pump.cooling_capacity_coff = self._compute_coefficients(c_data[0], "cool")
heat_pump.cooling_comp_power_coff = self._compute_coefficients(c_data[1], "cool")
heat_pump.heating_capacity = h_data[0] heat_pump.heating_capacity = h_data[0]
heat_pump.heating_comp_power = h_data[1] heat_pump.heating_comp_power = h_data[1]
heat_pump.heating_water_flow = h_data[2] heat_pump.heating_capacity_coff = self._compute_coefficients(h_data[0])
heat_pump.heating_comp_power_coff = self._compute_coefficients(h_data[1])
energy_system = EnergySystem('{} capacity heat pump'.format(heat_pump.model), 0, [], None) energy_system = EnergySystem('{} capacity heat pump'.format(heat_pump.model), 0, [], None)
energy_system.heat_pump = heat_pump energy_system.heat_pump = heat_pump
self._city.add_city_object(energy_system) self._city.add_city_object(energy_system)
return self._city return self._city
def _extract_heat_pump_data(self, heat_pump_capacity_data) -> [List, List, List]: def _extract_heat_pump_data(self, heat_pump_capacity_data) -> [List, List]:
""" """
Fetches a list of metric based data for heat pump for various temperature, Fetches a list of metric based data for heat pump for various temperature,
eg. cooling capacity data for 12 capacity heat pump eg. cooling capacity data for 12 capacity heat pump
@ -91,9 +97,42 @@ class XlsxHeatPumpParameters:
""" """
cooling_heating_capacity_data = [] cooling_heating_capacity_data = []
compressor_power_data = [] compressor_power_data = []
water_flow_data = []
for _, metric_data in heat_pump_capacity_data.items(): for _, metric_data in heat_pump_capacity_data.items():
cooling_heating_capacity_data.append(metric_data[0]) cooling_heating_capacity_data.append(metric_data[0])
compressor_power_data.append(metric_data[1]) compressor_power_data.append(metric_data[1])
water_flow_data.append(metric_data[2]) return [cooling_heating_capacity_data, compressor_power_data]
return [cooling_heating_capacity_data, compressor_power_data, water_flow_data]
def _compute_coefficients(self, heat_pump_data, data_type="heat") -> List[float]:
"""
Compute heat output and electrical demand coefficients
from heating and cooling performance data
:param heat_pump_data: a list of heat pump data. eg. cooling capacity
:param data_type: string to indicate if data is cooling performance data
or heating performance data
:return: Tuple[Dict, Dict]
"""
out_temp = [25, 30, 32, 35, 40, 45] * 6
heat_x_values = np.repeat([-5, 0, 7, 10, 15], 6)
cool_x_values = np.repeat([6, 7, 8, 9, 10, 11], 6)
x_values = heat_x_values if data_type == "heat" else cool_x_values
# convert list of lists to one list
heat_pump_data = list(itertools.chain.from_iterable(heat_pump_data))
# Compute heat output coefficients
popt, _ = curve_fit(self._objective_function, [x_values, out_temp], heat_pump_data)
return popt.tolist()
def _objective_function(self, xdata, a1, a2, a3, a4, a5, a6):
"""
Objective function for computing coefficients
:param xdata:
:param a1: float
:param a2: float
:param a3: float
:param a4: float
:param a5: float
:param a6: float
:return:
"""
x, y = xdata
return (a1 * x ** 2) + (a2 * x) + (a3 * x * y) + (a4 * y) + (a5 * y ** 2) + a6