Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(data): Add _interval_ input to construct data #270

Merged
merged 1 commit into from Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified ladybug_grasshopper/icon/LB Construct Data.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions ladybug_grasshopper/json/LB_Construct_Data.json
@@ -1,5 +1,5 @@
{
"version": "1.3.0",
"version": "1.3.1",
"nickname": "+Data",
"outputs": [
[
Expand All @@ -26,10 +26,17 @@
"description": "A list of numerical values for the data collection.",
"type": "double",
"default": null
},
{
"access": "item",
"name": "_interval_",
"description": "Text to indicate the time interval of the data collection, which\ndetermines the type of collection that is output. (Default: hourly).\n_\nChoose from the following:\n- hourly\n- daily\n- monthly\n- monthly-per-hour\n_\nNote that the \"hourly\" input is also used to represent sub-hourly\nintervals (in this case, the timestep of the analysis period\nmust not be 1).",
"type": "string",
"default": null
}
],
"subcategory": "1 :: Analyze Data",
"code": "\ntry:\n from ladybug.datacollection import HourlyContinuousCollection\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n data = HourlyContinuousCollection(_header, _values)",
"code": "\ntry:\n from ladybug.datacollection import HourlyContinuousCollection, DailyCollection, \\\n MonthlyCollection, MonthlyPerHourCollection\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n inter = _interval_.lower() if _interval_ is not None else 'hourly'\n if inter == 'hourly':\n data = HourlyContinuousCollection(_header, _values)\n elif inter == 'monthly':\n data = MonthlyCollection(\n _header, _values, _header.analysis_period.months_int)\n elif inter == 'daily':\n data = DailyCollection(\n _header, _values, _header.analysis_period.doys_int)\n elif inter == 'monthly-per-hour':\n data = MonthlyPerHourCollection(\n _header, _values, _header.analysis_period.months_per_hour)\n else:\n raise ValueError('{} is not a recongized interval.'.format(_interval_))\n",
"category": "Ladybug",
"name": "LB Construct Data",
"description": "Construct a Ladybug data collection from header and values.\n-"
Expand Down
32 changes: 29 additions & 3 deletions ladybug_grasshopper/src/LB Construct Data.py
Expand Up @@ -14,20 +14,33 @@
Args:
_header:A Ladybug header object describing the metadata of the data collection.
_values: A list of numerical values for the data collection.
_interval_: Text to indicate the time interval of the data collection, which
determines the type of collection that is output. (Default: hourly).
_
Choose from the following:
- hourly
- daily
- monthly
- monthly-per-hour
_
Note that the "hourly" input is also used to represent sub-hourly
intervals (in this case, the timestep of the analysis period
must not be 1).

Returns:
data: A Ladybug data collection object.
"""

ghenv.Component.Name = "LB Construct Data"
ghenv.Component.NickName = '+Data'
ghenv.Component.Message = '1.3.0'
ghenv.Component.Message = '1.3.1'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '1 :: Analyze Data'
ghenv.Component.AdditionalHelpFromDocStrings = '1'

try:
from ladybug.datacollection import HourlyContinuousCollection
from ladybug.datacollection import HourlyContinuousCollection, DailyCollection, \
MonthlyCollection, MonthlyPerHourCollection
except ImportError as e:
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

Expand All @@ -38,4 +51,17 @@


if all_required_inputs(ghenv.Component):
data = HourlyContinuousCollection(_header, _values)
inter = _interval_.lower() if _interval_ is not None else 'hourly'
if inter == 'hourly':
data = HourlyContinuousCollection(_header, _values)
elif inter == 'monthly':
data = MonthlyCollection(
_header, _values, _header.analysis_period.months_int)
elif inter == 'daily':
data = DailyCollection(
_header, _values, _header.analysis_period.doys_int)
elif inter == 'monthly-per-hour':
data = MonthlyPerHourCollection(
_header, _values, _header.analysis_period.months_per_hour)
else:
raise ValueError('{} is not a recongized interval.'.format(_interval_))
Binary file modified ladybug_grasshopper/user_objects/LB Construct Data.ghuser
Binary file not shown.