Beispiel #1
0
def compareTG(data):
    '''
    Does a comprehensive comparison between tide gauge height data and
    modeled data, much like the above function.

    Input is a dictionary containing all necessary tide gauge and model data.
    Outputs a dictionary of useful statistics.
    '''
    # load data
    mod_elev = data['mod_timeseries']['elev']
    obs_elev = data['obs_timeseries']['elev']
    obs_datenums = data['obs_time']
    mod_datenums = data['mod_time']
    mod_harm = data['elev_mod_harmonics']

    # convert times and grab values
    obs_time, mod_time = [], []
    for i, v in enumerate(obs_datenums):
        obs_time.append(dn2dt(v))
    for j, w in enumerate(mod_datenums):
        mod_time.append(dn2dt(w))

    # check if they line up in the time domain
    if (mod_time[-1] < obs_time[0] or obs_time[-1] < mod_time[0]):

        # use ut_reconstr to create a new timeseries
        mod_elev_int = ut_reconstr(obs_datenums, mod_harm)[0]
        obs_elev_int = obs_elev
        step_int = obs_time[1] - obs_time[0]
        start_int = obs_time[0]

    else:

        # interpolate timeseries onto a common timestep
        (obs_elev_int, mod_elev_int, step_int, start_int) = \
            smooth(mod_elev, mod_time, obs_elev, obs_time)

    # get validation statistics
    stats = TidalStats(mod_elev_int,
                       obs_elev_int,
                       step_int,
                       start_int,
                       debug=True,
                       type='height')
    elev_suite = stats.getStats()
    elev_suite['r_squared'] = stats.linReg()['r_2']
    elev_suite['phase'] = stats.getPhase(debug=False)

    return elev_suite
Beispiel #2
0
def compareTG(data):
    '''
    Does a comprehensive comparison between tide gauge height data and
    modeled data, much like the above function.

    Input is a dictionary containing all necessary tide gauge and model data.
    Outputs a dictionary of useful statistics.
    '''
    # load data
    mod_elev = data['mod_timeseries']['elev']
    obs_elev = data['obs_timeseries']['elev']
    obs_datenums = data['obs_time']
    mod_datenums = data['mod_time']
    mod_harm = data['elev_mod_harmonics']
    print data['name']

    # convert times and grab values
    obs_time, mod_time = [], []
    for i, v in enumerate(obs_datenums):
	obs_time.append(dn2dt(v))
    for j, w in enumerate(mod_datenums):
	mod_time.append(dn2dt(w))

    # check if they line up in the time domain
    if (mod_time[-1] < obs_time[0] or obs_time[-1] < mod_time[0]):

	# use ut_reconstr to create a new timeseries
	mod_elev_int = ut_reconstr(obs_datenums, mod_harm)[0]
	obs_elev_int = obs_elev
	step_int = obs_time[1] - obs_time[0]
	start_int = obs_time[0]

    else:

        # interpolate timeseries onto a common timestep
        (obs_elev_int, mod_elev_int, step_int, start_int) = \
            smooth(mod_elev, mod_time, obs_elev, obs_time)

    # get validation statistics
    stats = TidalStats(mod_elev_int, obs_elev_int, step_int, start_int,
		       debug=True, type='height')
    elev_suite = stats.getStats()
    elev_suite['r_squared'] = stats.linReg()['r_2']
    elev_suite['phase'] = stats.getPhase(debug=False)

    return elev_suite
