Beispiel #1
0
    def now(self, timestamp=None, weather_data=None, model='STC'):
        """Preditive power output"""
        if timestamp is None:
            timestamp = datetime.datetime.now() - \
                    datetime.timedelta(hours=self.tz)

        if model != 'STC' and weather_data == None:
            weather_data = forecast.data(self.place)['currently']

        if model == 'CC':
            record = irradiation.blave(timestamp, self.place, self.tilt, \
                    self.azimuth, cloudCover=weather_data['cloudCover'])
        else:
            record = irradiation.blave(timestamp, self.place, self.tilt, \
                    self.azimuth)

        irradiance = irradiation.irradiation(record, self.place, None,\
                t=self.tilt, array_azimuth=self.azimuth, model='p9')

        if hasattr(self, 'hourly_shade'):
            irradiance = irradiance * self.hourly_shade.shade(timestamp)

        if model == 'STC':
            return self.p_ac(irradiance)
        else:
            t_cell = irradiation.moduleTemp(irradiance, weather_data)
            return self.p_ac(irradiance, t_cell)
Beispiel #2
0
    def now(self, timestamp=None, weather_data=None, model='STC'):
        """Preditive power output"""
        if timestamp is None:
            timestamp = datetime.datetime.now() - \
                    datetime.timedelta(hours=self.tz)

        if model != 'STC' and  weather_data == None:
            weather_data = forecast.data(self.place)['currently']

        if model == 'CC':
            record = irradiation.blave(timestamp, self.place, self.tilt, \
                    self.azimuth, cloudCover=weather_data['cloudCover'])
        else:
            record = irradiation.blave(timestamp, self.place, self.tilt, \
                    self.azimuth)

        irradiance = irradiation.irradiation(record, self.place, None,\
                t=self.tilt, array_azimuth=self.azimuth, model='p9')

        if hasattr(self, 'hourly_shade'):
            irradiance = irradiance * self.hourly_shade.shade(timestamp)

        if model == 'STC':
            return self.p_ac(irradiance)
        else:
            t_cell = irradiation.moduleTemp(irradiance, weather_data)
            return self.p_ac(irradiance, t_cell)
Beispiel #3
0
def _calc(record):
    """internal fuction for multiprocessing hack"""
    properties, record = record
    horizon = None
    insolation = irradiation.irradiation(record, properties['place'], \
            horizon, properties['tilt'], properties['azimuth'], \
            properties['model_name'])
    year = 2000
    timestamp = tmy3.normalize_date(record['datetime'], year)
    return timestamp, insolation, record
Beispiel #4
0
def _calc(record):
    """internal fuction for multiprocessing hack"""
    properties, record = record
    horizon = None
    insolation = irradiation.irradiation(record, properties['place'], \
            horizon, properties['tilt'], properties['azimuth'], \
            properties['model_name'])
    year = 2000
    timestamp = tmy3.normalize_date(record['datetime'], year)
    return timestamp, insolation, record
Beispiel #5
0
        record['utc_datetime'] = strptime(_sd, self.tz)
        record['datetime'] = strptime(_sd)
        return record

    def __del__(self):
        self.csvfile.close()

def total(usaf, field='GHI (W/m^2)'):
    """total annual insolation, defaults to GHI"""
    running_total = 0
    usafdata = data(usaf)
    for record in usafdata:
        running_total += float(record[field])
    return running_total/1000.

if __name__ == "__main__":
    from solpy import geo
    TILT = 32.0
    #import matplotlib.pyplot as plt
    #place = zipToCoordinates('17601) #Lancaster
    PLACE = geo.zip_coordinates('19113') #Philadelphia
    DUMMY, USAF = geo.closest_usaf(PLACE)
    TOTAL_INS = 0
    for i in data(USAF):
        output = irradiation.irradiation(i, PLACE, t=TILT)
        TOTAL_INS += output

    print TOTAL_INS/1000
    print TOTAL_INS/(1000*365.0)
    print total(USAF)
