Esempio n. 1
0
def save_hourly_timeseries(months_years=[(12, 2015), (1, 2016)],
                           new_data_avail=True):
    """ This function saves the hourly time series of outdoor temperature, wind speed,
        humidity and solar radiation from the Steno weather station. Possibly 
        spanning several months. The timesteps are also saved.
        
        """

    dat_arrays_list = []
    for mnyr in months_years:
        month = mnyr[0]
        year = mnyr[1]
        if new_data_avail:
            create_timestamp_weather(month, year)
        data = load_timestamp_weather(month, year)
        local_ts = get_local_timesteps(data)
        TvWhsR_data = create_Tout_vWind_hum_sunRad_array(data)
        dat_arrays_list.append(agg_data_hourly(TvWhsR_data, local_ts))

    timestep_array = np.concatenate([d[1] for d in dat_arrays_list])
    full_timeseries_array = np.concatenate([d[0] for d in dat_arrays_list])
    filename = 'Steno_hourly_' + timestamp_str(
        timestep_array[0]) + '_to_' + timestamp_str(timestep_array[-1])
    np.savez(datapath + filename,
             timesteps=timestep_array,
             Tout_vWind_hum_sunRad=full_timeseries_array)

    return
Esempio n. 2
0
def most_recent_ens_timeseries(start_stop=(dt.datetime(2015,12,16,0), dt.datetime(2016,1,19,0)), pointcode=71699, shift_steno_one=False):
    """ star_stop can be a tupple with 2 date tim objects. The first
        is the first time step in the time series, the second is the last.
        
        """
    plt.close('all')    
    ylabels = ['[$\degree $C]', '[m/s]', '[%]', '[W/m$^2$]']  
    
    suffix = ''.join(['_geo', str(pointcode), '_', ens.timestamp_str(start_stop[0]), \
                        '_to_', ens.timestamp_str(start_stop[1]), '.npy'])
    timesteps = ens.gen_hourly_timesteps(start_stop[0], start_stop[1])
    
    Steno_data = np.load('Q:/Weatherdata/Steno_weatherstation/Steno_hourly_2015120111_to_2016011800.npz')
    Steno_Tvhs = Steno_data['Tout_vWind_hum_sunRad']
    Steno_timesteps = Steno_data['timesteps']
        
    for v, ylab in zip(weathervars, ylabels):
        plt.figure(figsize=(15,20))
        plt.grid(True)
        plt.subplot(2,1,1)        
        ens_data = np.load('time_series/' + v + suffix)
        BBSYD_measured = sq.fetch_BrabrandSydWeather(v, start_stop[0], start_stop[1])
        Steno_measured = Steno_Tvhs[:,weathervars.index(v)]
        if shift_steno_one:
            Steno_measured = np.roll(Steno_measured, -1)
        
        if v =='Tout':
            ens_data = ens.Kelvin_to_Celcius(ens_data)
        elif v=='hum':
            ens_data = ens.frac_to_percent(ens_data) # convert to percentage                
        
        
        plt.plot_date(timesteps, ens_data, '-')
        
        plt.plot_date(timesteps, BBSYD_measured, 'k-', lw=2, label='Measured: Brabrand Syd')
        plt.plot_date(Steno_timesteps, Steno_measured, 'r-', lw=2, label='Measured: Steno Museum')
        plt.ylabel(ylab)
        plt.grid(True)
        plt.xlim(start_stop)
        plt.title(v)
        plt.legend()
        
        plt.subplot(2,1,2)
        plt.plot_date(timesteps, ens.ensemble_std(ens_data), '-', label='Ensemble std')        
        plt.plot_date(timesteps, ens.ensemble_abs_spread(ens_data), '-', label='Max ensemble spread')
        plt.ylabel(ylab)
        plt.legend()
        plt.grid(True)
        plt.tight_layout()
        
        figfilename = v + '_most_recent_ens_timeseries.pdf'
        plt.savefig('figures/' + figfilename)
Esempio n. 3
0
def fetch_consumption(Forbrugssted_Key, from_time, to_time):
    conn = connect()
    sql_query = """ USE [DM_VT]
                    SELECT
                      [Tid_Key]
                      ,[ForbrugMWh]
                      FROM [DM_VT].[dbo].[vForbrug_Doegn]
                      WHERE Forbrugssted_Key = %i AND Tid_Key BETWEEN '%s' AND  '%s'
                      ORDER BY Tid_Key""" % (Forbrugssted_Key, ens.timestamp_str(from_time), ens.timestamp_str(to_time))
    data = extractdata(conn, sql_query)                 
    timestamps, consumption = zip(*data)
    assert(list(timestamps)==[int(ens.timestamp_str(ts)) for ts in ens.gen_hourly_timesteps(from_time, to_time)]), "Timesteps are not hour by hour"
    cons_array = np.array(consumption, dtype=float) 

    return cons_array
Esempio n. 4
0
def fetch_price(from_time, to_time, price_name='Timenspris'):
    """ Price_name should be either "Timenspris", "VariabelTimenspris"
        or "TimensprisMovingAVG".
        
        """
        
    conn = connect()
    sql_query = """ USE [DM_VT]
                    SELECT [Tid_Key]
                          ,[%s]
                      FROM [dbo].[vFact_Timepris_Doegn]
                      WHERE Tid_Key BETWEEN '%s' AND  '%s'
                      ORDER BY Tid_Key""" % (price_name, ens.timestamp_str(from_time), ens.timestamp_str(to_time))
                      
    data = extractdata(conn, sql_query)
    timestamps, price = zip(*data)
    assert(list(timestamps)==[int(ens.timestamp_str(ts)) for ts in ens.gen_hourly_timesteps(from_time, to_time)]), "Timesteps are not hour by hour"
    
    return np.array(price, dtype=float)
