Skip to content

Commit

Permalink
Fixes by format action (#264)
Browse files Browse the repository at this point in the history
Just testing
  • Loading branch information
tg359 authored Nov 7, 2024
2 parents ec2d2cb + 02755e6 commit 04df970
Show file tree
Hide file tree
Showing 103 changed files with 2,674 additions and 2,000 deletions.
14 changes: 9 additions & 5 deletions LadybugTools_Engine/Python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def _bhom_version() -> str:
here = Path(__file__).parent.resolve()
long_description = (here / "README.md").read_text(encoding="utf-8")
requirements = [
i.strip()
for i in (here / "requirements.txt").read_text(encoding="utf-8-sig").splitlines()
]
i.strip() for i in (
here /
"requirements.txt").read_text(
encoding="utf-8-sig").splitlines()]

setuptools.setup(
name=TOOLKIT_NAME.lower(),
Expand All @@ -33,8 +34,11 @@ def _bhom_version() -> str:
long_description=long_description,
long_description_content_type="text/markdown",
url=f"https://github.com/BHoM/{TOOLKIT_NAME}",
package_dir={"": "src"},
packages=setuptools.find_packages(where="src", exclude=["tests"]),
package_dir={
"": "src"},
packages=setuptools.find_packages(
where="src",
exclude=["tests"]),
install_requires=requirements,
version=BHOM_VERSION,
)
10 changes: 8 additions & 2 deletions LadybugTools_Engine/Python/src/ladybugtools_toolkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
"""Base module for the ladybugtools_toolkit package."""

# pylint: disable=E0401
import getpass
import os
from pathlib import Path

import matplotlib.pyplot as plt

# pylint: disable=E0401

import matplotlib.pyplot as plt

# override "HOME" in case IT has set this to something other than default
os.environ["HOME"] = (Path("C:/Users/") / getpass.getuser()).as_posix()

