Exemplo n.º 1
0
 def add_almanac(self, data):
     almanac = Almanac(
         time.time(),
         float(weecfg.get_station_info(self.config_dict)['latitude']),
         float(weecfg.get_station_info(self.config_dict)['longitude']),
         float(weecfg.get_station_info(self.config_dict)['altitude'][0]))
     data["sunrise"] = almanac.sun.rise.raw
     data["sunset"] = almanac.sun.set.raw
     data["sunaz"] = almanac.sun.az
     data["sunalt"] = almanac.sun.alt
     return data
Exemplo n.º 2
0
    def get_scalar(self, obs_type, record, db_manager):
        # We only know how to calculate some sun and moon related stuff. For everything else, raise an exception UnknownType
        if obs_type not in ('sun_altitude', 'sun_azimuth'):
            raise weewx.UnknownType(obs_type)

        # we only report sun values if the sun is above the horizon
        almanac = Almanac(record['dateTime'], self.lat, self.lng,
                          0)  # TODO convert alt  to meters
        sun_altitude = almanac.sun.alt
        if obs_type == 'sun_altitude':
            value = ValueTuple(sun_altitude if sun_altitude >= 0 else None,
                               'degree_compass', 'group_direction')
        elif obs_type == 'sun_azimuth':
            value = ValueTuple(almanac.sun.az if sun_altitude >= 0 else None,
                               'degree_compass', 'group_direction')

        # We have the calculated values as ValueTuples. Convert them back to the units used by
        # the incoming record and return it
        return weewx.units.convertStd(value, record['usUnits'])
Exemplo n.º 3
0
    def get_data(self, now_ts, last_ts):
        """ read data from almanac """
        try:
            alm = Almanac(time.time(), 53.605963, 11.341407, 53.2)

            son_alt = alm.sun.earth_distance
            sun_alt = alm.sun.alt
            mon_alt = alm.moon.alt
            mer_alt = alm.mercury.alt
            ven_alt = alm.venus.alt
            mar_alt = alm.mars.alt
            jup_alt = alm.jupiter.alt
            sat_alt = alm.saturn.alt
            ura_alt = alm.uranus.alt
            nep_alt = alm.neptune.alt
            plu_alt = alm.pluto.alt

        except:
            sr = None


        record = {}
        record['dateTime'] = now_ts                       # required
        record['usUnits'] = weewx.METRIC                  # required
        record['interval'] = int((now_ts - last_ts) / 60) # required
        record['hor_alt'] = 0.0
        record['son_alt'] = son_alt
        record['sun_alt'] = sun_alt
        record['mon_alt'] = mon_alt
        record['mer_alt'] = mer_alt
        record['ven_alt'] = ven_alt
        record['mar_alt'] = mar_alt
        record['jup_alt'] = jup_alt
        record['sat_alt'] = sat_alt
        record['ura_alt'] = ura_alt
        record['nep_alt'] = nep_alt
        record['plu_alt'] = plu_alt

        return record
Exemplo n.º 4
0
def solar_rad_RS(lat, lon, altitude_m, ts=None, atc=0.8):
    """Calculate maximum solar radiation
    Ryan-Stolzenbach, MIT 1972
    http://www.ecy.wa.gov/programs/eap/models.html

    lat, lon - latitude and longitude in decimal degrees

    altitude_m - altitude in meters

    ts - time as unix epoch

    atc - atmospheric transmission coefficient (0.7-0.91)

    Example:

    >>> for t in range(0,24):
    ...    print "%.2f" % solar_rad_RS(42, -72, 0, t*3600+1422936471)
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    0.09
    79.31
    234.77
    369.80
    455.66
    481.15
    443.44
    346.81
    204.64
    52.63
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    """
    from weewx.almanac import Almanac
    if atc < 0.7 or atc > 0.91:
        atc = 0.8
    if ts is None:
        ts = time.time()
    sr = 0.0
    try:
        alm = Almanac(ts, lat, lon, altitude_m)
        el = alm.sun.alt  # solar elevation degrees from horizon
        R = alm.sun.earth_distance
        z = altitude_m
        nrel = 1367.0  # NREL solar constant, W/m^2
        sinal = math.sin(math.radians(el))
        if sinal >= 0:  # sun must be above horizon
            rm = math.pow(
                (288.0 - 0.0065 * z) / 288.0,
                5.256) / (sinal + 0.15 * math.pow(el + 3.885, -1.253))
            toa = nrel * sinal / (R * R)
            sr = toa * math.pow(atc, rm)
    except (AttributeError, ValueError, OverflowError):
        sr = None
    return sr
Exemplo n.º 5
0
def solar_rad_Bras(lat, lon, altitude_m, ts=None, nfac=2):
    """Calculate maximum solar radiation using Bras method
    http://www.ecy.wa.gov/programs/eap/models.html

    lat, lon - latitude and longitude in decimal degrees

    altitude_m - altitude in meters

    ts - timestamp as unix epoch

    nfac - atmospheric turbidity (2=clear, 4-5=smoggy)

    Example:

    >>> for t in range(0,24):
    ...    print "%.2f" % solar_rad_Bras(42, -72, 0, t*3600+1422936471) 
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    1.86
    100.81
    248.71
    374.68
    454.90
    478.76
    443.47
    353.23
    220.51
    73.71
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    """
    from weewx.almanac import Almanac
    if ts is None:
        ts = time.time()
    sr = 0.0
    try:
        alm = Almanac(ts, lat, lon, altitude_m)
        el = alm.sun.alt  # solar elevation degrees from horizon
        R = alm.sun.earth_distance
        # NREL solar constant W/m^2
        nrel = 1367.0
        # radiation on horizontal surface at top of atmosphere (bras eqn 2.9)
        sinel = math.sin(math.radians(el))
        io = sinel * nrel / (R * R)
        if sinel >= 0:
            # optical air mass (bras eqn 2.22)
            m = 1.0 / (sinel + 0.15 * math.pow(el + 3.885, -1.253))
            # molecular scattering coefficient (bras eqn 2.26)
            a1 = 0.128 - 0.054 * math.log(m) / math.log(10.0)
            # clear-sky radiation at earth surface W / m^2 (bras eqn 2.25)
            sr = io * math.exp(-nfac * a1 * m)
    except (AttributeError, ValueError, OverflowError):
        sr = None
    return sr