Beispiel #6
0
            #     cloud_cover = ccddatabase[str(m_s)+str(d_s)]
            # else:
            #     cloud_cover = 0.0

            for setting in settings:
                if setting['Name'] not in res:
                    res[setting['Name']] = {}
                e = str(m_s) + str(d_s)
                if e not in res[setting['Name']]:
                    res[setting['Name']][e] = []

                #-- Global synthetic irradiation from Solpy
                global_irradiation_rec = irradiation.blave(dt, place, 0, 180)
                #-- Adjust it for the tilt. The value is now in W/m^2
                irrValue = irradiation.irradiation(global_irradiation_rec,
                                                   place, None,
                                                   setting['Tilt'],
                                                   setting['Azimuth'], 'p9')
                horr_irrValue = irradiation.irradiation(
                    global_irradiation_rec, place, None, 0, 180, 'p9')
                #-- Workaround to keep the data aligned
                d_ = datetime.date(2013, 1, 1)
                t_ = datetime.time(hour, minute)
                dt_ = datetime.datetime.combine(d_, t_)
                res[setting['Name']][e].append([dt_, irrValue, horr_irrValue])

import scipy
import os
#-- Fix LaTeX for macOS 10.12
os.environ['PATH'] = os.environ['PATH'] + ':/Library/TeX/texbin'
import matplotlib as mpl
mpl.use('TkAgg')
Beispiel #7
0
    def forecast_output(self, daylightSavings=False, source=None, hours=24):
        """forecast output of system"""
        #todo: model and forecast should use consistant units; Wh or KWh
        #default is forecast with solpy.blave
        #this is ugly code... sorry
        #todo: refactor
        d = datetime.date.today()
        endTimeUTC = datetime.datetime(d.year, d.month, d.day)\
                + datetime.timedelta(hours=hours-self.tz)
        if source == 'noaa':
            wseries = noaa.herp_derp_interp(self.place)
            ts = []
            irr = []
            for i in wseries:
                if i['utc_datetime'] > endTimeUTC:
                    break
                rec = irradiation.blave(i['utc_datetime'], self.place, \
                        self.tilt, self.azimuth, cloudCover=i['cloudCover'])
                irradiance = irradiation.irradiation(rec, self.place,\
                        t=self.tilt, array_azimuth=self.azimuth, model='p90')
                t_cell = irradiation.moduleTemp(irradiance, i)
                irr.append(self.p_ac(irradiance, t_cell))
                ts.append(i['utc_datetime'])

            resultset = ResultSet()
            resultset.values = irr
            resultset.timeseries = ts
            return resultset

        if source == 'forecast':
            wseries = forecast.hourly(self.place)
            ts = []
            irr = []
            for i in wseries:
                if i['utc_datetime'] > endTimeUTC:
                    break
                irradiance = irradiation.irradiation(i, self.place,\
                        t=self.tilt, array_azimuth=self.azimuth, model='p90')
                t_cell = irradiation.moduleTemp(irradiance, i)
                irr.append(self.p_ac(irradiance, t_cell))
                ts.append(i['utc_datetime'])

            resultset = ResultSet()
            resultset.values = irr
            resultset.timeseries = ts
            return resultset

        if source == 'blave':
            wseries = forecast.hourly(self.place)
            ts = []
            irr = []
            for i in wseries:
                if i['utc_datetime'] > endTimeUTC:
                    break
                rec = irradiation.blave(i['utc_datetime'], self.place, \
                        self.tilt, self.azimuth, cloudCover=i['cloudCover'])
                irradiance = irradiation.irradiation(rec, self.place,\
                        t=self.tilt, array_azimuth=self.azimuth, model='p90')
                t_cell = irradiation.moduleTemp(irradiance, i)
                irr.append(self.p_ac(irradiance, t_cell))
                ts.append(i['utc_datetime'])

            rs = ResultSet()
            rs.values = irr
            rs.timeseries = ts
            return rs
        else:
            #blave
            stime = datetime.datetime.today().timetuple()
            tz_off = datetime.timedelta(hours=self.tz)
            if daylightSavings:
                tz_off += datetime.timedelta(hours=1)
            else:
                tz_off += datetime.timedelta(hours=0)
            initTime = datetime.datetime(stime[0], stime[1], stime[2]) - tz_off
            timeseries = []
            values = []
            ts = initTime
            while ts < datetime.datetime.now()-tz_off:
                ts += datetime.timedelta(minutes=5)
                currentPower = self.now(ts)
                values.append(currentPower)
                timeseries.append(ts)
            rs = ResultSet()
            rs.values = values
            rs.timeseries = timeseries
            return rs
