Skip to content

Commit

Permalink
feat(csv): Import CSV objects, rebuild windows
Browse files Browse the repository at this point in the history
- Add Import CSV Component
- Add Rebuild Window Surfaces Component
- Fixe Phius Site Component
  • Loading branch information
ed-p-may committed Apr 2, 2023
1 parent 67511f5 commit 831f012
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 12 deletions.
77 changes: 77 additions & 0 deletions honeybee_grasshopper_ph/src/HBPH - Create Objects From CSV.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Honeybee-PH: A Plugin for adding Passive-House data to LadybugTools Honeybee-Energy Models
#
# This component is part of the PH-Tools toolkit <https://github.com/PH-Tools>.
#
# Copyright (c) 2022, PH-Tools and bldgtyp, llc <[email protected]>
# Honeybee-PH is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3 of the License,
# or (at your option) any later version.
#
# Honeybee-PH is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a copy of the GNU General Public License
# see <https://github.com/PH-Tools/honeybee_ph/blob/main/LICENSE>.
#
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
#
"""
Create a series of new objects based on an arbitrary CSV file input. Note that
the first row in the CSV should be the 'headers' which are used as the attribute
names for the object. Each row in the CSV will become a new object with the
attribute values as defined in the file.
-
EM April 2, 2023
Args:
_path: (str) The path to the .CSV file to read.
_object_name: (str) Optional name for the class of the new Objects.
_datatypes: (List[str]) Optional list of datatypes to use to cast the
input data values. This list should follow the structure "header: type"
for instance, inputing:
- - -
"Height: float"
"Width: float"
"ID: int"
- - -
will case the "Height" and "Width" attributes to float types, but will cast the
"ID" attribute as an int.
Returns:
objects_: The list of new Objects created from the CSV file.
"""

import scriptcontext as sc
import Rhino as rh
import rhinoscriptsyntax as rs
import ghpythonlib.components as ghc
import Grasshopper as gh

from honeybee_ph_rhino import gh_compo_io, gh_io

# ------------------------------------------------------------------------------
import honeybee_ph_rhino._component_info_
reload(honeybee_ph_rhino._component_info_)
ghenv.Component.Name = "HBPH - Create Objects From CSV"
DEV = honeybee_ph_rhino._component_info_.set_component_params(ghenv, dev=False)
if DEV:
from honeybee_ph_rhino.gh_compo_io import util_create_objs_from_csv as gh_compo_io
reload(gh_compo_io)

# ------------------------------------------------------------------------------
# -- GH Interface
IGH = gh_io.IGH( ghdoc, ghenv, sc, rh, rs, ghc, gh )

# ------------------------------------------------------------------------------
gh_compo_interface = gh_compo_io.GHCompo_CreateObjectsFromCSV(
IGH,
_path,
_object_name,
_datatypes,
)
objects_ = gh_compo_interface.run()
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
download cliamte data, see:
https://www.phius.org/climate-data-sets
-
EM October 18, 2022
EM April 2, 2023
Args:
_source_file_path: Input the full path to the Phius climate file you would
like to read in. Note: use only the 'TXT' files.
_station_elevation: The Site elevation. If none provided, the station
elevation will be used.
Returns:
site_: A new PHX-Site object with all the relevant Phius climate and location
Expand Down Expand Up @@ -57,11 +60,9 @@
#-------------------------------------------------------------------------------
import honeybee_ph_rhino._component_info_
reload(honeybee_ph_rhino._component_info_)
ghenv.Component.Name = "HBPH - Create Site From Phius File"
ghenv.Component.Name = "HBPH - Create Site From Phius File"
DEV = honeybee_ph_rhino._component_info_.set_component_params(ghenv, dev=False)
if DEV:
reload(gh_compo_io)
reload(gh_io)
from honeybee_ph_rhino.gh_compo_io import climate_site_from_phius_file as gh_compo_io
reload(gh_compo_io)

