Example #1
0
def plot_figure_7(gis_path=gis_path, save=True):
    from PW_stations import produce_geo_gnss_solved_stations
    from aux_gps import geo_annotate
    from ims_procedures import produce_geo_ims
    import matplotlib.pyplot as plt
    ax = plot_israel_map(gis_path)
    print('getting IMS temperature stations metadata...')
    ims = produce_geo_ims(path=gis_path, freq='10mins', plot=False)
    ims.plot(ax=ax, color='red', edgecolor='black', alpha=0.5)
    # ims, gps = produce_geo_df(gis_path=gis_path, plot=False)
    print('getting solved GNSS israeli stations metadata...')
    gps = produce_geo_gnss_solved_stations(path=gis_path, plot=False)
    gps.plot(ax=ax, color='green', edgecolor='black')
    gps_stations = [x for x in gps.index]
    to_plot_offset = ['mrav', 'klhv']
    [gps_stations.remove(x) for x in to_plot_offset]
    gps_normal_anno = gps.loc[gps_stations, :]
    gps_offset_anno = gps.loc[to_plot_offset, :]
    geo_annotate(ax,
                 gps_normal_anno.lon,
                 gps_normal_anno.lat,
                 gps_normal_anno.index,
                 xytext=(3, 3),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=None,
                 colorupdown=False)
    geo_annotate(ax,
                 gps_offset_anno.lon,
                 gps_offset_anno.lat,
                 gps_offset_anno.index,
                 xytext=(4, -6),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=None,
                 colorupdown=False)
    #    plt.legend(['IMS stations', 'GNSS stations'],
    #           prop={'size': 10}, bbox_to_anchor=(-0.15, 1.0),
    #           title='Stations')
    #    plt.legend(['IMS stations', 'GNSS stations'],
    #               prop={'size': 10}, loc='upper left')
    plt.legend(['IMS stations', 'GNSS stations'], loc='upper left')
    plt.tight_layout()
    plt.subplots_adjust(bottom=0.05)
    caption(
        '24 GNSS stations from the israeli network(green) and 88 IMS 10 mins automated stations(red).'
    )
    filename = 'gnss_ims_stations_map.png'
    if save:
        plt.savefig(savefig_path / filename, bbox_inches='tight')
    return ax
def plot_stations_and_gps(path=aero_path, gis_path=gis_path):
    from PW_from_gps_figures import plot_israel_map
    from PW_stations import produce_geo_gnss_solved_stations
    from aux_gps import geo_annotate
    ax = plot_israel_map(gis_path=gis_path)
    aero = produce_geo_aeronet(path=path, gis_path=gis_path)
    aero.plot(ax=ax, color='blue', edgecolor='black', marker='^')
    geo_annotate(ax,
                 aero.lon,
                 aero.lat,
                 aero.index,
                 xytext=(4, -6),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=None,
                 colorupdown=False)
    gps = produce_geo_gnss_solved_stations(path=gis_path, plot=False)
    gps.plot(ax=ax, color='green', edgecolor='black', marker='s')
    gps_stations = [x for x in gps.index]
    to_plot_offset = ['mrav', 'klhv']
    [gps_stations.remove(x) for x in to_plot_offset]
    gps_normal_anno = gps.loc[gps_stations, :]
    gps_offset_anno = gps.loc[to_plot_offset, :]
    geo_annotate(ax,
                 gps_normal_anno.lon,
                 gps_normal_anno.lat,
                 gps_normal_anno.index,
                 xytext=(3, 3),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=None,
                 colorupdown=False)
    geo_annotate(ax,
                 gps_offset_anno.lon,
                 gps_offset_anno.lat,
                 gps_offset_anno.index,
                 xytext=(4, -6),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=None,
                 colorupdown=False)
    return
