Ejemplo n.º 1
0
def plot_residual_forcing(ax, runs_list, t_orig):
    """ Plots the observed water level residual at Neah Bay against
    forced residuals from existing ssh*.txt files for Neah Bay.
    Function may produce none, any, or all (nowcast, forecast, forecast 2)
    forced residuals depending on availability for specified date (runs_list).

    :arg ax: The axis where the residuals are plotted.
    :type ax: axis object

    :arg runs_list: Runs that are verified as complete.
    :type runs_list: list

    :arg t_orig: Date being considered.
    :type t_orig: datetime object

    """

    # truncation times
    sdt = t_orig.replace(tzinfo=tz.tzutc())
    edt = sdt + datetime.timedelta(days=1)

    # retrieve observations, tides and residual
    tides = figures.shared.get_tides('Neah Bay', path=paths['tides'])
    res_obs, obs = obs_residual_ssh_NOAA('Neah Bay', tides, sdt, sdt)
    # truncate and plot
    res_obs_trun, time_trun = analyze.truncate_data(np.array(res_obs),
                                                    np.array(obs.time), sdt,
                                                    edt)
    ax.plot(time_trun,
            res_obs_trun,
            colours['observed'],
            label='observed',
            lw=2.5)

    # plot forcing for each simulation
    for mode in runs_list:
        filename_NB, run_date = analyze.create_path(mode, t_orig, 'ssh*.txt')
        if filename_NB:
            dates, surge, fflag = NeahBay_forcing_anom(filename_NB, run_date,
                                                       paths['tides'])
            surge_t, dates_t = analyze.truncate_data(np.array(surge),
                                                     np.array(dates), sdt, edt)
            ax.plot(dates_t, surge_t, label=mode, lw=2.5, color=colours[mode])
    ax.set_title('Comparison of observed and forced sea surface'
                 ' height residuals at Neah Bay:'
                 '{t_forcing:%d-%b-%Y}'.format(t_forcing=t_orig))
Ejemplo n.º 2
0
def get_error_forcing(runs_list, t_orig):
    """ Sets up the calculation for the forcing residual error.

    :arg runs_list: Runs that have been verified as complete.
    :type runs_list: list

    :arg t_orig: Date being considered.
    :type t_orig: datetime object

    :returns: error_frc_dict, t_frc_dict
    """

    # truncation times
    sdt = t_orig.replace(tzinfo=tz.tzutc())
    edt = sdt + datetime.timedelta(days=1)

    # retrieve observed residual
    tides = figures.shared.get_tides('Neah Bay', path=paths['tides'])
    res_obs, obs = obs_residual_ssh_NOAA('Neah Bay', tides, sdt, sdt)
    res_obs_trun, time_trun = analyze.truncate_data(np.array(res_obs),
                                                    np.array(obs.time), sdt,
                                                    edt)

    # calculate forcing error
    error_frc_dict = {}
    t_frc_dict = {}
    for mode in runs_list:
        filename_NB, run_date = analyze.create_path(mode, t_orig, 'ssh*.txt')
        if filename_NB:
            dates, surge, fflag = NeahBay_forcing_anom(filename_NB, run_date,
                                                       paths['tides'])
            surge_t, dates_t = analyze.truncate_data(np.array(surge),
                                                     np.array(dates), sdt, edt)
            error_frc = analyze.calculate_error(surge_t, dates_t, res_obs_trun,
                                                obs.time)
            error_frc_dict[mode] = error_frc
            t_frc_dict[mode] = dates_t

    return error_frc_dict, t_frc_dict
