Skip to content

Commit

Permalink
Adding to sphinx
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Ranalli committed Nov 7, 2024
1 parent e2d7304 commit 1384d38
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 12 deletions.
66 changes: 58 additions & 8 deletions demos/synthetic_clouds_demo.ipynb

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions demos/synthetic_clouds_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,25 @@
axs[1].set_aspect('equal')
axs[1].set_xlabel('X Position')
axs[1].set_ylabel('Y Position')
plt.show()

# It might also be interesting to compare the statistical distribution of the true and simulated timeseries. We can do this by comparing the histograms and CDFs of the two time series.
# show histograms and CDFs
fig, axs = plt.subplots(2, 2, figsize=(10, 8))
axs[0,0].hist(kt[40], bins=100, alpha=0.5, label='True')
axs[0,0].hist(sim_kt[40], bins=100, alpha=0.5, label='Simulated')
axs[0,0].legend()
axs[0,0].set_title('Hist - Sensor 40')
axs[0,1].ecdf(kt[40], label='True')
axs[0,1].ecdf(sim_kt[40], label='Simulated')
axs[0,1].set_title('CDF - Sensor 40')
axs[0,1].legend()
axs[1,0].hist(kt.values.flatten(), bins=100, alpha=0.5, label='True')
axs[1,0].hist(sim_kt.values.flatten(), bins=100, alpha=0.5, label='Simulated')
axs[1,0].legend()
axs[1,0].set_title('Hist - All Sensors')
axs[1,1].ecdf(kt.values.flatten(), label='True')
axs[1,1].ecdf(sim_kt.values.flatten(), label='Simulated')
axs[1,1].set_title('CDF - All Sensors')
axs[1,1].legend()
plt.show()
3 changes: 3 additions & 0 deletions docs/sphinx/source/demos/synthetic_clouds_demo.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path":"../../../../demos/synthetic_clouds_demo.ipynb"
}
10 changes: 10 additions & 0 deletions docs/sphinx/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ Field Analysis Examples
demos/field_demo_detailed
demos/field_reassignment_demo

.. _synthirrad-examples:

Synthetic Irradiance Examples
-----------------------------

.. toctree::
:maxdepth: 1

demos/synthetic_clouds_demo

Other Examples
--------------

Expand Down
3 changes: 3 additions & 0 deletions docs/sphinx/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ The :mod:`solarspatialtools.cmv` module contains functions for calculating the c

The :mod:`solarspatialtools.field` module contains functions for validating the layout of a PV plant or measurement network by calculating the relative delays between each sensor in the network subject to cloud motion.

The :mod:`solarspatialtools.synthirrad` package contains functions for downscaling and generation of synthetic irradiance timeseries.

The best starting point is to read through the :ref:`cmv-examples` and :ref:`field-examples` sections to see some sample Jupyter notebooks that demonstrate how these functions can be used in practice.


Expand All @@ -38,6 +40,7 @@ Contents

cmv
field
synthirrad
othermods

.. toctree::
Expand Down
25 changes: 25 additions & 0 deletions docs/sphinx/source/synthirrad.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. currentmodule:: solarspatialtools

Synthetic irradiance generation
----------------------------------
The `solarspatialtools.synthirrad` package contains tools for generating synthetic irradiance timeseries and performing downscaling of timeseries. The package implements the following approaches:

cloudfield
==========

Generate a simulated field of clouds from which spatially distributed timeseries of kt can be extracted. The field distributions are based on the properties of a time series of kt values. This is an implementation of the method described by Lave et al [1]. Some aspects of the implementation diverge slightly from the initial paper to follow a subsequent code implementation of the method shared by the original authors.

[1] Matthew Lave, Matthew J. Reno, Robert J. Broderick, "Creation and Value of Synthetic High-Frequency Solar Inputs for Distribution System QSTS Simulations," 2017 IEEE 44th Photovoltaic Specialist Conference (PVSC), Washington, DC, USA, 2017, pp. 3031-3033, doi: https://dx.doi.org/10.1109/PVSC.2017.8366378.

.. automodule:: solarspatialtools.synthirrad.cloudfield


.. rubric:: Functions

.. autosummary::
:toctree: generated/

get_timeseries_stats
cloudfield_timeseries


2 changes: 1 addition & 1 deletion src/solarspatialtools/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def rotate_vector(vector, theta):
vector : (x, y) numeric
A tuple (or numpy array) containing the input vector.
To operate on multiple points, vector should be of the form:
((x1, x2, x3, x4), (y1, y2, y3, y4))
((x1, x2, x3, x4), (y1, y2, y3, y4))
theta : numeric
Angle of rotation in radians
Expand Down
20 changes: 17 additions & 3 deletions src/solarspatialtools/synthirrad/cloudfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,15 @@ def get_positional_ts(tgt_position, field, cloud_speed, duration=3600, pixres=1)



def cloudfield_timeseries(weights, scales, size, frac_clear, ktmean, ktmax, kt1pct, edgesmoothing=3):
def cloudfield_timeseries(weights, scales, size, frac_clear, ktmean, ktmax, kt1pct, scaling='original', edgesmoothing=3):
"""
Generate a time series of cloud fields based on the properties of a time series of kt values.
Generate a time series of cloud fields based on the properties of a time series of kt values. This is an
implementation of the method described by Lave et al [1]. Some aspects of the implementation diverge slightly from
the initial paper to follow a subsequent code implementation of the method shared by the original authors.
[1] Matthew Lave, Matthew J. Reno, Robert J. Broderick, "Creation and Value of Synthetic High-Frequency Solar Inputs
for Distribution System QSTS Simulations," 2017 IEEE 44th Photovoltaic Specialist Conference (PVSC),
Washington, DC, USA, 2017, pp. 3031-3033, doi: https://dx.doi.org/10.1109/PVSC.2017.8366378.
Parameters
----------
Expand All @@ -590,6 +596,8 @@ def cloudfield_timeseries(weights, scales, size, frac_clear, ktmean, ktmax, kt1p
The maximum of the kt values
kt1pct : float
The 1st percentile of the kt values
scaling : str
The scaling method to use. Either 'original' or 'basic'
edgesmoothing : int
The size of the uniform filter for edge smoothing
Expand All @@ -604,5 +612,11 @@ def cloudfield_timeseries(weights, scales, size, frac_clear, ktmean, ktmax, kt1p

edges, smoothed = _find_edges(clear_mask, edgesmoothing)

field_final = _scale_field_lave(cfield, clear_mask, smoothed, ktmean, ktmax, kt1pct, plot=False)
if scaling == 'original':
field_final = _scale_field_lave(cfield, clear_mask, edges, ktmean, ktmax, kt1pct, plot=False)
elif scaling == 'basic':
field_final = _scale_field_basic(cfield, clear_mask, smoothed, ktmean, ktmax, kt1pct, plot=False)
else:
raise ValueError("Scaling method must be either 'original' or 'basic'.")

return field_final

0 comments on commit 1384d38

Please sign in to comment.