CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pvlib

A comprehensive toolbox for modeling and simulating photovoltaic energy systems.

Pending
Overview
Eval results
Files

atmosphere.mddocs/

Atmospheric Models

Model atmospheric effects including airmass calculations, precipitable water, aerosol optical depth, and atmospheric parameters essential for accurate irradiance and clear sky modeling.

Capabilities

Airmass Calculations

Calculate relative and absolute airmass using various models.

def get_relative_airmass(zenith, model='kastenyoung1989'):
    """
    Calculate relative airmass.
    
    Parameters:
    - zenith: numeric, solar zenith angle in degrees
    - model: str, airmass model ('simple', 'kasten1966', 'kastenyoung1989', 
             'gueymard1993', 'young1994', 'pickering2002')
    
    Returns:
    numeric, relative airmass
    """

def get_absolute_airmass(airmass_relative, pressure=101325.0):
    """
    Calculate absolute airmass.
    
    Parameters:
    - airmass_relative: numeric, relative airmass
    - pressure: numeric, atmospheric pressure in pascals
    
    Returns:
    numeric, absolute airmass
    """

Pressure and Altitude Conversions

Convert between atmospheric pressure and altitude.

def pres2alt(pressure):
    """
    Convert atmospheric pressure to altitude.
    
    Parameters:
    - pressure: numeric, atmospheric pressure in pascals
    
    Returns:
    numeric, altitude in meters above sea level
    """

def alt2pres(altitude):
    """
    Convert altitude to atmospheric pressure.
    
    Parameters:
    - altitude: numeric, altitude in meters above sea level
    
    Returns:
    numeric, atmospheric pressure in pascals
    """

Precipitable Water

Calculate precipitable water content in the atmosphere.

def gueymard94_pw(temp_air, relative_humidity):
    """
    Calculate precipitable water using Gueymard 1994 formula.
    
    Parameters:
    - temp_air: numeric, air temperature in degrees C
    - relative_humidity: numeric, relative humidity (0-100)
    
    Returns:
    numeric, precipitable water in cm
    """

Humidity Calculations

Convert between relative humidity and dew point temperature.

def rh_from_tdew(temp_air, temp_dew, coeff=(6.112, 17.62, 243.12)):
    """
    Calculate relative humidity from dew point temperature.
    
    Parameters:
    - temp_air: numeric, air temperature in degrees C
    - temp_dew: numeric, dew point temperature in degrees C
    - coeff: tuple, coefficients for Magnus formula
    
    Returns:
    numeric, relative humidity (0-100)
    """

def tdew_from_rh(temp_air, relative_humidity, coeff=(6.112, 17.62, 243.12)):
    """
    Calculate dew point temperature from relative humidity.
    
    Parameters:
    - temp_air: numeric, air temperature in degrees C
    - relative_humidity: numeric, relative humidity (0-100)
    - coeff: tuple, coefficients for Magnus formula
    
    Returns:
    numeric, dew point temperature in degrees C
    """

Aerosol Optical Depth

Calculate aerosol optical depth parameters.

def bird_hulstrom80_aod_bb(aod380, aod500):
    """
    Calculate broadband aerosol optical depth using Bird-Hulstrom model.
    
    Parameters:
    - aod380: numeric, aerosol optical depth at 380 nm
    - aod500: numeric, aerosol optical depth at 500 nm
    
    Returns:
    numeric, broadband aerosol optical depth
    """

def angstrom_aod_at_lambda(aod0, lambda0, alpha=1.14, lambda1=700.0):
    """
    Calculate aerosol optical depth at specific wavelength using Angstrom formula.
    
    Parameters:
    - aod0: numeric, aerosol optical depth at reference wavelength
    - lambda0: numeric, reference wavelength in nm
    - alpha: numeric, Angstrom alpha parameter
    - lambda1: numeric, target wavelength in nm
    
    Returns:
    numeric, aerosol optical depth at target wavelength
    """

def angstrom_alpha(aod1, lambda1, aod2, lambda2):
    """
    Calculate Angstrom alpha parameter.
    
    Parameters:
    - aod1: numeric, aerosol optical depth at wavelength 1
    - lambda1: numeric, wavelength 1 in nm
    - aod2: numeric, aerosol optical depth at wavelength 2
    - lambda2: numeric, wavelength 2 in nm
    
    Returns:
    numeric, Angstrom alpha parameter
    """

Linke Turbidity

Calculate Linke turbidity factor for clear sky modeling.

def kasten96_lt(airmass_absolute, precipitable_water, aod_bb):
    """
    Calculate Linke turbidity factor using Kasten 1996 model.
    
    Parameters:
    - airmass_absolute: numeric, absolute airmass
    - precipitable_water: numeric, precipitable water in cm
    - aod_bb: numeric, broadband aerosol optical depth
    
    Returns:
    numeric, Linke turbidity factor
    """

Wind Speed Modeling

Calculate wind speed at different heights using power law.

def windspeed_powerlaw(wind_speed_reference, height_reference, 
                      height_target, alpha=0.14):
    """
    Calculate wind speed at different height using power law.
    
    Parameters:
    - wind_speed_reference: numeric, wind speed at reference height (m/s)
    - height_reference: numeric, reference height in meters
    - height_target: numeric, target height in meters
    - alpha: numeric, power law exponent
    
    Returns:
    numeric, wind speed at target height (m/s)
    """

