Esempio n. 1
0
def get_xy(ll_ul, ll_lr):
    N6 = e2.Ease2Transform("EASE2_N6.25km")
    N3 = e2.Ease2Transform("EASE2_N3.125km")
    # get x,y for 6.25
    row, col = N6.geographic_to_grid(ll_ul[0], ll_ul[1])
    x6ul, y6ul = N6.grid_to_map(row, col)
    row, col = N6.geographic_to_grid(ll_lr[0], ll_lr[1])
    x6lr, y6lr = N6.grid_to_map(row, col)
    # get x,y for 3.125
    row, col = N6.geographic_to_grid(ll_ul[0], ll_ul[1])
    x3ul, y3ul = N6.grid_to_map(row, col)
    row, col = N6.geographic_to_grid(ll_lr[0], ll_lr[1])
    x3lr, y3lr = N6.grid_to_map(row, col)
    list_6 = [x6ul, y6ul, x6lr, y6lr]
    list_3 = [x3ul, y3ul, x3lr, y3lr]
    return list_3
Esempio n. 2
0
def plot_a_day(file1, file2, path, token):
    '''read tb,x,y data from final files,
    with the purpose of plotting.'''
    os.chdir(path + '/data/Subsetted_19H')
    fid_19H = Dataset(file1, "r", format="NETCDF4")
    os.chdir(path + '/data/Subsetted_37H')
    fid_37H = Dataset(file2, "r", format="NETCDF4")
    x = fid_19H.variables['x'][:]
    y = fid_37H.variables['y'][:]
    tb_19H = fid_19H.variables['TB'][:]
    tb_37H = fid_37H.variables['TB'][:]
    tb_37H = block_reduce(tb_37H, block_size = (1,2,2), func = np.mean)
    tb= tb_19H  - tb_37H
    lats = np.zeros((len(y), len(x)), dtype=np.float64)
    lons = np.zeros((len(y), len(x)), dtype=np.float64)
    grid = e2.Ease2Transform(gridname=fid_19H.variables["crs"].long_name)
    for i, xi in enumerate(x):
        for j, yj in enumerate(y):
            row, col = grid.map_to_grid(xi, yj)
            lat, lon = grid.grid_to_geographic(row, col)
            lats[j, i] = lat
            lons[j, i] = lon
    one_day = tb[0,:,:]
    df = pd.DataFrame(columns = ['lat', 'lon', 'swe'])
    for i in range(len(one_day[:,1])):
        for j in range(1,:):
            df = df.append({'lat': lats[i][j], 'lon': lons[i][j], 'swe':one_day[i][j]}, ignore_index = True)
Esempio n. 3
0
def get_xy(ll_ul, ll_lr):
    '''Use NSIDC scripts to convert user inputted
    lat/lon into Ease grid 2.0 coordinates'''
    N6 = e2.Ease2Transform("EASE2_N6.25km")
    N3 = e2.Ease2Transform("EASE2_N3.125km")
    # get x,y for 6.25
    row, col = N6.geographic_to_grid(ll_ul[0], ll_ul[1])
    x6ul, y6ul = N6.grid_to_map(row,col)
    row, col = N6.geographic_to_grid(ll_lr[0], ll_lr[1])
    x6lr, y6lr = N6.grid_to_map(row, col)
    # get x,y for 3.125
    row, col = N6.geographic_to_grid(ll_ul[0], ll_ul[1])
    x3ul, y3ul = N6.grid_to_map(row, col)
    row, col = N6.geographic_to_grid(ll_lr[0], ll_lr[1])
    x3lr, y3lr = N6.grid_to_map(row, col)
    list_6 = [x6ul, y6ul, x6lr, y6lr]
    list_3 = [x3ul, y3ul, x3lr, y3lr]
    return list_3
Esempio n. 4
0
def plot_a_day(file1, file2, path, token):
    '''read tb,x,y data from final files,
    with the purpose of plotting.'''
    os.chdir(path + '/data/Subsetted_19H')
    fid_19H = Dataset(file1, "r", format="NETCDF4")
    os.chdir(path + '/data/Subsetted_37H')
    fid_37H = Dataset(file2, "r", format="NETCDF4")
    x = fid_19H.variables['x'][:]
    y = fid_37H.variables['y'][:]
    tb_19H = fid_19H.variables['TB'][:]
    tb_37H = fid_37H.variables['TB'][:]
    tb_37H = block_reduce(tb_37H, block_size=(1, 2, 2), func=np.mean)
    tb = tb_19H - tb_37H
    lats = np.zeros((len(y), len(x)), dtype=np.float64)
    lons = np.zeros((len(y), len(x)), dtype=np.float64)
    grid = e2.Ease2Transform(gridname=fid_19H.variables["crs"].long_name)
    for i, xi in enumerate(x):
        for j, yj in enumerate(y):
            row, col = grid.map_to_grid(xi, yj)
            lat, lon = grid.grid_to_geographic(row, col)
            lats[j, i] = lat
            lons[j, i] = lon
    one_day = tb[0, :, :]
    df = pd.DataFrame(columns=['lat', 'lon', 'swe'])
    for i in range(len(one_day[:, 1])):
        for j in range(len(one_day[1, :])):
            df = df.append(
                {
                    'lat': lats[i][j],
                    'lon': lons[i][j],
                    'swe': one_day[i][j]
                },
                ignore_index=True)
    df_to_geojson(df,
                  filename='swe_1day.geojson',
                  properties=['swe'],
                  lat='lat',
                  lon='lon')
    measure = 'swe'
    color_breaks = [
        round(df[measure].quantile(q=x * 0.1), 2) for x in range(1, 9)
    ]
    color_stops = create_color_stops(color_breaks, colors='YlGnBu')

    # Create the viz from the dataframe
    viz = CircleViz('swe_1day.geojson',
                    access_token=token,
                    color_property="swe",
                    color_stops=color_stops,
                    center=(-154, 67),
                    zoom=3,
                    below_layer='waterway-label')

    viz.show()