예제 #1
0
def track_on_bathy(Float, hpids, projection='cyl', bathy_file=None):
    """TODO: Docstring..."""

    __, idxs = Float.get_profiles(hpids, ret_idxs=True)
    lons = Float.lon_start[idxs]
    lats = Float.lat_start[idxs]

    llcrnrlon = np.floor(np.min(lons)) - 1.
    llcrnrlat = np.floor(np.min(lats)) - 1.
    urcrnrlon = np.ceil(np.max(lons)) + 1.
    urcrnrlat = np.ceil(np.max(lats)) + 1.

    lon_lat = np.array([llcrnrlon, urcrnrlon, llcrnrlat, urcrnrlat])

    lon_grid, lat_grid, bathy_grid = sandwell.read_grid(lon_lat, bathy_file)
    bathy_grid[bathy_grid > 0] = 0

    m = bm.Basemap(projection=projection,
                   llcrnrlon=llcrnrlon,
                   llcrnrlat=llcrnrlat,
                   urcrnrlon=urcrnrlon,
                   urcrnrlat=urcrnrlat,
                   lon_0=0.5 * (llcrnrlon + urcrnrlon),
                   lat_0=0.5 * (llcrnrlat + urcrnrlat),
                   resolution='f')

    plt.figure()
    x, y = m(lon_grid, lat_grid)
    m.pcolormesh(x, y, bathy_grid, cmap=plt.get_cmap('binary_r'))
    x, y = m(lons, lats)
    m.plot(x, y, 'r-', linewidth=2)

    m.fillcontinents()
    m.drawcoastlines()

    r = np.abs((urcrnrlon - llcrnrlon) / (urcrnrlat - llcrnrlat))

    if r > 1.:
        Nm = 8
        Np = max(3, np.round(Nm / r))
        orientation = 'horizontal'
    elif r < 1.:
        Np = 8
        Nm = max(3, np.round(Nm / r))
        orientation = 'vertical'
    else:
        Np = 4
        Nm = 4
        orientation = 'horizontal'

    parallels = np.round(np.linspace(llcrnrlat, urcrnrlat, Np), 1)
    m.drawparallels(parallels, labels=[1, 0, 0, 0])
    meridians = np.round(np.linspace(llcrnrlon, urcrnrlon, Nm), 1)
    m.drawmeridians(meridians, labels=[0, 0, 0, 1])

    cbar = plt.colorbar(orientation=orientation)
    cbar.set_label('Depth (m)')
예제 #2
0
def track_on_bathy(Float, hpids, projection='cyl', bathy_file=None):
    """TODO: Docstring..."""

    __, idxs = Float.get_profiles(hpids, ret_idxs=True)
    lons = Float.lon_start[idxs]
    lats = Float.lat_start[idxs]

    llcrnrlon = np.floor(np.min(lons)) - 1.
    llcrnrlat = np.floor(np.min(lats)) - 1.
    urcrnrlon = np.ceil(np.max(lons)) + 1.
    urcrnrlat = np.ceil(np.max(lats)) + 1.

    lon_lat = np.array([llcrnrlon, urcrnrlon, llcrnrlat, urcrnrlat])

    lon_grid, lat_grid, bathy_grid = sandwell.read_grid(lon_lat, bathy_file)
    bathy_grid[bathy_grid > 0] = 0

    m = bm.Basemap(projection=projection, llcrnrlon=llcrnrlon,
                   llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon,
                   urcrnrlat=urcrnrlat, lon_0=0.5*(llcrnrlon+urcrnrlon),
                   lat_0=0.5*(llcrnrlat+urcrnrlat), resolution='f')

    plt.figure()
    x, y = m(lon_grid, lat_grid)
    m.pcolormesh(x, y, bathy_grid, cmap=plt.get_cmap('binary_r'))
    x, y = m(lons, lats)
    m.plot(x, y, 'r-', linewidth=2)

    m.fillcontinents()
    m.drawcoastlines()

    r = np.abs((urcrnrlon-llcrnrlon)/(urcrnrlat-llcrnrlat))

    if r > 1.:
        Nm = 8
        Np = max(3, np.round(Nm/r))
        orientation = 'horizontal'
    elif r < 1.:
        Np = 8
        Nm = max(3, np.round(Nm/r))
        orientation = 'vertical'
    else:
        Np = 4
        Nm = 4
        orientation = 'horizontal'

    parallels = np.round(np.linspace(llcrnrlat, urcrnrlat, Np), 1)
    m.drawparallels(parallels, labels=[1, 0, 0, 0])
    meridians = np.round(np.linspace(llcrnrlon, urcrnrlon, Nm), 1)
    m.drawmeridians(meridians, labels=[0, 0, 0, 1])

    cbar = plt.colorbar(orientation=orientation)
    cbar.set_label('Depth (m)')