Example #3
0
def plot_line_from_dsea_opera_to_coast(dem_path=dem_path,
                                       work_path=work_yuval):
    from PW_from_gps_figures import plot_israel_map
    from PW_stations import produce_geo_gnss_solved_stations
    from ims_procedures import plot_closest_line_from_point_to_israeli_coast
    from shapely.geometry import Point
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    from aux_gps import geo_annotate
    import xarray as xr
    # df = produce_geo_gnss_solved_stations(plot=False)
    gnss = xr.load_dataset(work_path / 'DSEA_PWV_GNSS_2014-08.nc')
    fig = plt.figure(figsize=(7, 15))
    ax = fig.add_subplot(projection=ccrs.PlateCarree())  # plt.subplot(122)
    # fig, ax = plt.subplots(projection=ccrs.PlateCarree())
    extent = [34.5, 35.75, 30.9, 31.89]
    ax.set_extent(extent)
    ax = plot_israel_map(ax=ax)
    cmap = plt.get_cmap('terrain', 41)
    dem = xr.open_dataarray(dem_path / 'israel_dem_250_500.nc')
    # dem = xr.open_dataarray(dem_path / 'israel_dem_500_1000.nc')
    dem = dem.sel(lat=slice(29.2, 32.5), lon=slice(34, 36.3))
    fg = dem.plot.imshow(ax=ax,
                         alpha=0.5,
                         cmap=cmap,
                         vmin=dem.min(),
                         vmax=dem.max(),
                         add_colorbar=False)
    #    scale_bar(ax_map, 50)
    cbar_kwargs = {'fraction': 0.1, 'aspect': 50, 'pad': 0.03}
    cb = plt.colorbar(fg, **cbar_kwargs)
    cb.set_label(label='meters above sea level', size=14, weight='normal')
    cb.ax.tick_params(labelsize=14)

    soi_point = Point(gnss['pwv-soi'].lon, gnss['pwv-soi'].lat)
    axis_point = Point(gnss['pwv-axis'].lon, gnss['pwv-axis'].lat)
    opera = Point(35.3725, 31.3177)
    ds1 = plot_closest_line_from_point_to_israeli_coast(soi_point,
                                                        ax=ax,
                                                        color='k')
    print('{} km of soi-point to coast.'.format(ds1))
    ax.plot(*opera.xy, marker='o', markersize=5, color='k')
    ax.plot(*soi_point.xy, marker='o', markersize=5, color='k')
    ax.plot(*axis_point.xy, marker='o', markersize=5, color='k')
    geo_annotate(ax, [soi_point.x], [soi_point.y],
                 ['GNSS-SOI ({:.0f} km)'.format(ds1)],
                 xytext=(4, -6),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=14,
                 colorupdown=False)
    ds3 = plot_closest_line_from_point_to_israeli_coast(axis_point,
                                                        ax=ax,
                                                        color='k')
    print('{} km of axis-point to coast.'.format(ds3))
    geo_annotate(ax, [axis_point.x], [axis_point.y],
                 ['GNSS-AXIS ({:.0f} km)'.format(ds3)],
                 xytext=(4, -6),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=14,
                 colorupdown=False)
    ds2 = plot_closest_line_from_point_to_israeli_coast(opera,
                                                        ax=ax,
                                                        color='k')
    print('{} km of OPERA to coast.'.format(ds2))
    geo_annotate(ax, [opera.x], [opera.y],
                 ['Opera-pt. ({:.0f} km)'.format(ds2)],
                 xytext=(4, -6),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=14,
                 colorupdown=False)
    ax.set_xticks([34, 35, 36])
    ax.set_yticks([29.5, 30, 30.5, 31, 31.5, 32, 32.5])
    ax.tick_params(top=True,
                   bottom=True,
                   left=True,
                   right=True,
                   direction='out',
                   labelsize=14)
    return ax