Beispiel #3
0
def compareTG(data, plot=False, save_csv=False, debug=False, debug_plot=False):
    '''
    Does a comprehensive comparison between tide gauge height data and
    modeled data, much like the above function.

    Input is a dictionary containing all necessary tide gauge and model data.
    Outputs a dictionary of useful statistics.
    '''
    if debug: print "CompareTG..."
    # load data
    mod_elev = data['mod_timeseries']['elev']
    obs_elev = data['obs_timeseries']['elev']
    obs_datenums = data['obs_time']
    mod_datenums = data['mod_time']
    #TR: comment out
    #mod_harm = data['elev_mod_harmonics']

    # convert times and grab values
    obs_time, mod_time = [], []
    for i, v in enumerate(obs_datenums):
        obs_time.append(dn2dt(v))
    for j, w in enumerate(mod_datenums):
        mod_time.append(dn2dt(w))

    if debug: print "...check if they line up in the time domain..."
    if (mod_time[-1] < obs_time[0] or obs_time[-1] < mod_time[0]):
        print "---time periods do not match up---"
        sys.exit()

    else:

        if debug: print "...interpolate timeseries onto a common timestep..."
        (mod_elev_int, obs_elev_int, step_int, start_int) = \
            smooth(mod_elev, mod_time, obs_elev, obs_time,
                   debug=debug, debug_plot=debug_plot)

    if debug: print "...get validation statistics..."
    stats = TidalStats(mod_elev_int,
                       obs_elev_int,
                       step_int,
                       start_int,
                       type='elevation',
                       debug=debug,
                       debug_plot=debug_plot)

    elev_suite = tidalSuite(mod_elev_int,
                            obs_elev_int,
                            step_int,
                            start_int,
                            type='elevation',
                            plot=plot,
                            save_csv=save_csv,
                            debug=debug,
                            debug_plot=debug_plot)

    if debug: print "...CompareTG done."

    return elev_suite
Beispiel #4
0
def tidalSuite(model, observed, step, start, type, plot=False):
    '''
    Create stats classes for a given tidal variable.

    Accepts interpolated model and observed data, the timestep, and start
    time. Type is a string representing the type of data. If plot is set
    to true, a time plot and regression plot will be produced.
    
    Returns a dictionary containing all the stats.
    '''
    stats = TidalStats(model, observed, step, start, type=type)
    stats_suite = stats.getStats()
    stats_suite['r_squared'] = stats.linReg()['r_2']
    stats_suite['phase'] = stats.getPhase()

    if plot:
        stats.plotData()
        stats.plotRegression(stats.linReg())

    return stats_suite
Beispiel #5
0
def tidalSuite(gear, model, observed, step, start,
               model_u, observed_u, model_v, observed_v,
               model_time, observed_time,
               kind='', plot=False, save_csv=False, save_path='./',
               debug=False, debug_plot=False):
    """
    Create stats classes for a given tidal variable.

    Accepts interpolated model and observed data, the timestep, and start
    time. kind is a string representing the kind of data. If plot is set
    to true, a time plot and regression plot will be produced.

    Returns a dictionary containing all the stats.
    """
    if debug: print "tidalSuite..."
    stats = TidalStats(gear, model, observed, step, start,
                       model_u = model_u, observed_u = observed_u, model_v = model_v, observed_v = observed_v,
                       model_time = model_time, observed_time = observed_time,
                       kind=kind, debug=debug, debug_plot=debug_plot)
    stats_suite = stats.getStats()
    stats_suite['r_squared'] = stats.linReg()['r_2']
    # calling special methods
    if kind == 'direction':
        rmse, nrmse = stats.statsForDirection(debug=debug)
        stats_suite['RMSE'] = rmse
        stats_suite['NRMSE'] = nrmse
    try: #Fix for Drifter's data
        stats_suite['phase'] = stats.getPhase(debug=debug)
    except:
        stats_suite['phase'] = 0.0

    if plot or debug_plot:
        plotData(stats)
        plotRegression(stats, stats.linReg())

    if save_csv:
        stats.save_data(path=save_path)
        plotData(stats, savepath=save_path, fname=kind+"_"+gear+"_time_series.png")
        plotRegression(stats, stats.linReg(), savepath=save_path, fname=kind+"_"+gear+"_linear_regression.png")

    if debug: print "...tidalSuite done."

    return stats_suite
