From 777aec362f4899a6781ce117b15ed71759228a4e Mon Sep 17 00:00:00 2001 From: BenWinchester Date: Mon, 22 Jan 2024 14:56:49 +0000 Subject: [PATCH 1/3] :art: Format code with black --- src/heatdesalination/heat_pump.py | 17 +++++++++++++++-- src/heatdesalination/plant.py | 19 +++++++++++++++++++ src/heatdesalination/simulator.py | 1 + 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/heatdesalination/heat_pump.py b/src/heatdesalination/heat_pump.py index 0da549d..5e3c27b 100644 --- a/src/heatdesalination/heat_pump.py +++ b/src/heatdesalination/heat_pump.py @@ -110,6 +110,7 @@ def get_emissions(self, thermal_power: float) -> float: def _coefficient_of_performance( condensation_temperature: float, evaporation_temperature: float, + pinch_point_temperature_difference: float, system_efficiency: float, ) -> float: """ @@ -135,6 +136,10 @@ def _coefficient_of_performance( the temperature at which heat is absorbed from the environment in order to evaporate the heat-transfer fluid (refrigerant) within the heat pump, measured in degrees Kelvin. + - pinch_point_temperature_difference: + The temperature difference between the desired condensation and evaporation + temperatures and the real temperatures achieved, dictated by the effective + possible rate of heat transfer across the heat exchangers in the system. - system_efficiency: The efficiency of the heat pump system given as a fraction of its efficiency against the Carnot efficiency. @@ -146,7 +151,7 @@ def _coefficient_of_performance( return ( system_efficiency - * condensation_temperature + * (condensation_temperature + pinch_point_temperature_difference) / (condensation_temperature - evaporation_temperature) ) @@ -156,6 +161,7 @@ def calculate_heat_pump_electricity_consumption_and_cost_and_emissions( evaporation_temperature: float, heat_demand: float, heat_pump: HeatPump, + pinch_point_temperature_difference, ) -> Tuple[float, float, float]: """ Calculate the electricity comsumption and the cost and emissions of the heat pump. @@ -189,6 +195,10 @@ def calculate_heat_pump_electricity_consumption_and_cost_and_emissions( The heat demand flux, measured in kiloWatts. - heat_pump: The heat pump currently being considered. + - pinch_point_temperature_difference: + The temperature difference between the desired condensation and evaporation + temperatures and the real temperatures achieved, dictated by the effective + possible rate of heat transfer across the heat exchangers in the system. Outputs: - The cost of the heat pump in USD, @@ -199,7 +209,10 @@ def calculate_heat_pump_electricity_consumption_and_cost_and_emissions( power_consumption = heat_demand / ( cop := _coefficient_of_performance( - condensation_temperature, evaporation_temperature, heat_pump.efficiency + condensation_temperature, + evaporation_temperature, + pinch_point_temperature_difference, + heat_pump.efficiency, ) ) cost = heat_pump.get_cost(cop, heat_demand) diff --git a/src/heatdesalination/plant.py b/src/heatdesalination/plant.py index b87c324..29f3795 100644 --- a/src/heatdesalination/plant.py +++ b/src/heatdesalination/plant.py @@ -49,6 +49,10 @@ # Keyword for plant outputs. OUTPUTS: str = "outputs" +# PINCH_POINT_TEMPERATURE_DIFFERENCE: +# Keyword for the pinch-point temperature difference. +PINCH_POINT_TEMPERATURE_DIFFERENCE: str = "pinch_point_temperature_difference" + # PLANT_DISABLED: # Keyword for when the plant is disabled, i.e., not operating. PLANT_DISABLED: str = "plant_disabled" @@ -149,6 +153,11 @@ class DesalinationPlant: .. attribute:: operating_hours The number of hours a day that the plant is operating. + .. attribute:: pinch_point_temperature_difference + The temperature difference between the desired condensation and evaporation + temperatures and the real temperatures achieved, dictated by the effective + possible rate of heat transfer across the heat exchangers in the system. + .. attribute:: plant_outputs The outputs of the plant when in operation (True) and not in operation (False). @@ -165,6 +174,7 @@ def __init__( self, name: str, operating_hours: int, + pinch_point_temperature_difference: float, plant_outputs: dict[bool, PlantOutputs], plant_requirements: dict[bool, PlantRequirements], start_hour: int, @@ -177,6 +187,11 @@ def __init__( The name of the desalination plant. - operating_hours: The number of hours a day that the plant is in operation. + - pinch_point_temperature_difference: + The temperature difference between the desired condensation and + evaporation temperatures and the real temperatures achieved, dictated by + the effective possible rate of heat transfer across the heat exchangers + in the system. - plant_outputs: The outputs from the desalination plant. - plant_reqiurements: @@ -191,6 +206,9 @@ def __init__( ) self.name: str = name self.operating_hours = operating_hours + self.pinch_point_temperature_difference: float = ( + pinch_point_temperature_difference + ) self.plant_outputs: dict[bool, PlantOutputs] = plant_outputs self.plant_requirements: dict[bool, PlantRequirements] = plant_requirements self.start_hour: int = start_hour @@ -264,6 +282,7 @@ def from_dict( return cls( input_data[NAME], input_data[OPERATING_HOURS], + input_data.get(PINCH_POINT_TEMPERATURE_DIFFERENCE, 0), plant_outputs, plant_requirements, start_hour, diff --git a/src/heatdesalination/simulator.py b/src/heatdesalination/simulator.py index 5e41d62..a2cea86 100644 --- a/src/heatdesalination/simulator.py +++ b/src/heatdesalination/simulator.py @@ -854,6 +854,7 @@ def run_simulation( # pylint: disable=too-many-statements ambient_temperatures[hour], auxiliary_heating_demand, heat_pump, + desalination_plant.pinch_point_temperature_difference, ) auxiliary_heating_electricity_demand: float = max( From 561d4d1472b3a6460608eeed5c7277afbb4f00b4 Mon Sep 17 00:00:00 2001 From: BenWinchester Date: Mon, 22 Jan 2024 14:58:35 +0000 Subject: [PATCH 2/3] Update plotter --- plotter.py | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/plotter.py b/plotter.py index d2c48b8..8870cd7 100644 --- a/plotter.py +++ b/plotter.py @@ -313,7 +313,7 @@ ALPHA = 0.9 sns.set_style("whitegrid") -sns.set_context("notebook") +sns.set_context("poster") colorblind_palette = sns.color_palette( [ @@ -2949,7 +2949,7 @@ sns.set_palette(colorblind_palette) # Read input data -with open("31_mar_23_v2.json", "r", encoding="UTF-8") as f: +with open("clean_water_optimisations_data.json", "r", encoding="UTF-8") as f: full_data = json.load(f) data = { @@ -7928,7 +7928,7 @@ def _post_process_split_axes(ax1, ax2): # Plot using an added 10% height ONLY to the error bars -fig, axes = plt.subplots(2, 2, figsize=(48 / 5, 32 / 5)) +fig, axes = plt.subplots(2, 2, figsize=(15, 10)) fig.subplots_adjust(hspace=0.35) @@ -8079,7 +8079,7 @@ def _post_process_split_axes(ax1, ax2): data_to_plot = data_to_plot.drop("Total").transpose() data_to_plot.plot.bar(ax=(axis := axes[0, 1]), rot=0, stacked=True, edgecolor="none") axis.errorbar( - x=data_to_error_bar.index, + x=data_to_plot.index, y=[(y_min[index] + max_entry) / 2 for index, max_entry in enumerate(y_max)], yerr=[abs(max_entry - y_min[index]) / 2 for index, max_entry in enumerate(y_max)], capsize=10, @@ -8305,9 +8305,9 @@ def _post_process_split_axes(ax1, ax2): plt.savefig( - "specific_costs_comparison_15_10_percent_error.png", + "specific_costs_comparison_poster_15_10_percent_error.png", transparent=True, - dpi=300, + dpi=1200, bbox_inches="tight", ) @@ -9012,7 +9012,7 @@ def _post_process_split_axes(ax1, ax2): import math -fig, axes = plt.subplots(2, 2, figsize=(48 / 5, 32 / 5)) +fig, axes = plt.subplots(2, 2, figsize=(15, 10)) fig.subplots_adjust(hspace=0.35) K_DEPTH: int = 3 @@ -9245,14 +9245,14 @@ def _post_process_split_axes(ax1, ax2): data_to_plot.plot.bar(ax=axis, rot=0, stacked=True, edgecolor="none") axis.grid(axis="x") axis.set_xlabel("MED Plant") -axis.set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axis.set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") axis.set_title("Abu Dhabi, UAE") axis.yaxis.set_minor_formatter(ticker.ScalarFormatter()) axis.yaxis.set_major_formatter(ticker.ScalarFormatter()) axis.set_ylim(0, specific_emissions_y_lim) axis.text( - -0.08, - 1.1, + 0, + 1.15, "a.", transform=axis.transAxes, fontsize=16, @@ -9385,12 +9385,12 @@ def _post_process_split_axes(ax1, ax2): data_to_plot.plot.bar(ax=axis, rot=0, stacked=True, edgecolor="none") axis.grid(axis="x") axis.set_xlabel("MED Plant") -axis.set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axis.set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") axis.set_title("Gando, Gran Canaria") axis.set_ylim(0, specific_emissions_y_lim) axis.text( - -0.08, - 1.1, + 0, + 1.15, "b.", transform=axis.transAxes, fontsize=16, @@ -9519,12 +9519,12 @@ def _post_process_split_axes(ax1, ax2): data_to_plot.plot.bar(ax=axis, rot=0, stacked=True, edgecolor="none") axis.grid(axis="x") axis.set_xlabel("MED Plant") -axis.set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axis.set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") axis.set_ylim(0, specific_emissions_y_lim) axis.set_title("Tijuana, Mexico") axis.text( - -0.08, - 1.1, + 0, + 1.15, "c.", transform=axis.transAxes, fontsize=16, @@ -9653,12 +9653,12 @@ def _post_process_split_axes(ax1, ax2): data_to_plot.plot.bar(ax=axis, rot=0, stacked=True, edgecolor="none") axis.grid(axis="x") axis.set_xlabel("MED Plant") -axis.set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axis.set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") axis.set_ylim(0, specific_emissions_y_lim) axis.set_title("La Paz, Mexico") axis.text( - -0.08, - 1.1, + 0, + 1.15, "d.", transform=axis.transAxes, fontsize=16, @@ -9691,7 +9691,7 @@ def _post_process_split_axes(ax1, ax2): plt.savefig( "specific_emissions_comparison_15.png", transparent=True, - dpi=300, + dpi=1200, bbox_inches="tight", ) @@ -11278,7 +11278,7 @@ def plot_battery_inverter_line_map( ) axis.set_xlabel("Specific cost / USD/m$^3$") -axis.set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axis.set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") axis.set_title("Smallest-capacity plant") locmin = mticker.LogLocator(base=10, subs=np.arange(0.1, 10, 0.1), numticks=100) @@ -11525,7 +11525,7 @@ def _post_process_split_kde_axes(ax1, ax2): bw_adjust=bw_adjust, ) axis.set_xlabel("Specific cost / USD/m$^3$") -axes[0].set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axes[0].set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") axis.set_title("Medium-capacity plant") axis.set_ylabel("") @@ -11711,7 +11711,7 @@ def _post_process_split_kde_axes(ax1, ax2): ) axis.set_xlabel("Specific cost / USD/m$^3$") -axis.set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axis.set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") axis.set_title("Medium-capacity plant") axis.legend() @@ -11956,7 +11956,7 @@ def _post_process_split_kde_axes(ax1, ax2): bw_adjust=bw_adjust, ) axis.set_xlabel("Specific cost / USD/m$^3$") -axes[0].set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axes[0].set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") # axis.set_title("Medium-capacity plant") axis.set_ylabel("") @@ -12143,7 +12143,7 @@ def _post_process_split_kde_axes(ax1, ax2): ) axis.set_xlabel("Specific cost / USD/m$^3$") -axis.set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axis.set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") axis.set_title("Medium-capacity plant") axis.legend() @@ -12396,7 +12396,7 @@ def _post_process_split_kde_axes(ax1, ax2): ha="center", va="center", ) -axes[0].set_ylabel("Specific emissions / kg CO$_2$eq/m$^3$") +axes[0].set_ylabel("Spec. emissions / kg CO$_2$eq/m$^3$") plt.figtext( 0.5, axis.get_position().y1 + 0.014, From 0e66deffe4b2612a73c7578fdfb7a6d3a25dbb63 Mon Sep 17 00:00:00 2001 From: BenWinchester Date: Mon, 22 Jan 2024 14:58:54 +0000 Subject: [PATCH 3/3] Add PPTD to plant input file --- inputs/plants.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inputs/plants.yaml b/inputs/plants.yaml index c1936e9..5e2396b 100644 --- a/inputs/plants.yaml +++ b/inputs/plants.yaml @@ -11,6 +11,7 @@ desalination_plants: - name: default_med operating_hours: !!int 10 # Number of operating hours per day + pinch_point_temperature_difference: !!float 1 plant_disabled: requirements: electricity: !!float 30 # [kW] Electricity requirements @@ -39,6 +40,7 @@ desalination_plants: # NOTE: This plant is capable of producing 3 m^3 of desalinated water per day. - name: !!str joo_med_24_hour operating_hours: !!int 24 # Number of operating hours per day + pinch_point_temperature_difference: !!float 1 plant_disabled: requirements: electricity: !!float 0 # [kW] Electricity requirements @@ -67,6 +69,7 @@ desalination_plants: # day and runs for 24 hours of the day. - name: !!str el_nashar_24_hour operating_hours: !!int 24 # Number of operating hours per day + pinch_point_temperature_difference: !!float 1 plant_disabled: requirements: electricity: !!float 0 # [kW] Electricity requirements @@ -96,6 +99,7 @@ desalination_plants: # day and runs for 24 hours of the day. - name: !!str rahimi_24_hour operating_hours: !!int 24 # Number of operating hours per day + pinch_point_temperature_difference: !!float 1 plant_disabled: requirements: electricity: !!float 0 # [kW] Electricity requirements