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
Prev Previous commit
Merge remote-tracking branch 'upstream/master'
# Conflicts:
#	examples/02_eddy_identification/pet_display_id.py
#	examples/02_eddy_identification/pet_eddy_detection.py
#	examples/02_eddy_identification/pet_eddy_detection_gulf_stream.py
#	examples/02_eddy_identification/pet_filter_and_detection.py
#	notebooks/python_module/02_eddy_identification/pet_display_id.ipynb
#	notebooks/python_module/02_eddy_identification/pet_eddy_detection.ipynb
#	notebooks/python_module/02_eddy_identification/pet_eddy_detection_gulf_stream.ipynb
#	src/py_eddy_tracker/observations/observation.py
  • Loading branch information
CoriPegliasco committed Nov 3, 2020
commit 719c7b0325b96c02624c6d249d865c9bac916ac9
8 changes: 4 additions & 4 deletions examples/02_eddy_identification/pet_display_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
c = EddiesObservations.load_file(data.get_path("Cyclonic_20190223.nc"))

# %%
# Fill effective contour with amplitude
# Fill effective contour with amplitude
fig = plt.figure(figsize=(15, 8))
ax = fig.add_axes([0.03, 0.03, 0.90, 0.94])
ax.set_aspect("equal")
ax.set_xlim(0, 140)
ax.set_ylim(-80, 0)
kwargs = dict(extern_only=True, color="k", lw=1)
a.display(ax, **kwargs), c.display(ax, **kwargs)
a.filled(ax, "amplitude", cmap="magma_r", vmin=0, vmax=.5)
m = c.filled(ax, "amplitude", cmap="magma_r", vmin=0, vmax=.5)
a.filled(ax, "amplitude", cmap="magma_r", vmin=0, vmax=0.5)
m = c.filled(ax, "amplitude", cmap="magma_r", vmin=0, vmax=0.5)
colorbar = plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.03, 0.02, 0.94]))
colorbar.set_label('Amplitude (m)')
colorbar.set_label("Amplitude (m)")

# %%
# Draw speed contours
Expand Down
19 changes: 13 additions & 6 deletions examples/02_eddy_identification/pet_eddy_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def start_axes(title):
ax = fig.add_axes([0.03, 0.03, 0.90, 0.94])
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
ax.set_aspect("equal")
ax.set_title(title, weight='bold')
ax.set_title(title, weight="bold")
return ax


Expand All @@ -42,7 +42,7 @@ def update_axes(ax, mappable=None):

# %%
# Get geostrophic speed u,v
# -------
# -------------------------
# U/V are deduced from ADT, this algortihm is not ok near the equator (~+- 2°)
g.add_uv("adt")
ax = start_axes("U/V deduce from ADT (m)")
Expand Down Expand Up @@ -82,7 +82,7 @@ def update_axes(ax, mappable=None):

# %%
# Post analysis
# ------------
# -------------
# Contours can be rejected for several reasons (shape error to high, several extremum in contour, ...)
ax = start_axes("ADT rejected contours")
g.contours.display(ax, only_unused=True)
Expand Down Expand Up @@ -113,7 +113,11 @@ def update_axes(ax, mappable=None):
g.contours.label_contour_unused_which_contain_eddies(a)
g.contours.label_contour_unused_which_contain_eddies(c)
g.contours.display(
ax, only_contain_eddies=True, color="k", lw=1, label="Could be a contour of interaction"
ax,
only_contain_eddies=True,
color="k",
lw=1,
label="Could be a contour of interaction",
)
a.display(ax, color="r", linewidth=0.75, label="Anticyclonic", ref=-10)
c.display(ax, color="b", linewidth=0.75, label="Cyclonic", ref=-10)
Expand All @@ -123,7 +127,8 @@ def update_axes(ax, mappable=None):
# %%
# Output
# ------
# When displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of the maximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1
# When displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of
# the maximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1

