Exemplo n.º 1
0
def plot_ts(lon, lat):

    experiments = ['US_M36_SMAP_TB_MadKF_DA_it34', 'US_M36_SMOS40_TB_MadKF_DA_it614', 'US_M36_SMOS40_TB_MadKF_DA_it615', 'US_M36_SMOS40_TB_MadKF_DA_it613']

    f = plt.figure(figsize=(18,10))

    for i, exp in enumerate(experiments):

        if 'SMAP' in exp:
            ol = 'US_M36_SMAP_TB_OL_noScl'
        else:
            ol = 'US_M36_SMOS40_TB_OL_noScl'

        ds_ol = LDAS_io('ObsFcstAna', ol)
        ds_da = LDAS_io('ObsFcstAna', exp)

        ts_fcst = ds_ol.read_ts('obs_fcst', lon, lat)
        ts_obs = ds_da.read_ts('obs_obs', lon, lat)
        ts_ana = ds_da.read_ts('obs_ana', lon, lat)

        spc = 1
            # if spc == 1:
            #     spc_tit = 'H pol. / Asc.'
            # elif spc == 2:
            #     spc_tit = 'H pol. / Dsc.'
            # elif spc == 3:
            #     spc_tit = 'V pol. / Asc.'
            # else:
            #     spc_tit = 'V pol. / Dsc.'

        df = pd.concat((ts_fcst[spc], ts_obs[spc], ts_ana[spc]), axis='columns').dropna()
        df.columns = ['Fcst', 'Obs', 'Ana']
        df['time'] = df.index

        ax = plt.subplot(4, 1, i+1)
        g = sns.lineplot(x='time', y='Tb', hue='Variable', data=df.melt('time', df.columns[0:-1], 'Variable', 'Tb'))
        plt.legend(loc='upper right')
        if spc != 4:
            g.set(xticklabels=[])
        ax.set_xlabel('')
        ax.set_xlim([date(2010,1,1), date(2020,1,1)])
        ax.set_ylim([170,280])
        # ax.set_ylabel('')
        plt.title(exp)

    plt.tight_layout()
    plt.show()
Exemplo n.º 2
0
def plot_cat_timeseries():

    outpath = r'D:\work\LDAS\2018-02_scaling\_new\ismn_eval\timeseries'

    fname = r"D:\work\LDAS\2018-02_scaling\_new\ismn_eval\validation.csv"
    res = pd.read_csv(fname)

    diff_srf = res['corr_DA_cal_pent_ma_sm_surface'] - res[
        'corr_DA_uncal_pent_ma_sm_surface']
    diff_rz = res['corr_DA_cal_pent_ma_sm_rootzone'] - res[
        'corr_DA_uncal_pent_ma_sm_rootzone']
    diff_prof = res['corr_DA_cal_pent_ma_sm_profile'] - res[
        'corr_DA_uncal_pent_ma_sm_profile']
    ind = (diff_srf > 0.2) | (diff_rz > 0.2) | (diff_prof > 0.2)
    res = res.loc[ind, ['network', 'station', 'lat', 'lon']]

    ismn = ISMN_io()
    cal = LDAS_io('xhourly', 'US_M36_SMOS_DA_calibrated_scaled')
    uncal = LDAS_io('xhourly', 'US_M36_SMOS_DA_nocal_scaled_pentadal')

    variables = ['sm_surface', 'sm_rootzone', 'sm_profile']

    for idx, stat in res.iterrows():

        fname = os.path.join(outpath,
                             stat.network + '_' + stat.station + '.png')

        ts_ismn = ismn.read(stat.network, stat.station)
        lat = stat.lat
        lon = stat.lon

        plt.figure(figsize=(17, 9))

        for i, var in enumerate(variables):

            ax = plt.subplot(3, 1, i + 1)

            ts_cal = calc_anomaly(cal.read_ts(var, lon, lat), method='ma')
            ts_cal.index += pd.to_timedelta('2 hours')
            ts_uncal = calc_anomaly(uncal.read_ts(var, lon, lat), method='ma')
            ts_uncal.index += pd.to_timedelta('2 hours')

            df = pd.DataFrame({
                'cal': ts_cal,
                'uncal': ts_uncal,
                'insitu': calc_anomaly(ts_ismn[var], method='ma')
            }).dropna()
            if len(df) > 0:
                df.plot(ax=ax)
            else:
                continue

            title = 'R(ismn - cal) = %.2f , R(ismn - uncal) = %.2f' % (
                df.corr().loc['insitu', 'cal'], df.corr().loc['insitu',
                                                              'uncal'])

            ax.set_title(title, fontsize=12)
            ax.set_xlim('2010-01-01', '2016-01-01')
            ax.set_ylim(-0.3, 0.3)
            ax.set_xlabel('')

        plt.tight_layout()

        plt.savefig(fname, dpi=150)
        plt.close()