Beispiel #8
0
def yearly_total_irr(place, az, tr): #, interval=30, ccd=None
    """Function which estimates the total irradiation.
    Input: location (lat, lon),
    az (azimuth in degrees, south is at 180 degrees),
    tr (tilt of the roof in degrees, flat roof is 0),
    #interval (what is the precision of the integration in minutes),
    #cloud cover data (dictionary with floats from 0 to 1, for each day of the year in mmdd format (e.g. '1231');
        get it from your local weather station).
    Returns total yearly irradiation for the tilted and oriented surface in kWh/m^2.
    """

    #-- Old method with KNMI data

    #-- Counter for the yearly irradiation in kWh/m^2
    # yearly_sum = 0

    # #-- Compute for all dates and times
    # for month in range(1, 13):
    #     for day in range(1, 32):
    #         #-- Skip these dates
    #         if (day == 29 or day == 30) and month == 2:
    #             continue
    #         if day == 31 and month in (2, 4, 6, 9, 11):
    #             continue

    #         #-- Daily value reset
    #         daily_rads = 0
    #         #-- Tweaking to get the proper key values for dates
    #         if month < 10:
    #             m_s = '0' + str(month)
    #         else:
    #             m_s = str(month)
    #         if day < 10:
    #             d_s = '0' + str(day)
    #         else:
    #             d_s = str(day)
    #         d = datetime.date(2013, month, day)
    #         #-- These are UTC times. The program is not smart enough to use sunrise and sunset times, but this works too
    #         for hour in range(3, 20):
    #             for minute in range(0, 60, interval):
    #                 #-- Datetime
    #                 t = datetime.time(hour, minute)
    #                 dt = datetime.datetime.combine(d, t)
    #                 #-- Get the historic cloud cover for that day
    #                 if ccd:
    #                     cloud_cover = ccd[str(m_s)+str(d_s)]
    #                 else:
    #                     cloud_cover = 0.0
    #                 #-- Global synthetic irradiation from Solpy
    #                 global_irradiation_rec = irradiation.blave(dt, place, 0, 180, cloud_cover)
    #                 #-- Adjust it for the tilt. The value is now in W/m^2
    #                 irrValue = irradiation.irradiation(global_irradiation_rec, place, None, tr, az, 'p9')

    #                 #-- Integrate the value over the time interval (get Wh/m^2) and convert it to kWh/m^2 and add it to the daily summed value
    #                 daily_rads += (irrValue * (float(interval)/60.0)) / 1000.0

    #         #-- When finished with the day, add the estimated value to the yearly sum
    #         yearly_sum += daily_rads



    #-- EPW Weather data
    STATION_CODE = '062400' # '062400' for Amsterdam
    #-- Fetch the dataset thanks to the caelum library
    records = eere.EPWdata(STATION_CODE)
    #-- Get the global yearly irradiance (Wh/m^2/year)
    TOTAL = sum([irradiation.irradiation(record=rec, location=place, horizon=None, t=tr, array_azimuth=az, model='p9') for rec in records])     
    #-- Divide it by 1000 to get the value in kWh/m^2/year
    yearly_sum = TOTAL/1000.

    #-- Yearly irradiation in kWh/m^2/year
    return yearly_sum
