Skip to content

Update variable names #70

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

Merged
merged 14 commits into from
Jul 5, 2015
11 changes: 10 additions & 1 deletion docs/sphinx/source/whatsnew/v0.2.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
v0.2.0 (??, 2015)
-----------------------

This is a major release from 0.1 and includes a small number of API changes,
This is a major release from 0.1 and includes a large number of API changes,
several new features and enhancements along with a number of bug fixes.
We recommend that all users upgrade to this version.

Due to the large number of API changes, you will probably need to update your
code.


API changes
~~~~~~~~~~~

* Change variable names to conform with new
`Variables and style rules wiki <https://github.com/pvlib/pvlib-python/wiki/Variables-and-style-rules>`_.
This impacts many function declarations and return values.
Your existing code probably will not work! (:issue:`37`, :issue:`54`).
* Move ``dirint`` and ``disc`` algorithms from ``clearsky.py``
to ``irradiance.py`` (:issue:`42`)
* Mark some ``pvsystem.py`` methods as private (:issue:`20`)
* Make output of ``pvsystem.sapm_celltemp`` a DataFrame (:issue:`54`)

Enhancements
~~~~~~~~~~~~
Expand All @@ -23,6 +31,7 @@ Enhancements
* Add optional ``projection_ratio`` keyword argument to the ``haydavies``
calculator. Speeds calculations when irradiance changes but
solar position remains the same (:issue:`58`)
* Improved installation instructions in README.

Bug fixes
~~~~~~~~~
Expand Down
11,631 changes: 2,048 additions & 9,583 deletions docs/tutorials/pvsystem.ipynb

Large diffs are not rendered by default.

55 changes: 34 additions & 21 deletions pvlib/atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def pres2alt(pressure):

Parameters
----------
Pressure : scalar or Series
Atomspheric pressure (Pascals)
pressure : scalar or Series
Atmospheric pressure (Pascals)

Returns
-------
Expand Down Expand Up @@ -100,7 +100,7 @@ def alt2pres(altitude):



def absoluteairmass(AMrelative, pressure=101325.):
def absoluteairmass(airmass_relative, pressure=101325.):
'''
Determine absolute (pressure corrected) airmass from relative
airmass and pressure
Expand All @@ -117,7 +117,7 @@ def absoluteairmass(AMrelative, pressure=101325.):
Parameters
----------

AMrelative : scalar or Series
airmass_relative : scalar or Series
The airmass at sea-level.

pressure : scalar or Series
Expand All @@ -136,13 +136,12 @@ def absoluteairmass(AMrelative, pressure=101325.):

'''

AMa = AMrelative * pressure / 101325.

return AMa
airmass_absolute = airmass_relative * pressure / 101325.

return airmass_absolute


def relativeairmass(z, model='kastenyoung1989'):
def relativeairmass(zenith, model='kastenyoung1989'):
'''
Gives the relative (not pressure-corrected) airmass

Expand All @@ -155,17 +154,20 @@ def relativeairmass(z, model='kastenyoung1989'):
Parameters
----------

z : float or DataFrame
zenith : float or Series
Zenith angle of the sun in degrees.
Note that some models use the apparent (refraction corrected)
zenith angle, and some models use the true (not refraction-corrected)
zenith angle. See model descriptions to determine which type of zenith
angle is required. Apparent zenith angles must be calculated at sea level.
zenith angle, and some models use the true
(not refraction-corrected) zenith angle.
See model descriptions to determine which type of zenith
angle is required.
Apparent zenith angles must be calculated at sea level.

model : String
Available models include the following:

* 'simple' - secant(apparent zenith angle) - Note that this gives -inf at zenith=90
* 'simple' - secant(apparent zenith angle) -
Note that this gives -inf at zenith=90
* 'kasten1966' - See reference [1] - requires apparent sun zenith
* 'youngirvine1967' - See reference [2] - requires true sun zenith
* 'kastenyoung1989' - See reference [3] - requires apparent sun zenith
Expand All @@ -175,7 +177,7 @@ def relativeairmass(z, model='kastenyoung1989'):

Returns
-------
AM : float or DataFrame
airmass_relative : float or Series
Relative airmass at sea level. Will return NaN values for any
zenith angle greater than 90 degrees.

Expand Down Expand Up @@ -207,27 +209,38 @@ def relativeairmass(z, model='kastenyoung1989'):
Sandia Report, (2012).
'''