Ejemplo n.º 3
0
def get_error_model(names, runs_list, grid_B, t_orig):
    """ Sets up the calculation for the model residual error.

    :arg names: Names of station.
    :type names: list of strings

    :arg runs_list: Runs that have been verified as complete.
    :type runs_list: list

    :arg grid_B: Bathymetry dataset for the Salish Sea NEMO model.
    :type grid_B: :class:`netCDF4.Dataset`

    :arg t_orig: Date being considered.
    :type t_orig: datetime object

    :returns: error_mod_dict, t_mod_dict, t_orig_dict
    """

    bathy, X, Y = tidetools.get_bathy_data(grid_B)
    t_orig_obs = t_orig + datetime.timedelta(days=-1)
    t_final_obs = t_orig + datetime.timedelta(days=1)

    # truncation times
    sdt = t_orig.replace(tzinfo=tz.tzutc())
    edt = sdt + datetime.timedelta(days=1)

    error_mod_dict = {}
    t_mod_dict = {}
    for name in names:
        error_mod_dict[name] = {}
        t_mod_dict[name] = {}
        # Look up model grid
        lat = figures.SITES[name]['lat']
        lon = figures.SITES[name]['lon']
        j, i = geo_tools.find_closest_model_point(lon,
                                                  lat,
                                                  X,
                                                  Y,
                                                  land_mask=bathy.mask)
        # Observed residuals and wlevs and tides
        ttide = figures.shared.get_tides(name, path=paths['tides'])
        res_obs, wlev_meas = obs_residual_ssh(name, ttide, t_orig_obs,
                                              t_final_obs)
        res_obs_trun, time_obs_trun = analyze.truncate_data(
            np.array(res_obs), np.array(wlev_meas.time), sdt, edt)

        for mode in runs_list:
            filename, run_date = analyze.create_path(
                mode, t_orig, 'SalishSea_1h_*_grid_T.nc')
            grid_T = nc.Dataset(filename)
            res_mod, t_model, ssh_corr, ssh_mod = model_residual_ssh(
                grid_T, j, i, ttide)
            # Truncate
            res_mod_trun, t_mod_trun = analyze.truncate_data(
                res_mod, t_model, sdt, edt)
            # Error
            error_mod = analyze.calculate_error(res_mod_trun, t_mod_trun,
                                                res_obs_trun, time_obs_trun)
            error_mod_dict[name][mode] = error_mod
            t_mod_dict[name][mode] = t_mod_trun

    return error_mod_dict, t_mod_dict
Ejemplo n.º 4
0
def plot_residual_model(axs, names, runs_list, grid_B, t_orig):
    """ Plots the observed sea surface height residual against the
    sea surface height model residual (calculate_residual) at
    specified stations. Function may produce none, any, or all
    (nowcast, forecast, forecast 2) model residuals depending on
    availability for specified date (runs_list).

    :arg ax: The axis where the residuals are plotted.
    :type ax: list of axes

    :arg names: Names of station.
    :type names: list of names

    :arg runs_list: Runs that have been verified as complete.
    :type runs_list: list

    :arg grid_B: Bathymetry dataset for the Salish Sea NEMO model.
    :type grid_B: :class:`netCDF4.Dataset`

    :arg t_orig: Date being considered.
    :type t_orig: datetime object

    """

    bathy, X, Y = tidetools.get_bathy_data(grid_B)
    t_orig_obs = t_orig + datetime.timedelta(days=-1)
    t_final_obs = t_orig + datetime.timedelta(days=1)

    # truncation times
    sdt = t_orig.replace(tzinfo=tz.tzutc())
    edt = sdt + datetime.timedelta(days=1)

    for ax, name in zip(axs, names):
        # Identify model grid point
        lat = figures.SITES[name]['lat']
        lon = figures.SITES[name]['lon']
        j, i = geo_tools.find_closest_model_point(lon,
                                                  lat,
                                                  X,
                                                  Y,
                                                  land_mask=bathy.mask)
        # Observed residuals and wlevs and tides
        ttide = figures.shared.get_tides(name, path=paths['tides'])
        res_obs, wlev_meas = obs_residual_ssh(name, ttide, t_orig_obs,
                                              t_final_obs)
        # truncate and plot
        res_obs_trun, time_obs_trun = analyze.truncate_data(
            np.array(res_obs), np.array(wlev_meas.time), sdt, edt)
        ax.plot(time_obs_trun,
                res_obs_trun,
                c=colours['observed'],
                lw=2.5,
                label='observed')

        for mode in runs_list:
            filename, run_date = analyze.create_path(
                mode, t_orig, 'SalishSea_1h_*_grid_T.nc')
            grid_T = nc.Dataset(filename)
            res_mod, t_model, ssh_corr, ssh_mod = model_residual_ssh(
                grid_T, j, i, ttide)
            # truncate and plot
            res_mod_trun, t_mod_trun = analyze.truncate_data(
                res_mod, t_model, sdt, edt)
            ax.plot(t_mod_trun,
                    res_mod_trun,
                    label=mode,
                    c=colours[mode],
                    lw=2.5)

        ax.set_title('Comparison of modelled sea surface height residuals at'
                     ' {station}: {t:%d-%b-%Y}'.format(station=name, t=t_orig))