Example #4
0
def plot_figure_rinex_with_map(path=work_yuval,
                               gis_path=gis_path,
                               dem_path=dem_path,
                               save=True):
    from aux_gps import gantt_chart
    import xarray as xr
    import pandas as pd
    import geopandas as gpd
    from PW_stations import produce_geo_gnss_solved_stations
    from aux_gps import geo_annotate
    from ims_procedures import produce_geo_ims
    from matplotlib.colors import ListedColormap
    fig = plt.figure(figsize=(20, 10))
    grid = plt.GridSpec(1, 2, width_ratios=[5, 2], wspace=0.1)
    ax_gantt = fig.add_subplot(grid[0, 0])  # plt.subplot(221)
    ax_map = fig.add_subplot(grid[0, 1])  # plt.subplot(122)
    #    fig, ax = plt.subplots(1, 2, sharex=False, sharey=False, figsize=(20, 6))
    # RINEX gantt chart:
    ds = xr.open_dataset(path / 'GNSS_PW.nc')
    just_pw = [x for x in ds if 'error' not in x]
    ds = ds[just_pw]
    da = ds.to_array('station')
    da['station'] = [x.upper() for x in da.station.values]
    ds = da.to_dataset('station')
    title = 'RINEX files availability for the Israeli GNSS stations'
    ax_gantt = gantt_chart(ds, ax=ax_gantt, fw='normal', title='')
    # Israel gps ims map:
    ax_map = plot_israel_map(gis_path=gis_path, ax=ax_map)
    # overlay with dem data:
    cmap = plt.get_cmap('terrain', 41)
    dem = xr.open_dataarray(dem_path / 'israel_dem_250_500.nc')
    # dem = xr.open_dataarray(dem_path / 'israel_dem_500_1000.nc')
    fg = dem.plot.imshow(ax=ax_map,
                         alpha=0.5,
                         cmap=cmap,
                         vmin=dem.min(),
                         vmax=dem.max(),
                         add_colorbar=False)
    cbar_kwargs = {'fraction': 0.1, 'aspect': 50, 'pad': 0.03}
    cb = plt.colorbar(fg, **cbar_kwargs)
    cb.set_label(label='meters above sea level', size=8, weight='normal')
    cb.ax.tick_params(labelsize=8)
    ax_map.set_xlabel('')
    ax_map.set_ylabel('')
    #    print('getting IMS temperature stations metadata...')
    #    ims = produce_geo_ims(path=gis_path, freq='10mins', plot=False)
    #    ims.plot(ax=ax_map, color='red', edgecolor='black', alpha=0.5)
    # ims, gps = produce_geo_df(gis_path=gis_path, plot=False)
    print('getting solved GNSS israeli stations metadata...')
    gps = produce_geo_gnss_solved_stations(path=gis_path, plot=False)
    gps.plot(ax=ax_map,
             color='black',
             edgecolor='black',
             marker='s',
             alpha=0.7,
             markersize=25)
    gps_stations = [x for x in gps.index]
    to_plot_offset = ['mrav', 'klhv', 'nzrt', 'katz', 'elro']
    [gps_stations.remove(x) for x in to_plot_offset]
    gps_normal_anno = gps.loc[gps_stations, :]
    gps_offset_anno = gps.loc[to_plot_offset, :]
    geo_annotate(ax_map,
                 gps_normal_anno.lon,
                 gps_normal_anno.lat,
                 gps_normal_anno.index.str.upper(),
                 xytext=(3, 3),
                 fmt=None,
                 c='k',
                 fw='normal',
                 fs=10,
                 colorupdown=False)
    geo_annotate(ax_map,
                 gps_offset_anno.lon,
                 gps_offset_anno.lat,
                 gps_offset_anno.index.str.upper(),
                 xytext=(4, -6),
                 fmt=None,
                 c='k',
                 fw='normal',
                 fs=10,
                 colorupdown=False)
    # plot bet-dagan:
    df = pd.Series([32.00, 34.81]).to_frame().T
    df.index = ['Beit Dagan']
    df.columns = ['lat', 'lon']
    bet_dagan = gpd.GeoDataFrame(df,
                                 geometry=gpd.points_from_xy(df.lon, df.lat),
                                 crs=gps.crs)
    bet_dagan.plot(ax=ax_map, color='black', edgecolor='black', marker='+')
    geo_annotate(ax_map,
                 bet_dagan.lon,
                 bet_dagan.lat,
                 bet_dagan.index,
                 xytext=(4, -6),
                 fmt=None,
                 c='k',
                 fw='normal',
                 fs=10,
                 colorupdown=False)
    plt.legend(['GNSS sites', 'radiosonde'], loc='upper left')
    fig.subplots_adjust(top=0.95,
                        bottom=0.11,
                        left=0.05,
                        right=0.95,
                        hspace=0.2,
                        wspace=0.2)
    # plt.legend(['IMS stations', 'GNSS stations'], loc='upper left')

    filename = 'rinex_israeli_gnss_map.png'
    caption(
        'RINEX files availability for the Israeli GNSS station network at the SOPAC/GARNER website'
    )
    if save:
        plt.savefig(savefig_path / filename, bbox_inches='tight')
    return fig
