Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
# override "HOME" in case this is set to something other than default for windows
os.environ["HOME"] = (Path("C:/Users/") / getpass.getuser()).as_posix()

import python_toolkit
# set plotting style for modules within this toolkit
plt.style.use(Path(list(python_toolkit.__path__)[0]).absolute() / "bhom" / "bhom.mplstyle")

# get dataset paths
SRI_DATA = DATA_DIRECTORY / "sri_data.csv"
KOEPPEN_DATA = DATA_DIRECTORY / "koeppen.csv"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@

def directional_solar_radiation(epw_file, directions, tilts, irradiance_type, analysis_period, cmap, title, save_path) -> str:
try:
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")

if cmap not in plt.colormaps():
cmap = "YlOrRd"

Expand All @@ -93,11 +95,12 @@ def directional_solar_radiation(epw_file, directions, tilts, irradiance_type, an
elif irradiance_type == "Reflected":
irradiance_type = IrradianceType.REFLECTED

fig, ax = plt.subplots(1, 1, figsize=(22.8/2, 7.6/2))
values, dirs, tts = create_radiation_matrix(Path(epw_file), rad_type=irradiance_type, analysis_period=analysis_period, directions=directions, tilts=tilts)
tilt_orientation_factor(Path(epw_file), ax=ax, rad_type=irradiance_type, analysis_period=analysis_period, directions=directions, tilts=tilts, cmap=cmap)
if not (title == "" or title is None):
ax.set_title(title)
with plt.style.context(style):
fig, ax = plt.subplots(1, 1, figsize=(22.8/2, 7.6/2))
values, dirs, tts = create_radiation_matrix(Path(epw_file), rad_type=irradiance_type, analysis_period=analysis_period, directions=directions, tilts=tilts)
tilt_orientation_factor(Path(epw_file), ax=ax, rad_type=irradiance_type, analysis_period=analysis_period, directions=directions, tilts=tilts, cmap=cmap, style_context=style)
if not (title == "" or title is None):
ax.set_title(title)

return_dict = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# pylint: disable=C0415,E0401,W0703
import argparse
import json
import os
import sys
import traceback
from pathlib import Path
Expand Down Expand Up @@ -66,17 +67,19 @@

def diurnal(epw_file, data_type_key="Dry Bulb Temperature", colour="#000000", title=None, period="monthly", save_path = None) -> str:
try:
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")
epw = EPW(epw_file)

if data_type_key == "Wet Bulb Temperature":
coll = wet_bulb_temperature(epw)
else:
coll = HourlyContinuousCollection.from_dict([a for a in epw.to_dict()["data_collections"] if a["header"]["data_type"]["name"] == data_type_key][0])

fig, ax = plt.subplots()

dnal(collection_to_series(coll), ax=ax, title=title, period=period, color=colour)
return_dict = {"data": collection_metadata(coll)}
with plt.style.context(style):
fig, ax = plt.subplots()

dnal(collection_to_series(coll), ax=ax, title=title, period=period, color=colour, style_context=style)
return_dict = {"data": collection_metadata(coll)}

if save_path == None or save_path == "":
base64 = figure_to_base64(fig, html=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Method to wrap creation of diurnal plots"""
# pylint: disable=C0415,E0401,W0703
import argparse
import os
import textwrap

from pathlib import Path
Expand Down Expand Up @@ -50,10 +51,12 @@


def facade_condensation_risk_chart(epw_file: str, thresholds: list[float], save_path: str = None) -> None:
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")

epw = EPW(epw_file)
hcc = epw.dry_bulb_temperature

fig = facade_condensation_risk_chart_table(epw_file, thresholds)
fig = facade_condensation_risk_chart_table(epw_file, thresholds, style_context=style)

return_dict = {"data": collection_metadata(hcc)}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Method to wrap creation of diurnal plots"""
# pylint: disable=C0415,E0401,W0703
import argparse
import os
import textwrap

from pathlib import Path
Expand Down Expand Up @@ -49,10 +50,12 @@
)

def facade_condensation_risk_heatmap(epw_file: str, thresholds: list[float], save_path: str = None) -> None:
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")

epw = EPW(epw_file)
hcc = epw.dry_bulb_temperature

fig = facade_condensation_risk_heatmap_histogram(epw_file, thresholds)
fig = facade_condensation_risk_heatmap_histogram(epw_file, thresholds, style_context=style)

return_dict = {"data": collection_metadata(hcc)}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Method to wrap for conversion of EPW to CSV file."""
# pylint: disable=C0415,E0401,W0703
import argparse
import os
from pathlib import Path
import json
import sys
Expand Down Expand Up @@ -54,19 +55,21 @@
def heatmap(epw_file: str, data_type_key: str, colour_map: str, save_path:str = None) -> str:
"""Create a CSV file version of an EPW."""
try:
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")
if colour_map not in plt.colormaps():
colour_map = "YlGnBu"

fig, ax = plt.subplots()
with plt.style.context(style):
fig, ax = plt.subplots()

epw = EPW(epw_file)
epw = EPW(epw_file)

if data_type_key == "Wet Bulb Temperature":
coll = wet_bulb_temperature(epw)
else:
coll = HourlyContinuousCollection.from_dict([a for a in epw.to_dict()["data_collections"] if a["header"]["data_type"]["name"] == data_type_key][0])
if data_type_key == "Wet Bulb Temperature":
coll = wet_bulb_temperature(epw)
else:
coll = HourlyContinuousCollection.from_dict([a for a in epw.to_dict()["data_collections"] if a["header"]["data_type"]["name"] == data_type_key][0])

hmap(collection_to_series(coll), ax=ax, cmap=colour_map)
hmap(collection_to_series(coll), ax=ax, cmap=colour_map, style_context=style)

return_dict = {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Method to wrap creation of sunpath plots"""
# pylint: disable=C0415,E0401,W0703
import argparse
import os
import sys
import traceback
from pathlib import Path
Expand Down Expand Up @@ -52,11 +53,13 @@

def sunpath(epw_file, analysis_period, size, save_path) -> str:
try:
fig, ax = plt.subplots()
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")
with plt.style.context(style):
fig, ax = plt.subplots()

analysis_period = AnalysisPeriod.from_dict(json.loads(analysis_period))
epw = EPW(epw_file)
spath(location=epw.location, analysis_period=analysis_period, sun_size=size, ax=ax)
analysis_period = AnalysisPeriod.from_dict(json.loads(analysis_period))
epw = EPW(epw_file)
spath(location=epw.location, analysis_period=analysis_period, sun_size=size, ax=ax, style_context=style)

return_dict = {"data": sunpath_metadata(Sunpath.from_location(epw.location))}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Method to wrap UTCI plots"""
# pylint: disable=C0415,E0401,W0703
import argparse
import os
import sys
import traceback
import matplotlib
Expand Down Expand Up @@ -42,6 +43,7 @@

def utci_heatmap(input_json:str, save_path = None, epw_file:str = None) -> str:
try:
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")

if not input_json.startswith("{"): #assume it's a path
with open(input_json, "r") as f:
Expand All @@ -61,14 +63,15 @@ def utci_heatmap(input_json:str, save_path = None, epw_file:str = None) -> str:
colors=(bin_colours),
name="UTCI")

fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ec.plot_utci_heatmap(utci_categories = custom_bins, ax=ax)
with plt.style.context(style):
fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ec.plot_utci_heatmap(utci_categories = custom_bins, ax=ax, style_context=style)

utci_collection = ec.universal_thermal_climate_index
utci_collection = ec.universal_thermal_climate_index

return_dict = {"data": utci_metadata(utci_collection), "external_comfort": ec.to_dict()}
return_dict = {"data": utci_metadata(utci_collection), "external_comfort": ec.to_dict()}

plt.tight_layout()
plt.tight_layout()

if save_path == None or save_path == "":
base64 = figure_to_base64(fig,html=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import os
import sys
import matplotlib
import traceback
Expand Down Expand Up @@ -38,18 +39,21 @@

def walkability_heatmap(input_json: str, save_path: str, epw_file:str = None) -> str:
try:
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")
argsDict = json.loads(input_json)

ec = ExternalComfort.from_dict(json.loads(argsDict["external_comfort"]))
fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ec.plot_walkability_heatmap(ax=ax)

#TODO: create walkability collection metadata
utci_collection = ec.universal_thermal_climate_index
with plt.style.context(style):
fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ec.plot_walkability_heatmap(ax=ax, style_context=style)

return_dict = {"data": utci_metadata(utci_collection), "external_comfort": ec.to_dict()}
#TODO: create walkability collection metadata
utci_collection = ec.universal_thermal_climate_index

plt.tight_layout()
return_dict = {"data": utci_metadata(utci_collection), "external_comfort": ec.to_dict()}

plt.tight_layout()

if save_path == None or save_path == "":
base64 = figure_to_base64(fig,html=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Method to wrap for creating wind roses from epw files."""
# pylint: disable=C0415,E0401,W0703
import argparse
import os
import sys
import traceback
from pathlib import Path
Expand Down Expand Up @@ -59,22 +60,24 @@
def windrose(epw_file: str, analysis_period: str, colour_map: str, bins: int, save_path: str = None) -> str:
"""Method to wrap for creating wind roses from epw files."""
try:
style = os.environ.get("BHOM_style_context", "python_toolkit.bhom")
if colour_map not in plt.colormaps():
colour_map = "YlGnBu"

epw = EPW(epw_file)
analysis_period = AnalysisPeriod.from_dict(json.loads(analysis_period))
w_epw = Wind.from_epw(epw_file)

fig, ax = plt.subplots(1, 1, figsize=(6, 6), subplot_kw={"projection": "polar"})
with plt.style.context(style):
fig, ax = plt.subplots(1, 1, figsize=(6, 6), subplot_kw={"projection": "polar"})

wind_filtered = w_epw.filter_by_analysis_period(analysis_period=analysis_period)
wind_filtered = w_epw.filter_by_analysis_period(analysis_period=analysis_period)

w_epw.filter_by_analysis_period(analysis_period=analysis_period).plot_windrose(ax=ax, directions=bins, ylim=(0, 3.6/bins), colors=colour_map)
wind_filtered.plot_windrose(ax=ax, directions=bins, ylim=(0, 3.6/bins), colors=colour_map, style_context=style)

return_dict = {"data": wind_metadata(wind_filtered, directions=bins)}
return_dict = {"data": wind_metadata(wind_filtered, directions=bins)}

plt.tight_layout()
plt.tight_layout()
if save_path == None or save_path == "":
return_dict["figure"] = figure_to_base64(fig,html=False)
else:
Expand Down
Loading