Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add filter to grid_stat and grid_count
  • Loading branch information
CoriPegliasco committed Nov 18, 2020
commit 80fc9650794a8ae6ccb0adc55cd4a5348c5e95ad
4 changes: 1 addition & 3 deletions examples/02_eddy_identification/pet_filter_and_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def update_axes(ax, mappable=None):
# 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",
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude",
)
g.add_uv("adt")
g.copy("adt", "adt_high")
Expand Down
4 changes: 1 addition & 3 deletions examples/02_eddy_identification/pet_sla_and_adt.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def update_axes(ax, mappable=None):
# 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",
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude",
)
g.add_uv("adt", "ugos", "vgos")
g.add_uv("sla", "ugosa", "vgosa")
Expand Down
4 changes: 1 addition & 3 deletions examples/06_grid_manipulation/pet_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def update_axes(ax, mappable=None):
# %%
# All information will be for regular grid
g = RegularGridDataset(
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"),
"longitude",
"latitude",
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude",
)
# %%
# Kernel
Expand Down
16 changes: 2 additions & 14 deletions examples/08_tracking_manipulation/pet_select_track_across_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,8 @@
c.plot(ax, color="gray", lw=0.1, ref=-10, label="all tracks")
c_subset.plot(ax, color="red", lw=0.2, ref=-10, label="selected tracks")
ax.plot(
(
x0,
x0,
x1,
x1,
x0,
),
(
y0,
y1,
y1,
y0,
y0,
),
(x0, x0, x1, x1, x0,),
(y0, y1, y1, y0, y0,),
color="green",
lw=1.5,
label="Box of selection",
Expand Down
18 changes: 18 additions & 0 deletions examples/10_tracking_diagnostics/pet_center_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,21 @@
ax.set_aspect("equal")
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
ax.grid()

# %%
# Count Anticyclones as a function of lifetime
# --------------------------------------------
# Count at the center's position

fig = plt.figure(figsize=(12, 10))
ax = fig.add_subplot(211)
g_a = a.grid_count(bins, center=True, filter=a.lifetime >= 30)
m = g_a.display(ax, **kwargs_pcolormesh)
ax.set_aspect("equal")
ax.set_title("Anticyclones with lifetime >= 30 days")
cb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.1, 0.015, 0.8]))
ax = fig.add_subplot(212)
g_a = a.grid_count(bins, center=True, filter=a.lifetime < 30)
m = g_a.display(ax, **kwargs_pcolormesh)
ax.set_aspect("equal")
ax.set_title("Anticyclones with lifetime < 30 days")
17 changes: 17 additions & 0 deletions examples/10_tracking_diagnostics/pet_pixel_used.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,20 @@
ax.set_aspect("equal")
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
ax.grid()

# %%
# Count Anticyclones as a function of lifetime
# --------------------------------------------