Example #5
0
def plot_grp_anomlay_heatmap(load_path=work_yuval,
                             gis_path=gis_path,
                             thresh=None,
                             grp='hour',
                             remove_grp=None,
                             season=None,
                             n_clusters=4,
                             save=True,
                             title=False):
    import xarray as xr
    import seaborn as sns
    import numpy as np
    from PW_stations import group_anoms_and_cluster
    from aux_gps import geo_annotate
    import matplotlib.pyplot as plt
    import pandas as pd
    from matplotlib.colors import ListedColormap
    from palettable.scientific import diverging as divsci
    from PW_stations import produce_geo_gnss_solved_stations
    div_cmap = divsci.Vik_20.mpl_colormap
    dem_path = load_path / 'AW3D30'

    def weighted_average(grp_df, weights_col='weights'):
        return grp_df._get_numeric_data().multiply(
            grp_df[weights_col], axis=0).sum() / grp_df[weights_col].sum()

    df, labels_sorted, weights = group_anoms_and_cluster(load_path=load_path,
                                                         thresh=thresh,
                                                         grp=grp,
                                                         season=season,
                                                         n_clusters=n_clusters,
                                                         remove_grp=remove_grp)
    # create figure and subplots axes:
    fig = plt.figure(figsize=(15, 10))
    if title:
        if season is not None:
            fig.suptitle(
                'Precipitable water {}ly anomalies analysis for {} season'.
                format(grp, season))
        else:
            fig.suptitle(
                'Precipitable water {}ly anomalies analysis (Weighted KMeans {} clusters)'
                .format(grp, n_clusters))
    grid = plt.GridSpec(2,
                        2,
                        width_ratios=[3, 2],
                        height_ratios=[4, 1],
                        wspace=0.1,
                        hspace=0)
    ax_heat = fig.add_subplot(grid[0, 0])  # plt.subplot(221)
    ax_group = fig.add_subplot(grid[1, 0])  # plt.subplot(223)
    ax_map = fig.add_subplot(grid[0:, 1])  # plt.subplot(122)
    # get the camp and zip it to groups and produce dictionary:
    cmap = plt.get_cmap("Accent")
    cmap = qualitative_cmap(n_clusters)
    # cmap = plt.get_cmap("Set2_r")
    # cmap = ListedColormap(cmap.colors[::-1])
    groups = list(set(labels_sorted.values()))
    palette = dict(zip(groups, [cmap(x) for x in range(len(groups))]))
    label_cmap_dict = dict(
        zip(labels_sorted.keys(),
            [palette[x] for x in labels_sorted.values()]))
    cm = ListedColormap([x for x in palette.values()])
    # plot heatmap and colorbar:
    cbar_ax = fig.add_axes([0.57, 0.24, 0.01, 0.69])  #[left, bottom, width,
    # height]
    ax_heat = sns.heatmap(df.T,
                          center=0.0,
                          cmap=div_cmap,
                          yticklabels=True,
                          ax=ax_heat,
                          cbar_ax=cbar_ax,
                          cbar_kws={'label': '[mm]'})
    # activate top ticks and tickslabales:
    ax_heat.xaxis.set_tick_params(top='on', labeltop='on')
    # emphasize the yticklabels (stations):
    ax_heat.yaxis.set_tick_params(left='on')
    ax_heat.set_yticklabels(ax_heat.get_ymajorticklabels(),
                            fontweight='bold',
                            fontsize=10)
    # paint ytick labels with categorical cmap:
    boxes = [
        dict(facecolor=x, boxstyle="square,pad=0.7", alpha=0.6)
        for x in label_cmap_dict.values()
    ]
    ylabels = [x for x in ax_heat.yaxis.get_ticklabels()]
    for label, box in zip(ylabels, boxes):
        label.set_bbox(box)
    # rotate xtick_labels:
