Skip to content

Commit 458f0a8

Browse files
committed
Merge branch 'master' into fix-download
2 parents 54f11c9 + 57119a6 commit 458f0a8

File tree

18 files changed

+224
-126
lines changed

18 files changed

+224
-126
lines changed

cea/datamanagement/surroundings_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def generate_empty_surroundings(crs) -> gdf:
3333
return gdf(columns=["name", "height_ag", "floors_ag"], geometry=[], crs=crs)
3434

3535

36-
def calc_surrounding_area(zone_gdf, buffer_m):
36+
def calc_surrounding_area(zone_gdf: gdf, buffer_m: float):
3737
"""
3838
Adds buffer to zone to get surroundings area
3939
4040
:param geopandas.GeoDataFrame zone_gdf: Zone GeoDataFrame
4141
:param float buffer_m: Buffer to add to zone building geometries
4242
:return: Surrounding area GeoDataFrame
4343
"""
44-
merged_zone = zone_gdf.geometry.unary_union
44+
merged_zone = zone_gdf.geometry.union_all()
4545
if isinstance(merged_zone, MultiPolygon):
4646
merged_zone = merged_zone.convex_hull
4747

cea/datamanagement/weather_helper/weather_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def fetch_weather_data(weather_file: str, zone_file: str):
3535
weather_data = gpd.read_file(WEATHER_DATA_LOCATION)
3636

3737
# Find nearest weather data based on centroid of zone
38-
centroid = zone_gdf.make_valid().to_crs(weather_data.crs).unary_union.centroid
38+
centroid = zone_gdf.make_valid().to_crs(weather_data.crs).union_all().centroid
3939
index = weather_data.sindex.nearest(centroid)[1][0]
4040
url = f"https://climate.onebuilding.org/{weather_data.iloc[index]['url']}"
4141
data_source_url = "https://climate.onebuilding.org/sources/default.html"

cea/datamanagement/zone_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111
import osmnx
1212
from geopandas import GeoDataFrame as Gdf
13-
from shapely.geometry import Polygon
13+
from shapely import Polygon
1414
import pandas as pd
1515

1616
import cea.config

cea/demand/demand_writers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@
1111
import numpy as np
1212
import pandas as pd
1313

