Esempio n. 1
0
def compareUV(data, threeDim, depth=5, plot=False):
    '''
    Does a comprehensive validation process between modeled and observed
    data on the following:
        Current speed
        Current direction
        Harmonic constituents (for height and speed)

    Outputs a list of important statistics for each variable, calculated
    using the TidalStats class
    '''
    # take data from input dictionary
    mod_time = data['mod_time']
    obs_time = data['obs_time']
    mod_el = data['mod_timeseries']['elev']
    obs_el = data['obs_timeseries']['elev']
    v_mod_harm = data['vel_mod_harmonics']
    v_obs_harm = data['vel_obs_harmonics']
    el_mod_harm = data['elev_mod_harmonics']
    el_obs_harm = data['elev_mod_harmonics']

    #Check if 3D simulation
    if threeDim:
        obs_u_all = data['obs_timeseries']['u']
        obs_v_all = data['obs_timeseries']['v']
        mod_u_all = data['mod_timeseries']['u']
        mod_v_all = data['mod_timeseries']['v']
        bins = data['obs_timeseries']['bins']
        siglay = data['mod_timeseries']['siglay']
        # use depth interpolation to get a single timeseries
        mod_depth = mod_el + np.mean(obs_el)
        (mod_u, obs_u) = depthFromSurf(mod_u_all,
                                       mod_depth,
                                       siglay,
                                       obs_u_all,
                                       obs_el,
                                       bins,
                                       depth=depth)
        (mod_v, obs_v) = depthFromSurf(mod_v_all,
                                       mod_depth,
                                       siglay,
                                       obs_v_all,
                                       obs_el,
                                       bins,
                                       depth=depth)
    else:
        obs_u = data['obs_timeseries']['ua']
        obs_v = data['obs_timeseries']['va']
        mod_u = data['mod_timeseries']['ua']
        mod_v = data['mod_timeseries']['va']

    # convert times to datetime
    mod_dt, obs_dt = [], []
    for i in mod_time:
        mod_dt.append(dn2dt(i))
    for j in obs_time:
        obs_dt.append(dn2dt(j))

    # put data into a useful format
    mod_spd = np.sqrt(mod_u**2 + mod_v**2)
    obs_spd = np.sqrt(obs_u**2 + obs_v**2)
    mod_dir = np.arctan2(mod_v, mod_u) * 180 / np.pi
    obs_dir = np.arctan2(obs_v, obs_u) * 180 / np.pi
    obs_el = obs_el - np.mean(obs_el)

    # check if the modeled data lines up with the observed data
    if (mod_time[-1] < obs_time[0] or obs_time[-1] < mod_time[0]):

        pred_uv = ut_reconstr(obs_time, v_mod_harm)
        pred_uv = np.asarray(pred_uv)
        pred_h = ut_reconstr(obs_time, el_mod_harm)
        pred_h = np.asarray(pred_h)

        # redo speed and direction and set interpolated variables
        mod_sp_int = np.sqrt(pred_uv[0]**2 + pred_uv[1]**2)
        mod_ve_int = mod_sp_int * np.sign(pred_uv[1])
        mod_dr_int = np.arctan2(pred_uv[1], pred_uv[0]) * 180 / np.pi
        mod_el_int = pred_h[0]
        mod_u_int = pred_uv[0]
        mod_v_int = pred_uv[1]
        obs_sp_int = obs_spd
        obs_ve_int = obs_spd * np.sign(obs_v)
        obs_dr_int = obs_dir
        obs_el_int = obs_el
        obs_u_int = obs_u
        obs_v_int = obs_v
        step_int = obs_dt[1] - obs_dt[0]
        start_int = obs_dt[0]

    else:
        # interpolate the data onto a common time step for each data type
        # elevation
        (mod_el_int, obs_el_int, step_int, start_int) = \
     smooth(mod_el, mod_dt, obs_el, obs_dt)

        # speed
        (mod_sp_int, obs_sp_int, step_int, start_int) = \
            smooth(mod_spd, mod_dt, obs_spd, obs_dt)

        # direction
        (mod_dr_int, obs_dr_int, step_int, start_int) = \
            smooth(mod_dir, mod_dt, obs_dir, obs_dt)

        # u velocity
        (mod_u_int, obs_u_int, step_int, start_int) = \
            smooth(mod_u, mod_dt, obs_u, obs_dt)

        # v velocity
        (mod_v_int, obs_v_int, step_int, start_int) = \
            smooth(mod_v, mod_dt, obs_v, obs_dt)

        # velocity i.e. signed speed
        (mod_ve_int, obs_ve_int, step_int, start_int) = \
            smooth(mod_spd * np.sign(mod_v), mod_dt,
            obs_spd * np.sign(obs_v), obs_dt)
    '''
    # separate into ebb and flow
    mod_dir_n = get_DirFromN(mod_u_int, mod_v_int)
    obs_dir_n = get_DirFromN(obs_u_int, mod_v_int)
    mod_signed_s, mod_PA = sign_speed(mod_u_int, mod_v_int, mod_sp_int,
				      mod_dr_int, 0)
    obs_signed_s, obs_PA = sign_speed(obs_u_int, obs_v_int, obs_sp_int,
				      obs_dr_int, 0)
    print mod_signed_s[:20], mod_PA[:20]
    print obs_signed_s[:20], obs_PA[:20]
    '''

    # remove directions where velocities are small
    MIN_VEL = 0.5
    for i in np.arange(obs_sp_int.size):
        if (obs_sp_int[i] < MIN_VEL):
            obs_dr_int[i] = np.nan
        if (mod_sp_int[i] < MIN_VEL):
            mod_dr_int[i] = np.nan

    # get stats for each tidal variable
    elev_suite = tidalSuite(mod_el_int,
                            obs_el_int,
                            step_int,
                            start_int,
                            type='elevation',
                            plot=plot)
    speed_suite = tidalSuite(mod_sp_int,
                             obs_sp_int,
                             step_int,
                             start_int,
                             type='speed',
                             plot=plot)
    dir_suite = tidalSuite(mod_dr_int,
                           obs_dr_int,
                           step_int,
                           start_int,
                           type='direction',
                           plot=plot)
    u_suite = tidalSuite(mod_u_int,
                         obs_u_int,
                         step_int,
                         start_int,
                         type='u velocity',
                         plot=plot)
    v_suite = tidalSuite(mod_v_int,
                         obs_v_int,
                         step_int,
                         start_int,
                         type='v velocity',
                         plot=plot)
    vel_suite = tidalSuite(mod_ve_int,
                           obs_ve_int,
                           step_int,
                           start_int,
                           type='velocity',
                           plot=plot)
    #ebb_suite = tidalSuite(mod_ebb, obs_ebb, step_int, start_int,
    #		    type='ebb', plot=True)
    #flo_suite = tidalSuite(mod_flo, obs_flo, step_int, start_int,
    #		    type='flow', plot=True)
    # output statistics in useful format
    return (elev_suite, speed_suite, dir_suite, u_suite, v_suite, vel_suite)