#    ax_heat.set_xticklabels(ax_heat.get_xticklabels(), rotation=0,
#                            fontsize=10)
# plot summed groups (with weights):
    df_groups = df.T
    df_groups['groups'] = pd.Series(labels_sorted)
    df_groups['weights'] = weights
    df_groups = df_groups.groupby('groups').apply(weighted_average)
    df_groups.drop(['groups', 'weights'], axis=1, inplace=True)
    df_groups.T.plot(ax=ax_group, linewidth=2.0, legend=False, cmap=cm)
    if grp == 'hour':
        ax_group.set_xlabel('hour (UTC)')
    ax_group.grid()
    group_limit = ax_heat.get_xlim()
    ax_group.set_xlim(group_limit)
    ax_group.set_ylabel('[mm]')
    # set ticks and align with heatmap axis (move by 0.5):
    ax_group.set_xticks(df.index.values)
    offset = 1
    ax_group.xaxis.set(ticks=np.arange(
        offset / 2.,
        max(df.index.values) + 1 - min(df.index.values), offset),
                       ticklabels=df.index.values)
    # move the lines also by 0.5 to align with heatmap:
    lines = ax_group.lines  # get the lines
    [x.set_xdata(x.get_xdata() - min(df.index.values) + 0.5) for x in lines]
    # plot israel map:
    ax_map = plot_israel_map(gis_path=gis_path, ax=ax_map)
    # overlay with dem data:
    cmap = plt.get_cmap('terrain', 41)
    dem = xr.open_dataarray(dem_path / 'israel_dem_250_500.nc')
    # dem = xr.open_dataarray(dem_path / 'israel_dem_500_1000.nc')
    im = dem.plot.imshow(ax=ax_map,
                         alpha=0.5,
                         cmap=cmap,
                         vmin=dem.min(),
                         vmax=dem.max(),
                         add_colorbar=False)
    cbar_kwargs = {'fraction': 0.1, 'aspect': 50, 'pad': 0.03}
    cb = fig.colorbar(im, ax=ax_map, **cbar_kwargs)
    # cb = plt.colorbar(fg, **cbar_kwargs)
    cb.set_label(label='meters above sea level', size=8, weight='normal')
    cb.ax.tick_params(labelsize=8)
    ax_map.set_xlabel('')
    ax_map.set_ylabel('')
    print('getting solved GNSS israeli stations metadata...')
    gps = produce_geo_gnss_solved_stations(path=gis_path, plot=False)
    gps.index = gps.index.str.upper()
    gps = gps.loc[[x for x in df.columns], :]
    gps['group'] = pd.Series(labels_sorted)
    gps.plot(ax=ax_map,
             column='group',
             categorical=True,
             marker='o',
             edgecolor='black',
             cmap=cm,
             s=100,
             legend=True,
             alpha=1.0,
             legend_kwds={
                 'prop': {
                     'size': 10
                 },
                 'fontsize': 14,
                 'loc': 'upper left',
                 'title': 'clusters'
             })
    # ax_map.set_title('Groupings of {}ly anomalies'.format(grp))
    # annotate station names in map:
    geo_annotate(ax_map,
                 gps.lon,
                 gps.lat,
                 gps.index,
                 xytext=(6, 6),
                 fmt=None,
                 c='k',
                 fw='bold',
                 fs=10,
                 colorupdown=False)
    #    plt.legend(['IMS stations', 'GNSS stations'],
    #           prop={'size': 10}, bbox_to_anchor=(-0.15, 1.0),
    #           title='Stations')
    #    plt.legend(prop={'size': 10}, loc='upper left')
    # plt.tight_layout()
    plt.subplots_adjust(top=0.92,
                        bottom=0.065,
                        left=0.065,
                        right=0.915,
                        hspace=0.19,
                        wspace=0.215)
    filename = 'pw_{}ly_anoms_{}_clusters_with_map.png'.format(grp, n_clusters)
    if save:
        #        plt.savefig(savefig_path / filename, bbox_inches='tight')
        plt.savefig(savefig_path / filename, orientation='landscape')
    return df