Beispiel #6
0
def tidalSuite(model, observed, step, start, type, 
		  plot=False):
    '''
    Create stats classes for a given tidal variable.

    Accepts interpolated model and observed data, the timestep, and start
    time. Type is a string representing the type of data. If plot is set
    to true, a time plot and regression plot will be produced.
    
    Returns a dictionary containing all the stats.
    '''
    stats = TidalStats(model, observed, step, start, type=type)
    stats_suite = stats.getStats()
    stats_suite['r_squared'] = stats.linReg()['r_2']
    stats_suite['phase'] = stats.getPhase()

    if plot:
	stats.plotData()
	stats.plotRegression(stats.linReg())

    return stats_suite
Beispiel #7
0
import numpy as np
from tidalStats import TidalStats
from datetime import datetime, timedelta

# test of the tidalStats class with known data

n = 100
data_1, data_2 = np.zeros(n), np.zeros(n)
for i in np.arange(n):
    data_1[i] = i**2
    data_2[i] = i ** 3

start = datetime(1994, 04, 20)
step = timedelta(minutes=10)

stats = TidalStats(data_1, data_2, step, start)

print stats.getStats()
stats.plotRegression(stats.linReg())
Beispiel #8
0
'''
Test of loading in previously saved pickle data, and running it through
interpolation and smoothing functions.
'''

# grab the data
filename_1 = '/array/home/116822s/tidal_data/stats_test/ADCP_data1.pkl'
ADCP_f = open(filename_1, 'rb')
filename_2 = '/array/home/116822s/tidal_data/stats_test/FVCOM_data1.pkl'
FVC_f = open(filename_2, 'rb')
filename_3 = '/array/home/116822s/tidal_data/stats_test/hindcast_1.pkl'
hind_f = open(filename_3, 'rb')

ADCP = pickle.load(ADCP_f)
FVCOM = pickle.load(FVC_f)
hind = pickle.load(hind_f)

# plot the data
#plt.scatter(ADCP[0]['pts'], FVCOM[0]['pts'], c='b')
#plt.show()

# first test
(ADCP_i, FVCOM_i, step, start) = interpolate.interpol(ADCP[0], hind[0], timedelta(minutes=20))

speed_stats = TidalStats(ADCP_i, FVCOM_i, step, start)
#lr = speed_stats.linReg()
#speed_stats.plotRegression(lr)

#speed_stats.plotData(graph='scatter')
speed_stats.plotData()
Beispiel #9
0
def tidalSuite(gear,
               model,
               observed,
               step,
               start,
               model_u,
               observed_u,
               model_v,
               observed_v,
               model_time,
               observed_time,
               kind='',
               plot=False,
               save_csv=False,
               save_path='./',
               debug=False,
               debug_plot=False):
    """
    Create stats classes for a given tidal variable.

    Accepts interpolated model and observed data, the timestep, and start
    time. kind is a string representing the kind of data. If plot is set
    to true, a time plot and regression plot will be produced.

    Returns a dictionary containing all the stats.
    """
    if debug: print "tidalSuite..."
    stats = TidalStats(gear,
                       model,
                       observed,
                       step,
                       start,
                       model_u=model_u,
                       observed_u=observed_u,
                       model_v=model_v,
                       observed_v=observed_v,
                       model_time=model_time,
                       observed_time=observed_time,
                       kind=kind,
                       debug=debug,
                       debug_plot=debug_plot)
    stats_suite = stats.getStats()
    stats_suite['r_squared'] = stats.linReg()['r_2']
    # calling special methods
    if kind == 'direction':
        rmse, nrmse = stats.statsForDirection(debug=debug)
        stats_suite['RMSE'] = rmse
        stats_suite['NRMSE'] = nrmse
    try:  #Fix for Drifter's data
        stats_suite['phase'] = stats.getPhase(debug=debug)
    except:
        stats_suite['phase'] = 0.0

    if plot or debug_plot:
        plotData(stats)
        plotRegression(stats, stats.linReg())

    if save_csv:
        stats.save_data(path=save_path)
        plotData(stats,
                 savepath=save_path,
                 fname=kind + "_" + gear + "_time_series.png")
        plotRegression(stats,
                       stats.linReg(),
                       savepath=save_path,
                       fname=kind + "_" + gear + "_linear_regression.png")

    if debug: print "...tidalSuite done."

    return stats_suite