Skip to content

Commit

Permalink
add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
uvchik committed Sep 24, 2015
1 parent 3d4cfe3 commit 4c12454
Showing 1 changed file with 196 additions and 21 deletions.
217 changes: 196 additions & 21 deletions feedinlib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ class Photovoltaic:
References
----------
Cite the relevant literature, e.g. [1]_. You may also cite these
references in the notes section above.
.. [1] `pvlib on github <https://github.com/pvlib/pvlib-python>`_, pvlib.
Examples
--------
>>> required_ls = ['module_name', 'azimuth', 'tilt', 'albedo', 'tz',
...'latitude', 'longitude']
>>> required_ls = ['module_name', 'azimuth', 'tilt', 'albedo', 'tz', 'latitude', 'longitude']
>>> pv_model = models.Photovoltaic(required=required_ls)
"""
Expand Down Expand Up @@ -90,18 +86,19 @@ def solarposition_hourly_mean(self, location, data, **kwargs):
method : string, optional
Method to calulate the position of the sun according to the
methods provided by the pvlib function (default: 'ephemeris')
'pvlib.solarposition.get_solarposition'.[1]_
'pvlib.solarposition.get_solarposition'.[2]_
freq : string, optional
The time interval to create the hourly mean (default: '5Min').
Returns
-------
pandas.DataFrame
The DataFrame contains the following new columns: azimuth, zenith
The DataFrame contains the following new columns: azimuth, zenith,
elevation
See Also
--------
solarposition : calculates the position of the sun for a given time
solarposition : calculates the position of the sun at a given time
Notes
-----
Expand All @@ -111,8 +108,8 @@ def solarposition_hourly_mean(self, location, data, **kwargs):
References
----------
.. [1] `pvlib solarposition <http://pvlib-python.readthedocs.org/en/latest/pvlib.html#module-pvlib.solarposition>`_.
.. [2] `pvlib solarposition <http://pvlib-python.readthedocs.org/en/
latest/pvlib.html#pvlib.solarposition.get_solarposition>`_.
"""
data_5min = pd.DataFrame(
index=pd.date_range(data.index[0],
Expand All @@ -127,21 +124,121 @@ def solarposition_hourly_mean(self, location, data, **kwargs):
axis=1, join='inner')

def solarposition(location, data, **kwargs):
'Determine the position of the sun unsing the time of the time index.'
r"""
Determine the position of the sun unsing the time of the time index.
Parameters
----------
location : pvlib.location.Location
A pvlib location object containing the longitude, latitude and the
timezone of the location
data : pandas.DataFrame
Containing the timeseries of the weather data and the time index of
the location.
method : string, optional
Method to calulate the position of the sun according to the
methods provided by the pvlib function (default: 'ephemeris')
'pvlib.solarposition.get_solarposition'.[3]_
Returns
-------
pandas.DataFrame
The DataFrame contains the following new columns: azimuth, zenith,
elevation
See Also
--------
solarposition_hourly_mean : calculates the position of the sun as an
hourly mean.
Notes
-----
This method is not use in favour to solarposition_hourly_mean.
References
----------
.. [3] `pvlib solarposition <http://pvlib-python.readthedocs.org/en/
latest/pvlib.html#pvlib.solarposition.get_solarposition>`_.
"""
return pd.concat(
[data, pvlib.solarposition.get_solarposition(
time=data.index, location=location, method='ephemeris')],
axis=1, join='inner')

def angle_of_incidence(self, data, **kwargs):
'Determine the angle of incidence'
r"""
Determine the angle of incidence using the pvlib aoi funktion.[4]_
Parameters
----------
data : pandas.DataFrame
Containing the timeseries of the azimuth and zenith angle
tilt : float
Tilt angle of the pv module (horizontal=0°).
azimuth : float
Azimuth angle of the pv module (south=180°).
Returns
-------
pandas.Series
Angle of incidence in degrees.
See Also
--------
solarposition_hourly_mean, solarposition
References
----------
.. [4] `pvlib angle of incidence <http://pvlib-python.readthedocs.org/
en/latest/pvlib.html#pvlib.irradiance.aoi>`_.
"""
return pvlib.irradiance.aoi(
solar_azimuth=data['zenith'], solar_zenith=data['zenith'],
solar_azimuth=data['azimuth'], solar_zenith=data['zenith'],
surface_tilt=kwargs['tilt'], surface_azimuth=kwargs['azimuth'])

def global_in_plane_irradiation(self, data, **kwargs):
''
r"""
Determine the global irradiaton on the tilted surface.
This method determines the global irradiation in plane knowing
the direct and diffuse irradiation, the incident angle and the
orientation of the surface. The method uses the
pvlib.irradiance.globalinplane function [5]_ and some other functions
of the pvlib.atmosphere [6]_ and the pvlib.solarposition [7]_ module to
provide the input parameters for the globalinplane function.
Parameters
----------
data : pandas.DataFrame
Containing the time index of the location and columns with the
following timeseries: (dirhi, dhi, zenith, azimuth, aoi)
tilt : float
Tilt angle of the pv module (horizontal=0°).
azimuth : float
Azimuth angle of the pv module (south=180°).
albedo : float
Albedo factor arround the module
Returns
-------
pandas.DataFrame
The DataFrame contains the following new columns: poa_global,
poa_diffuse, poa_direct
See Also
--------
solarposition_hourly_mean, solarposition, angle_of_incidenc
References
----------
.. [5] `pvlib globalinplane <http://pvlib-python.readthedocs.org/en/
latest/pvlib.html#pvlib.irradiance.globalinplane>`_.
.. [6] `pvlib globalinplane <http://pvlib-python.readthedocs.org/en/
latest/pvlib.html#module-pvlib.atmosphere>`_.
.. [7] `pvlib globalinplane <http://pvlib-python.readthedocs.org/en/
latest/pvlib.html#module-pvlib.solarposition>`_.
"""
# Determine the extraterrestrial radiation
data['dni_extra'] = pvlib.irradiance.extraradiation(
datetime_or_doy=data.index.dayofyear)
Expand All @@ -150,7 +247,7 @@ def global_in_plane_irradiation(self, data, **kwargs):
data['airmass'] = pvlib.atmosphere.relativeairmass(data['zenith'])

# Determine direct normal irradiation
data['dni'] = (data['dirhi']) / np.sin(np.radians(data['elevation']))
data['dni'] = (data['dirhi']) / np.sin(np.radians(90 - data['zenith']))

# what for??
data['dni'][data['zenith'] > 88] = data['dirhi']
Expand Down Expand Up @@ -189,7 +286,43 @@ def global_in_plane_irradiation(self, data, **kwargs):
return data

def pv_module_output(self, data, **kwargs):
''
r"""
Determine the output of pv-system.
Using the pvlib.pvsystem.sapm function of the pvlib [8]_.
Parameters
----------
module_name : string
Name of a pv module from the sam.nrel database [9]_.
data : pandas.DataFrame
Containing the time index of the location and columns with the
following timeseries: (temp_air [K], v_wind, poa_global,
poa_diffuse, poa_direct, airmass, aoi)
method : string, optional
Method to calulate the position of the sun according to the
methods provided by the pvlib function (default: 'ephemeris')
'pvlib.solarposition.get_solarposition'.[9b]_
Returns
-------
pandas.DataFrame
The DataFrame contains the following new columns: p_pv_norm,
p_pv_norm_area
See Also
--------
global_in_plane_irradiation
References
----------
.. [8] `pvlib solarposition <http://pvlib-python.readthedocs.org/en/
latest/pvlib.html#pvlib.pvsystem.sapm>`_.
.. [9] `module library <https://sam.nrel.gov/sites/sam.nrel.gov/files/
sam-library-sandia-modules-2015-6-30.csv>`_.
.. [9b] `pvlib solarposition <http://pvlib-python.readthedocs.org/en/
latest/pvlib.html#pvlib.solarposition.get_solarposition>`_.
"""
# Determine module and cell temperature
data['temp_air_celsius'] = data['temp_air'] - 273.15
data = pd.concat([data, pvlib.pvsystem.sapm_celltemp(
Expand Down Expand Up @@ -225,7 +358,48 @@ def pv_module_output(self, data, **kwargs):
return data

def get_normalized_pv_time_series(self, **kwargs):
'Normalized to one kW_peak'
r"""
Normalized to one kW_peak or one square meter. For the theoretical
background see the pvlib documentation [10]_.
Parameters
----------
latitude : float
latitude of the irradiation data
longitude: float
longitude of the irradiation data
tz : string
timezone of the irradiation data e.g. Europe/Berlin
data : pandas.DataFrame
Containing the timeseries as columns (temp_air, v_wind, dhi,
dirhi).
weather : oemof.energy_weather object
Containing a DataFrame with all needed data sets.
modul_name : string
name of a pv module from the sam.nrel database [11]_
tilt : float
tilt angle of the pv module (horizontal=0°)
azimuth : float
azimuth angle of the pv module (south=180°)
albedo : float
albedo factor arround the module
Returns
-------
pandas.DataFrame
The DataFrame contains the following new columns: p_pv_norm,
p_pv_norm_area and all timeseries calculated before.
See Also
--------
pv_module_output
References
----------
.. [10] `pvlib documentation <https://readthedocs.org/projects/
pvlib-python/>`_.
.. [11] `module library <https://sam.nrel.gov/sites/sam.nrel.gov/files/
sam-library-sandia-modules-2015-6-30.csv>`_.
"""
# If no DataFrame is given, try to get the data from a weather object
if kwargs.get('data', None) is None:
data = kwargs['weather'].get_feedin_data(
Expand All @@ -234,7 +408,7 @@ def get_normalized_pv_time_series(self, **kwargs):
data = kwargs.pop('data')

# Create a location object
location = (kwargs['latitude'],
location = pvlib.location.Location(kwargs['latitude'],
kwargs['longitude'],
kwargs['tz'])

Expand Down Expand Up @@ -331,11 +505,12 @@ def rho_hub(self, **kwargs):
References
----------
Cite the relevant literature, e.g. [1]_. You may also cite these
Cite the relevant literature, e.g. [31]_. You may also cite these
references in the notes section above.
.. [1] `pvlib on github <https://github.com/pvlib/pvlib-python>`_, pvlib.
.. [2] O. McNoleg, "The integration of GIS, remote sensing,
.. [31] `pvlib on github <https://github.com/pvlib/pvlib-python>`_,
pvlib.
.. [32] O. McNoleg, "The integration of GIS, remote sensing,
expert systems and adaptive co-kriging for environmental habitat
modelling of the Highland Haggis using object-oriented, fuzzy-logic
and neural-network techniques," Computers & Geosciences, vol. 22,
Expand Down

0 comments on commit 4c12454

Please sign in to comment.