Skip to content

Commit

Permalink
fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nllong committed Sep 14, 2024
1 parent f282298 commit 2607f67
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion urbanopt_des/urbanopt_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def create_summary_results(self) -> None:
# only save off the useful columns for the summary table
year_end = f"{self.year_of_data}-12-31"
summary_data_columns = ["Metric", "Units"]
for analysis_name in ["Non-Connected"], *list(self.modelica.keys()):
for analysis_name in ["Non-Connected", *list(self.modelica.keys())]:
summary_data_columns.append(analysis_name)
if analysis_name == "Non-Connected":
self.urbanopt.grid_metrics_daily
Expand Down
83 changes: 66 additions & 17 deletions urbanopt_des/urbanopt_geojson.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import json
import tempfile
from pathlib import Path
from typing import Union

from geopandas import GeoDataFrame
from shapely.geometry import box


class URBANoptGeoJSON:
def __init__(self, filename: Path):
Expand Down Expand Up @@ -138,23 +142,68 @@ def create_aggregated_representation(self, building_names: list[str]) -> None:
"""Go through the GeoJSON file and if it is of type Building, then aggregate the characteristics.
#TODO: This is a work in progress and can more easily be accomplished with GeoPandas."""
# fields that are summed in the aggregations
sum_fields = ["floor_area", "footprint_area"]
avg_fields = [
"year_built",
"number_of_stories",
"window_wall_ratio",
]

# create a dictionary to hold the aggregated values
aggregated_values = {}
for field in sum_fields:
aggregated_values[field] = 0
for field in avg_fields:
aggregated_values[field] = 0

for building_id in building_names:
pass

# pull out the project data, because it will need to be stitched into
# the geojson file at the end
project_data = self.data["project"]

# read into geodataframe
gdf = GeoDataFrame.from_features(self.data)

# related is a list typically, which isn't supported in geodataframes
gdf = gdf.drop(columns=["related"])

# init new obj, can delete this once the if statement below is
# fully fleshed out.
gdf_2 = None

# add a new field to "enable/disable"
gdf["enabled"] = True
if len(building_names) == 1 and building_names[0] == "all":
# dissolve
gdf_2 = gdf.dissolve(
by="type",
aggfunc={
"footprint_area": "sum",
"Footprint Area (m2)": "sum",
"Footprint Area (ft2)": "sum",
"Height": "mean",
"floor_area": "sum",
"Gross Floor Area": "sum",
"number_of_stories": "mean",
"number_of_stories_above_ground": "mean",
"Building Levels": "mean",
"attic_type": "any",
"foundation_type": "any",
"number_of_bedrooms": "mean",
"number_of_residential_units": "mean",
"enabled": "any",
"id": "first",
},
)

# splat the total_bounds into a box (total_bounds returns minx, miny, maxx, maxy)
gdf_2["geometry"] = box(*gdf_2.total_bounds)

# Set the id on the first element to "all""
gdf_2.loc[gdf_2.index == "Building", "id"] = "all_buildings"
else:
print("This still needs to be implemented")

# save the gdf_2 to a temp geojson file
temp_dir = Path(tempfile.mkdtemp())

if gdf_2 is not None:
gdf_2.to_file(temp_dir / "temp.geojson", driver="GeoJSON")

# read it back in as a dict
with open(temp_dir / "temp.geojson") as f:
gdf_2 = json.load(f)

# update the project data
gdf_2["project"] = project_data

return gdf_2

def save(self) -> None:
"""Save the GeoJSON file"""
Expand Down
10 changes: 7 additions & 3 deletions urbanopt_des/urbanopt_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def process_load_results(self, building_names: list[str], year_of_data: int = 20
# skip if Datetime
if column == "Datetime":
continue
load_report.rename(columns={column: f"{column} Building {building_id}"})
load_report = load_report.rename(columns={column: f"{column} Building {building_id}"})

# convert Datetime column in data frame to be datetime from the string. The year
# should be set to a year that has the day of week starting correctly for the real data
Expand Down Expand Up @@ -902,10 +902,14 @@ def create_abstract_run(self, run_id: str, load_dataframe: pd.DataFrame) -> None
# duplicate the load_dataframe so that we can calculate the seconds in the year
tmp_dataframe = load_dataframe.copy()
# time column is seconds from the start of the year, as integers
tmp_dataframe["time"] = (tmp_dataframe.index - tmp_dataframe.index[0]).total_seconds() + 3600
tmp_dataframe["time"] = (tmp_dataframe.index - tmp_dataframe.index[0]).total_seconds()
# the last timestamp is weird as it will be negative. Take the second to last value and add 3600
tmp_dataframe["time"].iloc[-1] = tmp_dataframe["time"].iloc[-2] + 3600
# the first value of the hot water must be zero, else there will be an error
tmp_dataframe["TotalWaterHeating"].iloc[0] = 0

# coerce time into int
tmp_dataframe["time"] = tmp_dataframe["time"].astype(int)
print(tmp_dataframe["time"])
header = "#1\n"
header += "#Created from results of URBANopt\n\n"
header += "#First column: Seconds in the year (loads are hourly)\n"
Expand Down

0 comments on commit 2607f67

Please sign in to comment.