-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify timeseries calculation API (#14)
* Remove "save_segments" arguments as not needed anymore * Compact formatting in timeseries calculation function * Fix issue with test_serial_perez that wasn't caught in previous PR * Improving test for perez luminance calculation * Major update of timeseries calculation API * all tests are now passing * now passing individual arguments instead of dataframes with all arguments * broke custom perez calculation from pvarray timeseries calculation: this will allow the users to use one or the other separately * next step will be to remove the "simple" calculation mode * Add pytest-mock to circleci config for testing * Removed the specific functions related to "isotropic" calcs * now only using the perez functions, even when using isotropic approach (just setting circumsolar and horizon to 0) * Reorganizing package: seperate timeseries fns from plotting ones * Update docstrings in timeseries and plot modules
- Loading branch information
Showing
17 changed files
with
797 additions
and
694 deletions.
There are no files selected for viewing
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
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,117 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import numpy as np | ||
from pvfactors import logging | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
LOGGER.setLevel(logging.INFO) | ||
|
||
# Define colors used for plotting the 2D arrays | ||
COLOR_dic = { | ||
'i': '#FFBB33', | ||
's': '#A7A49D', | ||
't': '#6699cc', | ||
'pvrow_illum': '#6699cc', | ||
'pvrow_shaded': '#ff0000', | ||
'ground_shaded': '#A7A49D', | ||
'ground_illum': '#FFBB33' | ||
} | ||
|
||
|
||
def plot_array_from_registry(ax, registry, line_types_selected=None, | ||
fontsize=20): | ||
""" | ||
Plot a 2D PV array using the ``shapely`` geometry objects located in | ||
a :class:`pvarray.Array` surface registry. | ||
:param matplotlib.axes.Axes ax: axes to use for the plot | ||
:param pd.DataFrame registry: registry containing geometries to plot | ||
:param list line_types_selected: parameter used to select a subset of | ||
'line_type' to plot; e.g. 'pvrow' or 'ground' | ||
:return: None (``ax`` is updated) | ||
""" | ||
|
||
registry = registry.copy() | ||
registry.loc[:, 'color'] = ( | ||
registry.line_type.values + '_' | ||
+ np.where(registry.shaded.values, 'shaded', 'illum')) | ||
# TODO: distance may not exist | ||
if line_types_selected: | ||
for line_type in line_types_selected: | ||
surface_reg_selected = registry.loc[ | ||
registry.line_type == line_type, :] | ||
for index, row in surface_reg_selected.iterrows(): | ||
LOGGER.debug("Plotting %s", row['line_type']) | ||
plot_coords(ax, row['geometry']) | ||
plot_bounds(ax, row['geometry']) | ||
plot_line(ax, row['geometry'], row['style'], | ||
row['shading_type']) | ||
else: | ||
for index, row in registry.iterrows(): | ||
LOGGER.debug("Plotting %s", row['line_type']) | ||
plot_coords(ax, row['geometry']) | ||
plot_bounds(ax, row['geometry']) | ||
plot_line(ax, row['geometry'], row['style'], row['color']) | ||
|
||
ax.axis('equal') | ||
ax.set_xlabel("x [m]", fontsize=fontsize) | ||
ax.set_ylabel("y [m]", fontsize=fontsize) | ||
|
||
|
||
def plot_pvarray(ax, pvarray, line_types_selected=None, fontsize=20): | ||
""" | ||
Plot a 2D PV array from a :class:`pvarray.Array` using its | ||
:attr:`pvarray.Array.surface_registry`. | ||
:param ax: :class:`matplotlib.axes.Axes` object to use for the plot | ||
:param pvarray: object containing the surface registry as attribute | ||
:type pvarray: :class:`pvarray.Array` | ||
:param list line_types_selected: parameter used to select a subset of | ||
'line_type' to plot; e.g. 'pvrow' or 'ground' | ||
:return: None (``ax`` is updated) | ||
""" | ||
|
||
# FIXME: repeating code from plot_line_registry | ||
surface_registry = pvarray.surface_registry.copy() | ||
plot_array_from_registry(ax, surface_registry, | ||
line_types_selected=line_types_selected) | ||
|
||
# Plot details | ||
distance = pvarray.pvrow_distance | ||
height = pvarray.pvrow_height | ||
n_pvrows = pvarray.n_pvrows | ||
ax.set_xlim(- 0.5 * distance, (n_pvrows - 0.5) * distance) | ||
ax.set_ylim(-height, 2 * height) | ||
ax.set_title("PV Array", fontsize=fontsize) | ||
|
||
|
||
# Base functions used to plot the 2D array | ||
def plot_coords(ax, ob): | ||
try: | ||
x, y = ob.xy | ||
ax.plot(x, y, 'o', color='#999999', zorder=1) | ||
except NotImplementedError: | ||
for line in ob: | ||
x, y = line.xy | ||
ax.plot(x, y, 'o', color='#999999', zorder=1) | ||
|
||
|
||
def plot_bounds(ax, ob): | ||
# Check if shadow reduces to one point (for very specific sun alignment) | ||
if len(ob.boundary) == 0: | ||
x, y = ob.coords[0] | ||
else: | ||
x, y = zip(*list((p.x, p.y) for p in ob.boundary)) | ||
ax.plot(x, y, 'o', color='#000000', zorder=1) | ||
|
||
|
||
def plot_line(ax, ob, line_style, line_color): | ||
try: | ||
x, y = ob.xy | ||
ax.plot(x, y, color=COLOR_dic[line_color], ls=line_style, alpha=0.7, | ||
linewidth=3, solid_capstyle='round', zorder=2) | ||
except NotImplementedError: | ||
for line in ob: | ||
x, y = line.xy | ||
ax.plot(x, y, color=COLOR_dic[line_color], ls=line_style, | ||
alpha=0.7, linewidth=3, solid_capstyle='round', zorder=2) |
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
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
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,5 @@ | ||
datetime,solar_zenith,solar_azimuth,array_tilt,array_azimuth,dni,dhi,poa_isotropic,poa_circumsolar,poa_horizon,vf_horizon,vf_circumsolar,vf_isotropic,luminance_horizon,luminance_circumsolar,luminance_isotropic,poa_total_diffuse | ||
2015-10-02 12:40:00.001200,42.54210405,174.3715553,5.142972856,90,1000,100,53.9049589579,46.1721986001,1.8417661189,0.0896413203484,1.00404216032,0.99798705648,20.5459503691,45.986314544,54.013685456,101.918923677 | ||
2015-10-02 12:49:59.998800,42.41609807,178.0613184,1.77035709,90,1000,100,53.9393074992,46.0698063615,0.633882293345,0.0308936438071,1.00047755049,0.999761338734,20.5182107136,46.0478162043,53.9521837957,100.642996154 | ||
2015-10-02 13:00:00.000000,42.41574779,181.7602662,1.607556458,270,1000,100,53.9413957759,46.0661176346,0.575604882308,0.0280534721322,1.00039373104,0.99980321195,20.518133356,46.0479871126,53.9520128874,100.583118293 | ||
2015-10-02 13:10:00.001200,42.54106148,185.4501296,4.98118732,270,1000,100,53.9111795968,46.161162222,1.78395715039,0.0868286442933,1.00379105643,0.998111630694,20.545721575,45.9868235788,54.0131764212,101.856298969 |
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
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
Oops, something went wrong.