How to use the pvlib.solarposition function in pvlib

To help you get started, we’ve selected a few pvlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pvlib / pvlib-python / pvlib / location.py View on Github external
solarposition.sun_rise_set_transit_ for details.

        Returns
        -------
        result : DataFrame
            Column names are: ``sunrise, sunset, transit``.
        """

        if method == 'pyephem':
            result = solarposition.sun_rise_set_transit_ephem(
                times, self.latitude, self.longitude, **kwargs)
        elif method == 'spa':
            result = solarposition.sun_rise_set_transit_spa(
                times, self.latitude, self.longitude, **kwargs)
        elif method == 'geometric':
            sr, ss, tr = solarposition.sun_rise_set_transit_geometric(
                times, self.latitude, self.longitude, **kwargs)
            result = pd.DataFrame(index=times,
                                  data={'sunrise': sr,
                                        'sunset': ss,
                                        'transit': tr})
        else:
            raise ValueError('{} is not a valid method. Must be '
                             'one of pyephem, spa, geometric'
                             .format(method))
        return result
github BreakingBytes / pvfree / pvfree / api.py View on Github external
else:
        return JsonResponse(params.errors, status=400)
    tz = tz or 0  # if tz is None then use zero
    freq = freq or 'H'  # if freq if '' then use 'H'
    if start > end:
        return JsonResponse(
            {'start': ['End time must be after start.']}, status=400)
    # drop the timezone
    start = start.replace(tzinfo=None)
    end = end.replace(tzinfo=None)
    tz = 'Etc/GMT{:+d}'.format(-tz)
    try:
        times = pd.DatetimeIndex(start=start, end=end, freq=freq, tz=tz)
    except ValueError as exc:
        return JsonResponse({'freq': [str(exc)]}, status=400)
    solpos = solarposition.get_solarposition(times, lat, lon)
    solpos.index = times.strftime('%Y-%m-%dT%H:%M:%S%z')
    # [t.isoformat() for t in times.to_pydatetime()]
    data = solpos.to_dict('index')
    return JsonResponse(data)
github sandialabs / pecos / examples / pv / pv_example.py View on Github external
df = pecos.io.read_campbell_scientific(database_file)
df.index = df.index.tz_localize(location['Timezone'])
pm.add_dataframe(df)
pm.add_translation_dictionary(BASE_translation_dictionary)

database_file = 'MET_2015_11_11.dat'
df = pecos.io.read_campbell_scientific(database_file)
df.index = df.index.tz_localize(location['Timezone'])
pm.add_dataframe(df)
pm.add_translation_dictionary(MET_translation_dictionary)

# Check timestamp
pm.check_timestamp(60) 
    
# Generate a time filter based on sun position
solarposition = pvlib.solarposition.ephemeris(pm.df.index, location['Latitude'], 
                                              location['Longitude'])
time_filter = solarposition['apparent_elevation'] > 10 
pm.add_time_filter(time_filter)

# Check missing
pm.check_missing()

# Check corrupt
pm.check_corrupt(corrupt_values) 

# Add composite signals
for composite_signal in composite_signals:
    for key,value in composite_signal.items():
        signal = pecos.utils.evaluate_string(value, data=pm.df, 
                                             trans=pm.trans, col_name=key)
        pm.add_dataframe(signal)
github sunspec / prodromos / forecasting / pv_forecast_dev.py View on Github external
def get_sr_ss(pvobj, dt):
    """
    Returns sunrise and sunset for local datetime dt at location of pbobj
    """
    # for sunrise and sunset calculation, time must be in timezone for location
    local_dt = dt.astimezone(pvobj.timezone)
    doy = pd.Timestamp(local_dt).dayofyear
    declination = pvlib.solarposition.declination_spencer71(doy)
    eot = pvlib.solarposition.equation_of_time_spencer71(doy)
    sr, ss, _ = sun_rise_set_transit_geometric(local_dt, pvobj.lat,
        pvobj.lon, declination, eot)
    if len(sr)==1: # return as datetime
        return sr[0], ss[0]
    else:  # return as pd.DatetimeIndex
        return sr, ss
github SolarArbiter / solarforecastarbiter-core / solarforecastarbiter / pvmodel.py View on Github external
Parameters
    ----------
    latitude : float
    longitude : float
    elevation : float
    times : pd.DatetimeIndex

    Returns
    -------
    solar_position : pd.DataFrame
        The DataFrame will have the following columns: apparent_zenith
        (degrees), zenith (degrees), apparent_elevation (degrees),
        elevation (degrees), azimuth (degrees),
        equation_of_time (minutes).
    """
    solpos = pvlib.solarposition.get_solarposition(times, latitude,
                                                   longitude,
                                                   altitude=elevation,
                                                   method='nrel_numpy')
    return solpos
github pvlib / pvlib-python / pvlib / irradiance.py View on Github external
.. [4] Duffie, J. A. and Beckman, W. A. 1991. Solar Engineering of
       Thermal Processes, 2nd edn. J. Wiley and Sons, New York.

    .. [5] ASCE, 2005. The ASCE Standardized Reference Evapotranspiration
       Equation, Environmental and Water Resources Institute of the American
       Civil Engineers, Ed. R. G. Allen et al.
    """

    to_doy, to_datetimeindex, to_output = \
        _handle_extra_radiation_types(datetime_or_doy, epoch_year)

    # consider putting asce and spencer methods in their own functions
    method = method.lower()
    if method == 'asce':
        B = solarposition._calculate_simple_day_angle(to_doy(datetime_or_doy),
                                                      offset=0)
        RoverR0sqrd = 1 + 0.033 * np.cos(B)
    elif method == 'spencer':
        B = solarposition._calculate_simple_day_angle(to_doy(datetime_or_doy))
        RoverR0sqrd = (1.00011 + 0.034221 * np.cos(B) + 0.00128 * np.sin(B) +
                       0.000719 * np.cos(2 * B) + 7.7e-05 * np.sin(2 * B))
    elif method == 'pyephem':
        times = to_datetimeindex(datetime_or_doy)
        RoverR0sqrd = solarposition.pyephem_earthsun_distance(times) ** (-2)
    elif method == 'nrel':
        times = to_datetimeindex(datetime_or_doy)
        RoverR0sqrd = \
            solarposition.nrel_earthsun_distance(times, **kwargs) ** (-2)
    else:
        raise ValueError('Invalid method: %s', method)
github sunspec / prodromos / forecasting / pv_forecast_dev.py View on Github external
def get_sr_ss(pvobj, dt):
    """
    Returns sunrise and sunset for local datetime dt at location of pbobj
    """
    # for sunrise and sunset calculation, time must be in timezone for location
    local_dt = dt.astimezone(pvobj.timezone)
    doy = pd.Timestamp(local_dt).dayofyear
    declination = pvlib.solarposition.declination_spencer71(doy)
    eot = pvlib.solarposition.equation_of_time_spencer71(doy)
    sr, ss, _ = sun_rise_set_transit_geometric(local_dt, pvobj.lat,
        pvobj.lon, declination, eot)
    if len(sr)==1: # return as datetime
        return sr[0], ss[0]
    else:  # return as pd.DatetimeIndex
        return sr, ss