20240731 set a city from a geojson file, plot monthly district PV with different efficiencies
This commit is contained in:
parent
0ce76bef13
commit
1488c9dbce
|
@ -16,12 +16,12 @@ import json
|
|||
input_files_path = (Path(__file__).parent / 'input_files')
|
||||
output_path = (Path(__file__).parent / 'out_files').resolve()
|
||||
output_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
geojson_file_path_baseline = output_path / 'updated_buildings_with_all_data_baseline.geojson'
|
||||
geojson_file_path = output_path / 'updated_buildings_with_all_data.geojson'
|
||||
with open(geojson_file_path , 'r') as f:
|
||||
building_type_data = json.load(f)
|
||||
|
||||
|
||||
with open(geojson_file_path_baseline, 'r') as f:
|
||||
building_type_data_baseline = json.load(f)
|
||||
|
||||
# Create city object from GeoJSON file
|
||||
city = GeometryFactory('geojson',
|
||||
|
@ -110,37 +110,30 @@ enrich_buildings_with_geojson_data (building_type_data, city)
|
|||
# building.appliances_electrical_demand[cte.YEAR] = [max(monthly_values) / cte.WATTS_HOUR_TO_JULES]
|
||||
|
||||
|
||||
print('test')
|
||||
for building in city.buildings:
|
||||
building.energy_systems_archetype_name = 'system 1 gas'
|
||||
|
||||
|
||||
# def to_dict(building, total_floor_area):
|
||||
# return {
|
||||
# 'roof_area': building.floor_area,
|
||||
# 'total_floor_area': total_floor_area,
|
||||
# 'year_of_construction' : building.year_of_construction,
|
||||
# 'type_function':building.function,
|
||||
# 'beam_kWh_per_m2': sum(building.beam[cte.HOUR])/ (3.6e6),
|
||||
# 'diffuse_kWh_per_m2': sum(building.diffuse[cte.HOUR])/ (3.6e6),
|
||||
# 'direct_normal_kWh_per_m2': sum(building.direct_normal[cte.HOUR])/ (3.6e6),
|
||||
# 'average_storey_height_meters': building.average_storey_height,
|
||||
# 'max_height_meters_meters': building.max_height,
|
||||
# 'global_horizontal_kWh_per_m2': sum(building.global_horizontal[cte.HOUR])/ (3.6e6),
|
||||
# 'appliances_peak_load_kW':building.appliances_peak_load[cte.YEAR][0]/ (1e3),
|
||||
# 'domestic_hot_water_peak_load_kW': building.domestic_hot_water_peak_load[cte.YEAR][0]/ (1e3),
|
||||
# 'heating_peak_load_kW': building.heating_peak_load[cte.YEAR][0]/ (1e3),
|
||||
# 'cooling_peak_load_kW': building.cooling_peak_load[cte.YEAR][0]/ (1e3),
|
||||
# 'lighting_peak_load_kW': building.lighting_peak_load[cte.YEAR][0]/ (1e3),
|
||||
# 'heating_demand_kWh_per_m2' : sum(building.heating_demand[cte.HOUR])/ (3.6e6 * total_floor_area),
|
||||
# 'cooling_demand_kWh_per_m2' : sum(building.cooling_demand[cte.HOUR])/ (3.6e6 * total_floor_area),
|
||||
# 'domestic_hot_water_heat_demand_kWh_per_m2': sum(building.domestic_hot_water_heat_demand[cte.HOUR])/ (3.6e6 * total_floor_area),
|
||||
# 'appliances_electrical_demand_kWh_per_m2':sum(building.appliances_electrical_demand[cte.HOUR])/ (3.6e6 * total_floor_area),
|
||||
# 'lighting_electrical_demand_kWh_per_m2': sum(building.lighting_electrical_demand[cte.HOUR])/ (3.6e6 * total_floor_area),
|
||||
# 'heating_demand_kWh': [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.heating_demand[cte.HOUR]],
|
||||
# 'cooling_demand_kWh':[x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.cooling_demand[cte.HOUR]],
|
||||
# 'domestic_hot_water_heat_demand_kWh': [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.domestic_hot_water_heat_demand[cte.HOUR]],
|
||||
# 'appliances_electrical_demand_kWh':[x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.appliances_electrical_demand[cte.HOUR]],
|
||||
# 'lighting_electrical_demand_kWh': [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.lighting_electrical_demand[cte.HOUR]]
|
||||
# }
|
||||
# buildings_dic={}
|
||||
EnergySystemsFactory('montreal_custom', city).enrich()
|
||||
for building in city.buildings:
|
||||
energy_systems = building.energy_systems
|
||||
for energy_system in energy_systems:
|
||||
generation_units = energy_system.generation_systems
|
||||
if cte.HEATING in energy_system.demand_types:
|
||||
for generation_unit in generation_units:
|
||||
generation_unit.heat_efficiency = 0.96
|
||||
def to_dict(building, total_floor_area):
|
||||
return {
|
||||
'roof_area': building.floor_area,
|
||||
'total_floor_area': total_floor_area,
|
||||
'heating_consumption_kWh': [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.energy_consumption_breakdown[cte.HOUR]],
|
||||
# 'cooling_consumption_kWh':[x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.cooling_demand[cte.HOUR]],
|
||||
# 'domestic_hot_water_consumption_kWh': [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.domestic_hot_water_heat_demand[cte.HOUR]],
|
||||
# 'appliances_consumption_kWh':[x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.appliances_electrical_demand[cte.HOUR]],
|
||||
# 'lighting_consumption_kWh': [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in building.lighting_electrical_demand[cte.HOUR]]
|
||||
}
|
||||
buildings_dic={}
|
||||
|
||||
|
||||
for building in city.buildings:
|
||||
|
@ -149,23 +142,9 @@ for building in city.buildings:
|
|||
for thermal_zone in building.thermal_zones_from_internal_zones:
|
||||
total_floor_area += thermal_zone.total_floor_area
|
||||
print(building.heating_demand[cte.YEAR][0] / (3.6e6 * total_floor_area))
|
||||
building.energy_systems_archetype_name = 'system 1 gas'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EnergySystemsFactory('montreal_custom', city).enrich()
|
||||
print('test')
|
||||
for building in city.buildings:
|
||||
energy_systems = building.energy_systems
|
||||
for energy_system in energy_systems:
|
||||
generation_units = energy_system.generation_systems
|
||||
if cte.HEATING in energy_system.demand_types:
|
||||
for generation_unit in generation_units:
|
||||
generation_unit.heat_efficiency = 0.96
|
||||
|
||||
|
||||
# for building in city.buildings:
|
||||
# print(building.heating_demand[cte.YEAR][0] / 3.6e6)
|
||||
# print(building.name)
|
||||
|
|
79
plot.py
Normal file
79
plot.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
# Load the CSV file
|
||||
file_path = r'C:\Users\a_gabald\Desktop\solar_different_efficiencies.csv' # Replace with your file path
|
||||
data = pd.read_csv(file_path)
|
||||
|
||||
|
||||
# Assuming the CSV has a datetime column, parse it
|
||||
data['datetime'] = pd.date_range(start='1/1/2023', periods=8760, freq='h')
|
||||
|
||||
# Set the datetime column as the index
|
||||
data.set_index('datetime', inplace=True)
|
||||
|
||||
# Resample the data to monthly data
|
||||
monthly_data = data.resample('ME').sum()
|
||||
|
||||
# Extract data for different efficiencies
|
||||
monthly_16_horizontal = monthly_data['district MWh Horizontal_16%']
|
||||
monthly_18_horizontal = monthly_data['district MWh Horizontal_18%']
|
||||
monthly_14_horizontal = monthly_data['district MWh Horizontal_14%']
|
||||
|
||||
monthly_16_tilted = monthly_data['district MWh tilted_16%']
|
||||
monthly_18_tilted = monthly_data['district MWh tilted_18%']
|
||||
monthly_14_tilted = monthly_data['district MWh tilted_14%']
|
||||
|
||||
# Combine the data into a single DataFrame for easier plotting
|
||||
combined_data_horizontal = pd.DataFrame({
|
||||
'Month': monthly_data.index.month,
|
||||
'Horizontal_16%': monthly_16_horizontal,
|
||||
'Horizontal_18%': monthly_18_horizontal,
|
||||
'Horizontal_14%': monthly_14_horizontal
|
||||
})
|
||||
|
||||
combined_data_tilted = pd.DataFrame({
|
||||
'Month': monthly_data.index.month,
|
||||
'Tilted_16%': monthly_16_tilted,
|
||||
'Tilted_18%': monthly_18_tilted,
|
||||
'Tilted_14%': monthly_14_tilted
|
||||
})
|
||||
# Function to plot box and whisker plot
|
||||
import numpy as np
|
||||
|
||||
# Function to plot box and whisker plot
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Function to plot error bars
|
||||
def plot_error_bars(data, title, ylabel):
|
||||
fig, ax = plt.subplots(figsize=(14, 8))
|
||||
|
||||
months = range(1, 13)
|
||||
means_16 = []
|
||||
err_low = []
|
||||
err_high = []
|
||||
|
||||
for month in months:
|
||||
month_data = data[data['Month'] == month]
|
||||
mean_16 = month_data.iloc[:, 1].mean()
|
||||
low_14 = month_data.iloc[:, 3].mean()
|
||||
high_18 = month_data.iloc[:, 2].mean()
|
||||
|
||||
means_16.append(mean_16)
|
||||
err_low.append(mean_16 - low_14)
|
||||
err_high.append(high_18 - mean_16)
|
||||
|
||||
ax.errorbar(months, means_16, yerr=[err_low, err_high], fmt='o', capsize=5, capthick=2, ecolor='gray')
|
||||
|
||||
ax.set_xticks(months)
|
||||
ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
|
||||
ax.set_xlabel('Month')
|
||||
ax.set_ylabel(ylabel)
|
||||
ax.set_title(title)
|
||||
|
||||
plt.show()
|
||||
|
||||
# Plot for Horizontal
|
||||
plot_error_bars(combined_data_horizontal, 'Monthly District MWh (Horizontal)', 'MWh')
|
||||
|
||||
# Plot for Tilted
|
||||
plot_error_bars(combined_data_tilted, 'Monthly District MWh (Tilted)', 'MWh')
|
Loading…
Reference in New Issue
Block a user