Expand All @@ -74,7 +75,8 @@
# -------------------------------------------------------------------------------------
gh_compo_interface = gh_compo_io.GHCompo_CreateSiteFromPhiusFile(
IGH,
_source_file_path
_source_file_path,
_site_elevation,
)

site_ = gh_compo_interface.run()
Expand Down
78 changes: 78 additions & 0 deletions honeybee_grasshopper_ph/src/HBPH - Rebuild Window Surfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# Honeybee-PH: A Plugin for adding Passive-House data to LadybugTools Honeybee-Energy Models
#
# This component is part of the PH-Tools toolkit <https://github.com/PH-Tools>.
#
# Copyright (c) 2022, PH-Tools and bldgtyp, llc <[email protected]>
# Honeybee-PH is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3 of the License,
# or (at your option) any later version.
#
# Honeybee-PH is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a copy of the GNU General Public License
# see <https://github.com/PH-Tools/honeybee_ph/blob/main/LICENSE>.
#
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
#
"""
Re-build rectangular surface geometry based on a series of input widths and heights. This
is useful when you need to re-draw windows based on a detailed schedule, or other similar
model-wide revisions to geometry. This component will center the new geometry in the same location
as the old geometry. Use Bake (or HumanUI Bake to get names and custom layers) to push this
new geometry back to the Rhino scene.
-
EM April 2, 2023
Args:
_window_surfaces: (List[Guid]) A list of surface Guids to perform the transformation on.
_widths: (List[float]) A list of the new widths.
_heights: (List[float]) A list of the new heights.
Returns:
new_surfaces_: The new surfaces with the specified width and height values
names_: A list of the names of the new surfaces.
"""

import scriptcontext as sc
import Rhino as rh
import rhinoscriptsyntax as rs
import ghpythonlib.components as ghc
import Grasshopper as gh

try:
from honeybee_ph_utils import preview
except ImportError as e:
raise ImportError('Failed to import honeybee_ph_utils:\t{}'.format(e))

try:
from honeybee_ph_rhino import gh_compo_io, gh_io
except ImportError as e:
raise ImportError('Failed to import honeybee_ph_rhino:\t{}'.format(e))

# -------------------------------------------------------------------------------
import honeybee_ph_rhino._component_info_
reload(honeybee_ph_rhino._component_info_)
ghenv.Component.Name = "HBPH - Rebuild Window Surfaces"
DEV = honeybee_ph_rhino._component_info_.set_component_params(ghenv, dev="23402")
if DEV:
reload(gh_io)
from honeybee_ph_rhino.gh_compo_io import win_rebuild_rh_geom as gh_compo_io
reload(gh_compo_io)


# ------------------------------------------------------------------------------
# -- GH Interface
IGH = gh_io.IGH( ghdoc, ghenv, sc, rh, rs, ghc, gh )

