Example #1
0
def day_both_calc(dayvalues):
    day, temp_avg, temp_amp, temp_min, temp_delta, latitude, longitude, elevation, pressure, wavelengths = dayvalues
    spectra = Spectra(latitude=latitude,
                      longitude=longitude,
                      elevation=elevation,
                      pressure=pressure,
                      wavelengths=wavelengths)
    rvals = []
    sunrise_dt, sunset_dt = util.get_sunrise_sunset(latitude, longitude, day)
    # offset the sine so that the coldest time of the day is 30m after sunrise
    # see http://cliffmass.blogspot.com.au/2011/01/what-is-coldest-time-of-day.html
    sr_offset = 360 - (sunrise_dt.hour * 60.0 + sunrise_dt.minute + 30.0)

    for d in daterange(day, minutes=1):
        # this was wrong....
        minute = d.minute + (d.hour * 60.0)

        # temp = tavgamp * np.sin(minute * 7.27220521664304e-05 * 60.0)
        temp = temp_avg - temp_amp * np.sin((minute + sr_offset) * daily_freq)
        rh = 100 * np.exp((17.625 * temp_min) / (243.04 + temp_min)) / \
                        np.exp((17.625 * temp) / (243.04 + temp))

        tao = 0.7
        if abs(latitude / np.pi * 180) < 60:
            if temp_delta <= 10 and temp_delta != 0:
                tao /= 11.0 - temp_delta
        th = np.array([temp, rh], dtype=np.float64)
        if sunrise_dt <= d <= sunset_dt:
            rvals.append(
                np.append(th, spectra.calc_vis_spectral(d, temp, rh, tao)))
        else:
            rvals.append(
                np.append(th, np.append(0, np.zeros_like(wavelengths))))
    return rvals
Example #2
0
def get_operating_hours():
    today = datetime.now()
    operating_hours = 0
    for single_date in daterange(START_DATE, today):
        day = datetime.fromtimestamp(time.mktime(single_date.timetuple()))
        sun_rise_set = get_sunrise_sunset(LAT, LON, day)
        daily_operating_hours = sun_rise_set[1] - sun_rise_set[0]
        operating_hours += divmod(daily_operating_hours.total_seconds(), 3600)[0]
    return 1.05 * operating_hours  # adding 5% overhead
Example #3
0
def get_operating_hours():
    today = datetime.now()
    operating_hours = 0
    for single_date in daterange(START_DATE, today):
        day = datetime.fromtimestamp(time.mktime(single_date.timetuple()))
        sun_rise_set = get_sunrise_sunset(LAT, LON, day)
        daily_operating_hours = sun_rise_set[1] - sun_rise_set[0]
        operating_hours += divmod(daily_operating_hours.total_seconds(), 3600)[0]
    return 1.05 * operating_hours  # adding 5% overhead
Example #4
0
    def calc_temp_humidity_spline(self):
        """
        calculates a temperature humidity spline with deltat.

        returns a spline of [temp[:], humidity[:], deltat[:]]
        """

        d = self.start
        xx = list()
        ff = [[], []]

        while d < self.end:
            # increment time by one day
            d += datetime.timedelta(days=1)
            # calculate sr ss
            sunrise_dt, sunset_dt = util.get_sunrise_sunset(
                self.latitude, self.longitude, d)
            sunrise = solar.get_solar_time(self.longitude, sunrise_dt)
            sunset = solar.get_solar_time(self.longitude, sunset_dt)
            doy = d.timetuple().tm_yday

            temp, deltat = self.monthly_temperature_spline(doy)
            deltat = abs(deltat)
            mintemp, maxtemp = temp - deltat, temp + deltat
            t_amplitude = (maxtemp - mintemp) / 2.0
            t_avg = (mintemp + maxtemp) / 2.0

            if self.use_ces:
                tomorrow = d + datetime.timedelta(hours=24)
                tdoy = tomorrow.timetuple().tm_yday
                tomorrow_temp, tomorrow_deltat = self.monthly_temperature_spline(
                    tdoy)
                tomorrow_mintemp = tomorrow_temp - abs(tomorrow_deltat)
                for m in range(1440):
                    t = self.ces_temp_fit(m, mintemp, maxtemp,
                                          tomorrow_mintemp, sunrise, sunset)
                    ff[0].append(t)
                    ff[1].append(self.relative_humidity(mintemp, t))
                    xx.append(doy + (m / 1440))
            else:
                for m in range(1440):
                    # assume daily fluctuation mimics sinewave...period 24 h
                    # freq = 2 * pi / 86400 sec = 7.27 E-5 sec-1
                    t = t_avg - t_amplitude * np.sin(
                        m * 7.27220521664304e-05 * 60.0)
                    ff[0].append(t)
                    ff[1].append(self.relative_humidity(mintemp, t))
                    xx.append(doy + (m / 1440))

        xx.append(xx[-1] + (1 / 1440))
        ff[0].append(ff[0][0])
        ff[1].append(ff[1][0])
        ff = np.array(ff)
        ff = np.swapaxes(ff, 0, 1)
        xx = np.array(xx)
        return CubicSpline(xx, ff)
def sunrise_sunset(time, place = sevilla):
    return get_sunrise_sunset(place.latitude, place.longitude, time)
 def test_util_get_sunrise_sunset_raise_error(self):
     with self.assertRaises(NoTimeZoneInfoError):
         util.get_sunrise_sunset(self.lat, self.lon, self.unaware)
    def test_util_get_sunrise_sunset_no_error(self):
        try:
            util.get_sunrise_sunset(self.lat, self.lon, self.aware)
        except NoTimeZoneInfoError:
            self.fail("""'NoTimeZoneInfoError' should not be raised \
as 'datetime' object is tz-aware.""")