Exemplo n.º 1
0
fn_fig = '/Users/dbyrne/Projects/CO9_AMM15/data/figs/ha_variance'

ha = xr.open_dataset(fn_out)
ana = xr.open_dataset(fn_ana)
const = 'M2'
file_type = '.png'

#%% Anal map plots

ind0 = ana.ana_length <= 30
ind1 = np.logical_and(ana.ana_length <= 90, ana.ana_length > 30)
ind2 = np.logical_and(ana.ana_length <= 180, ana.ana_length > 90)
ind3 = np.logical_and(ana.ana_length <= 365, ana.ana_length > 180)
ind4 = ana.ana_length > 365

f, a = pu.create_geo_axes([-15, 15], [45, 65])
sca = a.scatter(ana.longitude[ind0], ana.latitude[ind0], zorder=100, s=2)
sca = a.scatter(ana.longitude[ind1], ana.latitude[ind1], zorder=70, s=4)
sca = a.scatter(ana.longitude[ind2], ana.latitude[ind2], zorder=60, s=6)
sca = a.scatter(ana.longitude[ind3], ana.latitude[ind3], zorder=50, s=10)
sca = a.scatter(ana.longitude[ind4],
                ana.latitude[ind4],
                zorder=40,
                s=10,
                marker='s',
                color='k')
f.legend(
    ['l <= 30', '30 < l <= 90', '90 < l <= 180', '180 < l <= 365', 'l > 365'],
    loc='lower right')