14-
from cea.demand.time_series_data import (EnergyBalanceDashboard, Solar, ElectricalLoads, HeatingLoads,
14+
from cea.demand.time_series_data import (ElectricalLoads, HeatingLoads,
1515
CoolingLoads, FuelSource, HeatingSystemMassFlows,
1616
CoolingSystemMassFlows, HeatingSystemTemperatures,
1717
CoolingSystemTemperatures, RCModelTemperatures)
1818

19+
from cea.utilities.reporting import TSD_KEYS_ENERGY_BALANCE_DASHBOARD, TSD_KEYS_SOLAR
20+
1921
if TYPE_CHECKING:
2022
from cea.demand.building_properties.building_properties_row import BuildingPropertiesRow
2123
from cea.demand.time_series_data import TimeSeriesData
2224

2325
FLOAT_FORMAT = '%.3f'
2426

25-
TSD_KEYS_ENERGY_BALANCE_DASHBOARD = list(EnergyBalanceDashboard.__dataclass_fields__.keys())
26-
TSD_KEYS_SOLAR = list(Solar.__dataclass_fields__.keys())
27-
2827

2928
def get_all_load_keys():
3029
"""Get all available load keys from time series data classes."""
@@ -66,7 +65,7 @@ def __init__(self, loads=None, massflows=None, temperatures=None):
6665
self.mass_flow_vars = massflows if massflows else get_all_massflow_keys()
6766
self.temperature_vars = temperatures if temperatures else get_all_temperature_keys()
6867

69-
self.load_plotting_vars = TSD_KEYS_ENERGY_BALANCE_DASHBOARD + TSD_KEYS_SOLAR
68+
self.load_plotting_vars = TSD_KEYS_ENERGY_BALANCE_DASHBOARD | TSD_KEYS_SOLAR
7069

7170
self.OTHER_VARS = ['name', 'Af_m2', 'Aroof_m2', 'GFA_m2', 'Aocc_m2', 'people0']
7271

cea/demand/thermal_loads.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ def write_results(bpr: BuildingPropertiesRow, building_name, date, locator, reso
204204
print('Creating instant plotly visualizations of demand variable time series.')
205205
print('Behavior can be changed in cea.utilities.reporting code.')
206206
print('Writing detailed demand results of {} to .xls file.'.format(building_name))
207-
reporting.quick_visualization_tsd(tsd, locator.get_demand_results_folder(), building_name)
208-
reporting.full_report_to_xls(tsd, locator.get_demand_results_folder(), building_name)
207+
tsd_df = reporting.calc_full_hourly_dataframe(tsd, date)
208+
reporting.quick_visualization_tsd(tsd_df, locator.get_demand_results_folder(), building_name)
209+
reporting.full_report_to_xls(tsd_df, locator.get_demand_results_folder(), building_name)
209210

210211
writer.results_to_csv(tsd, bpr, locator, date, building_name)
211212

cea/demand/time_series_data.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,4 +838,60 @@ def get_temperature_value(self, temperature_type: str):
838838
if hasattr(obj, temperature_type):
839839
return getattr(obj, temperature_type)
840840

841-
raise ValueError(f"Temperature type '{temperature_type}' not found in any temperature properties.")
841+
raise ValueError(f"Temperature type '{temperature_type}' not found in any temperature properties.")
842+
843+
def get_moisture_value(self, moisture_type: str):
844+
"""
845+
Get the moisture values for a specific moisture measurement type.
846+
"""
847+
load_objects = [
848+
self.moisture
849+
]
850+
851+
for obj in load_objects:
852+
if hasattr(obj, moisture_type):
853+
return getattr(obj, moisture_type)
854+
855+
raise ValueError(f"Moisture type '{moisture_type}' not found in any moisture properties.")
856+
857+
def get_ventilation_mass_flow_value(self, ventilation_type: str):
858+
"""
859+
Get the ventilation mass flow value for a specific ventilation type.
860+
"""
861+
load_objects = [
862+
self.ventilation_mass_flows
863+
]
864+
865+
for obj in load_objects:
866+
if hasattr(obj, ventilation_type):
867+
return getattr(obj, ventilation_type)
868+
869+
raise ValueError(f"Moisture type '{ventilation_type}' not found in any ventilation properties.")
870+
871+
def get_occupancy_value(self, occupancy_var: str):
872+
"""
873+
Get the value for a specific occupancy-related variable.
874+
"""
875+
load_objects = [
876+
self.occupancy
877+
]
878+
879+
for obj in load_objects:
880+
if hasattr(obj, occupancy_var):
881+
return getattr(obj, occupancy_var)
882+
883+
raise ValueError(f"Moisture type '{occupancy_var}' not found in any occupancy-related properties.")
884+
885+
def get_solar_value(self, solar_irradiation_type: str):
886+
"""
887+
Get the solar irradiation value for a specific solar irradiation type.
888+
"""
889+
load_objects = [
890+
self.solar
891+
]
892+
893+
for obj in load_objects:
894+
if hasattr(obj, solar_irradiation_type):
895+
return getattr(obj, solar_irradiation_type)
896+
897+
raise ValueError(f"Moisture type '{solar_irradiation_type}' not found in any occupancy-related properties.")

cea/interfaces/cli/excel_to_shapefile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def excel_to_shapefile(excel_file, shapefile, index, crs, polygon=True):
4444
"""
4545
df = pd.read_excel(excel_file)
4646
if polygon:
47-
geometry = [shapely.geometry.polygon.Polygon(json.loads(g)) for g in df.geometry]
47+
geometry = [shapely.Polygon(json.loads(g)) for g in df.geometry]
4848
else:
49-
geometry = [shapely.geometry.LineString(json.loads(g)) for g in df.geometry]
49+
geometry = [shapely.LineString(json.loads(g)) for g in df.geometry]
5050
df.drop('geometry', axis=1)
5151

5252
gdf = gpd.GeoDataFrame(df, crs=crs, geometry=geometry)

cea/interfaces/cli/shapefile_to_excel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ def shapefile_to_excel(shapefile, excel_file, index=None):
4646

4747

4848
def serialize_geometry(geometry):
49-
"""Take a shapely.geometry.polygon.Polygon and represent it as a string of tuples (x, y)
49+
"""Take a shapely.Polygon and represent it as a string of tuples (x, y)
5050
5151
:param geometry: a polygon or polyline to extract the points from and represent as a json object
52-
:type geometry: shapely.geometry.polygon.Polygon
52+
:type geometry: shapely.Polygon
5353
"""
54-
if isinstance(geometry, shapely.geometry.polygon.Polygon):
54+
if isinstance(geometry, shapely.Polygon):
5555
points = list(geometry.exterior.coords)
56-
elif isinstance(geometry, shapely.geometry.LineString):
56+
elif isinstance(geometry, shapely.LineString):
5757
points = list(geometry.coords)
5858
else:
5959
raise ValueError("Expected either a Polygon or a LineString, got %s" % type(geometry))

cea/optimization_new/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from geopandas import GeoDataFrame as Gdf
2626
import networkx as nx
2727
from networkx.algorithms.approximation.steinertree import steiner_tree
28-
from shapely.geometry import LineString, Point
28+
from shapely import LineString, Point
2929
import wntr
3030
import random
3131

cea/technologies/network_layout/connectivity_potential.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import pandas as pd
1313
from geopandas import GeoDataFrame as gdf
14-
from shapely.geometry import Point, LineString, MultiPoint, box
14+
from shapely import Point, LineString, MultiPoint, box
1515
from shapely.ops import split, linemerge, snap
1616

1717
import cea.config
@@ -211,7 +211,7 @@ def snappy_endings(lines, max_distance, crs):
211211
return df
212212

213213

214-
def split_line_by_nearest_points(gdf_line, gdf_points, tolerance_grid_snap, crs):
214+
def split_line_by_nearest_points(gdf_line: gdf, gdf_points: gdf, tolerance_grid_snap: float, crs: str):
215215
"""
216216
Split the union of lines with the union of points resulting
217217
@@ -225,8 +225,8 @@ def split_line_by_nearest_points(gdf_line, gdf_points, tolerance_grid_snap, crs)
225225
"""
226226

227227
# union all geometries
228-
line = gdf_line.geometry.unary_union
229-
snap_points = gdf_points.geometry.unary_union
228+
line = gdf_line.geometry.union_all()
229+
snap_points = gdf_points.geometry.union_all()
230230

231231
# snap and split coords on line
232232
# returns GeometryCollection

0 commit comments

Comments
 (0)