Ejemplo n.º 1
0
            else:
                ids["previous_obs"][i_next_] = i_next
            i_next = i_next_


def get_obs(dataset):
    "Function to isolate a specific obs"
    return np.where((dataset.lat > 33) * (dataset.lat < 34) *
                    (dataset.lon > 22) * (dataset.lon < 23) *
                    (dataset.time > 20630) * (dataset.time < 20650))[0][0]


# %%
# Get original network, we will isolate only relative at order *2*
n = NetworkObservations.load_file(
    "/data/adelepoulle/work/Eddies/20201217_network_build/tracking/med/Anticyclonic_seg.nc"
)

n = n.extract_with_mask(n.track == n.track[get_obs(n)])
n_ = n.relative(get_obs(n), order=2)

# %%
# Display the default segmentation
ax = start_axes(n_.infos())
n_.plot(ax, color_cycle=n.COLORS)
update_axes(ax)
fig = plt.figure(figsize=(15, 5))
ax = fig.add_axes([0.04, 0.05, 0.92, 0.92])
ax.xaxis.set_major_formatter(formatter), ax.grid()
_ = n_.display_timeline(ax)
Ejemplo n.º 2
0
"""
Network Analysis
================
"""
from matplotlib import pyplot as plt
from numpy import ma

import py_eddy_tracker.gui
from py_eddy_tracker.data import get_remote_sample
from py_eddy_tracker.observations.network import NetworkObservations

n = NetworkObservations.load_file(
    get_remote_sample(
        "eddies_med_adt_allsat_dt2018_err70_filt500_order1/Anticyclonic_network.nc"
    ))
# %%
# Parameters
step = 1 / 10.0
bins = ((-10, 37, step), (30, 46, step))
kw_time = dict(cmap="terrain_r", factor=100.0 / n.nb_days, name="count")
kw_ratio = dict(cmap=plt.get_cmap("YlGnBu_r", 10))


# %%
# Functions
def start_axes(title):
    fig = plt.figure(figsize=(13, 5))
    ax = fig.add_axes([0.03, 0.03, 0.90, 0.94], projection="full_axes")
    ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
    ax.set_aspect("equal")
    ax.set_title(title, weight="bold")
Ejemplo n.º 3
0
                i_next_ = -1
            else:
                ids["previous_obs"][i_next_] = i_next
            i_next = i_next_


def get_obs(dataset):
    "Function to isolate a specific obs"
    return where((dataset.lat > 33) * (dataset.lat < 34) * (dataset.lon > 22) *
                 (dataset.lon < 23) * (dataset.time > 20630) *
                 (dataset.time < 20650))[0][0]


# %%
# Get original network, we will isolate only relative at order *2*
n = NetworkObservations.load_file(get_demo_path("network_med.nc")).network(651)
n_ = n.relative(get_obs(n), order=2)

# %%
# Display the default segmentation
ax = start_axes(n_.infos())
n_.plot(ax, color_cycle=n.COLORS)
update_axes(ax)
fig = plt.figure(figsize=(15, 5))
ax = fig.add_axes([0.04, 0.05, 0.92, 0.92])
ax.xaxis.set_major_formatter(formatter), ax.grid()
_ = n_.display_timeline(ax)

# %%
# Run a new segmentation
# ----------------------
Ejemplo n.º 4
0
# In this example some fields are removed (effective_contour_longitude,...) in order to save time for doc building
eddies_tracks.field_table()

# %%
# Networks
# --------
# Network files use some specific fields :
#
# - track :  ID of network (ID 0 correspond to lonely eddies)
# - segment :  ID of a segment within a network (from 1 to N)
# - previous_obs : Index of the previous observation in the full dataset,
#   if -1 there are no previous observation (the segment starts)
# - next_obs : Index of the next observation in the full dataset, if -1 there are no next observation (the segment ends)
# - previous_cost : Result of the cost function (1 is a good association, 0 is bad) with previous observation
# - next_cost : Result of the cost function (1 is a good association, 0 is bad) with next observation
eddies_network = NetworkObservations.load_file(get_demo_path("network_med.nc"))
eddies_network.field_table()