# ------------------------------------------------------------------------------
gh_compo_interface = gh_compo_io.GHCompo_RebuildWindowSurfaces(
IGH, _window_surfaces, _widths, _heights
)
new_surfaces_, names_ = gh_compo_interface.run()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 8 additions & 2 deletions honeybee_ph_rhino/_component_info_.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
These are called when the component is instantiated within the Grasshopper canvas.
"""

RELEASE_VERSION = "Honeybee-PH v1.0.29"
RELEASE_VERSION = "Honeybee-PH v1.0.30"
CATEGORY = "HB-PH"
SUB_CATEGORIES = {
0: "00 | Utils",
Expand Down Expand Up @@ -84,7 +84,7 @@
"SubCategory": 1,
},
"HBPH - Create Site From Phius File": {
"NickName": "Create Phius Site",
"NickName": "Create Site from File",
"Message": RELEASE_VERSION,
"Category": CATEGORY,
"SubCategory": 1,
Expand Down Expand Up @@ -455,6 +455,12 @@
"Category": CATEGORY,
"SubCategory": 4,
},
"HBPH - Create Objects From CSV": {
"NickName": "Create Objs from CSV",
"Message": RELEASE_VERSION,
"Category": CATEGORY,
"SubCategory": 4,
},
}


Expand Down
4 changes: 3 additions & 1 deletion honeybee_ph_rhino/gh_compo_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from honeybee_ph_rhino.gh_compo_io.win_create_frame_element import GHCompo_CreatePhWinFrameElement
from honeybee_ph_rhino.gh_compo_io.win_set_inst_depth import GHCompo_SetApertureInstallDepth
from honeybee_ph_rhino.gh_compo_io.win_calc_phius_blind import GHCompo_CalcPhiusShadeTransmittance
from honeybee_ph_rhino.gh_compo_io.win_rebuild_rh_geom import GHCompo_RebuildWindowSurfaces
# -- Envelope
from honeybee_ph_rhino.gh_compo_io.assmbly_create_sd_const import GHCompo_CreateSDConstructions
from honeybee_ph_rhino.gh_compo_io.assmbly_create_mixed_mat import GHCompo_CreateMixedHBMaterial
Expand Down Expand Up @@ -75,4 +76,5 @@
# -- Utility
from honeybee_ph_rhino.gh_compo_io.util_create_collection import GHCompo_CreateCustomCollection
from honeybee_ph_rhino.gh_compo_io.util_get_from_collection import GHCompo_GetFromCustomCollection
from honeybee_ph_rhino.gh_compo_io.util_get_brep_subface_mats import GHCompo_GetSubFaceMaterials
from honeybee_ph_rhino.gh_compo_io.util_get_brep_subface_mats import GHCompo_GetSubFaceMaterials
from honeybee_ph_rhino.gh_compo_io.util_create_objs_from_csv import GHCompo_CreateObjectsFromCSV
17 changes: 13 additions & 4 deletions honeybee_ph_rhino/gh_compo_io/climate_site_from_phius_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""GHCompo Interface: HBPH - Create Site From Phius File."""

try:
from typing import List, Union, Dict, Optional
from typing import List, Dict, Optional
except ImportError:
pass # IronPython 2.7

Expand All @@ -18,6 +18,11 @@
except ImportError as e:
raise ImportError('\nFailed to import honeybee_ph:\n\t{}'.format(e))

try:
from honeybee_ph_rhino import gh_io
from honeybee_ph_rhino.gh_compo_io import ghio_validators
except ImportError as e:
raise ImportError('\nFailed to import honeybee_ph_rhino:\n\t{}'.format(e))

def remove_non_ascii(string):
return ''.join(char for char in string if ord(char) < 128)
Expand Down Expand Up @@ -225,13 +230,15 @@ def __init__(self):

class GHCompo_CreateSiteFromPhiusFile(object):
"""Interface for the GH Component"""
site_elevation = ghio_validators.UnitM("station_elevation")

def __init__(self, _IGH, _source_file_path):
# type: (gh_io.IGH, str) -> None
def __init__(self, _IGH, _source_file_path, _site_elevation, *args, **kwargs):
# type: (gh_io.IGH, str, str, List, Dict) -> None
self.IGH = _IGH
self.data = self._read_file(_source_file_path)
self.monthly_data_collection = MonthlyDataInputCollection()
self.peak_load_data_collection = PeakLoadInputCollection()
self.site_elevation = _site_elevation

def _read_file(self, _source_file_path):
# type: (Optional[str]) -> List[str]
Expand Down Expand Up @@ -287,10 +294,12 @@ def _create_input_data_collection(self):
def _create_location(self):
# type: () -> site.Location

site_elevation = self.site_elevation or self.monthly_data_collection.station_elevation

return site.Location(
latitude=self.monthly_data_collection.latitude,
longitude=self.monthly_data_collection.longitude,
site_elevation=self.monthly_data_collection.station_elevation,
site_elevation=site_elevation,
climate_zone=1,
hours_from_UTC=-5, # TODO: make automatic somehow?
)
Expand Down
Loading

0 comments on commit 831f012

Please sign in to comment.