z = zenith
zenith_rad = np.radians(z)

model = model.lower()

if 'kastenyoung1989' == model:
AM = 1.0 / (np.cos(zenith_rad) + 0.50572*(((6.07995 + (90 - z)) ** - 1.6364)))
AM = ( 1.0 / (np.cos(zenith_rad) +
0.50572*(((6.07995 + (90 - z)) ** - 1.6364))) )
elif 'kasten1966' == model:
AM = 1.0 / (np.cos(zenith_rad) + 0.15*((93.885 - z) ** - 1.253))
elif 'simple' == model:
AM = 1.0 / np.cos(zenith_rad)
elif 'pickering2002' == model:
AM = 1.0 / (np.sin(np.radians(90 - z + 244.0 / (165 + 47.0 * (90 - z) ** 1.1))))
AM = ( 1.0 / (np.sin(np.radians(90 - z +
244.0 / (165 + 47.0 * (90 - z) ** 1.1)))) )
elif 'youngirvine1967' == model:
AM = (1.0 / np.cos(zenith_rad)) * (1 - 0.0012*( (1.0 / np.cos(zenith_rad)) ** 2) - 1)
AM = ( (1.0 / np.cos(zenith_rad)) *
(1 - 0.0012*( (1.0 / np.cos(zenith_rad)) ** 2) - 1) )
elif 'young1994' == model:
AM = (1.002432*((np.cos(zenith_rad)) ** 2) + 0.148386*(np.cos(zenith_rad)) + 0.0096467) / (np.cos(zenith_rad) ** 3 + 0.149864*(np.cos(zenith_rad) ** 2) + 0.0102963*(np.cos(zenith_rad)) + 0.000303978)
AM = ( (1.002432*((np.cos(zenith_rad)) ** 2) +
0.148386*(np.cos(zenith_rad)) + 0.0096467) /
(np.cos(zenith_rad) ** 3 +
0.149864*(np.cos(zenith_rad) ** 2) +
0.0102963*(np.cos(zenith_rad)) + 0.000303978) )
elif 'gueymard1993' == model:
AM = 1.0 / (np.cos(zenith_rad) + 0.00176759*(z)*((94.37515 - z) ** - 1.21563))
AM = ( 1.0 / (np.cos(zenith_rad) +
0.00176759*(z)*((94.37515 - z) ** - 1.21563)) )
else:
pvl_logger.warning("{} is not a valid model type for relative airmass. The 'kastenyoung1989' model was used.".format(model))
AM = 1.0 / (np.cos(zenith_rad) + 0.50572*(((6.07995 + (90 - z)) ** - 1.6364)))
pvl_logger.warning("{} is not a valid model type for relative airmass. The 'kastenyoung1989' model was used."
.format(model))
AM = ( 1.0 / (np.cos(zenith_rad) +
0.50572*(((6.07995 + (90 - z)) ** - 1.6364))) )