Constants

Airmass Models

APPARENT_ZENITH_MODELS = (
    'simple', 'kasten1966', 'kastenyoung1989', 'gueymard1993', 
    'young1994', 'pickering2002'
)

TRUE_ZENITH_MODELS = (
    'simple', 'kasten1966', 'kastenyoung1989', 'gueymard1993', 
    'young1994', 'pickering2002'
)

AIRMASS_MODELS = APPARENT_ZENITH_MODELS + TRUE_ZENITH_MODELS

Surface Type Exponents

HELLMANN_SURFACE_EXPONENTS = {
    'water': 0.10,
    'smooth': 0.13,
    'open': 0.16,
    'roughlyopen': 0.20,
    'rough': 0.25,
    'veryrough': 0.40,
    'closed': 0.60
}

Usage Examples

Basic Airmass Calculation

import pvlib
from pvlib import atmosphere, solarposition
import pandas as pd

# Location and time
lat, lon = 40.0583, -74.4057
times = pd.date_range('2023-06-21 06:00', '2023-06-21 18:00', 
                     freq='H', tz='US/Eastern')

# Solar position
solar_pos = solarposition.get_solarposition(times, lat, lon)

# Calculate relative airmass
am_rel = atmosphere.get_relative_airmass(
    solar_pos['zenith'], 
    model='kastenyoung1989'
)

# Calculate absolute airmass (at sea level pressure)
am_abs = atmosphere.get_absolute_airmass(am_rel, pressure=101325)

print("Time, Zenith, Relative AM, Absolute AM")
for i in range(len(times)):
    print(f"{times[i].strftime('%H:%M')}, {solar_pos['zenith'].iloc[i]:.1f}°, "
          f"{am_rel.iloc[i]:.2f}, {am_abs.iloc[i]:.2f}")

Precipitable Water Calculation

import pvlib
from pvlib import atmosphere
import numpy as np

# Meteorological conditions
temp_air = 25  # degrees C
relative_humidity = 65  # percent

# Calculate precipitable water
pw = atmosphere.gueymard94_pw(temp_air, relative_humidity)
print(f"Precipitable water: {pw:.2f} cm")

# Array of conditions
temps = np.array([10, 15, 20, 25, 30, 35])
rh = np.array([40, 50, 60, 70, 80, 90])

pw_array = atmosphere.gueymard94_pw(temps, rh)
print("\nTemperature (°C), RH (%), PW (cm)")
for i in range(len(temps)):
    print(f"{temps[i]}, {rh[i]}, {pw_array[i]:.2f}")

Aerosol Optical Depth Calculations

import pvlib
from pvlib import atmosphere
import numpy as np

# Measured AOD values
aod380 = 0.25
aod500 = 0.15

# Calculate broadband AOD
aod_bb = atmosphere.bird_hulstrom80_aod_bb(aod380, aod500)
print(f"Broadband AOD: {aod_bb:.3f}")

# Calculate Angstrom alpha parameter
alpha = atmosphere.angstrom_alpha(aod380, 380, aod500, 500)
print(f"Angstrom alpha: {alpha:.3f}")

# Calculate AOD at different wavelengths
wavelengths = np.array([400, 550, 700, 900, 1020])
aod_spectrum = atmosphere.angstrom_aod_at_lambda(
    aod500, 500, alpha, wavelengths
)

print("\nWavelength (nm), AOD")
for i, wl in enumerate(wavelengths):
    print(f"{wl}, {aod_spectrum[i]:.3f}")

Wind Speed Profile

import pvlib
from pvlib import atmosphere
import numpy as np

# Reference wind speed at 10m height
wind_10m = 5.0  # m/s
ref_height = 10.0  # meters

# Target heights
heights = np.array([2, 5, 10, 20, 50, 100])

# Calculate wind speeds using power law
wind_speeds = atmosphere.windspeed_powerlaw(
    wind_10m, ref_height, heights, alpha=0.14
)

print("Height (m), Wind Speed (m/s)")
for i, h in enumerate(heights):
    print(f"{h}, {wind_speeds[i]:.2f}")

Humidity Conversions

import pvlib
from pvlib import atmosphere
import numpy as np

# Temperature and humidity data
temp_air = np.array([15, 20, 25, 30])
relative_humidity = np.array([60, 65, 70, 75])

# Calculate dew point temperatures
dew_points = atmosphere.tdew_from_rh(temp_air, relative_humidity)

print("Temp (°C), RH (%), Dew Point (°C)")
for i in range(len(temp_air)):
    print(f"{temp_air[i]}, {relative_humidity[i]}, {dew_points[i]:.1f}")

# Verify by calculating RH from dew point
rh_calc = atmosphere.rh_from_tdew(temp_air, dew_points)
print("\nVerification - calculated RH should match input:")
for i in range(len(temp_air)):
    print(f"Input: {relative_humidity[i]}%, Calculated: {rh_calc[i]:.1f}%")

Install with Tessl CLI

npx tessl i tessl/pypi-pvlib

docs

atmosphere.md

bifacial.md

clearsky.md

iam.md

index.md

inverter.md

iotools.md

irradiance.md

losses.md

pvsystem.md

solar-position.md

spectrum.md

temperature.md

tile.json