예제 #3
0
################

# %% Float trajectories FULL
# ------------------

lons = np.hstack([Float.lon_start for Float in [E76, E77]])
lats = np.hstack([Float.lat_start for Float in [E76, E77]])

llcrnrlon = np.floor(np.min(lons)) - 1.
llcrnrlat = np.floor(np.min(lats)) - 1.
urcrnrlon = np.ceil(np.max(lons)) + 1.
urcrnrlat = np.ceil(np.max(lats)) + 1.

lon_lat = np.array([llcrnrlon, urcrnrlon + 5, llcrnrlat - 5, urcrnrlat])

lon_grid, lat_grid, bathy_grid = sandwell.read_grid(lon_lat, bf)
bathy_grid[bathy_grid > 0] = 0
bathy_grid *= -1  # Convert to depth

m = bm.Basemap(projection='tmerc',
               llcrnrlon=llcrnrlon,
               llcrnrlat=llcrnrlat,
               urcrnrlon=urcrnrlon,
               urcrnrlat=urcrnrlat,
               lon_0=0.5 * (llcrnrlon + urcrnrlon),
               lat_0=0.5 * (llcrnrlat + urcrnrlat),
               resolution='f')

fig = plt.figure(figsize=(6.5, 3.5))
x, y = m(lon_grid, lat_grid)
m.pcolormesh(x,
예제 #4
0
def deployments():
    """This function gets data on all float deployments and plots them up."""

    files = glob('../../data/EM-APEX/allprof*.mat')
    FIDs = np.array([])  # Stores all float IDs.
    LONs = np.array([])
    LATs = np.array([])
    DATEs = np.array([])
    var_keys = ['flid', 'lon_gps', 'lat_gps', 'utc_dep']

    for f in files:

        data = io.loadmat(f, squeeze_me=True, variable_names=var_keys)
        fids = data['flid']
        dates = data['utc_dep']
        lons = data['lon_gps']
        lats = data['lat_gps']

        ufids = np.unique(fids[~np.isnan(fids)])

        FIDs = np.hstack((FIDs, ufids))

        for fid in ufids:
            flons = lons[fids == fid]
            flats = lats[fids == fid]
            fdates = dates[fids == fid]
            # Find the index of the
            idx = list(lons).index(filter(lambda x: ~np.isnan(x), lons)[0])
            LONs = np.hstack((LONs, flons[idx]))
            LATs = np.hstack((LATs, flats[idx]))
            DATEs = np.hstack((DATEs, fdates[idx]))


#    DTs = utils.datenum_to_datetime(DATEs)

# Plot map.

    llcrnrlon = np.floor(np.nanmin(LONs)) - 8.
    llcrnrlat = np.floor(np.nanmin(LATs)) - 1.
    urcrnrlon = np.ceil(np.nanmax(LONs)) + 1.
    urcrnrlat = np.ceil(np.nanmax(LATs)) + 8.

    lon_lat = np.array([llcrnrlon, -20., -80, urcrnrlat])

    lon_grid, lat_grid, bathy_grid = sandwell.read_grid(lon_lat)
    bathy_grid[bathy_grid > 0] = 0

    m = bm.Basemap(projection='tmerc',
                   llcrnrlon=llcrnrlon,
                   llcrnrlat=llcrnrlat,
                   urcrnrlon=urcrnrlon,
                   urcrnrlat=urcrnrlat,
                   lon_0=0.5 * (llcrnrlon + urcrnrlon),
                   lat_0=0.5 * (llcrnrlat + urcrnrlat),
                   resolution='f')

    plt.figure(figsize=(10, 10))
    x, y = m(lon_grid, lat_grid)
    m.pcolormesh(x, y, bathy_grid, cmap=plt.get_cmap('binary_r'))
    m.fillcontinents()
    m.drawcoastlines()

    parallels = np.array([-64, -54])
    m.drawparallels(parallels, labels=[1, 0, 0, 0])
    meridians = np.array([-105, -95, -85, -75, -65, -55, -45])
    m.drawmeridians(meridians, labels=[0, 0, 0, 1])

    x, y = m(LONs, LATs)
    m.scatter(x, y, s=60, c=DATEs, cmap=plt.get_cmap('spring'))

    save_name = '../figures/deployments.png'
    plt.savefig(save_name, bbox_inches='tight')
예제 #5
0
def spew_track(Floats, dt=12., fstr='test'):
    """Given a sequence of floats this function plots a time-lapse of
    their tracks onto bathymetry

    If you want it to work for one float you must put it in a sequence.
    """

    t_mins, t_maxs = [], []
    for Float in Floats:
        t_mins.append(np.min(Float.UTC_start))
        t_maxs.append(np.max(Float.UTC_start))

    t_min = np.min(t_mins)
    t_max = np.max(t_maxs)
    ti = np.arange(t_min, t_max, dt / 24.)
    lons = np.empty((ti.size, len(Floats)))
    lats = np.empty((ti.size, len(Floats)))

    for i, Float in enumerate(Floats):
        lon = Float.lon_start
        lat = Float.lat_start
        t = Float.UTC_start
        lons[:, i] = np.interp(ti, t, lon, left=np.nan, right=np.nan)
        lats[:, i] = np.interp(ti, t, lat, left=np.nan, right=np.nan)

    llcrnrlon = np.floor(np.nanmin(lons)) - 1.
    llcrnrlat = np.floor(np.nanmin(lats)) - 1.
    urcrnrlon = np.ceil(np.nanmax(lons)) + 1.
    urcrnrlat = np.ceil(np.nanmax(lats)) + 1.

    lon_lat = np.array([llcrnrlon, -30., -70, urcrnrlat])

    lon_grid, lat_grid, bathy_grid = sandwell.read_grid(lon_lat)
    bathy_grid[bathy_grid > 0] = 0

    m = bm.Basemap(projection='tmerc',
                   llcrnrlon=llcrnrlon,
                   llcrnrlat=llcrnrlat,
                   urcrnrlon=urcrnrlon,
                   urcrnrlat=urcrnrlat,
                   lon_0=0.5 * (llcrnrlon + urcrnrlon),
                   lat_0=0.5 * (llcrnrlat + urcrnrlat),
                   resolution='f')

    plt.figure(figsize=(10, 10))
    x, y = m(lon_grid, lat_grid)
    m.pcolormesh(x, y, bathy_grid, cmap=plt.get_cmap('binary_r'))
    m.fillcontinents()
    m.drawcoastlines()

    r = np.abs((urcrnrlon - llcrnrlon) / (urcrnrlat - llcrnrlat))

    if r > 1.:
        Nm = 8
        Np = max(3, np.round(Nm / r))

    elif r < 1.:
        Np = 8
        Nm = max(3, np.round(Nm / r))

    parallels = np.round(np.linspace(llcrnrlat, urcrnrlat, Np), 1)
    m.drawparallels(parallels, labels=[1, 0, 0, 0])
    meridians = np.round(np.linspace(llcrnrlon, urcrnrlon, Nm), 1)
    m.drawmeridians(meridians, labels=[0, 0, 0, 1])

    colours = ['b', 'r', 'm', 'c', 'g', 'y']

    for i, (time, lonr, latr) in enumerate(zip(ti, lons, lats)):

        print('Creating... {i:03d}'.format(i=i))
        plt.title(utils.datenum_to_datetime(time).strftime('%Y-%m-%d %H:%M'))

        for j, (lon, lat) in enumerate(zip(lonr, latr)):
            x, y = m(lon, lat)
            m.plot(x, y, '.', color=colours[j])

        if i == 0:
            leg_str = [str(Float.floatID) for Float in Floats]
            plt.legend(leg_str, loc=0)

        save_name = '../figures/animated_tracks/{}{i:03d}.png'.format(fstr,
                                                                      i=i)
        plt.savefig(save_name, bbox_inches='tight')

    print('Finished.')
예제 #6
0
def deployments():
    """This function gets data on all float deployments and plots them up."""

    files = glob('../../data/EM-APEX/allprof*.mat')
    FIDs = np.array([])  # Stores all float IDs.
    LONs = np.array([])
    LATs = np.array([])
    DATEs = np.array([])
    var_keys = ['flid', 'lon_gps', 'lat_gps', 'utc_dep']

    for f in files:

        data = io.loadmat(f, squeeze_me=True, variable_names=var_keys)
        fids = data['flid']
        dates = data['utc_dep']
        lons = data['lon_gps']
        lats = data['lat_gps']

        ufids = np.unique(fids[~np.isnan(fids)])

        FIDs = np.hstack((FIDs, ufids))

        for fid in ufids:
            flons = lons[fids == fid]
            flats = lats[fids == fid]
            fdates = dates[fids == fid]
            # Find the index of the
            idx = list(lons).index(filter(lambda x: ~np.isnan(x), lons)[0])
            LONs = np.hstack((LONs, flons[idx]))
            LATs = np.hstack((LATs, flats[idx]))
            DATEs = np.hstack((DATEs, fdates[idx]))

#    DTs = utils.datenum_to_datetime(DATEs)

    # Plot map.

    llcrnrlon = np.floor(np.nanmin(LONs)) - 8.
    llcrnrlat = np.floor(np.nanmin(LATs)) - 1.
    urcrnrlon = np.ceil(np.nanmax(LONs)) + 1.
    urcrnrlat = np.ceil(np.nanmax(LATs)) + 8.

    lon_lat = np.array([llcrnrlon, -20., -80, urcrnrlat])

    lon_grid, lat_grid, bathy_grid = sandwell.read_grid(lon_lat)
    bathy_grid[bathy_grid > 0] = 0

    m = bm.Basemap(projection='tmerc', llcrnrlon=llcrnrlon,
                   llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon,
                   urcrnrlat=urcrnrlat, lon_0=0.5*(llcrnrlon+urcrnrlon),
                   lat_0=0.5*(llcrnrlat+urcrnrlat), resolution='f')

    plt.figure(figsize=(10, 10))
    x, y = m(lon_grid, lat_grid)
    m.pcolormesh(x, y, bathy_grid, cmap=plt.get_cmap('binary_r'))
    m.fillcontinents()
    m.drawcoastlines()

    parallels = np.array([-64, -54])
    m.drawparallels(parallels, labels=[1, 0, 0, 0])
    meridians = np.array([-105, -95, -85, -75, -65, -55, -45])
    m.drawmeridians(meridians, labels=[0, 0, 0, 1])

    x, y = m(LONs, LATs)
    m.scatter(x, y, s=60, c=DATEs, cmap=plt.get_cmap('spring'))

    save_name = '../figures/deployments.png'
    plt.savefig(save_name, bbox_inches='tight')
예제 #7
0
def spew_track(Floats, dt=12., fstr='test'):
    """Given a sequence of floats this function plots a time-lapse of
    their tracks onto bathymetry

    If you want it to work for one float you must put it in a sequence.
    """

    t_mins, t_maxs = [], []
    for Float in Floats:
        t_mins.append(np.min(Float.UTC_start))
        t_maxs.append(np.max(Float.UTC_start))

    t_min = np.min(t_mins)
    t_max = np.max(t_maxs)
    ti = np.arange(t_min, t_max, dt/24.)
    lons = np.empty((ti.size, len(Floats)))
    lats = np.empty((ti.size, len(Floats)))

    for i, Float in enumerate(Floats):
        lon = Float.lon_start
        lat = Float.lat_start
        t = Float.UTC_start
        lons[:, i] = np.interp(ti, t, lon, left=np.nan, right=np.nan)
        lats[:, i] = np.interp(ti, t, lat, left=np.nan, right=np.nan)

    llcrnrlon = np.floor(np.nanmin(lons)) - 1.
    llcrnrlat = np.floor(np.nanmin(lats)) - 1.
    urcrnrlon = np.ceil(np.nanmax(lons)) + 1.
    urcrnrlat = np.ceil(np.nanmax(lats)) + 1.

    lon_lat = np.array([llcrnrlon, -30., -70, urcrnrlat])

    lon_grid, lat_grid, bathy_grid = sandwell.read_grid(lon_lat)
    bathy_grid[bathy_grid > 0] = 0

    m = bm.Basemap(projection='tmerc', llcrnrlon=llcrnrlon,
                   llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon,
                   urcrnrlat=urcrnrlat, lon_0=0.5*(llcrnrlon+urcrnrlon),
                   lat_0=0.5*(llcrnrlat+urcrnrlat), resolution='f')

    plt.figure(figsize=(10, 10))
    x, y = m(lon_grid, lat_grid)
    m.pcolormesh(x, y, bathy_grid, cmap=plt.get_cmap('binary_r'))
    m.fillcontinents()
    m.drawcoastlines()

    r = np.abs((urcrnrlon-llcrnrlon)/(urcrnrlat-llcrnrlat))

    if r > 1.:
        Nm = 8
        Np = max(3, np.round(Nm/r))

    elif r < 1.:
        Np = 8
        Nm = max(3, np.round(Nm/r))

    parallels = np.round(np.linspace(llcrnrlat, urcrnrlat, Np), 1)
    m.drawparallels(parallels, labels=[1, 0, 0, 0])
    meridians = np.round(np.linspace(llcrnrlon, urcrnrlon, Nm), 1)
    m.drawmeridians(meridians, labels=[0, 0, 0, 1])

    colours = ['b', 'r', 'm', 'c', 'g', 'y']

    for i, (time, lonr, latr) in enumerate(zip(ti, lons, lats)):

        print('Creating... {i:03d}'.format(i=i))
        plt.title(utils.datenum_to_datetime(time).strftime('%Y-%m-%d %H:%M'))

        for j, (lon, lat) in enumerate(zip(lonr, latr)):
            x, y = m(lon, lat)
            m.plot(x, y, '.', color=colours[j])

        if i == 0:
            leg_str = [str(Float.floatID) for Float in Floats]
            plt.legend(leg_str, loc=0)

        save_name = '../figures/animated_tracks/{}{i:03d}.png'.format(fstr,
                                                                      i=i)
        plt.savefig(save_name, bbox_inches='tight')

    print('Finished.')
예제 #8
0
for i in range(N):
    fid = IDS_[i]
    filename = os.path.join(psdir, "{}_wfi.p".format(fid))
    with open(filename, 'rb') as f:
        wfi = pickle.load(f)
        FLOATS_ALT[i].apply_w_model(wfi)

E4596, E4814 = FLOATS_ALT

# %% map
lon_lat = [-70, -30, -65, -45]
proj = ccrs.PlateCarree()

###############################################################################
lons, lats, bathy = sandwell.read_grid(lon_lat, bf)
bathy = -1*np.ma.masked_where(bathy > 0, bathy)

fig = plt.figure(figsize=(6.5, 5))
ax = plt.subplot(111, projection=proj)
ax.set_extent(lon_lat, ccrs.PlateCarree())
cax = fig.add_axes([0.6, 0.45, 0.2, 0.01])

ax.contour(lons, lats, bathy.data, [0.], colors='k')

C = ax.pcolormesh(lons[::10, ::10], lats[::10, ::10], bathy[::10, ::10],
                  vmin=0., vmax=6000., cmap=cmocean.cm.deep, rasterized=True)
cbp = plt.colorbar(C, cax=cax, orientation='horizontal')
cbp.set_ticks([0., 3000., 6000])
cbp.set_label('Depth (m)')