# %%
sl = slice(70, 100)
Table(
    eddies_network.network(651).obs[sl][[
        "time",
        "track",
        "segment",
        "previous_obs",
        "previous_cost",
        "next_obs",
        "next_cost",
    ]])
Ejemplo n.º 5
0
    fig = plt.figure(figsize=(15, 5))
    ax = fig.add_axes([0.03, 0.06, 0.90, 0.88])
    ax.set_title(title, weight="bold")
    ax.xaxis.set_major_formatter(formatter), ax.grid()
    return ax


def update_axes(ax, mappable=None):
    ax.grid(True)
    if mappable:
        return plt.colorbar(mappable, cax=ax.figure.add_axes([0.94, 0.05, 0.01, 0.9]))


# %%
# We know the network ID, we will get directly
ioannou_case = NetworkObservations.load_file(get_path("network_med.nc")).network(651)
print(ioannou_case.infos())

# %%
# It seems that this network is huge! Our case is visible at 22E 33.5N
ax = start_axes()
ioannou_case.plot(ax, color_cycle=ioannou_case.COLORS)
update_axes(ax)

# %%
# Full Timeline
# -------------
# The network span for many years... How to cut the interesting part?
fig = plt.figure(figsize=(15, 5))
ax = fig.add_axes([0.04, 0.05, 0.92, 0.92])
ax.xaxis.set_major_formatter(formatter), ax.grid()
    ax.xaxis.set_major_formatter(formatter), ax.grid()
    return ax


def update_axes(ax, mappable=None):
    ax.grid(True)
    if mappable:
        return plt.colorbar(mappable,
                            cax=ax.figure.add_axes([0.94, 0.05, 0.01, 0.9]))


# %%
# We know the position and the time of a specific eddy
#
# `n.extract_with_mask` give us the corresponding network
n = NetworkObservations.load_file("med/Anticyclonic_seg.nc")
i = np.where((n.lat > 33) * (n.lat < 34) * (n.lon > 22) * (n.lon < 23) *
             (n.time > 20630) * (n.time < 20650))[0][0]
ioannou_case = n.extract_with_mask(n.track == n.track[i])
print(ioannou_case.infos())

# %%
# It seems that this network is huge! Our case is in purple...
ax = start_axes()
ioannou_case.plot(ax)
update_axes(ax)

# %%
# Full Timeline
# -------------
# The network span for many years... How to cut the interesting part?
Ejemplo n.º 7
0
"""
Network basic manipulation
==========================
"""
from matplotlib import pyplot as plt
from numpy import where

import py_eddy_tracker.gui
from py_eddy_tracker import data
from py_eddy_tracker.observations.network import NetworkObservations

# %%
# Load data
# ---------
# Load data where observations are put in same network but no segmentation
n = NetworkObservations.load_file(data.get_path("network_med.nc")).network(651)
i = where((n.lat > 33) * (n.lat < 34) * (n.lon > 22) * (n.lon < 23) *
          (n.time > 20630) * (n.time < 20650))[0][0]
# For event use
n2 = n.relative(i, order=2)
n = n.relative(i, order=4)
n.numbering_segment()

# %%
# Timeline
# --------

# %%
# Display timeline with events
# A segment generated by a splitting is marked with a star
#
Ejemplo n.º 8
0
pcolormesh = ax.pcolorfast(x_g_, y_g_, lavd, **kw_vorticity)
update_axes(ax, pcolormesh)
ani = VideoAnimation(ax.figure, update, **kw_video)

# %%
# Final LAVD
# ^^^^^^^^^^

# %%
# Format LAVD data
lavd = RegularGridDataset.with_array(
    coordinates=("lon", "lat"),
    datas=dict(
        lavd=lavd.T,
        lon=x_g,
        lat=y_g,
    ),
    centered=True,
)

# %%
# Display final LAVD with py eddy tracker detection.
# Period used for LAVD integration(8 days) is too short for a real use, but choose for example efficiency.
fig, ax, _ = start_ax()
mappable = lavd.display(ax, "lavd", **kw_vorticity)
NetworkObservations.load_file(get_path("Anticyclonic_20160515.nc")).display(
    ax, color="k"
)
NetworkObservations.load_file(get_path("Cyclonic_20160515.nc")).display(ax, color="k")
update_axes(ax, mappable)