ax = start_axes("Detected Eddies")
a.display(ax, color="r", linewidth=0.75, label="Anticyclonic", ref=-10)
Expand All @@ -135,7 +140,9 @@ def update_axes(ax, mappable=None):
# Display the speed radius of the detected eddies
ax = start_axes("Speed Radius (km)")
a.scatter(ax, "radius_s", vmin=10, vmax=50, s=80, ref=-10, cmap="magma_r", factor=0.001)
m = c.scatter(ax, "radius_s", vmin=10, vmax=50, s=80, ref=-10, cmap="magma_r", factor=0.001)
m = c.scatter(
ax, "radius_s", vmin=10, vmax=50, s=80, ref=-10, cmap="magma_r", factor=0.001
)
update_axes(ax, m)

# %%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def update_axes(ax, mappable=None):

# %%
# Get geostrophic speed u,v
# -------
# -------------------------
# U/V are deduced from ADT, this algortihm is not ok near the equator (~+- 2°)
g.add_uv("adt")

Expand Down Expand Up @@ -91,7 +91,7 @@ def update_axes(ax, mappable=None):

# %%
# Post analysis
# ------------
# -------------
# Contours can be rejected for several reasons (shape error to high, several extremum in contour, ...)
ax = start_axes("ADT rejected contours")
g.contours.display(ax, only_unused=True, lw=0.25)
Expand Down Expand Up @@ -123,7 +123,11 @@ def update_axes(ax, mappable=None):
g.contours.label_contour_unused_which_contain_eddies(a)
g.contours.label_contour_unused_which_contain_eddies(c)
g.contours.display(
ax, only_contain_eddies=True, color="k", lw=1, label="Could be a contour of interaction"
ax,
only_contain_eddies=True,
color="k",
lw=1,
label="Could be a contour of interaction",
)
a.display(ax, color="r", linewidth=0.75, label="Anticyclonic", ref=-10)
c.display(ax, color="b", linewidth=0.75, label="Cyclonic", ref=-10)
Expand All @@ -133,7 +137,8 @@ def update_axes(ax, mappable=None):
# %%
# Output
# ------
# When displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of the maximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1
# When displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of the
# maximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1