a.set_title('tideanal.edited locations and analysis length')
fn = "ana_lengths{0}".format(file_type)
Exemplo n.º 2
0
    def __init__(self,
                 fn_ssh_hourly_stats1,
                 fn_ssh_hourly_stats2,
                 dn_out,
                 run_name1,
                 run_name2,
                 file_type='.png'):

        stats1 = xr.open_dataset(fn_ssh_hourly_stats1)
        stats2 = xr.open_dataset(fn_ssh_hourly_stats2)

        lonmax = np.max(stats1.longitude)
        lonmin = np.min(stats1.longitude)
        latmax = np.max(stats1.latitude)
        latmin = np.min(stats1.latitude)
        lonbounds = [lonmin - 4, lonmax + 4]
        latbounds = [latmin - 4, latmax + 4]

        ### GEOGRAPHICAL SCATTER PLOTS
        # Plot correlations
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.ntr_corr,
                        vmin=.85,
                        vmax=1,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100)
        f.colorbar(sca)
        a.set_title(
            'Hourly NTR Correlations with Tide Gauge | {0}'.format(run_name),
            fontsize=9)
        fn = "ssh_hourly_ntr_correlations_" + run_name + file_type
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot std_err
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.std_err,
                        vmin=-.15,
                        vmax=.15,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100,
                        cmap='seismic')
        f.colorbar(sca)
        a.set_title('Hourly SSH St. Dev Error (m) | {0}'.format(run_name),
                    fontsize=9)
        fn = "ssh_hourly_stderr_" + run_name + file_type
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot mae
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.ntr_mae,
                        vmin=-.05,
                        vmax=.05,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100)
        f.colorbar(sca)
        a.set_title('Hourly NTR MAE (m) | {0}'.format(run_name), fontsize=9)
        fn = "ssh_hourly_ntr_mae_" + run_name + file_type
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        ### HARMONIC ERRORS
        constit = stats.constituent.values
        n_constit = len(constit)

        for cc in range(0, n_constit):
            # AMPLITUDE MAP
            f, a = pu.create_geo_axes(lonbounds, latbounds)
            sca = a.scatter(stats.longitude,
                            stats.latitude,
                            c=stats.amp_err[:, cc],
                            vmin=-.2,
                            vmax=.2,
                            edgecolors='k',
                            linewidths=.5,
                            zorder=100,
                            cmap='seismic')
            f.colorbar(sca)
            a.set_title('Amplitude Error (m) | {1} - Obs | {0}'.format(
                constit[cc], run_name),
                        fontsize=9)
            fn = "ssh_hourly_amp_err_{0}_{1}{2}".format(
                constit[cc], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

            # PHASE MAP
            f, a = pu.create_geo_axes(lonbounds, latbounds)
            sca = a.scatter(stats.longitude,
                            stats.latitude,
                            c=stats.pha_err[:, cc],
                            vmin=-15,
                            vmax=15,
                            edgecolors='k',
                            linewidths=.5,
                            zorder=100,
                            cmap='seismic')
            f.colorbar(sca)
            a.set_title('Phase Error (deg) | {1} - Obs | {0}'.format(
                constit[cc], run_name),
                        fontsize=9)
            fn = "ssh_hourly_pha_err_{0}_{1}{2}".format(
                constit[cc], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

            # AMPLITUDE SCATTER
            f, a = pu.scatter_with_fit(stats.amp_mod[:, cc], stats.amp_obs[:,
                                                                           cc])
            a.set_title('Amplitude Comparison | {0} | {1}'.format(
                constit[cc], run_name),
                        fontsize=9)
            a.set_xlabel("Model Amplitude (m)")
            a.set_ylabel("Observed Amplitude (m)")
            fn = "ssh_hourly_scatter_amp_{0}_{1}{2}".format(
                constit[cc], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

            # PHASE SCATTER
            f, a = pu.scatter_with_fit(stats.pha_mod[:, cc], stats.pha_obs[:,
                                                                           cc])
            a.set_title('Phase Comparison | {0} | {1}'.format(
                constit[cc], run_name),
                        fontsize=9)
            a.set_xlabel("Model Phase(deg)")
            a.set_ylabel("Observed Phase (deg)")
            fn = "ssh_hourly_scatter_pha_{0}_{1}{2}".format(
                constit[cc], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

        ### CLIM VAR ERROR
        # Jan
        m_ind = [0, 3, 6, 9]
        m_str = ['Jan', 'Mar', 'Jul', 'Oct']
        n_m = len(m_ind)
        for mm in range(0, n_m):
            f, a = pu.create_geo_axes(lonbounds, latbounds)
            sca = a.scatter(stats.longitude,
                            stats.latitude,
                            c=stats.ntr_mod_clim_var[:, m_ind[mm]] -
                            stats.ntr_obs_clim_var[:, m_ind[mm]],
                            vmin=-.05,
                            vmax=.05,
                            edgecolors='k',
                            linewidths=.5,
                            zorder=100,
                            cmap='seismic')
            f.colorbar(sca)
            a.set_title(
                'Climatological Variance Error | {1} | var({0}) - var(Obs)'.
                format(run_name, m_str[mm]),
                fontsize=9)
            fn = "ssh_hourly_clim_var_error_{0}_{1}{2}".format(
                m_str[mm], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

        ### FITTED SCATTER PLOTS
        # Plot st.dev comparisons
        f, a = pu.scatter_with_fit(stats.skew_mod, stats.skew_obs)
        a.set_title('Skew Surge Comparison | {0}'.format(run_name), fontsize=9)
        a.set_xlabel("{0} SSH st. dev (m)".format(run_name))
        a.set_ylabel("PSMSL SSH st. dev (m)")
        fn = "ssh_hourly_skew_scatter_{0}{1}".format(run_name, file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')
        return
    def __init__(self,
                 fn_monthly_ssh_stats0,
                 fn_monthly_ssh_stats1,
                 dn_out,
                 run_names,
                 file_type='.png'):

        stats0 = xr.open_dataset(fn_monthly_ssh_stats0)
        stats1 = xr.open_dataset(fn_monthly_ssh_stats1)

        lonmax = np.max(stats0.longitude)
        lonmin = np.min(stats0.longitude)
        latmax = np.max(stats0.latitude)
        latmin = np.min(stats0.latitude)
        lonbounds = [lonmin - 4, lonmax + 4]
        latbounds = [latmin - 4, latmax + 4]

        # Plot correlations
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats0.longitude,
                        stats0.latitude,
                        c=stats0.corr - stats1.corr,
                        vmin=-.03,
                        vmax=.03,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100,
                        cmap='PiYG')
        f.colorbar(sca)
        a.set_title(
            "SSH correlation difference  {1} - {0} (m)\n Correlations between monthly mean model SSH and PSMSL"
            .format(run_names[1], run_names[0]),
            fontsize=9)
        fn = "ssh_diff_corr_{0}_{1}{2}".format(run_names[0], run_names[1],
                                               file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot std_err
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats0.longitude,
                        stats0.latitude,
                        c=np.abs(stats1.std_err) - np.abs(stats0.std_err),
                        vmin=-.01,
                        vmax=.01,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100,
                        cmap='PiYG')
        f.colorbar(sca)
        a.set_title(
            'Absolute St. Dev Error Difference {0} - {1} (m) \n Error between monthly mean model SSH and PSMSL'
            .format(run_names[1], run_names[0]),
            fontsize=9)
        fn = "ssh_diff_stderr_{0}_{1}{2}".format(run_names[0], run_names[1],
                                                 file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot mae
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats0.longitude,
                        stats0.latitude,
                        c=stats1.mae - stats0.mae,
                        vmin=-.01,
                        vmax=.01,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100,
                        cmap='PiYG')
        f.colorbar(sca)
        a.set_title(
            'MAE Difference {0} - {1} (m) \n Error between monthly mean model SSH and PSMSL'
            .format(run_names[1], run_names[0]),
            fontsize=9)
        fn = "ssh_diff_mae_{0}_{1}{2}".format(run_names[0], run_names[1],
                                              file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')
Exemplo n.º 4
0
    def __init__(self,
                 fn_ssh_hourly_stats,
                 dn_out,
                 run_name,
                 file_type='.png'):

        stats = xr.open_dataset(fn_ssh_hourly_stats)

        lonmax = np.max(stats.longitude)
        lonmin = np.min(stats.longitude)
        latmax = np.max(stats.latitude)
        latmin = np.min(stats.latitude)
        lonbounds = [lonmin - 4, lonmax + 4]
        latbounds = [latmin - 4, latmax + 4]

        ### GEOGRAPHICAL SCATTER PLOTS
        # Plot correlations
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.ntr_corr,
                        vmin=.85,
                        vmax=1,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100)
        f.colorbar(sca)
        a.set_title(
            'Hourly NTR Correlations with Tide Gauge | {0}'.format(run_name),
            fontsize=9)
        fn = "ssh_hourly_ntr_correlations_" + run_name + file_type
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot std_err
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.std_err,
                        vmin=-.15,
                        vmax=.15,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100,
                        cmap='seismic')
        f.colorbar(sca)
        a.set_title('Hourly SSH St. Dev Error (m) | {0}'.format(run_name),
                    fontsize=9)
        fn = "ssh_hourly_stderr_" + run_name + file_type
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot mae
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.ntr_mae,
                        vmin=-.05,
                        vmax=.05,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100)
        f.colorbar(sca)
        a.set_title('Hourly NTR MAE (m) | {0}'.format(run_name), fontsize=9)
        fn = "ssh_hourly_ntr_mae_" + run_name + file_type
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        ### HARMONIC ERRORS
        constit = stats.constituent.values
        n_constit = len(constit)

        for cc in range(0, n_constit):
            # AMPLITUDE MAP
            f, a = pu.create_geo_axes(lonbounds, latbounds)
            sca = a.scatter(stats.longitude,
                            stats.latitude,
                            c=stats.amp_err[:, cc],
                            vmin=-.2,
                            vmax=.2,
                            edgecolors='k',
                            linewidths=.5,
                            zorder=100,
                            cmap='seismic')
            f.colorbar(sca)
            a.set_title('Amplitude Error (m) | {1} - Obs | {0}'.format(
                constit[cc], run_name),
                        fontsize=9)
            fn = "ssh_hourly_amp_err_{0}_{1}{2}".format(
                constit[cc], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

            # PHASE MAP
            f, a = pu.create_geo_axes(lonbounds, latbounds)
            sca = a.scatter(stats.longitude,
                            stats.latitude,
                            c=stats.pha_err[:, cc],
                            vmin=-15,
                            vmax=15,
                            edgecolors='k',
                            linewidths=.5,
                            zorder=100,
                            cmap='seismic')
            f.colorbar(sca)
            a.set_title('Phase Error (deg) | {1} - Obs | {0}'.format(
                constit[cc], run_name),
                        fontsize=9)
            fn = "ssh_hourly_pha_err_{0}_{1}{2}".format(
                constit[cc], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

            # AMPLITUDE SCATTER
            f, a = pu.scatter_with_fit(stats.amp_mod[:, cc], stats.amp_obs[:,
                                                                           cc])
            a.set_title('Amplitude Comparison | {0} | {1}'.format(
                constit[cc], run_name),
                        fontsize=9)
            a.set_xlabel("Model Amplitude (m)")
            a.set_ylabel("Observed Amplitude (m)")
            fn = "ssh_hourly_scatter_amp_{0}_{1}{2}".format(
                constit[cc], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

            # PHASE SCATTER
            f, a = pu.scatter_with_fit(stats.pha_mod[:, cc], stats.pha_obs[:,
                                                                           cc])
            a.set_title('Phase Comparison | {0} | {1}'.format(
                constit[cc], run_name),
                        fontsize=9)
            a.set_xlabel("Model Phase(deg)")
            a.set_ylabel("Observed Phase (deg)")
            fn = "ssh_hourly_scatter_pha_{0}_{1}{2}".format(
                constit[cc], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

        ### CLIM VAR ERROR
        # Jan
        m_ind = [0, 3, 6, 9]
        m_str = ['Jan', 'Mar', 'Jul', 'Oct']
        n_m = len(m_ind)
        for mm in range(0, n_m):
            f, a = pu.create_geo_axes(lonbounds, latbounds)
            sca = a.scatter(stats.longitude,
                            stats.latitude,
                            c=stats.ntr_mod_clim_var[:, m_ind[mm]] -
                            stats.ntr_obs_clim_var[:, m_ind[mm]],
                            vmin=-.05,
                            vmax=.05,
                            edgecolors='k',
                            linewidths=.5,
                            zorder=100,
                            cmap='seismic')
            f.colorbar(sca)
            a.set_title(
                'Climatological Variance Error | {1} | var({0}) - var(Obs)'.
                format(run_name, m_str[mm]),
                fontsize=9)
            fn = "ssh_hourly_clim_var_error_{0}_{1}{2}".format(
                m_str[mm], run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

        ### FITTED SCATTER PLOTS
        # Plot st.dev comparisons
        f, a = pu.scatter_with_fit(stats.skew_mod.values.flatten(),
                                   stats.skew_obs.values.flatten())
        a.set_title('Skew Surge Comparison | {0}'.format(run_name), fontsize=9)
        a.set_xlabel("Model Skew Surge (m)".format(run_name))
        a.set_ylabel("Observed Skew Surge (m)")
        a.set_xlim(-3, 3)
        a.set_ylim(-3, 3)
        a.set_title(
            "Comparison of modelled and observed skew surges | {0}".format(
                run_name))
        fn = "ssh_hourly_skew_scatter_{0}{1}".format(run_name, file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # THRESHOLD PLOTS
        prop = stats.thresh_freq_ntr_mod / stats.thresh_freq_ntr_obs
        plot_thresh = [5, 10, 15]
        for pp in range(0, len(plot_thresh)):
            prop_tmp = prop.isel(threshold=plot_thresh[pp])
            f, a = pu.create_geo_axes(lonbounds, latbounds)
            sca = a.scatter(stats.longitude,
                            stats.latitude,
                            c=prop_tmp,
                            vmin=0,
                            vmax=2,
                            edgecolors='k',
                            linewidths=.5,
                            zorder=100,
                            cmap='seismic')
            f.colorbar(sca)
            a.set_title(
                'Number of model NTR peaks as a proportion of observed NTR peaks \n Threshold = {0}m | {1}'
                .format(prop_tmp.threshold.values, run_name),
                fontsize=9)
            fn = "thresh_freq_{0}_{1}{2}".format(prop_tmp.threshold.values,
                                                 run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')

        prop = stats.thresh_int_ntr_mod / stats.thresh_int_ntr_obs
        plot_thresh = [5, 10, 15]
        for pp in range(0, len(plot_thresh)):
            prop_tmp = prop.isel(threshold=plot_thresh[pp])
            f, a = pu.create_geo_axes(lonbounds, latbounds)
            sca = a.scatter(stats.longitude,
                            stats.latitude,
                            c=prop_tmp,
                            vmin=0,
                            vmax=2,
                            edgecolors='k',
                            linewidths=.5,
                            zorder=100,
                            cmap='seismic')
            f.colorbar(sca)
            a.set_title(
                'Model hours over threshold as a proportion of observed time \n Threshold = {0}m | {1}'
                .format(prop_tmp.threshold.values, run_name),
                fontsize=9)
            fn = "thresh_int_{0}_{1}{2}".format(prop_tmp.threshold.values,
                                                run_name, file_type)
            f.savefig(os.path.join(dn_out, fn))
            plt.close('all')
    def __init__(self,
                 fn_monthly_ssh_stats,
                 dn_out,
                 run_name,
                 file_type='.png'):

        stats = xr.open_dataset(fn_monthly_ssh_stats)

        lonmax = np.max(stats.longitude)
        lonmin = np.min(stats.longitude)
        latmax = np.max(stats.latitude)
        latmin = np.min(stats.latitude)
        lonbounds = [lonmin - 4, lonmax + 4]
        latbounds = [latmin - 4, latmax + 4]

        # Plot correlations
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.corr,
                        vmin=.75,
                        vmax=1,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100)
        f.colorbar(sca)
        a.set_title(
            'SSH correlations \n Monthly mean PSMSL tide gauge vs {0} \n Mean Corr = {1}'
            .format(run_name, np.nanmean(stats.corr)),
            fontsize=9)
        fn = "ssh_monthly_correlations_{0}{1}".format(run_name, file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot std_err
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.std_err,
                        vmin=-.075,
                        vmax=.075,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100,
                        cmap='seismic')
        f.colorbar(sca)
        a.set_title(
            'Standard Deviation Difference (m) \n Monthly mean {0} - PSMSL Tide Gauge \n Mean err = {1}'
            .format(run_name, np.nanmean(stats.std_err)),
            fontsize=9)
        fn = "ssh_monthly_stderr_{0}{1}".format(run_name, file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot me
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.me,
                        vmin=-.05,
                        vmax=.05,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100,
                        cmap='seismic')
        f.colorbar(sca)
        a.set_title(
            'Mean Error (m) \n Monthly mean {0} - PSMSL Tide Gauge \n Mean ME = {1}'
            .format(run_name, np.nanmean(stats.me)),
            fontsize=9)
        fn = "ssh_monthly_me_{0}{1}".format(run_name, file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot mae
        f, a = pu.create_geo_axes(lonbounds, latbounds)
        sca = a.scatter(stats.longitude,
                        stats.latitude,
                        c=stats.mae,
                        vmin=0,
                        vmax=.05,
                        edgecolors='k',
                        linewidths=.5,
                        zorder=100)
        f.colorbar(sca)
        a.set_title(
            'Mean Absolute Error (m) \n Monthly mean {0} - PSMSL Tide Gauge \n Mean MAE = {1}'
            .format(run_name, np.nanmean(stats.mae)),
            fontsize=9)
        fn = "ssh_monthly_mae_{0}{1}".format(run_name, file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')

        # Plot st.dev comparisons
        f, a = pu.scatter_with_fit(stats.std_mod, stats.std_obs)
        a.set_title(
            'Monthly SSH standard deviation comparison (m) \n {0} vs {1}'.
            format(run_name, 'PSMSL'),
            fontsize=9)
        a.set_xlabel("{0} SSH st. dev (m)".format(run_name))
        a.set_ylabel("PSMSL SSH st. dev (m)")
        fn = "ssh_monthly_stdev_scatter_{0}{1}".format(run_name, file_type)
        f.savefig(os.path.join(dn_out, fn))
        plt.close('all')