Beispiel #9
0
    def forecast_output(self, daylightSavings=False, source=None, hours=24):
        """forecast output of system"""
        #todo: model and forecast should use consistant units; Wh or KWh
        #default is forecast with solpy.blave
        #this is ugly code... sorry
        #todo: refactor
        d = datetime.date.today()
        endTimeUTC = datetime.datetime(d.year, d.month, d.day)\
                + datetime.timedelta(hours=hours-self.tz)
        if source == 'noaa':
            wseries = noaa.herp_derp_interp(self.place)
            ts = []
            irr = []
            for i in wseries:
                if i['utc_datetime'] > endTimeUTC:
                    break
                rec = irradiation.blave(i['utc_datetime'], self.place, \
                        self.tilt, self.azimuth, cloudCover=i['cloudCover'])
                irradiance = irradiation.irradiation(rec, self.place,\
                        t=self.tilt, array_azimuth=self.azimuth, model='p90')
                t_cell = irradiation.moduleTemp(irradiance, i)
                irr.append(self.p_ac(irradiance, t_cell))
                ts.append(i['utc_datetime'])

            resultset = ResultSet()
            resultset.values = irr
            resultset.timeseries = ts
            return resultset

        if source == 'forecast':
            wseries = forecast.hourly(self.place)
            ts = []
            irr = []
            for i in wseries:
                if i['utc_datetime'] > endTimeUTC:
                    break
                irradiance = irradiation.irradiation(i, self.place,\
                        t=self.tilt, array_azimuth=self.azimuth, model='p90')
                t_cell = irradiation.moduleTemp(irradiance, i)
                irr.append(self.p_ac(irradiance, t_cell))
                ts.append(i['utc_datetime'])

            resultset = ResultSet()
            resultset.values = irr
            resultset.timeseries = ts
            return resultset

        if source == 'blave':
            wseries = forecast.hourly(self.place)
            ts = []
            irr = []
            for i in wseries:
                if i['utc_datetime'] > endTimeUTC:
                    break
                rec = irradiation.blave(i['utc_datetime'], self.place, \
                        self.tilt, self.azimuth, cloudCover=i['cloudCover'])
                irradiance = irradiation.irradiation(rec, self.place,\
                        t=self.tilt, array_azimuth=self.azimuth, model='p90')
                t_cell = irradiation.moduleTemp(irradiance, i)
                irr.append(self.p_ac(irradiance, t_cell))
                ts.append(i['utc_datetime'])

            rs = ResultSet()
            rs.values = irr
            rs.timeseries = ts
            return rs
        else:
            #blave
            stime = datetime.datetime.today().timetuple()
            tz_off = datetime.timedelta(hours=self.tz)
            if daylightSavings:
                tz_off += datetime.timedelta(hours=1)
            else:
                tz_off += datetime.timedelta(hours=0)
            initTime = datetime.datetime(stime[0], stime[1], stime[2]) - tz_off
            timeseries = []
            values = []
            ts = initTime
            while ts < datetime.datetime.now() - tz_off:
                ts += datetime.timedelta(minutes=5)
                currentPower = self.now(ts)
                values.append(currentPower)
                timeseries.append(ts)
            rs = ResultSet()
            rs.values = values
            rs.timeseries = timeseries
            return rs
Beispiel #10
0
            # if ccddatabase:
            #     cloud_cover = ccddatabase[str(m_s)+str(d_s)]
            # else:
            #     cloud_cover = 0.0

            for setting in settings:
                if setting['Name'] not in res:
                    res[setting['Name']] = {}
                e = str(m_s)+str(d_s)
                if e not in res[setting['Name']]:
                    res[setting['Name']][e] = []

                #-- Global synthetic irradiation from Solpy
                global_irradiation_rec = irradiation.blave(dt, place, 0, 180)
                #-- Adjust it for the tilt. The value is now in W/m^2
                irrValue = irradiation.irradiation(global_irradiation_rec, place, None, setting['Tilt'], setting['Azimuth'], 'p9')
                horr_irrValue = irradiation.irradiation(global_irradiation_rec, place, None, 0, 180, 'p9')
                #-- Workaround to keep the data aligned
                d_ = datetime.date(2013, 1, 1)
                t_ = datetime.time(hour, minute)
                dt_ = datetime.datetime.combine(d_, t_)
                res[setting['Name']][e].append([dt_, irrValue, horr_irrValue])

import scipy
import matplotlib as mpl
import matplotlib.pyplot as plt
# plt.rc('text', usetex=True)
# plt.rc('font', family='serif')


fig = plt.figure(1)