# set plotting style for modules within this toolkit
plt.style.use(Path("C:/ProgramData/BHoM/Extensions/PythonCode/Python_Toolkit/src/python_toolkit/bhom/bhom.mplstyle"))
plt.style.use(
Path(
"C:/ProgramData/BHoM/Extensions/PythonCode/Python_Toolkit/src/python_toolkit/bhom/bhom.mplstyle"
)
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Convert methods for objects generic to Ladybug."""

from honeybee_energy.material.opaque import EnergyMaterial, EnergyMaterialVegetation
from honeybee_energy.material.opaque import (EnergyMaterial,
EnergyMaterialVegetation)
from ladybug.analysisperiod import AnalysisPeriod
from ladybug.datacollection import HourlyContinuousCollection
from ladybug.epw import EPW, Location
Expand Down Expand Up @@ -109,7 +110,8 @@ def header_to_bhom(obj: Header) -> dict:
}


def hourlycontinuouscollection_to_bhom(obj: HourlyContinuousCollection) -> dict:
def hourlycontinuouscollection_to_bhom(
obj: HourlyContinuousCollection) -> dict:
"""Convert this object into a BHOM deserialisable dictionary."""
return {
"_t": "BH.oM.LadybugTools.HourlyContinuousCollection",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Method to wrap for conversion of EPW to CSV file."""

# pylint: disable=C0415,E0401,W0703
import argparse
import traceback
Expand All @@ -8,7 +9,8 @@
def main(epw_file: str, include_additional: bool) -> None:
"""Create a CSV file version of an EPW."""
try:
from ladybugtools_toolkit.ladybug_extension.epw import epw_to_dataframe, EPW
from ladybugtools_toolkit.ladybug_extension.epw import (
EPW, epw_to_dataframe)

epw = EPW(epw_file)
df = epw_to_dataframe(epw=epw, include_additional=include_additional)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Method to wrap for access to pre-defined materials."""

# pylint: disable=C0415,E0401,W0703
import argparse
import traceback
Expand All @@ -7,9 +8,8 @@
def main(json_file: str) -> None:
"""From a json file represention of an ExternalComfort, run the calculation."""
try:
from ladybugtools_toolkit.external_comfort._externalcomfortbase import (
ExternalComfort,
)
from ladybugtools_toolkit.external_comfort._externalcomfortbase import \
ExternalComfort

ec = ExternalComfort.from_file(json_file)
ec.to_file(json_file)
Expand All @@ -23,9 +23,7 @@ def main(json_file: str) -> None:
parser = argparse.ArgumentParser(
description=(
"Given a JSON file containing the string represention of a ExternalComfort object, "
"run all calculations Python-side for that object."
)
)
"run all calculations Python-side for that object."))
parser.add_argument(
"-j",
"--json_file",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Method to wrap for conversion of IES GEM to HBJSON file."""

# pylint: disable=C0415,E0401,W0703
import argparse
import traceback
Expand All @@ -12,7 +13,9 @@ def main(gem_file: str) -> None:

gem_file_path = Path(gem_file)
model = model_from_ies(gem_file_path.as_posix())
model.to_hbjson(folder=gem_file_path.parent.as_posix(), name=gem_file_path.stem)
model.to_hbjson(
folder=gem_file_path.parent.as_posix(),
name=gem_file_path.stem)

except Exception as e:
print(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Method to wrap for access to pre-defined materials."""

# pylint: disable=C0415,E0401,W0703
import argparse
import traceback
import json
import traceback


def main(json_file: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Method to wrap for access to pre-defined typologies."""

# pylint: disable=C0415,E0401,W0703
import argparse
import traceback
import json
import traceback


def main(json_file: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Method to wrap for conversion of HBJSON to GEM file."""

# pylint: disable=C0415,E0401,W0703
import argparse
import traceback
Expand All @@ -14,8 +15,9 @@ def main(hbjson_file: str) -> None:
hbjson_file_path = Path(hbjson_file)
model = Model.from_hbjson(hbjson_file_path.as_posix())
model_to_ies(
model, folder=hbjson_file_path.parent.as_posix(), name=hbjson_file_path.stem
)
model,
folder=hbjson_file_path.parent.as_posix(),
name=hbjson_file_path.stem)

except Exception as e:
print(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from ladybug.datacollection import BaseCollection
from ladybugtools_toolkit.ladybug_extension.datacollection import collection_to_series
from ladybugtools_toolkit.ladybug_extension.datacollection import \
collection_to_series


def collection_metadata(collection: BaseCollection) -> dict:
"""Returns a dictionary containing useful metadata about the series.
Args:
collection (BaseCollection):
ladybug data collection object
Returns:
dict:
A dictionary containing metadata about the collection, structured:
Expand All @@ -22,20 +24,20 @@ def collection_metadata(collection: BaseCollection) -> dict:
}
where month_means is a list of means indexed by month, and month_ranges is a list of diurnal month ranges as tuples: (min, max).
"""

series = collection_to_series(collection)
lowest = series.min()
highest = series.max()
lowest_index = series.idxmin()
highest_index = series.idxmax()
median = series.quantile(0.5)
mean = series.mean()

month_means = []
for month in range(12):
month_series = series[series.index.month == month + 1]
month_means.append(month_series.mean())

return {
"lowest": lowest,
"lowest_index": lowest_index,
Expand All @@ -44,4 +46,4 @@ def collection_metadata(collection: BaseCollection) -> dict:
"median": median,
"mean": mean,
"month_means": month_means,
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from ladybug.sunpath import Sunpath
from ladybugtools_toolkit.ladybug_extension.sunpath import sunrise_sunset_azimuths
from datetime import datetime
from datetime import datetime

from ladybug.sunpath import Sunpath
from ladybugtools_toolkit.ladybug_extension.sunpath import \
sunrise_sunset_azimuths


def sunpath_metadata(sunpath: Sunpath) -> dict:
"""Return a dictionary containing equinox and solstice azimuths and altitudes at sunrise, noon and sunset for the given sunpath.
Expand All @@ -12,15 +15,15 @@ def sunpath_metadata(sunpath: Sunpath) -> dict:
Returns:
dict:
A dictionary containing the azimuths and altitudes in the following structure:
{
'december_solstice': {'sunrise': azimuth, 'noon': altitude, 'sunset': azimuth},
'march_equinox': {...},
'june_solstice': {...},
'september_equinox': {...}
}
"""

december_solstice = sunrise_sunset_azimuths(sunpath, 2023, 12, 22)
march_equinox = sunrise_sunset_azimuths(sunpath, 2023, 3, 20)
june_solstice = sunrise_sunset_azimuths(sunpath, 2023, 6, 21)
Expand All @@ -30,5 +33,5 @@ def sunpath_metadata(sunpath: Sunpath) -> dict:
"december_solstice": december_solstice,
"march_equinox": march_equinox,
"june_solstice": june_solstice,
"september_equinox": september_equinox
}
"september_equinox": september_equinox,
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
from ladybug.datacollection import HourlyContinuousCollection
from ladybug.datatype.temperature import (
UniversalThermalClimateIndex as LB_UniversalThermalClimateIndex,
)
from ladybugtools_toolkit.ladybug_extension.datacollection import collection_to_series
from ladybug.datatype.temperature import \
UniversalThermalClimateIndex as LB_UniversalThermalClimateIndex
from ladybugtools_toolkit.ladybug_extension.datacollection import \
collection_to_series

def utci_metadata(utci_collection: HourlyContinuousCollection, comfort_lower: float = 9, comfort_higher: float = 26, use_start_hour: int=7, use_end_hour: int=23) -> dict:

def utci_metadata(
utci_collection: HourlyContinuousCollection,
comfort_lower: float = 9,
comfort_higher: float = 26,
use_start_hour: int = 7,
use_end_hour: int = 23,
) -> dict:
"""Returns a dictionary of useful metadata for the given collection dependant on the given comfortable range.
Args:
utci_collection (HourlyContinuousCollection):
utci headered ladybug hourly collection
comfort_lower (float):
lower value for the comfortable temperature range, where temperatures exclusively below this are too cold.
comfort_higher (float):
higher value for the comfortable temperature range, where temperatures above and equal to this are too hot.
use_start_hour (int):
start hour to filter usage time, inclusive
use_end_hour (int):
end hour to filter usage time, exclusive
Returns:
dict:
dictionary containing comfortable, hot and cold ratios, structured as follows:
Expand All @@ -35,21 +42,30 @@ def utci_metadata(utci_collection: HourlyContinuousCollection, comfort_lower: fl
'daytime_cold': daytime_cold_ratio
}
"""
if not isinstance(utci_collection.header.data_type, LB_UniversalThermalClimateIndex):
if not isinstance(
utci_collection.header.data_type, LB_UniversalThermalClimateIndex
):
raise ValueError("Input collection is not a UTCI collection.")

if not comfort_lower < comfort_higher:
raise ValueError(f"The lower comfort temperature {comfort_lower}, must be less than the higher comfort temperature {comfort_higher}.")
raise ValueError(
f"The lower comfort temperature {comfort_lower}, must be less than the higher comfort temperature {comfort_higher}."
)

series = collection_to_series(utci_collection)

daytime = series.loc[(series.index.hour >= use_start_hour) & (series.index.hour < use_end_hour)]

comfortable_ratio = ((series >= comfort_lower) & (series < comfort_higher)).sum() / len(series)
daytime = series.loc[(series.index.hour >= use_start_hour) & (
series.index.hour < use_end_hour)]

comfortable_ratio = (
(series >= comfort_lower) & (series < comfort_higher)
).sum() / len(series)
hot_ratio = (series >= comfort_higher).sum() / len(series)
cold_ratio = (series < comfort_lower).sum() / len(series)

day_comfortable = ((daytime >= comfort_lower) & (daytime < comfort_higher)).sum() / len(daytime)
day_comfortable = (
(daytime >= comfort_lower) & (daytime < comfort_higher)
).sum() / len(daytime)
day_hot = (daytime >= comfort_higher).sum() / len(daytime)
day_cold = (daytime < comfort_lower).sum() / len(daytime)

Expand All @@ -59,5 +75,5 @@ def utci_metadata(utci_collection: HourlyContinuousCollection, comfort_lower: fl
"cold_ratio": cold_ratio,
"daytime_comfortable": day_comfortable,
"daytime_hot": day_hot,
"daytime_cold": day_cold
}
"daytime_cold": day_cold,
}
Loading

0 comments on commit 04df970

Please sign in to comment.