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

[WIP] Switch to jupyter-sphinx for user guide pages #1380

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'IPython.sphinxext.ipython_console_highlighting',
'sphinx_gallery.gen_gallery',
'sphinx_toggleprompt',
'jupyter_sphinx.execute',
]

napoleon_use_rtype = False # group rtype on same line together with return
Expand Down
62 changes: 31 additions & 31 deletions docs/sphinx/source/user_guide/modelchain.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Before delving into the intricacies of ModelChain, we provide a brief
example of the modeling steps using ModelChain. First, we import pvlib’s
objects, module data, and inverter data.

.. ipython:: python
.. jupyter-execute::

import pandas as pd
import numpy as np
Expand All @@ -57,7 +57,7 @@ objects, module data, and inverter data.
Now we create a Location object, a Mount object, a PVSystem object, and a
ModelChain object.

.. ipython:: python
.. jupyter-execute::

location = Location(latitude=32.2, longitude=-110.9)
system = PVSystem(surface_tilt=20, surface_azimuth=200,
Expand All @@ -68,13 +68,13 @@ ModelChain object.

Printing a ModelChain object will display its models.

.. ipython:: python
.. jupyter-execute::

print(mc)

Next, we run a model with some simple weather data.

.. ipython:: python
.. jupyter-execute::

weather = pd.DataFrame([[1050, 1000, 100, 30, 5]],
columns=['ghi', 'dni', 'dhi', 'temp_air', 'wind_speed'],
Expand All @@ -87,19 +87,19 @@ ModelChain stores the modeling results in the ``results`` attribute. The
A few examples of attributes of :py:class:`~pvlib.modelchain.ModelChainResult`
are shown below.

.. ipython:: python
.. jupyter-execute::

mc.results.aoi

.. ipython:: python
.. jupyter-execute::

mc.results.cell_temperature

.. ipython:: python
.. jupyter-execute::

mc.results.dc

.. ipython:: python
.. jupyter-execute::

mc.results.ac

Expand All @@ -126,7 +126,7 @@ Below, we show some examples of how to define a ModelChain.
Let’s make the most basic Location and PVSystem objects and build from
there.

.. ipython:: python
.. jupyter-execute::

location = Location(32.2, -110.9)
poorly_specified_system = PVSystem()
Expand All @@ -137,8 +137,8 @@ These basic objects do not have enough information for ModelChain to be
able to automatically determine its set of models, so the ModelChain
will throw an error when we try to create it.

.. ipython:: python
:okexcept:
.. jupyter-execute::
:raises: ValueError

ModelChain(poorly_specified_system, location)

Expand All @@ -147,7 +147,7 @@ inverter from the CEC database. ModelChain will examine the PVSystem
object’s properties and determine that it should choose the SAPM DC
model, AC model, AOI loss model, and spectral loss model.

.. ipython:: python
.. jupyter-execute::

sapm_system = PVSystem(
module_parameters=sandia_module,
Expand All @@ -156,7 +156,7 @@ model, AC model, AOI loss model, and spectral loss model.
mc = ModelChain(sapm_system, location)
print(mc)

.. ipython:: python
.. jupyter-execute::

mc.run_model(weather);
mc.results.ac
Expand All @@ -169,7 +169,7 @@ it should choose PVWatts DC and AC models. ModelChain still needs us to specify
``system.module_parameters`` dictionary does not contain enough
information to determine which of those models to choose.

.. ipython:: python
.. jupyter-execute::

pvwatts_system = PVSystem(
module_parameters={'pdc0': 240, 'gamma_pdc': -0.004},
Expand All @@ -179,7 +179,7 @@ information to determine which of those models to choose.
aoi_model='physical', spectral_model='no_loss')
print(mc)

.. ipython:: python
.. jupyter-execute::

mc.run_model(weather);
mc.results.ac
Expand All @@ -188,7 +188,7 @@ User-supplied keyword arguments override ModelChain’s inspection
methods. For example, we can tell ModelChain to use different loss
functions for a PVSystem that contains SAPM-specific parameters.

.. ipython:: python
.. jupyter-execute::

sapm_system = PVSystem(
module_parameters=sandia_module,
Expand All @@ -197,7 +197,7 @@ functions for a PVSystem that contains SAPM-specific parameters.
mc = ModelChain(sapm_system, location, aoi_model='physical', spectral_model='no_loss')
print(mc)

.. ipython:: python
.. jupyter-execute::

mc.run_model(weather);
mc.results.ac
Expand All @@ -216,7 +216,7 @@ Each "with" method returns a ModelChain using a Location and PVSystem. Parameter
used to define the PVSystem need to be consistent with the models specified by
the "with" method. Using location and sapm_system defined above:

.. ipython:: python
.. jupyter-execute::

mc = mc.with_sapm(sapm_system, location)
print(mc)
Expand Down Expand Up @@ -272,7 +272,7 @@ wrapper methods for AOI loss, spectral loss, effective irradiance, cell
temperature, DC power, AC power, and other losses. These methods are
assigned to generic names, as described in the next section.

.. ipython:: python
.. jupyter-execute::

mc.run_model??

Expand Down Expand Up @@ -301,7 +301,7 @@ and sets the same attributes, thus creating a uniform API. For example,
the :py:meth:`~pvlib.modelchain.ModelChain.pvwatts_dc` method is shown below. Its only argument is
``self``, and it sets the ``dc`` attribute.

.. ipython:: python
.. jupyter-execute::

mc.pvwatts_dc??

Expand All @@ -312,7 +312,7 @@ using data that is stored in the ModelChain ``effective_irradiance`` and
result to the ``dc`` attribute of the ModelChain's ``results`` object. The code
below shows a simple example of this.

.. ipython:: python
.. jupyter-execute::

# make the objects
pvwatts_system = PVSystem(
Expand Down Expand Up @@ -348,11 +348,11 @@ All ModelChain methods for DC output use the
:py:meth:`~pvlib.pvsystem.PVSystem.scale_voltage_current_power` method to scale
DC quantities to the output of the full PVSystem.

.. ipython:: python
.. jupyter-execute::

mc.sapm??

.. ipython:: python
.. jupyter-execute::

# make the objects
sapm_system = PVSystem(
Expand Down Expand Up @@ -386,7 +386,7 @@ At object construction, ModelChain assigns the desired model’s method
parameter at construction, or by inference as described in the next
section.

.. ipython:: python
.. jupyter-execute::

pvwatts_system = PVSystem(
module_parameters={'pdc0': 240, 'gamma_pdc': -0.004},
Expand Down Expand Up @@ -419,11 +419,11 @@ respectively. A few examples are shown below. Inference methods generally work
by inspecting the parameters for all required parameters for a corresponding
method.

.. ipython:: python
.. jupyter-execute::

mc.infer_dc_model??

.. ipython:: python
.. jupyter-execute::

mc.infer_ac_model??
pvlib.modelchain._snl_params??
Expand All @@ -443,7 +443,7 @@ When the PVSystem contains multiple arrays, ``ModelChain.results`` attributes
are tuples with length equal to the number of Arrays. Each tuple's elements
are in the same order as in ``PVSystem.arrays``.

.. ipython:: python
.. jupyter-execute::

from pvlib.pvsystem import Array
location = Location(latitude=32.2, longitude=-110.9)
Expand Down Expand Up @@ -510,7 +510,7 @@ functions, and then implementing wrappers to make them easier to use in
specific applications. Of course, you could implement it in a single
function if you wanted to.

.. ipython:: python
.. jupyter-execute::

def pvusa(poa_global, wind_speed, temp_air, a, b, c, d):
"""
Expand Down Expand Up @@ -567,7 +567,7 @@ function if you wanted to.
return mc


.. ipython:: python
.. jupyter-execute::

module_parameters = {'a': 0.2, 'b': 0.00001, 'c': 0.001, 'd': -0.00005}
pvusa_system = PVSystem(module_parameters=module_parameters)
Expand All @@ -580,13 +580,13 @@ function if you wanted to.
A ModelChain object uses Python’s functools.partial function to assign
itself as the argument to the user-supplied functions.

.. ipython:: python
.. jupyter-execute::

mc.dc_model.func

The end result is that ModelChain.run_model works as expected!

.. ipython:: python
.. jupyter-execute::

mc = mc.run_model(weather)
mc.results.dc
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
'cftime >= 1.1.1'],
'doc': ['ipython', 'matplotlib', 'sphinx == 3.1.2',
'pydata-sphinx-theme', 'sphinx-gallery', 'docutils == 0.15.2',
'pillow', 'netcdf4', 'siphon',
'pillow', 'netcdf4', 'siphon', 'jupyter-sphinx',
'sphinx-toggleprompt >= 0.0.5'],
'test': TESTS_REQUIRE
}
Expand Down