Skip to content

Commit

Permalink
fix(windrose): Changing docstrings, and multiple data handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
saeranv authored and Chris Mackey committed Jul 1, 2020
1 parent 6052b9d commit 5cb0fdc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 39 deletions.
65 changes: 26 additions & 39 deletions ladybug_grasshopper/src/LB Wind Rose Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
difference between the North and the positive Y-axis in degrees. 90 is West
and 270 is East. This can also be Vector for the direction to North
(Default: 0).
_wind_data: A HourlyContinuousCollection or HourlyDiscontinuousCollection of
wind values, corresponding to the wind directions, which is "binned" by the
calculated direction intervals. This input usually consists of wind speed
values, but is not limited to this data type.
_data: Either a HourlyContinuousCollection or HourlyDiscontinuousCollection of
values, or a list of data collections corresponding to the wind directions,
which is "binned" by the direction intervals. This input usually consists
of wind speed values, but is not limited to this data type.
_wind_direction: A HourlyContinuousCollection or HourlyDiscontinuousCollection
of wind directions which will be used to "bin" the intervals for the
of wind directions which will be used to "bin" the _data items for the
windrose.
_dir_count_: Number that determines the number of directions to the wind rose
will display. The number of directions must be greater then three to plot
Expand All @@ -31,11 +31,11 @@
_show_calmrose_: A boolean to indicate if the wind rose displays a calm rose. The
calm rose is a radial plot in the center of the wind rose with a radius
corresponding to the total zero values divided by the number of directions.
This allows the wind rose to represent zero values from _wind_data even
This allows the wind rose to represent zero values from _data even
though such values don't have any direction associated with them.
_show_freq_: A boolean to show the frequency of _wind_data data values
_show_freq_: A boolean to show the frequency of _data data values
in the wind direction bins. The frequency lines represent constant intervals
in time while the color illustrates the average _wind_data data values
in time while the color illustrates the average _data data values
associated with each interval. The number of frequency lines with similar
colors therefore indicate a higher frequency of that value.
_freq_dist_: The distance for the frequency interval in model units
Expand All @@ -59,13 +59,13 @@
LegendParameter object is computed using values from the wind data with
11 segments (Default: None).
statement_: A conditional statement as a string (e.g. a > 25) for
the _wind_data and _wind_direction inputs.
the _data and _wind_direction inputs.
.
The variable of the first data collection should always be named 'a'
(without quotations), the variable of the second list should be
named 'b', and so on.
.
For example, if three data collections are connected to _wind_data
For example, if three data collections are connected to _data
and the following statement is applied:
'18 < a < 26 and b < 80 and c > 2'
The resulting collections will only include values where the first
Expand All @@ -89,7 +89,7 @@
"""
ghenv.Component.Name = "LB Wind Rose Plot"
ghenv.Component.NickName = 'WindRose'
ghenv.Component.Message = '0.1.2'
ghenv.Component.Message = '0.1.3'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '2 :: VisualizeWeatherData'
ghenv.Component.AdditionalHelpFromDocStrings = '1'
Expand Down Expand Up @@ -131,31 +131,16 @@ def title_text(data_col):

if all_required_inputs(ghenv.Component):

# Ensure equal list length
if len(_wind_data) > len(_wind_direction):
print('The number of _wind_data data collections is less than the _wind_direction data '
'collections. The final _wind_direction collection will be duplicated to match '
'the number of _wind_data data collections.')
num = len(_wind_data) - len(_wind_direction)
_wind_direction += [_wind_direction[-1].duplicate() for i in range(num)]

if len(_wind_direction) > len(_wind_data):
print('The number of _wind_data data collections is greater than the _wind_direction data '
'collections. The final _wind_data collection will be duplicated to match the number '
'of _wind_direction data collections.')
num = len(_wind_direction) - len(_wind_data)
_wind_data += [_wind_data[-1].duplicate() for i in range(num)]

# Apply any analysis periods to the input collections
if period_ is not None:
_wind_data = _wind_data.filter_by_analysis_period(period_)
_data = _data.filter_by_analysis_period(period_)
_wind_direction = _wind_direction.filter_by_analysis_period(period_)

if statement_ is not None and statement_.strip() != "":
for i in range(len(_wind_data)):
_data = HourlyContinuousCollection.filter_collections_by_statement(
[_wind_data[i], _wind_direction[i]], statement_)
_wind_data[i], _wind_direction[i] = _data
_fdata = HourlyContinuousCollection.filter_collections_by_statement(
_data + [_wind_direction], statement_)
_data = _fdata[:-1]
_wind_direction = _fdata[-1]

# Check for errors in input
if _dir_count_ is None:
Expand All @@ -168,10 +153,10 @@ def title_text(data_col):
try:
north_ = math.degrees(to_vector2d(north_).angle_clockwise(Vector2D(0, 1)))
except AttributeError: # north angle instead of vector
north_ = float(north_)
assert -360.0 <= north_ <= 360.0, 'The north orientation must be greater ' \
'then -360 and less then 360 to plot the wind rose. ' \
'Got: {}'.format(north_)
north_ = float(north_)
else:
north_ = 0.0

Expand All @@ -195,22 +180,24 @@ def title_text(data_col):
all_legends = []
all_title = []

# Calculate _max_freq_lines_ if it's not already set.
if len(_wind_data) > 1 and _max_freq_lines_ is None:
# Calculate _max_freq_lines_ if it's not already set, to use to
# determine spacing for multiple plots.
if len(_data) > 1 and _max_freq_lines_ is None:
max_freqs = []
for i, (dir_data, speed_data) in enumerate(zip(_wind_direction, _wind_data)):
w = WindRose(dir_data, speed_data, _dir_count_)
for i, _data_item in enumerate(_data):
w = WindRose(_wind_direction, _data_item, _dir_count_)
if _freq_hours_ is not None:
w.frequency_hours = _freq_hours_
if _freq_dist_ is not None:
w.frequency_spacing_distance = _freq_dist_
max_freqs.append(w.frequency_intervals_compass)
_max_freq_lines_ = max(max_freqs)

for i, (dir_data, speed_data) in enumerate(zip(_wind_direction, _wind_data)):
# Plot the windroses
for i, speed_data in enumerate(_data):

# Make the windrose
windrose = WindRose(dir_data, speed_data, _dir_count_)
windrose = WindRose(_wind_direction, speed_data, _dir_count_)

if len(legend_par_) > 0:
try: # sense when several legend parameters are connected
Expand Down Expand Up @@ -249,7 +236,7 @@ def title_text(data_col):
if _show_freq_:
freq_lines = [from_polygon2d(poly) for poly in windrose.frequency_lines]

# move the center point so sun paths are not on top of one another
# move the center point so wind roses are not on top of one another
fac = (i + 1) * windrose.compass_radius * 3
center_pt_2d = Point2D(_center_pt_.x + fac, _center_pt_.y)

Expand Down
Binary file modified ladybug_grasshopper/user_objects/LB Wind Rose Plot.ghuser
Binary file not shown.
Binary file modified samples/windrose_plot.gh
Binary file not shown.

0 comments on commit 5cb0fdc

Please sign in to comment.