예제 #1
0
# %%
# Pre-processings
# ---------------
# Apply high filter to remove long scale to highlight mesoscale
g.bessel_high_filter("adt", 500)
ax = start_axes("ADT (m) filtered (500km)")
m = g.display(ax, "adt", vmin=-0.15, vmax=0.15)
update_axes(ax, m)

# %%
# Identification
# --------------
# run identification with slice of 2 mm
date = datetime(2016, 5, 15)
a, c = g.eddy_identification("adt", "u", "v", date, 0.002)

# %%
# All closed contour found in this input grid (Display only 1 contour every 4)
ax = start_axes("ADT closed contour (only 1 / 4 levels)")
g.contours.display(ax, step=4)
update_axes(ax)

# %%
# Contours include in eddies
ax = start_axes("ADT contour used as eddies")
g.contours.display(ax, only_used=True)
update_axes(ax)

# %%
# Contours reject from several origin (shape error to high, several extremum in contour, ...)
예제 #2
0
g.bessel_high_filter("adt", 700)
g.bessel_low_filter("adt_low", 700)
g.add_uv("adt")

# %%
# Identification
# ^^^^^^^^^^^^^^
# Run the identification step with slices of 2 mm
date = datetime(2016, 5, 15)
kw_ident = dict(date=date,
                step=0.002,
                shape_error=70,
                sampling=30,
                uname="u",
                vname="v")
a, c = g.eddy_identification("adt", **kw_ident)
a_, c_ = g_raw.eddy_identification("adt", **kw_ident)