Esempio n. 2
0
def compareUV(data, threeDim, depth=5, plot=False, save_csv=False,
              debug=False, debug_plot=False):
    '''
    Does a comprehensive validation process between modeled and observed
    data on the following:
        Current speed
        Current direction
        Harmonic constituents (for height and speed)

    Outputs a list of important statistics for each variable, calculated
    using the TidalStats class
    '''
    if debug: print "CompareUV..."
    # take data from input dictionary
    mod_time = data['mod_time']
    obs_time = data['obs_time']
    mod_el = data['mod_timeseries']['elev']
    obs_el = data['obs_timeseries']['elev']

    # Check if 3D simulation
    if threeDim:
        obs_u_all = data['obs_timeseries']['u']
        obs_v_all = data['obs_timeseries']['v']
        mod_u_all = data['mod_timeseries']['u']
        mod_v_all = data['mod_timeseries']['v']
        bins = data['obs_timeseries']['bins']
        siglay = data['mod_timeseries']['siglay']
        # use depth interpolation to get a single timeseries
        mod_depth = mod_el + np.mean(obs_el[~np.isnan(obs_el)])
        (mod_u, obs_u) = depthFromSurf(mod_u_all, mod_depth, siglay,
                                       obs_u_all, obs_el, bins, depth=depth,
                                       debug=debug, debug_plot=debug_plot)
        (mod_v, obs_v) = depthFromSurf(mod_v_all, mod_depth, siglay,
                                       obs_v_all, obs_el, bins, depth=depth,
                                       debug=debug, debug_plot=debug_plot)
    else:
        obs_u = data['obs_timeseries']['ua']
        obs_v = data['obs_timeseries']['va']
        mod_u = data['mod_timeseries']['ua']
        mod_v = data['mod_timeseries']['va']


    if debug: print "...convert times to datetime..."
    mod_dt, obs_dt = [], []
    for i in mod_time:
        mod_dt.append(dn2dt(i))
    for j in obs_time:
        obs_dt.append(dn2dt(j))

    if debug: print "...put data into a useful format..."
    mod_spd = np.sqrt(mod_u**2.0 + mod_v**2.0)
    obs_spd = np.sqrt(obs_u**2.0 + obs_v**2.0)
    mod_dir = np.arctan2(mod_v, mod_u) * 180.0 / np.pi
    obs_dir = np.arctan2(obs_v, obs_u) * 180.0 / np.pi
    obs_el = obs_el - np.mean(obs_el[~np.isnan(obs_el)])
    mod_pow = 0.5 * rho**3 * mod_spd**3
    obs_pow = 0.5 * rho**3 * obs_spd**3

    if debug: print "...check if the modeled data lines up with the observed data..."
    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 the data onto a common time step for each data type..."
        # elevation
        (mod_el_int, obs_el_int, step_el_int, start_el_int) = \
            smooth(mod_el, mod_dt, obs_el, obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # speed
        (mod_sp_int, obs_sp_int, step_sp_int, start_sp_int) = \
            smooth(mod_spd, mod_dt, obs_spd, obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # direction
        (mod_dr_int, obs_dr_int, step_dr_int, start_dr_int) = \
            smooth(mod_dir, mod_dt, obs_dir, obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # u velocity
        (mod_u_int, obs_u_int, step_u_int, start_u_int) = \
            smooth(mod_u, mod_dt, obs_u, obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # v velocity
        (mod_v_int, obs_v_int, step_v_int, start_v_int) = \
            smooth(mod_v, mod_dt, obs_v, obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # velocity i.e. signed speed
        (mod_ve_int, obs_ve_int, step_ve_int, start_ve_int) = \
            smooth(mod_spd * np.sign(mod_v), mod_dt,
                   obs_spd * np.sign(obs_v), obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # power (or power density? not sure)
        (mod_pw_int, obs_pw_int, step_pw_int, start_pw_int) = \
            smooth(mod_pow, mod_dt, obs_pow, obs_dt,
                   debug=debug, debug_plot=debug_plot)

    if debug: print "...remove directions where velocities are small..."
    MIN_VEL = 0.1
    for i in np.arange(obs_sp_int.size):
        if (obs_sp_int[i] < MIN_VEL):
            obs_dr_int[i] = np.nan
        if (mod_sp_int[i] < MIN_VEL):
            mod_dr_int[i] = np.nan

    if debug: print "...get stats for each tidal variable..."
    elev_suite = tidalSuite(mod_el_int, obs_el_int, step_el_int, start_el_int,
                            type='elevation', plot=plot, save_csv=save_csv,
                            debug=debug, debug_plot=debug_plot)
    speed_suite = tidalSuite(mod_sp_int, obs_sp_int, step_sp_int, start_sp_int,
                             type='speed', plot=plot, save_csv=save_csv,
                             debug=debug, debug_plot=debug_plot)
    dir_suite = tidalSuite(mod_dr_int, obs_dr_int, step_dr_int, start_dr_int,
                           type='direction', plot=plot, save_csv=save_csv,
                           debug=debug, debug_plot=debug_plot)
    u_suite = tidalSuite(mod_u_int, obs_u_int, step_u_int, start_u_int,
                         type='u velocity', plot=plot, save_csv=save_csv,
                         debug=debug, debug_plot=debug_plot)
    v_suite = tidalSuite(mod_v_int, obs_v_int, step_v_int, start_v_int,
                         type='v velocity', plot=plot, save_csv=save_csv,
                         debug=debug, debug_plot=debug_plot)
    vel_suite = tidalSuite(mod_ve_int, obs_ve_int, step_ve_int, start_ve_int,
                           type='velocity', plot=plot, save_csv=save_csv,
                           debug=debug, debug_plot=debug_plot)
    pow_suite = tidalSuite(mod_pw_int, obs_pw_int, step_pw_int, start_pw_int,
                           type='power', plot=plot, save_csv=save_csv,
                           debug=debug, debug_plot=debug_plot)
    # output statistics in useful format

    if debug: print "...CompareUV done."

    return (elev_suite, speed_suite, dir_suite, u_suite, v_suite, vel_suite, pow_suite)
Esempio n. 3
0
def compareUV(data, threeDim, depth=5, plot=False, save_csv=False,
              debug=False, debug_plot=False):
    """
    Does a comprehensive validation process between modeled and observed.
    Outputs a list of important statistics for each variable, calculated
    using the TidalStats class

    Inputs:
        - data = dictionary containing all necessary observed and model data
        - threeDim = boolean flag, 3D or not
    Outputs:
       - elev_suite = dictionary of useful statistics for sea elevation
       - speed_suite = dictionary of useful statistics for flow speed
       - dir_suite = dictionary of useful statistics for flow direction
       - u_suite = dictionary of useful statistics for u velocity component
       - v_suite = dictionary of useful statistics for v velocity component
       - vel_suite = dictionary of useful statistics for signed flow velocity
       - csp_suite = dictionary of useful statistics for cubic flow speed
    Options:
       - depth = interpolation depth from surface, float
       - plot = boolean flag for plotting results
       - save_csv = boolean flag for saving statistical benchmarks in csv file
    """
    if debug: print "CompareUV..."
    # take data from input dictionary
    mod_time = data['mod_time']
    if not data['type'] == 'Drifter':
        obs_time = data['obs_time']

        mod_el = data['mod_timeseries']['elev']
        obs_el = data['obs_timeseries']['elev']
    else:
        obs_time = data['mod_time']

    # Save path & create folder
    name = data['name']
    save_path = name.split('/')[-1].split('.')[0]+'/'
    while exists(save_path):
        save_path = save_path[:-1] + '_bis/'
    mkdir(save_path)

    # Check if 3D simulation
    if threeDim:
        obs_u_all = data['obs_timeseries']['u']
        obs_v_all = data['obs_timeseries']['v']
        mod_u_all = data['mod_timeseries']['u']
        mod_v_all = data['mod_timeseries']['v']
        bins = data['obs_timeseries']['bins']
        siglay = data['mod_timeseries']['siglay']
        # use depth interpolation to get a single timeseries
        mod_depth = mod_el + np.mean(obs_el[~np.isnan(obs_el)])
        (mod_u, obs_u) = depthFromSurf(mod_u_all, mod_depth, siglay,
                                       obs_u_all, obs_el, bins, depth=depth,
                                       debug=debug, debug_plot=debug_plot)
        (mod_v, obs_v) = depthFromSurf(mod_v_all, mod_depth, siglay,
                                       obs_v_all, obs_el, bins, depth=depth,
                                       debug=debug, debug_plot=debug_plot)
    else:
        if not data['type'] == 'Drifter':
            obs_u = data['obs_timeseries']['ua']
            obs_v = data['obs_timeseries']['va']
            mod_u = data['mod_timeseries']['ua']
            mod_v = data['mod_timeseries']['va']
        else:
            obs_u = data['obs_timeseries']['u']
            obs_v = data['obs_timeseries']['v']
            mod_u = data['mod_timeseries']['u']
            mod_v = data['mod_timeseries']['v']


    if debug: print "...convert times to datetime..."
    mod_dt, obs_dt = [], []
    for i in mod_time:
        mod_dt.append(dn2dt(i))
    for j in obs_time:
        obs_dt.append(dn2dt(j))

    if debug: print "...put data into a useful format..."
    mod_spd = np.sqrt(mod_u**2.0 + mod_v**2.0)
    obs_spd = np.sqrt(obs_u**2.0 + obs_v**2.0)
    mod_dir = np.arctan2(mod_v, mod_u) * 180.0 / np.pi
    obs_dir = np.arctan2(obs_v, obs_u) * 180.0 / np.pi
    if not data['type'] == 'Drifter':
        obs_el = obs_el - np.mean(obs_el[~np.isnan(obs_el)])
    # Chose the component with the biggest variance as sign reference
    if np.var(mod_v) > np.var(mod_u):
            mod_signed = np.sign(mod_v)
            obs_signed = np.sign(obs_v)
    else:
            mod_signed = np.sign(mod_u)
            obs_signed = np.sign(obs_u)

    if debug: print "...check if the modeled data lines up with the observed data..."
    if (mod_time[-1] < obs_time[0] or obs_time[-1] < mod_time[0]):
        raise PyseidonError("---time periods do not match up---")

    else:
        if debug: print "...interpolate the data onto a common time step for each data type..."
        if not data['type'] == 'Drifter':
            # elevation
            (mod_el_int, obs_el_int, step_el_int, start_el_int) = smooth(mod_el, mod_dt, obs_el, obs_dt,
                                                                         debug=debug, debug_plot=debug_plot)
            # speed
            (mod_sp_int, obs_sp_int, step_sp_int, start_sp_int) = smooth(mod_spd, mod_dt, obs_spd, obs_dt,
                                                                         debug=debug, debug_plot=debug_plot)
            # direction
            (mod_dr_int, obs_dr_int, step_dr_int, start_dr_int) = smooth(mod_dir, mod_dt, obs_dir, obs_dt,
                                                                         debug=debug, debug_plot=debug_plot)
            # u velocity
            (mod_u_int, obs_u_int, step_u_int, start_u_int) = smooth(mod_u, mod_dt, obs_u, obs_dt,
                                                                     debug=debug, debug_plot=debug_plot)
            # v velocity
            (mod_v_int, obs_v_int, step_v_int, start_v_int) = smooth(mod_v, mod_dt, obs_v, obs_dt,
                                                                     debug=debug, debug_plot=debug_plot)
            # velocity i.e. signed speed
            (mod_ve_int, obs_ve_int, step_ve_int, start_ve_int) = smooth(mod_spd * mod_signed, mod_dt,
                                                                         obs_spd * obs_signed, obs_dt,
                                                                         debug=debug, debug_plot=debug_plot)
            # cubic signed speed
            #mod_cspd = mod_spd**3.0
            #obs_cspd = obs_spd**3.0
            mod_cspd = mod_signed * mod_spd**3.0
            obs_cspd = obs_signed * obs_spd**3.0
            (mod_cspd_int, obs_cspd_int, step_cspd_int, start_cspd_int) = smooth(mod_cspd, mod_dt, obs_cspd, obs_dt,
                                                                                 debug=debug, debug_plot=debug_plot)
        else:
            # Time steps
            step = mod_time[1] - mod_time[0]
            start = mod_time[0]

            # Already interpolated, so no need to use smooth...
            # speed
            (mod_sp_int, obs_sp_int, step_sp_int, start_sp_int) = (mod_spd, obs_spd, step, start)
            # direction
            (mod_dr_int, obs_dr_int, step_dr_int, start_dr_int) = (mod_dir, obs_dir, step, start)
            # u velocity
            (mod_u_int, obs_u_int, step_u_int, start_u_int) = (mod_u, obs_u, step, start)
            # v velocity
            (mod_v_int, obs_v_int, step_v_int, start_v_int) = (mod_v, obs_v, step, start)
            # velocity i.e. signed speed
            (mod_ve_int, obs_ve_int, step_ve_int, start_ve_int) = (mod_spd, obs_spd, step, start)
            # cubic signed speed
            #mod_cspd = mod_spd**3.0
            #obs_cspd = obs_spd**3.0
            mod_cspd = mod_signed * mod_spd**3.0
            obs_cspd = obs_signed * obs_spd**3.0
            (mod_cspd_int, obs_cspd_int, step_cspd_int, start_cspd_int) = (mod_cspd, obs_cspd, step, start)

    if debug: print "...remove directions where velocities are small..."
    MIN_VEL = 0.1
    indexMin = np.where(obs_sp_int < MIN_VEL)
    obs_dr_int[indexMin] = np.nan
    obs_u_int[indexMin] = np.nan
    obs_v_int[indexMin] = np.nan
    obs_ve_int[indexMin] = np.nan
    obs_cspd_int[indexMin] = np.nan

    indexMin = np.where(mod_sp_int < MIN_VEL)
    mod_dr_int[indexMin] = np.nan
    mod_u_int[indexMin] = np.nan
    mod_v_int[indexMin] = np.nan
    mod_ve_int[indexMin] = np.nan
    mod_cspd_int[indexMin] = np.nan

    if debug: print "...get stats for each tidal variable..."
    gear = data['type'] # Type of measurement gear (drifter, adcp,...)
    if not gear == 'Drifter':
        elev_suite = tidalSuite(gear, mod_el_int, obs_el_int, step_el_int, start_el_int,
                                [], [], [], [], [], [],
                                kind='elevation', plot=plot,
                                save_csv=save_csv, save_path=save_path,
                                debug=debug, debug_plot=debug_plot)
    else:
        elev_suite = []
    speed_suite = tidalSuite(gear, mod_sp_int, obs_sp_int, step_sp_int, start_sp_int,
                             [], [], [], [], [], [],
                             kind='speed', plot=plot,
                             save_csv=save_csv, save_path=save_path,
                             debug=debug, debug_plot=debug_plot)
    dir_suite = tidalSuite(gear, mod_dr_int, obs_dr_int, step_dr_int, start_dr_int,
                           mod_u, obs_u, mod_v, obs_v,
                           mod_dt, obs_dt,
                           kind='direction', plot=plot,
                           save_csv=save_csv, save_path=save_path,
                           debug=debug, debug_plot=debug_plot)
    u_suite = tidalSuite(gear, mod_u_int, obs_u_int, step_u_int, start_u_int,
                         [], [], [], [], [], [],
                         kind='u velocity', plot=plot, save_csv=save_csv, save_path=save_path,
                         debug=debug, debug_plot=debug_plot)
    v_suite = tidalSuite(gear, mod_v_int, obs_v_int, step_v_int, start_v_int,
                         [], [], [], [], [], [],
                         kind='v velocity', plot=plot, save_csv=save_csv, save_path=save_path,
                         debug=debug, debug_plot=debug_plot)

    # TR: requires special treatments from here on
    vel_suite = tidalSuite(gear, mod_ve_int, obs_ve_int, step_ve_int, start_ve_int,
                           mod_u, obs_u, mod_v, obs_v,
                           mod_dt, obs_dt,
                           kind='velocity', plot=plot, save_csv=save_csv, save_path=save_path,
                           debug=debug, debug_plot=debug_plot)
    csp_suite = tidalSuite(gear, mod_cspd_int, obs_cspd_int, step_cspd_int, start_cspd_int,
                           mod_u, obs_u, mod_v, obs_v,
                           mod_dt, obs_dt,
                           kind='cubic speed', plot=plot, save_csv=save_csv, save_path=save_path,
                           debug=debug, debug_plot=debug_plot)

    # output statistics in useful format

    if debug: print "...CompareUV done."


    return (elev_suite, speed_suite, dir_suite, u_suite, v_suite, vel_suite, csp_suite)
Esempio n. 4
0
def compareUV(data,
              threeDim,
              depth=5,
              plot=False,
              save_csv=False,
              debug=False,
              debug_plot=False):
    """
    Does a comprehensive validation process between modeled and observed.
    Outputs a list of important statistics for each variable, calculated
    using the TidalStats class

    Inputs:
        - data = dictionary containing all necessary observed and model data
        - threeDim = boolean flag, 3D or not
    Outputs:
       - elev_suite = dictionary of useful statistics for sea elevation
       - speed_suite = dictionary of useful statistics for flow speed
       - dir_suite = dictionary of useful statistics for flow direction
       - u_suite = dictionary of useful statistics for u velocity component
       - v_suite = dictionary of useful statistics for v velocity component
       - vel_suite = dictionary of useful statistics for signed flow velocity
       - csp_suite = dictionary of useful statistics for cubic flow speed
    Options:
       - depth = interpolation depth from surface, float
       - plot = boolean flag for plotting results
       - save_csv = boolean flag for saving statistical benchmarks in csv file
    """
    if debug: print "CompareUV..."
    # take data from input dictionary
    mod_time = data['mod_time']
    if not data['type'] == 'Drifter':
        obs_time = data['obs_time']

        mod_el = data['mod_timeseries']['elev']
        obs_el = data['obs_timeseries']['elev']
    else:
        obs_time = data['mod_time']

    # Save path & create folder
    name = data['name']
    save_path = name.split('/')[-1].split('.')[0] + '/'
    while exists(save_path):
        save_path = save_path[:-1] + '_bis/'
    mkdir(save_path)

    # Check if 3D simulation
    if threeDim:
        obs_u_all = data['obs_timeseries']['u']
        obs_v_all = data['obs_timeseries']['v']
        mod_u_all = data['mod_timeseries']['u']
        mod_v_all = data['mod_timeseries']['v']
        bins = data['obs_timeseries']['bins']
        siglay = data['mod_timeseries']['siglay']
        # use depth interpolation to get a single timeseries
        mod_depth = mod_el + np.mean(obs_el[~np.isnan(obs_el)])
        (mod_u, obs_u) = depthFromSurf(mod_u_all,
                                       mod_depth,
                                       siglay,
                                       obs_u_all,
                                       obs_el,
                                       bins,
                                       depth=depth,
                                       debug=debug,
                                       debug_plot=debug_plot)
        (mod_v, obs_v) = depthFromSurf(mod_v_all,
                                       mod_depth,
                                       siglay,
                                       obs_v_all,
                                       obs_el,
                                       bins,
                                       depth=depth,
                                       debug=debug,
                                       debug_plot=debug_plot)
    else:
        if not data['type'] == 'Drifter':
            obs_u = data['obs_timeseries']['ua']
            obs_v = data['obs_timeseries']['va']
            mod_u = data['mod_timeseries']['ua']
            mod_v = data['mod_timeseries']['va']
        else:
            obs_u = data['obs_timeseries']['u']
            obs_v = data['obs_timeseries']['v']
            mod_u = data['mod_timeseries']['u']
            mod_v = data['mod_timeseries']['v']

    if debug: print "...convert times to datetime..."
    mod_dt, obs_dt = [], []
    for i in mod_time:
        mod_dt.append(dn2dt(i))
    for j in obs_time:
        obs_dt.append(dn2dt(j))

    if debug: print "...put data into a useful format..."
    mod_spd = np.sqrt(mod_u**2.0 + mod_v**2.0)
    obs_spd = np.sqrt(obs_u**2.0 + obs_v**2.0)
    mod_dir = np.arctan2(mod_v, mod_u) * 180.0 / np.pi
    obs_dir = np.arctan2(obs_v, obs_u) * 180.0 / np.pi
    if not data['type'] == 'Drifter':
        obs_el = obs_el - np.mean(obs_el[~np.isnan(obs_el)])
    # Chose the component with the biggest variance as sign reference
    if np.var(mod_v) > np.var(mod_u):
        mod_signed = np.sign(mod_v)
        obs_signed = np.sign(obs_v)
    else:
        mod_signed = np.sign(mod_u)
        obs_signed = np.sign(obs_u)

    if debug:
        print "...check if the modeled data lines up with the observed data..."
    if (mod_time[-1] < obs_time[0] or obs_time[-1] < mod_time[0]):
        raise PyseidonError("---time periods do not match up---")

    else:
        if debug:
            print "...interpolate the data onto a common time step for each data type..."
        if not data['type'] == 'Drifter':
            # elevation
            (mod_el_int, obs_el_int, step_el_int,
             start_el_int) = smooth(mod_el,
                                    mod_dt,
                                    obs_el,
                                    obs_dt,
                                    debug=debug,
                                    debug_plot=debug_plot)
            # speed
            (mod_sp_int, obs_sp_int, step_sp_int,
             start_sp_int) = smooth(mod_spd,
                                    mod_dt,
                                    obs_spd,
                                    obs_dt,
                                    debug=debug,
                                    debug_plot=debug_plot)
            # direction
            (mod_dr_int, obs_dr_int, step_dr_int,
             start_dr_int) = smooth(mod_dir,
                                    mod_dt,
                                    obs_dir,
                                    obs_dt,
                                    debug=debug,
                                    debug_plot=debug_plot)
            # u velocity
            (mod_u_int, obs_u_int, step_u_int,
             start_u_int) = smooth(mod_u,
                                   mod_dt,
                                   obs_u,
                                   obs_dt,
                                   debug=debug,
                                   debug_plot=debug_plot)
            # v velocity
            (mod_v_int, obs_v_int, step_v_int,
             start_v_int) = smooth(mod_v,
                                   mod_dt,
                                   obs_v,
                                   obs_dt,
                                   debug=debug,
                                   debug_plot=debug_plot)
            # velocity i.e. signed speed
            (mod_ve_int, obs_ve_int, step_ve_int,
             start_ve_int) = smooth(mod_spd * mod_signed,
                                    mod_dt,
                                    obs_spd * obs_signed,
                                    obs_dt,
                                    debug=debug,
                                    debug_plot=debug_plot)
            # cubic signed speed
            #mod_cspd = mod_spd**3.0
            #obs_cspd = obs_spd**3.0
            mod_cspd = mod_signed * mod_spd**3.0
            obs_cspd = obs_signed * obs_spd**3.0
            (mod_cspd_int, obs_cspd_int, step_cspd_int,
             start_cspd_int) = smooth(mod_cspd,
                                      mod_dt,
                                      obs_cspd,
                                      obs_dt,
                                      debug=debug,
                                      debug_plot=debug_plot)
        else:
            # Time steps
            step = mod_time[1] - mod_time[0]
            start = mod_time[0]

            # Already interpolated, so no need to use smooth...
            # speed
            (mod_sp_int, obs_sp_int, step_sp_int,
             start_sp_int) = (mod_spd, obs_spd, step, start)
            # direction
            (mod_dr_int, obs_dr_int, step_dr_int,
             start_dr_int) = (mod_dir, obs_dir, step, start)
            # u velocity
            (mod_u_int, obs_u_int, step_u_int, start_u_int) = (mod_u, obs_u,
                                                               step, start)
            # v velocity
            (mod_v_int, obs_v_int, step_v_int, start_v_int) = (mod_v, obs_v,
                                                               step, start)
            # velocity i.e. signed speed
            (mod_ve_int, obs_ve_int, step_ve_int,
             start_ve_int) = (mod_spd, obs_spd, step, start)
            # cubic signed speed
            #mod_cspd = mod_spd**3.0
            #obs_cspd = obs_spd**3.0
            mod_cspd = mod_signed * mod_spd**3.0
            obs_cspd = obs_signed * obs_spd**3.0
            (mod_cspd_int, obs_cspd_int, step_cspd_int,
             start_cspd_int) = (mod_cspd, obs_cspd, step, start)

    if debug: print "...remove directions where velocities are small..."
    MIN_VEL = 0.1
    indexMin = np.where(obs_sp_int < MIN_VEL)
    obs_dr_int[indexMin] = np.nan
    obs_u_int[indexMin] = np.nan
    obs_v_int[indexMin] = np.nan
    obs_ve_int[indexMin] = np.nan
    obs_cspd_int[indexMin] = np.nan

    indexMin = np.where(mod_sp_int < MIN_VEL)
    mod_dr_int[indexMin] = np.nan
    mod_u_int[indexMin] = np.nan
    mod_v_int[indexMin] = np.nan
    mod_ve_int[indexMin] = np.nan
    mod_cspd_int[indexMin] = np.nan

    if debug: print "...get stats for each tidal variable..."
    gear = data['type']  # Type of measurement gear (drifter, adcp,...)
    if not gear == 'Drifter':
        elev_suite = tidalSuite(gear,
                                mod_el_int,
                                obs_el_int,
                                step_el_int,
                                start_el_int, [], [], [], [], [], [],
                                kind='elevation',
                                plot=plot,
                                save_csv=save_csv,
                                save_path=save_path,
                                debug=debug,
                                debug_plot=debug_plot)
    else:
        elev_suite = []
    speed_suite = tidalSuite(gear,
                             mod_sp_int,
                             obs_sp_int,
                             step_sp_int,
                             start_sp_int, [], [], [], [], [], [],
                             kind='speed',
                             plot=plot,
                             save_csv=save_csv,
                             save_path=save_path,
                             debug=debug,
                             debug_plot=debug_plot)
    dir_suite = tidalSuite(gear,
                           mod_dr_int,
                           obs_dr_int,
                           step_dr_int,
                           start_dr_int,
                           mod_u,
                           obs_u,
                           mod_v,
                           obs_v,
                           mod_dt,
                           obs_dt,
                           kind='direction',
                           plot=plot,
                           save_csv=save_csv,
                           save_path=save_path,
                           debug=debug,
                           debug_plot=debug_plot)
    u_suite = tidalSuite(gear,
                         mod_u_int,
                         obs_u_int,
                         step_u_int,
                         start_u_int, [], [], [], [], [], [],
                         kind='u velocity',
                         plot=plot,
                         save_csv=save_csv,
                         save_path=save_path,
                         debug=debug,
                         debug_plot=debug_plot)
    v_suite = tidalSuite(gear,
                         mod_v_int,
                         obs_v_int,
                         step_v_int,
                         start_v_int, [], [], [], [], [], [],
                         kind='v velocity',
                         plot=plot,
                         save_csv=save_csv,
                         save_path=save_path,
                         debug=debug,
                         debug_plot=debug_plot)

    # TR: requires special treatments from here on
    vel_suite = tidalSuite(gear,
                           mod_ve_int,
                           obs_ve_int,
                           step_ve_int,
                           start_ve_int,
                           mod_u,
                           obs_u,
                           mod_v,
                           obs_v,
                           mod_dt,
                           obs_dt,
                           kind='velocity',
                           plot=plot,
                           save_csv=save_csv,
                           save_path=save_path,
                           debug=debug,
                           debug_plot=debug_plot)
    csp_suite = tidalSuite(gear,
                           mod_cspd_int,
                           obs_cspd_int,
                           step_cspd_int,
                           start_cspd_int,
                           mod_u,
                           obs_u,
                           mod_v,
                           obs_v,
                           mod_dt,
                           obs_dt,
                           kind='cubic speed',
                           plot=plot,
                           save_csv=save_csv,
                           save_path=save_path,
                           debug=debug,
                           debug_plot=debug_plot)

    # output statistics in useful format

    if debug: print "...CompareUV done."

    return (elev_suite, speed_suite, dir_suite, u_suite, v_suite, vel_suite,
            csp_suite)
Esempio n. 5
0
def compareUV(data):
    '''
    Does a comprehensive validation process between modeled and observed
    data on the following:
        Current speed
        Current direction
        Harmonic constituents (for height and speed)

    Outputs a list of important statistics for each variable, calculated
    using the TidalStats class
    '''
    # take data from input dictionary
    mod_time = data['mod_time']
    obs_time = data['obs_time']
    print 'Loading mod timeseries'
    mod_u_all = data['mod_timeseries']['u'][:, :, 0]
    mod_v_all = data['mod_timeseries']['v'][:, :, 0]
    mod_el = data['mod_timeseries']['elev']
    print 'Loading obs timeseries'
    obs_u_all = data['obs_timeseries']['u']
    obs_v_all = data['obs_timeseries']['v']
    obs_el = data['obs_timeseries']['elev']
    v_obs_harm = data['vel_obs_harmonics']
    el_mod_harm = data['elev_mod_harmonics']
    el_obs_harm = data['elev_mod_harmonics']
    bins = data['obs_timeseries']['bins']
    sig = -data['mod_timeseries']['siglay'][:, 0]

    # for some reason, the siglayers are repeated within siglay
    # this bit of code will pick out only one of those repetitions
    siglay = []
    for i, v in enumerate(sig):
	siglay.append(v)
	if (sig[i + 1] < v):
	    break
    siglay = np.asarray(siglay)

    print 'siglay: {}'.format(siglay)
    print 'mod shape: {}'.format(mod_u_all.shape)
    print 'obs shape: {}'.format(obs_u_all.shape)

    # use depth interpolation to get a single timeseries
    print 'Performing depth interpolation'
    mod_depth = mod_el + np.mean(obs_el)
    (mod_u, obs_u) = depthFromSurf(mod_u_all, mod_depth, siglay,
				   obs_u_all, obs_el, bins)
    (mod_v, obs_v) = depthFromSurf(mod_v_all, mod_depth, siglay,
                                   obs_v_all, obs_el, bins)
    print 'Depth interpolation completed'

    # create new coefs based on depth interpolated timeseries
    v_mod_harm = ut_solv(mod_time, mod_u, mod_v, 
                         data['lat'], cnstit='auto', 
			 rmin=0.95, notrend=True, method='ols', nodiagn=True, 
			 linci=True, conf_int=True)

    # convert times to datetime
    mod_dt, obs_dt = [], []
    for i in mod_time:
	mod_dt.append(dn2dt(i))
    for j in obs_time:
	obs_dt.append(dn2dt(j))

    # put data into a useful format
    mod_spd = np.sqrt(mod_u**2 + mod_v**2)
    obs_spd = np.sqrt(obs_u**2 + obs_v**2)
    mod_dir = np.arctan2(mod_v, mod_u) * 180 / np.pi
    obs_dir = np.arctan2(obs_v, obs_u) * 180 / np.pi
    obs_el = obs_el - np.mean(obs_el)

    # check if the modeled data lines up with the observed data
    if (mod_time[-1] < obs_time[0] or obs_time[-1] < mod_time[0]):

	pred_uv = ut_reconstr(obs_time, v_mod_harm)
	pred_uv = np.asarray(pred_uv)
	pred_h = ut_reconstr(obs_time, el_mod_harm)
	pred_h = np.asarray(pred_h)

	# redo speed and direction and set interpolated variables
	mod_sp_int = np.sqrt(pred_uv[0]**2 + pred_uv[1]**2)
	mod_ve_int = mod_sp_int * np.sign(pred_uv[1])
	mod_dr_int = np.arctan2(pred_uv[1], pred_uv[0]) * 180 / np.pi
	mod_el_int = pred_h[0]
	mod_u_int = pred_uv[0]
	mod_v_int = pred_uv[1]
	obs_sp_int = obs_spd
	obs_ve_int = obs_spd * np.sign(obs_v)
	obs_dr_int = obs_dir
	obs_el_int = obs_el
	obs_u_int = obs_u
	obs_v_int = obs_v
	step_int = obs_dt[1] - obs_dt[0]
	start_int = obs_dt[0]

    else:
        # interpolate the data onto a common time step for each data type
	# elevation
        (mod_el_int, obs_el_int, step_int, start_int) = \
	    smooth(mod_el, mod_dt, obs_el, obs_dt)

	# speed
        (mod_sp_int, obs_sp_int, step_int, start_int) = \
            smooth(mod_spd, mod_dt, obs_spd, obs_dt)

	# direction
        (mod_dr_int, obs_dr_int, step_int, start_int) = \
            smooth(mod_dir, mod_dt, obs_dir, obs_dt)

	# u velocity
	(mod_u_int, obs_u_int, step_int, start_int) = \
	    smooth(mod_u, mod_dt, obs_u, obs_dt)

	# v velocity
	(mod_v_int, obs_v_int, step_int, start_int) = \
	    smooth(mod_v, mod_dt, obs_v, obs_dt)

	# velocity i.e. signed speed
	(mod_ve_int, obs_ve_int, step_int, start_int) = \
	    smooth(mod_spd * np.sign(mod_v), mod_dt, 
		   obs_spd * np.sign(obs_v), obs_dt)
    '''
    # separate into ebb and flow
    mod_dir_n = get_DirFromN(mod_u_int, mod_v_int)
    obs_dir_n = get_DirFromN(obs_u_int, mod_v_int)
    mod_signed_s, mod_PA = sign_speed(mod_u_int, mod_v_int, mod_sp_int,
				      mod_dr_int, 0)
    obs_signed_s, obs_PA = sign_speed(obs_u_int, obs_v_int, obs_sp_int,
				      obs_dr_int, 0)
    print mod_signed_s[:20], mod_PA[:20]
    print obs_signed_s[:20], obs_PA[:20]
    '''

    # remove directions where velocities are small
    MIN_VEL = 0.5
    for i in np.arange(obs_sp_int.size):
 	if (obs_sp_int[i] < MIN_VEL):
	    obs_dr_int[i] = np.nan
	if (mod_sp_int[i] < MIN_VEL):
	    mod_dr_int[i] = np.nan

    # get stats for each tidal variable
    elev_suite = tidalSuite(mod_el_int, obs_el_int, step_int, start_int,
			    type='elevation', plot=True)
    speed_suite = tidalSuite(mod_sp_int, obs_sp_int, step_int, start_int,
			    type='speed', plot=True)
    dir_suite = tidalSuite(mod_dr_int, obs_dr_int, step_int, start_int,
			    type='direction', plot=False)
    u_suite = tidalSuite(mod_u_int, obs_u_int, step_int, start_int,
			    type='u velocity', plot=False)
    v_suite = tidalSuite(mod_v_int, obs_v_int, step_int, start_int,
			    type='v velocity', plot=False)
    vel_suite = tidalSuite(mod_ve_int, obs_ve_int, step_int, start_int,
			    type='velocity', plot=False)
    #ebb_suite = tidalSuite(mod_ebb, obs_ebb, step_int, start_int,
	#		    type='ebb', plot=True)
    #flo_suite = tidalSuite(mod_flo, obs_flo, step_int, start_int,
	#		    type='flow', plot=True)
    # output statistics in useful format
    return (elev_suite, speed_suite, dir_suite, u_suite, v_suite, vel_suite)
Esempio n. 6
0
def compareUV(data, threeDim, depth=5, plot=False):
    '''
    Does a comprehensive validation process between modeled and observed
    data on the following:
        Current speed
        Current direction
        Harmonic constituents (for height and speed)

    Outputs a list of important statistics for each variable, calculated
    using the TidalStats class
    '''
    # take data from input dictionary
    mod_time = data['mod_time']
    obs_time = data['obs_time']
    mod_el = data['mod_timeseries']['elev']
    obs_el = data['obs_timeseries']['elev']
    v_mod_harm = data['vel_mod_harmonics']
    v_obs_harm = data['vel_obs_harmonics']
    el_mod_harm = data['elev_mod_harmonics']
    el_obs_harm = data['elev_mod_harmonics']

    #Check if 3D simulation
    if threeDim:
        obs_u_all = data['obs_timeseries']['u']
        obs_v_all = data['obs_timeseries']['v']
        mod_u_all = data['mod_timeseries']['u']
        mod_v_all = data['mod_timeseries']['v']
        bins = data['obs_timeseries']['bins']
        siglay = data['mod_timeseries']['siglay']
        # use depth interpolation to get a single timeseries
        mod_depth = mod_el + np.mean(obs_el)
        (mod_u, obs_u) = depthFromSurf(mod_u_all, mod_depth, siglay,
				       obs_u_all, obs_el, bins, depth=depth)
        (mod_v, obs_v) = depthFromSurf(mod_v_all, mod_depth, siglay,
                                       obs_v_all, obs_el, bins, depth=depth)
    else:
        obs_u = data['obs_timeseries']['ua']
        obs_v = data['obs_timeseries']['va']
        mod_u = data['mod_timeseries']['ua']
        mod_v = data['mod_timeseries']['va']        


    # convert times to datetime
    mod_dt, obs_dt = [], []
    for i in mod_time:
	mod_dt.append(dn2dt(i))
    for j in obs_time:
	obs_dt.append(dn2dt(j))

    # put data into a useful format
    mod_spd = np.sqrt(mod_u**2 + mod_v**2)
    obs_spd = np.sqrt(obs_u**2 + obs_v**2)
    mod_dir = np.arctan2(mod_v, mod_u) * 180 / np.pi
    obs_dir = np.arctan2(obs_v, obs_u) * 180 / np.pi
    obs_el = obs_el - np.mean(obs_el)

    # check if the modeled data lines up with the observed data
    if (mod_time[-1] < obs_time[0] or obs_time[-1] < mod_time[0]):

	pred_uv = ut_reconstr(obs_time, v_mod_harm)
	pred_uv = np.asarray(pred_uv)
	pred_h = ut_reconstr(obs_time, el_mod_harm)
	pred_h = np.asarray(pred_h)

	# redo speed and direction and set interpolated variables
	mod_sp_int = np.sqrt(pred_uv[0]**2 + pred_uv[1]**2)
	mod_ve_int = mod_sp_int * np.sign(pred_uv[1])
	mod_dr_int = np.arctan2(pred_uv[1], pred_uv[0]) * 180 / np.pi
	mod_el_int = pred_h[0]
	mod_u_int = pred_uv[0]
	mod_v_int = pred_uv[1]
	obs_sp_int = obs_spd
	obs_ve_int = obs_spd * np.sign(obs_v)
	obs_dr_int = obs_dir
	obs_el_int = obs_el
	obs_u_int = obs_u
	obs_v_int = obs_v
	step_int = obs_dt[1] - obs_dt[0]
	start_int = obs_dt[0]

    else:
        # interpolate the data onto a common time step for each data type
	# elevation
        (mod_el_int, obs_el_int, step_int, start_int) = \
	    smooth(mod_el, mod_dt, obs_el, obs_dt)

	# speed
        (mod_sp_int, obs_sp_int, step_int, start_int) = \
            smooth(mod_spd, mod_dt, obs_spd, obs_dt)

	# direction
        (mod_dr_int, obs_dr_int, step_int, start_int) = \
            smooth(mod_dir, mod_dt, obs_dir, obs_dt)

	# u velocity
	(mod_u_int, obs_u_int, step_int, start_int) = \
	    smooth(mod_u, mod_dt, obs_u, obs_dt)

	# v velocity
	(mod_v_int, obs_v_int, step_int, start_int) = \
	    smooth(mod_v, mod_dt, obs_v, obs_dt)

	# velocity i.e. signed speed
	(mod_ve_int, obs_ve_int, step_int, start_int) = \
	    smooth(mod_spd * np.sign(mod_v), mod_dt, 
		   obs_spd * np.sign(obs_v), obs_dt)
    '''
    # separate into ebb and flow
    mod_dir_n = get_DirFromN(mod_u_int, mod_v_int)
    obs_dir_n = get_DirFromN(obs_u_int, mod_v_int)
    mod_signed_s, mod_PA = sign_speed(mod_u_int, mod_v_int, mod_sp_int,
				      mod_dr_int, 0)
    obs_signed_s, obs_PA = sign_speed(obs_u_int, obs_v_int, obs_sp_int,
				      obs_dr_int, 0)
    print mod_signed_s[:20], mod_PA[:20]
    print obs_signed_s[:20], obs_PA[:20]
    '''

    # remove directions where velocities are small
    MIN_VEL = 0.5
    for i in np.arange(obs_sp_int.size):
 	if (obs_sp_int[i] < MIN_VEL):
	    obs_dr_int[i] = np.nan
	if (mod_sp_int[i] < MIN_VEL):
	    mod_dr_int[i] = np.nan

    # get stats for each tidal variable
    elev_suite = tidalSuite(mod_el_int, obs_el_int, step_int, start_int,
			    type='elevation', plot=plot)
    speed_suite = tidalSuite(mod_sp_int, obs_sp_int, step_int, start_int,
			    type='speed', plot=plot)
    dir_suite = tidalSuite(mod_dr_int, obs_dr_int, step_int, start_int,
			    type='direction', plot=plot)
    u_suite = tidalSuite(mod_u_int, obs_u_int, step_int, start_int,
			    type='u velocity', plot=plot)
    v_suite = tidalSuite(mod_v_int, obs_v_int, step_int, start_int,
			    type='v velocity', plot=plot)
    vel_suite = tidalSuite(mod_ve_int, obs_ve_int, step_int, start_int,
			    type='velocity', plot=plot)
    #ebb_suite = tidalSuite(mod_ebb, obs_ebb, step_int, start_int,
	#		    type='ebb', plot=True)
    #flo_suite = tidalSuite(mod_flo, obs_flo, step_int, start_int,
	#		    type='flow', plot=True)
    # output statistics in useful format
    return (elev_suite, speed_suite, dir_suite, u_suite, v_suite, vel_suite)
Esempio n. 7
0
def compareUV(data,
              threeDim,
              depth=5,
              plot=False,
              save_csv=False,
              debug=False,
              debug_plot=False):
    '''
    Does a comprehensive validation process between modeled and observed
    data on the following:
        Current speed
        Current direction
        Harmonic constituents (for height and speed)

    Outputs a list of important statistics for each variable, calculated
    using the TidalStats class
    '''
    if debug: print "CompareUV..."
    # take data from input dictionary
    mod_time = data['mod_time']
    obs_time = data['obs_time']
    mod_el = data['mod_timeseries']['elev']
    obs_el = data['obs_timeseries']['elev']

    #Check if 3D simulation
    if threeDim:
        obs_u_all = data['obs_timeseries']['u']
        obs_v_all = data['obs_timeseries']['v']
        mod_u_all = data['mod_timeseries']['u']
        mod_v_all = data['mod_timeseries']['v']
        bins = data['obs_timeseries']['bins']
        siglay = data['mod_timeseries']['siglay']
        # use depth interpolation to get a single timeseries
        mod_depth = mod_el + np.mean(obs_el[~np.isnan(obs_el)])
        (mod_u, obs_u) = depthFromSurf(mod_u_all,
                                       mod_depth,
                                       siglay,
                                       obs_u_all,
                                       obs_el,
                                       bins,
                                       depth=depth,
                                       debug=debug,
                                       debug_plot=debug_plot)
        (mod_v, obs_v) = depthFromSurf(mod_v_all,
                                       mod_depth,
                                       siglay,
                                       obs_v_all,
                                       obs_el,
                                       bins,
                                       depth=depth,
                                       debug=debug,
                                       debug_plot=debug_plot)
    else:
        obs_u = data['obs_timeseries']['ua']
        obs_v = data['obs_timeseries']['va']
        mod_u = data['mod_timeseries']['ua']
        mod_v = data['mod_timeseries']['va']

    if debug: print "...convert times to datetime..."
    mod_dt, obs_dt = [], []
    for i in mod_time:
        mod_dt.append(dn2dt(i))
    for j in obs_time:
        obs_dt.append(dn2dt(j))

    if debug: print "...put data into a useful format..."
    mod_spd = np.sqrt(mod_u**2.0 + mod_v**2.0)
    obs_spd = np.sqrt(obs_u**2.0 + obs_v**2.0)
    mod_dir = np.arctan2(mod_v, mod_u) * 180.0 / np.pi
    obs_dir = np.arctan2(obs_v, obs_u) * 180.0 / np.pi
    obs_el = obs_el - np.mean(obs_el[~np.isnan(obs_el)])

    if debug:
        print "...check if the modeled data lines up with the observed data..."
    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 the data onto a common time step for each data type..."
        # elevation
        (mod_el_int, obs_el_int, step_el_int, start_el_int) = \
     smooth(mod_el, mod_dt, obs_el, obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # speed
        (mod_sp_int, obs_sp_int, step_sp_int, start_sp_int) = \
            smooth(mod_spd, mod_dt, obs_spd, obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # direction
        (mod_dr_int, obs_dr_int, step_dr_int, start_dr_int) = \
            smooth(mod_dir, mod_dt, obs_dir, obs_dt,
                   debug=debug, debug_plot=debug_plot)

        # u velocity
        (mod_u_int, obs_u_int, step_u_int, start_u_int) = \
            smooth(mod_u, mod_dt, obs_u, obs_dt,
                          debug=debug, debug_plot=debug_plot)

        # v velocity
        (mod_v_int, obs_v_int, step_v_int, start_v_int) = \
            smooth(mod_v, mod_dt, obs_v, obs_dt,
                          debug=debug, debug_plot=debug_plot)

        # velocity i.e. signed speed
        (mod_ve_int, obs_ve_int, step_ve_int, start_ve_int) = \
            smooth(mod_spd * np.sign(mod_v), mod_dt,
            obs_spd * np.sign(obs_v), obs_dt,
                          debug=debug, debug_plot=debug_plot)

    if debug: print "...separate into ebb and flow..."

    ## separate into ebb and flow
    #mod_dir_n = get_DirFromN(mod_u_int, mod_v_int)
    #obs_dir_n = get_DirFromN(obs_u_int, mod_v_int)
    #mod_signed_s, mod_PA = sign_speed(mod_u_int, mod_v_int, mod_sp_int,
    #			      mod_dr_int, 0)
    #obs_signed_s, obs_PA = sign_speed(obs_u_int, obs_v_int, obs_sp_int,
    #			      obs_dr_int, 0)
    #print mod_signed_s[:20], mod_PA[:20]
    #print obs_signed_s[:20], obs_PA[:20]

    if debug: print "...remove directions where velocities are small..."
    MIN_VEL = 0.1
    for i in np.arange(obs_sp_int.size):
        if (obs_sp_int[i] < MIN_VEL):
            obs_dr_int[i] = np.nan
        if (mod_sp_int[i] < MIN_VEL):
            mod_dr_int[i] = np.nan

    if debug: print "...get stats for each tidal variable..."
    elev_suite = tidalSuite(mod_el_int,
                            obs_el_int,
                            step_el_int,
                            start_el_int,
                            type='elevation',
                            plot=plot,
                            save_csv=save_csv,
                            debug=debug,
                            debug_plot=debug_plot)
    speed_suite = tidalSuite(mod_sp_int,
                             obs_sp_int,
                             step_sp_int,
                             start_sp_int,
                             type='speed',
                             plot=plot,
                             save_csv=save_csv,
                             debug=debug,
                             debug_plot=debug_plot)
    dir_suite = tidalSuite(mod_dr_int,
                           obs_dr_int,
                           step_dr_int,
                           start_dr_int,
                           type='direction',
                           plot=plot,
                           save_csv=save_csv,
                           debug=debug,
                           debug_plot=debug_plot)
    u_suite = tidalSuite(mod_u_int,
                         obs_u_int,
                         step_u_int,
                         start_u_int,
                         type='u velocity',
                         plot=plot,
                         save_csv=save_csv,
                         debug=debug,
                         debug_plot=debug_plot)
    v_suite = tidalSuite(mod_v_int,
                         obs_v_int,
                         step_v_int,
                         start_v_int,
                         type='v velocity',
                         plot=plot,
                         save_csv=save_csv,
                         debug=debug,
                         debug_plot=debug_plot)
    vel_suite = tidalSuite(mod_ve_int,
                           obs_ve_int,
                           step_ve_int,
                           start_ve_int,
                           type='velocity',
                           plot=plot,
                           save_csv=save_csv,
                           debug=debug,
                           debug_plot=debug_plot)
    #ebb_suite = tidalSuite(mod_ebb, obs_ebb, step_ebb_int, start_ebb_int,
    #     		    type='ebb', plot=True, save_csv=save_csv,
    #                       debug=debug, debug_plot=debug_plot)
    #flo_suite = tidalSuite(mod_flo, obs_flo, step_flo_int, start_flo_int,
    #	         	    type='flow', plot=True, save_csv=save_csv,
    #                        debug=debug, debug_plot=debug_plot)
    # output statistics in useful format

    if debug: print "...CompareUV done."

    return (elev_suite, speed_suite, dir_suite, u_suite, v_suite, vel_suite)