ax = start_axes("Eddies detected")
a.display(ax, color="r", linewidth=0.75, label="Anticyclonic", ref=-10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def update_axes(ax, mappable=None):

# %%
# Amplitude and Speed Radius distributions
# -----------------------
# ----------------------------------------
fig = plt.figure(figsize=(12, 5))
ax_a = fig.add_subplot(121, xlabel="Amplitude (cm)")
ax_r = fig.add_subplot(122, xlabel="Speed Radius (km)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Fill effective contour with amplitude \n\n"
"Fill effective contour with amplitude\n\n"
]
},
{
Expand All @@ -62,7 +62,7 @@
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(15, 8))\nax = fig.add_axes([0.03, 0.03, 0.90, 0.94])\nax.set_aspect(\"equal\")\nax.set_xlim(0, 140)\nax.set_ylim(-80, 0)\nkwargs = dict(extern_only=True, color=\"k\", lw=1)\na.display(ax, **kwargs), c.display(ax, **kwargs)\na.filled(ax, \"amplitude\", cmap=\"magma_r\", vmin=0, vmax=.5)\nm = c.filled(ax, \"amplitude\", cmap=\"magma_r\", vmin=0, vmax=.5)\ncolorbar = plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.03, 0.02, 0.94]))\ncolorbar.set_label('Amplitude (m)')"
"fig = plt.figure(figsize=(15, 8))\nax = fig.add_axes([0.03, 0.03, 0.90, 0.94])\nax.set_aspect(\"equal\")\nax.set_xlim(0, 140)\nax.set_ylim(-80, 0)\nkwargs = dict(extern_only=True, color=\"k\", lw=1)\na.display(ax, **kwargs), c.display(ax, **kwargs)\na.filled(ax, \"amplitude\", cmap=\"magma_r\", vmin=0, vmax=0.5)\nm = c.filled(ax, \"amplitude\", cmap=\"magma_r\", vmin=0, vmax=0.5)\ncolorbar = plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.03, 0.02, 0.94]))\ncolorbar.set_label(\"Amplitude (m)\")"
]
},
{
Expand Down Expand Up @@ -129,7 +129,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.7"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"outputs": [],
"source": [
"def start_axes(title):\n fig = plt.figure(figsize=(13, 5))\n ax = fig.add_axes([0.03, 0.03, 0.90, 0.94])\n ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\n ax.set_aspect(\"equal\")\n ax.set_title(title, weight='bold')\n return ax\n\n\ndef update_axes(ax, mappable=None):\n ax.grid()\n if mappable:\n plt.colorbar(mappable, cax=ax.figure.add_axes([0.94, 0.05, 0.01, 0.9]))"
"def start_axes(title):\n fig = plt.figure(figsize=(13, 5))\n ax = fig.add_axes([0.03, 0.03, 0.90, 0.94])\n ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\n ax.set_aspect(\"equal\")\n ax.set_title(title, weight=\"bold\")\n return ax\n\n\ndef update_axes(ax, mappable=None):\n ax.grid()\n if mappable:\n plt.colorbar(mappable, cax=ax.figure.add_axes([0.94, 0.05, 0.01, 0.9]))"
]
},
{
Expand Down Expand Up @@ -217,14 +217,14 @@
},
"outputs": [],
"source": [
"ax = start_axes(\"ADT rejected contours containing eddies\")\ng.contours.label_contour_unused_which_contain_eddies(a)\ng.contours.label_contour_unused_which_contain_eddies(c)\ng.contours.display(\n ax, only_contain_eddies=True, color=\"k\", lw=1, label=\"Could be a contour of interaction\"\n)\na.display(ax, color=\"r\", linewidth=0.75, label=\"Anticyclonic\", ref=-10)\nc.display(ax, color=\"b\", linewidth=0.75, label=\"Cyclonic\", ref=-10)\nax.legend()\nupdate_axes(ax)"
"ax = start_axes(\"ADT rejected contours containing eddies\")\ng.contours.label_contour_unused_which_contain_eddies(a)\ng.contours.label_contour_unused_which_contain_eddies(c)\ng.contours.display(\n ax,\n only_contain_eddies=True,\n color=\"k\",\n lw=1,\n label=\"Could be a contour of interaction\",\n)\na.display(ax, color=\"r\", linewidth=0.75, label=\"Anticyclonic\", ref=-10)\nc.display(ax, color=\"b\", linewidth=0.75, label=\"Cyclonic\", ref=-10)\nax.legend()\nupdate_axes(ax)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Output\nWhen displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of the maximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1\n\n"
"## Output\nWhen displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of\nthe maximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1\n\n"
]
},
{
Expand Down Expand Up @@ -253,7 +253,7 @@
},
"outputs": [],
"source": [
"ax = start_axes(\"Speed Radius (km)\")\na.scatter(ax, \"radius_s\", vmin=10, vmax=50, s=80, ref=-10, cmap=\"magma_r\", factor=0.001)\nm = c.scatter(ax, \"radius_s\", vmin=10, vmax=50, s=80, ref=-10, cmap=\"magma_r\", factor=0.001)\nupdate_axes(ax, m)"
"ax = start_axes(\"Speed Radius (km)\")\na.scatter(ax, \"radius_s\", vmin=10, vmax=50, s=80, ref=-10, cmap=\"magma_r\", factor=0.001)\nm = c.scatter(\n ax, \"radius_s\", vmin=10, vmax=50, s=80, ref=-10, cmap=\"magma_r\", factor=0.001\n)\nupdate_axes(ax, m)"
]
},
{
Expand All @@ -271,7 +271,7 @@
},
"outputs": [],
"source": [
"ax = start_axes(\"Effective Radius (km)\")\nkwargs = dict(vmin=10, vmax=80, cmap=\"magma_r\", factor=0.001, lut=14, ref=-10)\na.filled(ax, \"radius_e\", **kwargs)\nm = c.filled(\n ax, \"radius_e\", vmin=10, vmax=80, cmap=\"magma_r\", factor=0.001, lut=14, ref=-10\n)\nupdate_axes(ax, m)"
"ax = start_axes(\"Effective Radius (km)\")\nkwargs = dict(vmin=10, vmax=80, cmap=\"magma_r\", factor=0.001, lut=14, ref=-10)\na.filled(ax, \"effective_radius\", **kwargs)\nm = c.filled(\n ax, \"radius_e\", vmin=10, vmax=80, cmap=\"magma_r\", factor=0.001, lut=14, ref=-10\n)\nupdate_axes(ax, m)"
]
}
],
Expand All @@ -291,7 +291,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.7"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@
},
"outputs": [],
"source": [
"ax = start_axes(\"ADT rejected contours containing eddies\")\ng.contours.label_contour_unused_which_contain_eddies(a)\ng.contours.label_contour_unused_which_contain_eddies(c)\ng.contours.display(\n ax, only_contain_eddies=True, color=\"k\", lw=1, label=\"Could be a contour of interaction\"\n)\na.display(ax, color=\"r\", linewidth=0.75, label=\"Anticyclonic\", ref=-10)\nc.display(ax, color=\"b\", linewidth=0.75, label=\"Cyclonic\", ref=-10)\nax.legend()\nupdate_axes(ax)"
"ax = start_axes(\"ADT rejected contours containing eddies\")\ng.contours.label_contour_unused_which_contain_eddies(a)\ng.contours.label_contour_unused_which_contain_eddies(c)\ng.contours.display(\n ax,\n only_contain_eddies=True,\n color=\"k\",\n lw=1,\n label=\"Could be a contour of interaction\",\n)\na.display(ax, color=\"r\", linewidth=0.75, label=\"Anticyclonic\", ref=-10)\nc.display(ax, color=\"b\", linewidth=0.75, label=\"Cyclonic\", ref=-10)\nax.legend()\nupdate_axes(ax)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Output\nWhen displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of the maximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1\n\n"
"## Output\nWhen displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of the\nmaximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1\n\n"
]
},
{
Expand Down Expand Up @@ -273,7 +273,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.7"
}
},
"nbformat": 4,
Expand Down
19 changes: 9 additions & 10 deletions src/py_eddy_tracker/observations/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def reset(self):