Esempio n. 5
0
def fetch_production(from_time, to_time):
    conn = connect()
    sql_query = """ USE [DM_VT]
                    SELECT [Tid_Key]
                          ,[SamletProduktionMWh]
                      FROM [dbo].[vFact_Timepris_Doegn]
                      WHERE Tid_Key BETWEEN '%s' AND  '%s'
                      ORDER BY Tid_Key""" % (ens.timestamp_str(from_time), ens.timestamp_str(to_time))
                      
    data = extractdata(conn, sql_query)
    timestamps, production = zip(*data)
    assert(list(timestamps)==[int(ens.timestamp_str(ts)) for ts in ens.gen_hourly_timesteps(from_time, to_time)]), "Timesteps are not hour by hour"
    prod_array = np.array(production, dtype=float)    
    for ts in (2016032702, 2016032703):
        if ts in timestamps:
            print "Correcting error in production by transition to daylight savings on timestamp %s"%ts
            index = timestamps.index(ts)
            prod_array[index] = 2*prod_array[index]
    
    return prod_array
def save_hourly_timeseries(months_years = [(12,2015), (1,2016)], new_data_avail=True):
    """ This function saves the hourly time series of outdoor temperature, wind speed,
        humidity and solar radiation from the Steno weather station. Possibly 
        spanning several months. The timesteps are also saved.
        
        """
        
    dat_arrays_list = []     
    for mnyr in months_years:
        month = mnyr[0]
        year = mnyr[1]
        if new_data_avail:
            create_timestamp_weather(month, year)
        data = load_timestamp_weather(month, year)
        local_ts = get_local_timesteps(data)
        TvWhsR_data = create_Tout_vWind_hum_sunRad_array(data)
        dat_arrays_list.append(agg_data_hourly(TvWhsR_data, local_ts))
        
    timestep_array = np.concatenate([d[1] for d in dat_arrays_list])
    full_timeseries_array = np.concatenate([d[0] for d in dat_arrays_list])
    filename = 'Steno_hourly_' + timestamp_str(timestep_array[0]) + '_to_' + timestamp_str(timestep_array[-1])
    np.savez(datapath+filename, timesteps=timestep_array, Tout_vWind_hum_sunRad=full_timeseries_array)    
    
    return                   
Esempio n. 7
0
def most_recent_ens_timeseries(start_stop=(dt.datetime(2015, 12, 16, 0),
                                           dt.datetime(2016, 1, 19, 0)),
                               pointcode=71699,
                               shift_steno_one=False):
    """ star_stop can be a tupple with 2 date tim objects. The first
        is the first time step in the time series, the second is the last.
        
        """
    plt.close('all')
    ylabels = ['[$\degree $C]', '[m/s]', '[%]', '[W/m$^2$]']

    suffix = ''.join(['_geo', str(pointcode), '_', ens.timestamp_str(start_stop[0]), \
                        '_to_', ens.timestamp_str(start_stop[1]), '.npy'])
    timesteps = ens.gen_hourly_timesteps(start_stop[0], start_stop[1])

    Steno_data = np.load(
        'Q:/Weatherdata/Steno_weatherstation/Steno_hourly_2015120111_to_2016011800.npz'
    )
    Steno_Tvhs = Steno_data['Tout_vWind_hum_sunRad']
    Steno_timesteps = Steno_data['timesteps']

    for v, ylab in zip(weathervars, ylabels):
        plt.figure(figsize=(15, 20))
        plt.grid(True)
        plt.subplot(2, 1, 1)
        ens_data = np.load('time_series/' + v + suffix)
        BBSYD_measured = sq.fetch_BrabrandSydWeather(v, start_stop[0],
                                                     start_stop[1])
        Steno_measured = Steno_Tvhs[:, weathervars.index(v)]
        if shift_steno_one:
            Steno_measured = np.roll(Steno_measured, -1)

        if v == 'Tout':
            ens_data = ens.Kelvin_to_Celcius(ens_data)
        elif v == 'hum':
            ens_data = ens.frac_to_percent(ens_data)  # convert to percentage

        plt.plot_date(timesteps, ens_data, '-')

        plt.plot_date(timesteps,
                      BBSYD_measured,
                      'k-',
                      lw=2,
                      label='Measured: Brabrand Syd')
        plt.plot_date(Steno_timesteps,
                      Steno_measured,
                      'r-',
                      lw=2,
                      label='Measured: Steno Museum')
        plt.ylabel(ylab)
        plt.grid(True)
        plt.xlim(start_stop)
        plt.title(v)
        plt.legend()

        plt.subplot(2, 1, 2)
        plt.plot_date(timesteps,
                      ens.ensemble_std(ens_data),
                      '-',
                      label='Ensemble std')
        plt.plot_date(timesteps,
                      ens.ensemble_abs_spread(ens_data),
                      '-',
                      label='Max ensemble spread')
        plt.ylabel(ylab)
        plt.legend()
        plt.grid(True)
        plt.tight_layout()

        figfilename = v + '_most_recent_ens_timeseries.pdf'
        plt.savefig('figures/' + figfilename)