Exemplo n.º 3
0
def plot_timeseries_cci():

    # Colorado
    # lat = 39.095962936
    # lon = -106.918945312

    # Nebraska
    # lat = 41.203456192
    # lon = -102.249755859

    # New Mexico
    # lat = 31.522361470
    # lon = -108.528442383

    # Western Siberia
    lats = np.arange(60, 61, 0.1)
    lons = np.arange(67, 69, 0.1)

    #lats = [60.5]
    #lons = [67.1]
    #lats = [60.26, 59.45,  52.71]
    #lons = [65.80, 42.00, -84.18]
    ''' get nearest in situ site 
    fname = '/staging/leuven/stg_00024/l_data/obs_insitu/peatland_data/WTD_peatlands_global_WGS84_DA.csv'
    np.genfromtxt(fname, names=True, delimiter=',', dtype=None)
    fname = '/staging/leuven/stg_00024/l_data/obs_insitu/peatland_data/000_all_wtd_GLOBAL/CO_Ek_avg.csv'
    sitewtd_tmp = np.genfromtxt(fname, names=True, delimiter=',', dtype=None)
    sitewtd = pd.DataFrame(sitewtd_tmp)
    '''

    # Congo
    # lats = [1.0]
    # lons = [17.5]

    exp = 'SMAP_EASEv2_M36_NORTH_DET2'
    domain = 'SMAP_EASEv2_M36_NORTH'
    outpath = '/data/leuven/317/vsc31786/FIG_tmp'
    PEATCLSM = LDAS_io('xhourly', exp=exp, domain=domain)
    exp = 'SMAP_EASEv2_M36_NORTH_DET2_CLSM'
    domain = 'SMAP_EASEv2_M36_NORTH'
    CLSM = LDAS_io('xhourly', exp=exp, domain=domain)

    #cci_version = 'v03.3'
    cci_version = 'v04.4'
    # CCI
    fname = '/scratch/leuven/317/vsc31786/CCI/PASSIVE_' + cci_version + '_timeseries.nc'
    # fname = '/mnt/vsc_scratch/CCI/PASSIVE_v04.4_timeseries.nc'
    CCI_PASSIVE = xr.open_dataset(fname)
    fname = '/scratch/leuven/317/vsc31786/CCI/ACTIVE_' + cci_version + '_timeseries.nc'
    CCI_ACTIVE = xr.open_dataset(fname)
    fname = '/scratch/leuven/317/vsc31786/CCI/COMBINED_' + cci_version + '_timeseries.nc'
    CCI_COMBINED = xr.open_dataset(fname)

    for lat in lats:
        for lon in lons:
            col, row = PEATCLSM.grid.lonlat2colrow(lon, lat, domain=True)
            title = ''

            fontsize = 12

            #PEATCLSM.timeseries['sfmc']

            ts_obs_PEATCLSM = PEATCLSM.read_ts('sfmc', lon, lat, lonlat=True)
            ts_obs_PEATCLSM.name = 'sfmc PEATCLSM'
            ts_obs_CLSM = CLSM.read_ts('sfmc', lon, lat, lonlat=True)
            ts_obs_CLSM.name = 'sfmc CLSM'
            #ts_obs_CCI_PASSIVE = CCI_PASSIVE.read_ts('sm', lon, lat, lonlat=True)
            ts_obs_CCI_PASSIVE = CCI_PASSIVE.sel(
                lat=lat, lon=lon, method='nearest').sm.to_series()
            ts_obs_CCI_PASSIVE.name = 'sm PASSIVE'
            #ts_obs_CCI_ACTIVE = CCI_ACTIVE.read_ts('sm', lon, lat, lonlat=True)
            ts_obs_CCI_ACTIVE = CCI_ACTIVE.sel(
                lat=lat, lon=lon, method='nearest').sm.to_series()
            ts_obs_CCI_ACTIVE.name = 'sm ACTIVE'
            #ts_obs_CCI_COMBINED = CCI_COMBINED.read_ts('sm', lon, lat, lonlat=True)
            ts_obs_CCI_COMBINED = CCI_COMBINED.sel(
                lat=lat, lon=lon, method='nearest').sm.to_series()
            ts_obs_CCI_COMBINED.name = 'sm COMBINED'

            ts_obs_PEATCLSM_daily = ts_obs_PEATCLSM.groupby(
                ts_obs_PEATCLSM.index.date).mean()
            ts_obs_CLSM_daily = ts_obs_CLSM.groupby(
                ts_obs_CLSM.index.date).mean()
            df = pd.concat(
                (ts_obs_PEATCLSM_daily, ts_obs_CLSM_daily, ts_obs_CCI_PASSIVE,
                 ts_obs_CCI_ACTIVE, ts_obs_CCI_COMBINED),
                axis=1).dropna()
            df_zscore = df.apply(zscore)

            if df.empty:
                continue

            # Fig 1
            fname = os.path.join(
                outpath, 'PEATCLSM_CCI' + cci_version + '_' + '%0.2f' % lat +
                '_' + '%0.2f' % lon + '.png')
            print fname

            f = plt.figure(figsize=(19, 13),
                           dpi=90,
                           facecolor='w',
                           edgecolor='k')
            ax1 = plt.subplot2grid((5, 6), (0, 0), colspan=4)
            csel = ts_obs_CLSM.name
            ax1.set_title(csel)
            df_zscore[csel].plot(ax=ax1,
                                 ylim=[-3, 3],
                                 xlim=['2010-01-01', '2015-01-01'],
                                 fontsize=fontsize,
                                 style=['.'])
            plt.xlabel('')
            plt.ylabel('zscore(sm)')

            ax2 = plt.subplot2grid((5, 6), (1, 0), colspan=4, sharex=ax1)
            csel = ts_obs_PEATCLSM.name
            ax2.set_title(csel)
            df_zscore[csel].plot(ax=ax2,
                                 ylim=[-3, 3],
                                 xlim=['2010-01-01', '2015-01-01'],
                                 fontsize=fontsize,
                                 style=['.'])
            #sitewtd.apply(zscore)[wtd](ax=ax2, ylim=[-3, 3], xlim=['2010-01-01', '2015-01-01'], fontsize=fontsize, style=['.'])
            plt.xlabel('')
            plt.ylabel('zscore(sm)')

            ax2 = plt.subplot2grid((5, 6), (2, 0), colspan=4, sharex=ax1)
            csel = ts_obs_CCI_PASSIVE.name
            ax2.set_title(csel)
            df_zscore[csel].plot(ax=ax2,
                                 ylim=[-3, 3],
                                 xlim=['2010-01-01', '2015-01-01'],
                                 fontsize=fontsize,
                                 style=['.'])
            plt.xlabel('')
            plt.ylabel('zscore(sm)')

            ax2 = plt.subplot2grid((5, 6), (3, 0), colspan=4, sharex=ax1)
            csel = ts_obs_CCI_ACTIVE.name
            ax2.set_title(csel)
            df_zscore[csel].plot(ax=ax2,
                                 ylim=[-3, 3],
                                 xlim=['2010-01-01', '2015-01-01'],
                                 fontsize=fontsize,
                                 style=['.'])
            plt.xlabel('')
            plt.ylabel('zscore(sm)')

            ax2 = plt.subplot2grid((5, 6), (4, 0), colspan=4, sharex=ax1)
            csel = ts_obs_CCI_COMBINED.name
            ax2.set_title(csel)
            df_zscore[csel].plot(ax=ax2,
                                 ylim=[-3, 3],
                                 xlim=['2010-01-01', '2015-01-01'],
                                 fontsize=fontsize,
                                 style=['.'])
            plt.xlabel('')
            plt.ylabel('zscore(sm)')

            ax2 = plt.subplot2grid((5, 6), (0, 4), rowspan=2, colspan=2)
            plt.plot(df[ts_obs_PEATCLSM.name], df[ts_obs_CLSM.name], '.')
            plt.xlabel(ts_obs_PEATCLSM.name)
            plt.ylabel(ts_obs_CLSM.name)
            #plt.xlim(-3, 3)
            #plt.ylim(-3, 3)

            ax2 = plt.subplot2grid((5, 6), (2, 4), colspan=1)
            plt.plot(df_zscore[ts_obs_CLSM.name],
                     df_zscore[ts_obs_CCI_PASSIVE.name], '.')
            plt.xlabel(ts_obs_CLSM.name)
            plt.ylabel(ts_obs_CCI_PASSIVE.name)
            plt.xlim(-3, 3)
            plt.ylim(-3, 3)

            ax2 = plt.subplot2grid((5, 6), (3, 4), colspan=1)
            plt.plot(df_zscore[ts_obs_CLSM.name],
                     df_zscore[ts_obs_CCI_ACTIVE.name], '.')
            plt.xlabel(ts_obs_CLSM.name)
            plt.ylabel(ts_obs_CCI_ACTIVE.name)
            plt.xlim(-3, 3)
            plt.ylim(-3, 3)

            ax2 = plt.subplot2grid((5, 6), (4, 4), colspan=1)
            plt.plot(df_zscore[ts_obs_CLSM.name],
                     df_zscore[ts_obs_CCI_COMBINED.name], '.')
            plt.xlabel(ts_obs_CLSM.name)
            plt.ylabel(ts_obs_CCI_COMBINED.name)
            plt.xlim(-3, 3)
            plt.ylim(-3, 3)

            ax2 = plt.subplot2grid((5, 6), (2, 5), colspan=1)
            plt.plot(df_zscore[ts_obs_PEATCLSM.name],
                     df_zscore[ts_obs_CCI_PASSIVE.name], '.')
            plt.xlabel(ts_obs_PEATCLSM.name)
            plt.ylabel(ts_obs_CCI_PASSIVE.name)
            plt.xlim(-3, 3)
            plt.ylim(-3, 3)

            ax2 = plt.subplot2grid((5, 6), (3, 5), colspan=1)
            plt.plot(df_zscore[ts_obs_PEATCLSM.name],
                     df_zscore[ts_obs_CCI_ACTIVE.name], '.')
            plt.xlabel(ts_obs_PEATCLSM.name)
            plt.ylabel(ts_obs_CCI_ACTIVE.name)
            plt.xlim(-3, 3)
            plt.ylim(-3, 3)

            ax2 = plt.subplot2grid((5, 6), (4, 5), colspan=1)
            plt.plot(df_zscore[ts_obs_PEATCLSM.name],
                     df_zscore[ts_obs_CCI_COMBINED.name], '.')
            plt.xlabel(ts_obs_PEATCLSM.name)
            plt.ylabel(ts_obs_CCI_COMBINED.name)
            plt.xlim(-3, 3)
            plt.ylim(-3, 3)

            plt.tight_layout()

            plt.savefig(fname, dpi=f.dpi)
            plt.close()
            #plt.show()
    '''
Exemplo n.º 4
0
def plot_timeseries():

    # Colorado
    # lat = 39.095962936
    # lon = -106.918945312

    # Nebraska
    # lat = 41.203456192
    # lon = -102.249755859

    # New Mexico
    # lat = 31.522361470
    # lon = -108.528442383

    # Oklahoma
    lat = 35.205233348
    lon = -97.910156250

    exp = 'SMAP_EASEv2_M36_NORTH_SCA_SMOSrw_DA'
    domain = 'SMAP_EASEv2_M36_NORTH'

    cal = LDAS_io('incr', 'US_M36_SMOS_DA_calibrated_scaled')
    uncal = LDAS_io('incr', 'US_M36_SMOS_DA_nocal_scaled_pentadal')

    incr_var_cal = (cal.timeseries['srfexc'] + cal.timeseries['rzexc'] -
                    cal.timeseries['catdef']).var(dim='time').values
    incr_var_uncal = (uncal.timeseries['srfexc'] + uncal.timeseries['rzexc'] -
                      uncal.timeseries['catdef']).var(dim='time').values

    col, row = LDAS_io().grid.lonlat2colrow(lon, lat, domain=True)

    title = 'increment variance (calibrated): %.2f        increment variance (uncalibrated): %.2f' % (
        incr_var_cal[row, col], incr_var_uncal[row, col])
    # title = ''

    fontsize = 12

    cal = LDAS_io('ObsFcstAna', 'US_M36_SMOS_DA_calibrated_scaled')
    uncal = LDAS_io('ObsFcstAna', 'US_M36_SMOS_DA_nocal_scaled_pentadal')
    orig = LDAS_io('ObsFcstAna', 'US_M36_SMOS_noDA_unscaled')

    ts_obs_cal = cal.read_ts('obs_obs', lon, lat, species=3, lonlat=True)
    ts_obs_cal.name = 'Tb obs (calibrated)'
    ts_obs_uncal = uncal.read_ts('obs_obs', lon, lat, species=3, lonlat=True)
    ts_obs_uncal.name = 'Tb obs (uncalibrated)'

    ts_obs_orig = orig.read_ts('obs_obs', lon, lat, species=3, lonlat=True)
    ts_obs_orig.name = 'Tb obs (uncalibrated, unscaled)'

    ts_fcst_cal = cal.read_ts('obs_fcst', lon, lat, species=3, lonlat=True)
    ts_fcst_cal.name = 'Tb fcst (calibrated)'
    ts_fcst_uncal = uncal.read_ts('obs_fcst', lon, lat, species=3, lonlat=True)
    ts_fcst_uncal.name = 'Tb fcst (uncalibrated)'

    df = pd.concat(
        (ts_obs_cal, ts_obs_uncal, ts_obs_orig, ts_fcst_cal, ts_fcst_uncal),
        axis=1).dropna()

    plt.figure(figsize=(19, 8))

    ax1 = plt.subplot(211)
    df.plot(ax=ax1,
            ylim=[140, 300],
            xlim=['2010-01-01', '2017-01-01'],
            fontsize=fontsize,
            style=['-', '--', ':', '-', '--'],
            linewidth=2)
    plt.xlabel('')
    plt.title(title, fontsize=fontsize + 2)

    cols = df.columns.values
    for i, col in enumerate(df):
        df[col] = calc_anomaly(df[col], method='ma', longterm=True).values
        if i < 3:
            cols[i] = col[0:7] + 'anomaly ' + col[7::]
        else:
            cols[i] = col[0:7] + ' anomaly' + col[7::]
    df.columns = cols
    df.dropna(inplace=True)

    ax2 = plt.subplot(212, sharex=ax1)
    df.plot(ax=ax2,
            ylim=[-60, 60],
            xlim=['2010-01-01', '2017-01-01'],
            fontsize=fontsize,
            style=['-', '--', ':', '-', '--'],
            linewidth=2)
    plt.xlabel('')

    plt.tight_layout()
    plt.show()
Exemplo n.º 5
0
species = ObsFcstAna.timeseries['species'].values

ds = ncfile_init(result_file, lats[:, 0], lons[0, :], species, tags)

# [col, row] = get_M09_ObsFcstAna(ObsFcstAna,lon,lat)
# [col, row] = get_M09_ObsFcstAna(ObsFcstAna,lons.min()+2,lats.min()+2)
# col = col%4

for row in range(poros.shape[0]):
    print("row: " + str(row))
    for col in range(poros.shape[1]):
        if poros[row, col] > 0.6:
            for i_spc, spc in enumerate(species):
                [col_obs, row_obs] = get_M09_ObsFcstAna(ObsFcstAna, col, row, lonlat=False)
                ts_sfmc = lsm.read_ts('sfmc', col, row, lonlat=False)
                ts_tp1 = lsm.read_ts('tp1', col, row, lonlat=False)
                ts_obsobs = ObsFcstAna.read_ts('obs_obs', col_obs, row_obs, species=i_spc + 1, lonlat=False)
                ts_obsobs.name = 'obsobs'

                df = pd.concat((ts_sfmc, ts_tp1, ts_obsobs), axis=1)
                ts_emissivity = df['obsobs'] / df['tp1']

                df = pd.concat((ts_sfmc, ts_emissivity), axis=1)
                if not np.isnan(df.corr().values[0, 1]):
                    ds.variables['pearsonR'][row, col, i_spc] = df.corr().values[0, 1]

                # pearsonr([0]['obs_obs'][i_spc] - [0]['obs_fcst'][i_spc]).mean(dim='time').values
                # tmp = [0]['obs_obs'][i_spc].values
                # np.place(tmp, ~np.isnan(tmp), 1.)
                # np.place(tmp, np.isnan(tmp), 0.)
Exemplo n.º 6
0
# natural
lon = 138.6
lat = -5.1
lon = 144.7
lat = -6.8

#sebangau forest
lon = 114.2
lat = -3
# Drained Indonesia
lon = 103
lat = -0.75
[col, row] = lsm.grid.lonlat2colrow(lon, lat, domain=True)

sfmc = lsm.read_ts('sfmc', col, row, lonlat=False)
zbar = lsm.read_ts('zbar', col, row, lonlat=False)

df = pd.concat((sfmc, zbar), axis=1)

fig = plt.figure(figsize=(20, 10))
fontsize = 18
ax1 = plt.subplot2grid((2, 1), (0, 0), rowspan=1, colspan=1, fig=None)
df['sfmc'].plot(ax=ax1,
                style=style,
                markersize=5,
                fontsize=fontsize + 8,
                linewidth=2)
plt.ylabel('Surface moisture content (vol/vol)', fontsize=18)
plt.legend(fontsize=16)
plt.xticks(fontsize=18)