fig = plt.figure(figsize=(12, 10))
ax = fig.add_subplot(211)
g_a = a.grid_count(bins, intern=True, filter=a.lifetime >= 30)
m = g_a.display(ax, **kwargs_pcolormesh)
ax.set_aspect("equal")
ax.set_title("Anticyclones with lifetime >= 30 days")
cb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.1, 0.015, 0.8]))
ax = fig.add_subplot(212)
g_a = a.grid_count(bins, intern=True, filter=a.lifetime < 30)
m = g_a.display(ax, **kwargs_pcolormesh)
ax.set_aspect("equal")
ax.set_title("Anticyclones with lifetime < 30 days")
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\nfrom matplotlib.colors import LogNorm\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations\nimport py_eddy_tracker_sample"
"import py_eddy_tracker_sample\nfrom matplotlib import pyplot as plt\nfrom matplotlib.colors import LogNorm\n\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations"
]
},
{
Expand Down Expand Up @@ -64,6 +64,24 @@
"source": [
"fig = plt.figure(figsize=(12, 18.5))\nax_a = fig.add_axes([0.03, 0.75, 0.90, 0.25])\nax_a.set_title(\"Anticyclonic center frequency\")\nax_c = fig.add_axes([0.03, 0.5, 0.90, 0.25])\nax_c.set_title(\"Cyclonic center frequency\")\nax_all = fig.add_axes([0.03, 0.25, 0.90, 0.25])\nax_all.set_title(\"All eddies center frequency\")\nax_ratio = fig.add_axes([0.03, 0.0, 0.90, 0.25])\nax_ratio.set_title(\"Ratio cyclonic / Anticyclonic\")\n\n# Count pixel used for each center\ng_a = a.grid_count(bins, intern=True, center=True)\ng_a.display(ax_a, **kwargs_pcolormesh)\ng_c = c.grid_count(bins, intern=True, center=True)\ng_c.display(ax_c, **kwargs_pcolormesh)\n# Compute a ratio Cyclonic / Anticyclonic\nratio = g_c.vars[\"count\"] / g_a.vars[\"count\"]\n\n# Mask manipulation to be able to sum the 2 grids\nm_c = g_c.vars[\"count\"].mask\nm = m_c & g_a.vars[\"count\"].mask\ng_c.vars[\"count\"][m_c] = 0\ng_c.vars[\"count\"] += g_a.vars[\"count\"]\ng_c.vars[\"count\"].mask = m\n\nm = g_c.display(ax_all, **kwargs_pcolormesh)\ncb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.27, 0.01, 0.7]))\ncb.set_label(\"Eddies by 1\u00b0^2 by day\")\n\ng_c.vars[\"count\"] = ratio\nm = g_c.display(\n ax_ratio, name=\"count\", vmin=0.1, vmax=10, norm=LogNorm(), cmap=\"coolwarm_r\"\n)\nplt.colorbar(m, cax=fig.add_axes([0.94, 0.02, 0.01, 0.2]))\n\nfor ax in (ax_a, ax_c, ax_all, ax_ratio):\n ax.set_aspect(\"equal\")\n ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\n ax.grid()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Count Anticyclones as a function of lifetime\nCount at the center's position\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(12, 10))\nax = fig.add_subplot(211)\ng_a = a.grid_count(bins, center=True, filter=a.lifetime >= 30)\nm = g_a.display(ax, **kwargs_pcolormesh)\nax.set_aspect(\"equal\")\nax.set_title(\"Anticyclones with lifetime >= 30 days\")\ncb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.1, 0.015, 0.8]))\nax = fig.add_subplot(212)\ng_a = a.grid_count(bins, center=True, filter=a.lifetime < 30)\nm = g_a.display(ax, **kwargs_pcolormesh)\nax.set_aspect(\"equal\")\nax.set_title(\"Anticyclones with lifetime < 30 days\")"
]
}
],
"metadata": {
Expand All @@ -82,7 +100,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\nfrom matplotlib.colors import LogNorm\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations\nimport py_eddy_tracker_sample"
"import py_eddy_tracker_sample\nfrom matplotlib import pyplot as plt\nfrom matplotlib.colors import LogNorm\n\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations"
]
},
{
Expand Down Expand Up @@ -64,6 +64,24 @@
"source": [
"fig = plt.figure(figsize=(12, 18.5))\nax_a = fig.add_axes([0.03, 0.75, 0.90, 0.25])\nax_a.set_title(\"Anticyclonic frequency\")\nax_c = fig.add_axes([0.03, 0.5, 0.90, 0.25])\nax_c.set_title(\"Cyclonic frequency\")\nax_all = fig.add_axes([0.03, 0.25, 0.90, 0.25])\nax_all.set_title(\"All eddies frequency\")\nax_ratio = fig.add_axes([0.03, 0.0, 0.90, 0.25])\nax_ratio.set_title(\"Ratio cyclonic / Anticyclonic\")\n\n# Count pixel used for each contour\ng_a = a.grid_count(bins, intern=True)\ng_a.display(ax_a, **kwargs_pcolormesh)\ng_c = c.grid_count(bins, intern=True)\ng_c.display(ax_c, **kwargs_pcolormesh)\n# Compute a ratio Cyclonic / Anticyclonic\nratio = g_c.vars[\"count\"] / g_a.vars[\"count\"]\n\n# Mask manipulation to be able to sum the 2 grids\nm_c = g_c.vars[\"count\"].mask\nm = m_c & g_a.vars[\"count\"].mask\ng_c.vars[\"count\"][m_c] = 0\ng_c.vars[\"count\"] += g_a.vars[\"count\"]\ng_c.vars[\"count\"].mask = m\n\nm = g_c.display(ax_all, **kwargs_pcolormesh)\nplt.colorbar(m, cax=fig.add_axes([0.95, 0.27, 0.01, 0.7]))\n\ng_c.vars[\"count\"] = ratio\nm = g_c.display(\n ax_ratio, name=\"count\", vmin=0.1, vmax=10, norm=LogNorm(), cmap=\"coolwarm_r\"\n)\nplt.colorbar(m, cax=fig.add_axes([0.95, 0.02, 0.01, 0.2]))\n\nfor ax in (ax_a, ax_c, ax_all, ax_ratio):\n ax.set_aspect(\"equal\")\n ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\n ax.grid()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Count Anticyclones as a function of lifetime\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(12, 10))\nax = fig.add_subplot(211)\ng_a = a.grid_count(bins, intern=True, filter=a.lifetime >= 30)\nm = g_a.display(ax, **kwargs_pcolormesh)\nax.set_aspect(\"equal\")\nax.set_title(\"Anticyclones with lifetime >= 30 days\")\ncb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.1, 0.015, 0.8]))\nax = fig.add_subplot(212)\ng_a = a.grid_count(bins, intern=True, filter=a.lifetime < 30)\nm = g_a.display(ax, **kwargs_pcolormesh)\nax.set_aspect(\"equal\")\nax.set_title(\"Anticyclones with lifetime < 30 days\")"
]
}
],
"metadata": {
Expand All @@ -82,7 +100,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down
48 changes: 11 additions & 37 deletions src/py_eddy_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ def parse_args(self, *args, **kwargs):
output_type="uint16",
scale_factor=50.0,
nc_dims=("obs",),
nc_attr=dict(
long_name="Distance to next position",
units="m",
),
nc_attr=dict(long_name="Distance to next position", units="m",),
),
virtual=dict(
attr_name=None,
Expand Down Expand Up @@ -304,18 +301,14 @@ def parse_args(self, *args, **kwargs):
nc_name="i",
nc_type="uint16",
nc_dims=("obs",),
nc_attr=dict(
long_name="Longitude index in the grid of the detection",
),
nc_attr=dict(long_name="Longitude index in the grid of the detection",),
),
j=dict(
attr_name="j",
nc_name="j",
nc_type="uint16",
nc_dims=("obs",),
nc_attr=dict(
long_name="Latitude index in the grid of the detection",
),
nc_attr=dict(long_name="Latitude index in the grid of the detection",),
),
eke=dict(
attr_name="eke",
Expand Down Expand Up @@ -364,8 +357,7 @@ def parse_args(self, *args, **kwargs):
nc_type="uint32",
nc_dims=("obs",),
nc_attr=dict(
long_name="Trajectory number",
comment="Trajectory identification number",
long_name="Trajectory number", comment="Trajectory identification number",
),
),
sub_track=dict(
Expand All @@ -374,8 +366,7 @@ def parse_args(self, *args, **kwargs):
nc_type="uint32",
nc_dims=("obs",),
nc_attr=dict(
long_name="Segment Number",
comment="Segment number inside a group",
long_name="Segment Number", comment="Segment number inside a group",
),
),
n=dict(
Expand Down Expand Up @@ -498,11 +489,7 @@ def parse_args(self, *args, **kwargs):
output_type="u1",
scale_factor=0.4,
nc_dims=("obs",),
nc_attr=dict(
units="%",
comment="score",
long_name="Score",
),
nc_attr=dict(units="%", comment="score", long_name="Score",),
),
index_other=dict(
attr_name=None,
Expand Down Expand Up @@ -571,10 +558,7 @@ def parse_args(self, *args, **kwargs):
old_nc_name=["Chl"],
nc_type="f4",
nc_dims=("obs",),
nc_attr=dict(
long_name="Log base 10 chlorophyll",
units="Log(Chl/[mg/m^3])",
),
nc_attr=dict(long_name="Log base 10 chlorophyll", units="Log(Chl/[mg/m^3])",),
),
dchl=dict(
attr_name=None,
Expand All @@ -594,8 +578,7 @@ def parse_args(self, *args, **kwargs):
nc_type="f4",
nc_dims=("obs",),
nc_attr=dict(
long_name="Log base 10 background chlorophyll",
units="Log(Chl/[mg/m^3])",
long_name="Log base 10 background chlorophyll", units="Log(Chl/[mg/m^3])",
),
),
year=dict(
Expand All @@ -604,32 +587,23 @@ def parse_args(self, *args, **kwargs):
old_nc_name=["Year"],
nc_type="u2",
nc_dims=("obs",),
nc_attr=dict(
long_name="Year",
units="year",
),
nc_attr=dict(long_name="Year", units="year",),
),
month=dict(
attr_name=None,
nc_name="month",
old_nc_name=["Month"],
nc_type="u1",
nc_dims=("obs",),
nc_attr=dict(
long_name="Month",
units="month",
),
nc_attr=dict(long_name="Month", units="month",),
),
day=dict(
attr_name=None,
nc_name="day",
old_nc_name=["Day"],
nc_type="u1",
nc_dims=("obs",),
nc_attr=dict(
long_name="Day",
units="day",
),
nc_attr=dict(long_name="Day", units="day",),
),
nb_contour_selected=dict(
attr_name=None,
Expand Down
9 changes: 2 additions & 7 deletions src/py_eddy_tracker/appli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
def build_network():
parser = EddyParser("Merge eddies")
parser.add_argument(
"identification_regex",
help="Give an expression which will use with glob",
"identification_regex", help="Give an expression which will use with glob",
)
parser.add_argument("out", help="output file")
parser.add_argument(
Expand Down Expand Up @@ -294,11 +293,7 @@ def display_network(x, y, tr, t, c):
lw=0.5,
)
ax_time.plot(
t[sl],
tr[s].repeat(e - s),
color=color,
lw=1,
marker="+",
t[sl], tr[s].repeat(e - s), color=color, lw=1, marker="+",
)
ax_time.text(t[s], tr[s] + 0.15, f"{x[s].mean():.2f}, {y[s].mean():.2f}")
ax_time.axvline(t[s], color=".75", lw=0.5, ls="--", zorder=-10)
Expand Down
8 changes: 2 additions & 6 deletions src/py_eddy_tracker/dataset/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ def __init__(
self.interpolators = dict()
if centered is None:
logger.warning(
"We assume pixel position of grid is center for %s",
filename,
"We assume pixel position of grid is center for %s", filename,
)
if not unset:
self.load_general_features()
Expand Down Expand Up @@ -344,10 +343,7 @@ def load_general_features(self):
self.variables_description = dict()
for i, v in h.variables.items():
args = (i, v.datatype)
kwargs = dict(
dimensions=v.dimensions,
zlib=True,
)
kwargs = dict(dimensions=v.dimensions, zlib=True,)
if hasattr(v, "_FillValue"):
kwargs["fill_value"] = (v._FillValue,)
attrs = dict()
Expand Down
4 changes: 2 additions & 2 deletions src/py_eddy_tracker/eddy_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ def __init__(self, x, y, z, levels, wrap_x=False, keep_unclose=False):
closed_contours = 0
# Count level and contour
for i, collection in enumerate(self.contours.collections):
collection.get_nearest_path_bbox_contain_pt = (
lambda x, y, i=i: self.get_index_nearest_path_bbox_contain_pt(i, x, y)
collection.get_nearest_path_bbox_contain_pt = lambda x, y, i=i: self.get_index_nearest_path_bbox_contain_pt(
i, x, y
)
nb_level += 1

Expand Down
Loading