-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(analyze): Add a component to filter data by a pattern
- Loading branch information
1 parent
8413368
commit 844523e
Showing
7 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"version": "1.8.0", | ||
"nickname": "Pattern", | ||
"outputs": [ | ||
[ | ||
{ | ||
"access": "None", | ||
"name": "data", | ||
"description": "A list of Data Collections that have been filtered by the _pattern.", | ||
"type": null, | ||
"default": null | ||
} | ||
] | ||
], | ||
"inputs": [ | ||
{ | ||
"access": "list", | ||
"name": "_data", | ||
"description": "A Data Collection or list of aligned Data Collections to be filtered\nby a pattern.", | ||
"type": "System.Object", | ||
"default": null | ||
}, | ||
{ | ||
"access": "list", | ||
"name": "_pattern", | ||
"description": "A list of True/False values. Typically, list has a length matching\nthe length of the Data Collection(s)'s values. However, it can also\nbe a pattern to be repeated over the Data Collection(s)'s values.", | ||
"type": "bool", | ||
"default": null | ||
} | ||
], | ||
"subcategory": "1 :: Analyze Data", | ||
"code": "\ntry:\n from ladybug.datacollection import BaseCollection\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 = []\n for dat in _data:\n assert isinstance(dat, BaseCollection), '_data must be a data' \\\n ' collection. Got {}.'.format(type(dat))\n data.append(dat.filter_by_pattern(_pattern))", | ||
"category": "Ladybug", | ||
"name": "LB Apply Pattern", | ||
"description": "Filter a data collection or list of data collections by a pattern of True/False\nvalues. True values will be kept while False values will be filtered out.\n-" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Ladybug: A Plugin for Environmental Analysis (GPL) | ||
# This file is part of Ladybug. | ||
# | ||
# Copyright (c) 2024, Ladybug Tools. | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with Ladybug; If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# @license AGPL-3.0-or-later <https://spdx.org/licenses/AGPL-3.0-or-later> | ||
|
||
""" | ||
Filter a data collection or list of data collections by a pattern of True/False | ||
values. True values will be kept while False values will be filtered out. | ||
- | ||
Args: | ||
_data: A Data Collection or list of aligned Data Collections to be filtered | ||
by a pattern. | ||
_pattern: A list of True/False values. Typically, list has a length matching | ||
the length of the Data Collection(s)'s values. However, it can also | ||
be a pattern to be repeated over the Data Collection(s)'s values. | ||
Returns: | ||
data: A list of Data Collections that have been filtered by the _pattern. | ||
""" | ||
|
||
ghenv.Component.Name = 'LB Apply Pattern' | ||
ghenv.Component.NickName = 'Pattern' | ||
ghenv.Component.Message = '1.8.0' | ||
ghenv.Component.Category = 'Ladybug' | ||
ghenv.Component.SubCategory = '1 :: Analyze Data' | ||
ghenv.Component.AdditionalHelpFromDocStrings = '0' | ||
|
||
try: | ||
from ladybug.datacollection import BaseCollection | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e)) | ||
|
||
try: | ||
from ladybug_rhino.grasshopper import all_required_inputs | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) | ||
|
||
|
||
if all_required_inputs(ghenv.Component): | ||
data = [] | ||
for dat in _data: | ||
assert isinstance(dat, BaseCollection), '_data must be a data' \ | ||
' collection. Got {}.'.format(type(dat)) | ||
data.append(dat.filter_by_pattern(_pattern)) |
Binary file modified
BIN
+14 Bytes
(100%)
ladybug_grasshopper/user_objects/LB Apply Conditional Statement.ghuser
Binary file not shown.
Binary file not shown.