@property
def obs(self):
"""Return an array observations.
"""Return observations.
"""
return self.observations

Expand Down Expand Up @@ -986,13 +986,13 @@ def mask_function(self, other, distance):

@staticmethod
def cost_function(records_in, records_out, distance):
"""Return the cost function between two obs
"""Return the cost function between two obs.

.. math::

cost = \sqrt{ ( {Amp_{_{in}} - Amp_{_{out}} \over Amp_{_{in}} } ) ^2 +
( {Rspeed_{_{in}} - Rspeed_{_{out}} \over Rspeed_{_{in}} }) ^2 +
( {distance \over 125} ) ^2
cost = \sqrt{({Amp_{_{in}} - Amp_{_{out}} \over Amp_{_{in}}}) ^2 +
({Rspeed_{_{in}} - Rspeed_{_{out}} \over Rspeed_{_{in}}}) ^2 +
({distance \over 125}) ^2
}

:param records_in: starting observations
Expand Down Expand Up @@ -1480,15 +1480,14 @@ def extract_with_area(self, area, **kwargs):
Extract geographically with a bounding box.

:param dict area: 4 coordinates in a dictionary to specify bounding box (lower left corner and upper right corner)
:param dict kwargs: look at :py:meth:`extract_with_mask`
:return: Return all eddy tracks which are in bounds
:rtype: EddiesObservations

.. code-block:: python

area = dict(llcrnrlon=x0, llcrnrlat=y0, urcrnrlon=x1, urcrnrlat=y1)

:param dict kwargs: look at :py:meth:`extract_with_mask`
:return: Return all eddy tracks which are in bounds
:rtype: EddiesObservations


.. minigallery:: py_eddy_tracker.EddiesObservations.extract_with_area
"""
mask = (self.latitude > area["llcrnrlat"]) * (self.latitude < area["urcrnrlat"])
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.