try:
AM[z > 90] = np.nan
Expand Down
49 changes: 25 additions & 24 deletions pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def ineichen(time, location, linke_turbidity=None,
Sets the solar position algorithm.
See solarposition.get_solarposition()

zenith_data : None or pandas.Series
zenith_data : None or Series
If None, ephemeris data will be calculated using ``solarposition_method``.

airmass_model : string
See pvlib.airmass.relativeairmass().

airmass_data : None or pandas.Series
airmass_data : None or Series
If None, absolute air mass data will be calculated using
``airmass_model`` and location.alitude.

Expand All @@ -65,14 +65,14 @@ def ineichen(time, location, linke_turbidity=None,

Returns
--------
DataFrame with the following columns: ``GHI, DNI, DHI``.
DataFrame with the following columns: ``ghi, dni, dhi``.

Notes
-----
If you are using this function
in a loop, it may be faster to load LinkeTurbidities.mat outside of
the loop and feed it in as a variable, rather than
having the function open the file each time it is called.
the loop and feed it in as a keyword argument, rather than
having the function open and process the file each time it is called.

References
----------
Expand All @@ -96,7 +96,7 @@ def ineichen(time, location, linke_turbidity=None,
'''
# Initial implementation of this algorithm by Matthew Reno.
# Ported to python by Rob Andrews
# Added functionality by Will Holmgren
# Added functionality by Will Holmgren (@wholmgren)

I0 = irradiance.extraradiation(time.dayofyear)

Expand Down Expand Up @@ -161,7 +161,7 @@ def ineichen(time, location, linke_turbidity=None,
# alt2pres) using Kasten and Young's 1989 formula for airmass.

if airmass_data is None:
AMabsolute = atmosphere.absoluteairmass(AMrelative=atmosphere.relativeairmass(ApparentZenith, airmass_model),
AMabsolute = atmosphere.absoluteairmass(airmass_relative=atmosphere.relativeairmass(ApparentZenith, airmass_model),
pressure=atmosphere.alt2pres(location.altitude))
else:
AMabsolute = airmass_data
Expand Down Expand Up @@ -195,7 +195,9 @@ def ineichen(time, location, linke_turbidity=None,

cos_zenith = tools.cosd(ApparentZenith)

clearsky_GHI = cg1 * I0 * cos_zenith * np.exp(-cg2*AMabsolute*(fh1 + fh2*(TL - 1))) * np.exp(0.01*AMabsolute**1.8)
clearsky_GHI = ( cg1 * I0 * cos_zenith *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would also change clearsky_GHI to all lower case (clearsky_ghi) for consistency.
Not sure, did you intended to change only names for the kw arguments (all api related) or all internal variable names too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only intended to change the API related names for now. I would like to see the internal variables get updated, but I think we can do this in smaller chunks.

np.exp(-cg2*AMabsolute*(fh1 + fh2*(TL - 1))) *
np.exp(0.01*AMabsolute**1.8) )
clearsky_GHI[clearsky_GHI < 0] = 0

# BncI == "normal beam clear sky radiation"
Expand All @@ -204,25 +206,24 @@ def ineichen(time, location, linke_turbidity=None,
logger.debug('b={}'.format(b))

# "empirical correction" SE 73, 157 & SE 73, 312.
BncI_2 = clearsky_GHI * ( 1 - (0.1 - 0.2*np.exp(-TL))/(0.1 + 0.882/fh1) ) / cos_zenith
#return BncI, BncI_2
clearsky_DNI = np.minimum(BncI, BncI_2) # Will H: use np.minimum explicitly
BncI_2 = ( clearsky_GHI *
( 1 - (0.1 - 0.2*np.exp(-TL))/(0.1 + 0.882/fh1) ) /
cos_zenith )

clearsky_DNI = np.minimum(BncI, BncI_2)

clearsky_DHI = clearsky_GHI - clearsky_DNI*cos_zenith

df_out = pd.DataFrame({'GHI':clearsky_GHI, 'DNI':clearsky_DNI,
'DHI':clearsky_DHI})
df_out = pd.DataFrame({'ghi':clearsky_GHI, 'dni':clearsky_DNI,
'dhi':clearsky_DHI})
df_out.fillna(0, inplace=True)
#df_out['BncI'] = BncI
#df_out['BncI_2'] = BncI

return df_out



def haurwitz(ApparentZenith):


def haurwitz(apparent_zenith):
'''
Determine clear sky GHI from Haurwitz model
Determine clear sky GHI from Haurwitz model.

Implements the Haurwitz clear sky model for global horizontal
irradiance (GHI) as presented in [1, 2]. A report on clear
Expand All @@ -232,7 +233,7 @@ def haurwitz(ApparentZenith):

Parameters
----------
ApparentZenith : DataFrame
apparent_zenith : Series
The apparent (refraction corrected) sun zenith angle
in degrees.

Expand All @@ -258,13 +259,13 @@ def haurwitz(ApparentZenith):
Laboratories, SAND2012-2389, 2012.
'''

cos_zenith = tools.cosd(ApparentZenith)
cos_zenith = tools.cosd(apparent_zenith)

clearsky_GHI = 1098.0 * cos_zenith * np.exp(-0.059/cos_zenith)

clearsky_GHI[clearsky_GHI < 0] = 0

df_out = pd.DataFrame({'GHI':clearsky_GHI})
df_out = pd.DataFrame({'ghi':clearsky_GHI})

return df_out

Expand All @@ -274,5 +275,5 @@ def _linearly_scale(inputmatrix, inputmin, inputmax, outputmin, outputmax):

inputrange = inputmax - inputmin
outputrange = outputmax - outputmin
OutputMatrix = (inputmatrix - inputmin) * outputrange / inputrange + outputmin
OutputMatrix = (inputmatrix-inputmin) * outputrange/inputrange + outputmin
return OutputMatrix
Loading