Exemple #1
0
def tidalSuite(model, observed, step, start, type, plot=False,
               save_csv=False, debug=False, debug_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.
    '''
    if debug: print "tidalSuite..."
    stats = TidalStats(model, observed, step, start, type=type,
                       debug=debug, debug_plot=debug_plot)
    stats_suite = stats.getStats()
    stats_suite['r_squared'] = stats.linReg()['r_2']
    stats_suite['phase'] = stats.getPhase()

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

    if save_csv:
        stats.save_data()

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

    return stats_suite
Exemple #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']

    # 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
Exemple #3
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
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
Exemple #5
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
Exemple #6
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