# %%
# Figures
# -------
kw_adt = dict(vmin=-1.5, vmax=1.5, cmap=plt.get_cmap("RdBu_r", 30))
fig, axs = quad_axes("General properties field")
g_raw.display(axs[0], "adt", **kw_adt)
axs[0].set_title("Total ADT (m)")
m = g.display(axs[1], "adt_low", **kw_adt)
axs[1].set_title("ADT (m) large scale, cutoff at 700 km")
m2 = g.display(axs[2],
               "adt",
               cmap=plt.get_cmap("RdBu_r", 20),
               vmin=-0.5,
예제 #3
0
if True:
    import logging
    logging.getLogger().setLevel(
        'DEBUG')  # Values: ERROR, WARNING, INFO, DEBUG
    from datetime import datetime
    h = RegularGridDataset(grid_name, lon_name, lat_name)
    h.bessel_high_filter('adt', 500, order=3)
    # h.bessel_high_filter('adt', 300, order=1)
    date = datetime(2019, 2, 23)
    a, c = h.eddy_identification(
        'adt',
        'ugos',
        'vgos',  # Variable to use for identification
        date,  # Date of identification
        0.002,  # step between two isolines of detection (m)
        # 0.02, # step between two isolines of detection (m)
        pixel_limit=(5,
                     2000),  # Min and max of pixel can be include in contour
        shape_error=
        55,  # Error maximal of circle fitting over contour to be accepted
        bbox_surface_min_degree=.125**
        2,  # degrees surface minimal to take in account contour
    )
    fig = plt.figure(figsize=(15, 7))
    ax = fig.add_axes([.03, .03, .94, .94])
    ax.set_title('Eddies detected -- Cyclonic(red) and Anticyclonic(blue)')
    ax.set_ylim(-75, 75)
    ax.set_xlim(0, 360)
    ax.set_aspect('equal')
    a.display(ax, color='b', linewidth=.5)
    c.display(ax, color='r', linewidth=.5)
    ax.grid()
예제 #4
0
m = g.display(ax, "sst", vmin=295, vmax=300)
u,v = g.grid("ugosa").T,g.grid("vgosa").T
ax.quiver(g.x_c, g.y_c, u, v, scale=10)
update_axes(ax, m, unit='[°K]')

# %%
# Now, with eddy contours, and displaying SST anomaly
# ! lazy patch since add_grid isn't currently completing g.variables_description
g.variables_description['sst'] = t.variables_description[var_name_sst]
g.copy("sst", "sst_high")
g.bessel_high_filter('sst_high',200)

# %% 
# Eddy detection
date = datetime.strptime(datest,'%Y%m%d')
a, c = g.eddy_identification("sla", "ugosa", "vgosa", date, 0.002)

# %%
kwargs_a = dict(lw=2, label="Anticyclonic", ref=-10, color="b")
kwargs_c = dict(lw=2, label="Cyclonic", ref=-10, color="r")
ax = start_axes("SST anomaly")
m = g.display(ax, "sst_high", vmin=-1, vmax=1)
ax.quiver(g.x_c, g.y_c, u, v, scale=20)
a.display(ax, **kwargs_a), c.display(ax, **kwargs_c)
update_axes(ax, m, unit='[°K]')

# %% 
# Example of post-processing
# --------------------------
# Get mean of sst anomaly_high in each internal contour
anom_a = a.interp_grid(g, "sst_high", method="mean", intern=True)
예제 #5
0
# %%
# Load Input grid, ADT is used to detect eddies.
# Add a new filed to store the high-pass filtered ADT

g = RegularGridDataset(
    data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude",
    "latitude")
g.add_uv("adt")
g.copy("adt", "adt_high")
wavelength = 800
g.bessel_high_filter("adt_high", wavelength)
date = datetime(2016, 5, 15)

# %%
# Run the detection for the total grid and the filtered grid
a_filtered, c_filtered = g.eddy_identification("adt_high", "u", "v", date,
                                               0.002)
merge_f = a_filtered.merge(c_filtered)
a_tot, c_tot = g.eddy_identification("adt", "u", "v", date, 0.002)
merge_t = a_tot.merge(c_tot)

# %%
# Display the two detections
ax = start_axes("Eddies detected over ADT")
m = g.display(ax, "adt", vmin=-0.15, vmax=0.15)
merge_f.display(
    ax,
    lw=0.75,
    label="Eddies in the filtered grid ({nb_obs} eddies)",
    ref=-10,
    color="k",
)
예제 #6
0
# %%
# Pre-processings
# ---------------
# Apply a high-pass filter to remove the large scale and highlight the mesoscale
g.bessel_high_filter("adt", 500)
ax = start_axes("ADT (m) filtered (500km)")
m = g.display(ax, "adt", vmin=-0.15, vmax=0.15, cmap="RdBu_r")
update_axes(ax, m)

# %%
# Identification
# --------------
# Run the identification step with slices of 2 mm
date = datetime(2016, 5, 15)
a, c = g.eddy_identification("adt", "u", "v", date, 0.002, shape_error=55)

# %%
# Display of all closed contours found in the grid (only 1 contour every 4)
ax = start_axes("ADT closed contours (only 1 / 4 levels)")
g.contours.display(ax, step=4)
update_axes(ax)

# %%
# Contours included in eddies
ax = start_axes("ADT contours used as eddies")
g.contours.display(ax, only_used=True)
update_axes(ax)

# %%
# Post analysis
u, v = sst.grid("u").T, sst.grid("v").T
ax.quiver(sst.x_c[::3], sst.y_c[::3], u[::3, ::3], v[::3, ::3], scale=10)
update_axes(ax, m, unit="[°K]")

# %%
# Now, with eddy contours, and displaying SST anomaly
sst.bessel_high_filter("analysed_sst", 400)

# %%
# Eddy detection
sst.bessel_high_filter("sla", 400)
# ADT filtered
ax = start_axes("SLA", extent=extent)
m = sst.display(ax, "sla", vmin=-0.1, vmax=0.1)
update_axes(ax, m, unit="[m]")
a, c = sst.eddy_identification("sla", "u", "v", date, 0.002)

# %%
kwargs_a = dict(lw=2, label="Anticyclonic", ref=-10, color="b")
kwargs_c = dict(lw=2, label="Cyclonic", ref=-10, color="r")
ax = start_axes("SST anomaly")
m = sst.display(ax, "analysed_sst", vmin=-1, vmax=1)
a.display(ax, **kwargs_a), c.display(ax, **kwargs_c)
ax.legend()
update_axes(ax, m, unit="[°K]")

# %%
# Example of post-processing
# --------------------------
# Get mean of sst anomaly_high in each internal contour
anom_a = a.interp_grid(sst, "analysed_sst", method="mean", intern=True)
# Load Input grid, ADT will be used to detect eddies

g = RegularGridDataset(
    data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"),
    "longitude",
    "latitude",
)
g.add_uv("adt")
g.copy("adt", "adt_high")
wavelength = 400
g.bessel_high_filter("adt_high", wavelength)
date = datetime(2016, 5, 15)

# %%
# Run algorithm of detection
a_f, c_f = g.eddy_identification("adt_high", "u", "v", date, 0.002)
merge_f = a_f.merge(c_f)
a_r, c_r = g.eddy_identification("adt", "u", "v", date, 0.002)
merge_r = a_r.merge(c_r)

# %%
# Display detection
ax = start_axes("Eddies detected over ADT")
m = g.display(ax, "adt", vmin=-0.15, vmax=0.15)
merge_f.display(ax,
                lw=0.5,
                label="Eddy from filtered grid",
                ref=-10,
                color="k")
merge_r.display(ax, lw=0.5, label="Eddy from raw grid", ref=-10, color="r")
ax.legend()
예제 #9
0
kwargs_c_adt = dict(lw=0.5,
                    label="Cyclonic ADT ({nb_obs} eddies)",
                    ref=-10,
                    color="r")
kwargs_a_sla = dict(lw=0.5,
                    label="Anticyclonic SLA ({nb_obs} eddies)",
                    ref=-10,
                    color="g")
kwargs_c_sla = dict(lw=0.5,
                    label="Cyclonic SLA ({nb_obs} eddies)",
                    ref=-10,
                    color="b")

# %%
# Run algorithm of detection
a_adt, c_adt = g.eddy_identification("adt", "ugos", "vgos", date, 0.002)
a_sla, c_sla = g.eddy_identification("sla", "ugosa", "vgosa", date, 0.002)

# %%
# over filtered
ax = start_axes(f"ADT (m) filtered ({wavelength}km)")
m = g.display(ax, "adt", vmin=-0.15, vmax=0.15)
a_adt.display(ax, **kwargs_a_adt), c_adt.display(ax, **kwargs_c_adt)
ax.legend(), update_axes(ax, m)

ax = start_axes(f"SLA (m) filtered ({wavelength}km)")
m = g.display(ax, "sla", vmin=-0.15, vmax=0.15)
a_sla.display(ax, **kwargs_a_sla), c_sla.display(ax, **kwargs_c_sla)
ax.legend(), update_axes(ax, m)

# %%
예제 #10
0
ax.grid(True)
plt.colorbar(m, cax=fig.add_axes([0.94, 0.02, 0.01, 0.45]))
fig.savefig("png/filter.png")

logging.getLogger().setLevel("DEBUG")  # Values: ERROR, WARNING, INFO, DEBUG

h = RegularGridDataset(grid_name, lon_name, lat_name)
h.bessel_high_filter("adt", 500, order=3)
# h.bessel_high_filter('adt', 300, order=1)
date = datetime(2019, 2, 23)
a, c = h.eddy_identification(
    "adt",
    "ugos",
    "vgos",  # Variable to use for identification
    date,  # Date of identification
    0.002,  # step between two isolines of detection (m)
    # 0.02, # step between two isolines of detection (m)
    pixel_limit=(5, 2000),  # Min and max of pixel can be include in contour
    shape_error=
    55,  # Error maximal of circle fitting over contour to be accepted
)
fig = plt.figure(figsize=(15, 7))
ax = fig.add_axes([0.03, 0.03, 0.94, 0.94])
ax.set_title("Eddies detected -- Cyclonic(red) and Anticyclonic(blue)")
ax.set_ylim(-75, 75)
ax.set_xlim(0, 360)
ax.set_aspect("equal")
a.display(ax, color="b", linewidth=0.5)
c.display(ax, color="r", linewidth=0.5)
ax.grid()
fig.savefig("png/eddies.png")
예제 #11
0
from netCDF4 import Dataset
from py_eddy_tracker.dataset.grid import RegularGridDataset, UnRegularGridDataset
import logging
logging.basicConfig(level=logging.DEBUG)

# h = UnRegularGridDataset('NEATL36_1d_grid2D_20140515-20140515_short.nc', 'nav_lon', 'nav_lat')
# h.high_filter('sossheig', 20, 10)
# h.add_uv('sossheig')
# h.write('unregular.nc')

h = RegularGridDataset(
    '/data/adelepoulle/Test/Test_eddy/20180417_eddy_tracker_validation_object_oriented/nrt_global_allsat_phy_l4_20180409_20180415.nc',
    'longitude', 'latitude')
h.high_filter('sla', 10, 5)
anticyclonic, cyclonic = h.eddy_identification('sla', 'ugos', 'vgos', 0.0025)
print(len(anticyclonic))
print(len(cyclonic))
with Dataset('/tmp/a.nc', 'w') as h:
    anticyclonic.to_netcdf(h)
with Dataset('/tmp/c.nc', 'w') as h:
    cyclonic.to_netcdf(h)

# h = UnRegularGridDataset('/tmp/t.nc', 'nav_lon', 'nav_lat')
# eddies = h.eddy_identification('sossheig', step=0.005)