Skip to content

Commit e761210

Browse files
committed
Do some change on sst example : AntSimi#24
1 parent 0f189be commit e761210

File tree

6 files changed

+364
-144
lines changed

6 files changed

+364
-144
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
[![PyPI version](https://badge.fury.io/py/pyEddyTracker.svg)](https://badge.fury.io/py/pyEddyTracker) [![Documentation Status](https://readthedocs.org/projects/py-eddy-tracker/badge/?version=stable)](https://py-eddy-tracker.readthedocs.io/en/stable/?badge=stable) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/AntSimi/py-eddy-tracker/master?urlpath=lab/tree/notebooks/python_module/)
1+
[![PyPI version](https://badge.fury.io/py/pyEddyTracker.svg)](https://badge.fury.io/py/pyEddyTracker)
2+
[![Documentation Status](https://readthedocs.org/projects/py-eddy-tracker/badge/?version=stable)](https://py-eddy-tracker.readthedocs.io/en/stable/?badge=stable)
3+
[![Gitter](https://badges.gitter.im/py-eddy-tracker/community.svg)](https://gitter.im/py-eddy-tracker/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
4+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/AntSimi/py-eddy-tracker/master?urlpath=lab/tree/notebooks/python_module/)
25

36
# README #
47

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
External data
2+
=============

examples/12_external_data/SST_collocation.py

Lines changed: 0 additions & 143 deletions
This file was deleted.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
"""
2+
Collocating external data
3+
==========================
4+
5+
Script will use py-eddy-tracker methods to upload external data (sea surface temperature, SST)
6+
in a common structure with altimetry.
7+
8+
Figures higlights the different steps.
9+
"""
10+
11+
from matplotlib import pyplot as plt
12+
from py_eddy_tracker.dataset.grid import RegularGridDataset
13+
from datetime import datetime
14+
from py_eddy_tracker import data
15+
16+
date = datetime(2016, 7, 7)
17+
18+
filename_alt = data.get_path(f"dt_blacksea_allsat_phy_l4_{date:%Y%m%d}_20200801.nc")
19+
filename_sst = data.get_path(
20+
f"{date:%Y%m%d}000000-GOS-L4_GHRSST-SSTfnd-OISST_HR_REP-BLK-v02.0-fv01.0.nc"
21+
)
22+
var_name_sst = "analysed_sst"
23+
24+
extent = [27, 42, 40.5, 47]
25+
26+
# %%
27+
# Loading data
28+
# -----------------------------
29+
sst = RegularGridDataset(filename=filename_sst, x_name="lon", y_name="lat")
30+
alti = RegularGridDataset(
31+
data.get_path(filename_alt), x_name="longitude", y_name="latitude"
32+
)
33+
# We can use `Grid` tools to interpolate ADT on the sst grid
34+
sst.regrid(alti, "sla")
35+
sst.add_uv("sla")
36+
37+
38+
# %%
39+
# Functions to initiate figure axes
40+
def start_axes(title, extent=extent):
41+
fig = plt.figure(figsize=(13, 6), dpi=120)
42+
ax = fig.add_axes([0.03, 0.05, 0.89, 0.91])
43+
ax.set_xlim(extent[0], extent[1])
44+
ax.set_ylim(extent[2], extent[3])
45+
ax.set_title(title)
46+
ax.set_aspect("equal")
47+
return ax
48+
49+
50+
def update_axes(ax, mappable=None, unit=""):
51+
ax.grid()
52+
if mappable:
53+
cax = ax.figure.add_axes([0.93, 0.05, 0.01, 0.9], title=unit)
54+
plt.colorbar(mappable, cax=cax)
55+
56+
57+
# %%
58+
# ADT first display
59+
# -----------------------------
60+
ax = start_axes("SLA", extent=extent)
61+
m = sst.display(ax, "sla", vmin=0.05, vmax=0.35)
62+
update_axes(ax, m, unit="[m]")
63+
64+
# %%
65+
# SST first display
66+
# -----------------------------
67+
68+
# %%
69+
# We can now plot SST from `sst`
70+
ax = start_axes("SST")
71+
m = sst.display(ax, "analysed_sst", vmin=295, vmax=300)
72+
update_axes(ax, m, unit="[°K]")
73+
74+
# %%
75+
ax = start_axes("SST")
76+
m = sst.display(ax, "analysed_sst", vmin=295, vmax=300)
77+
u, v = sst.grid("u").T, sst.grid("v").T
78+
ax.quiver(sst.x_c[::3], sst.y_c[::3], u[::3, ::3], v[::3, ::3], scale=10)
79+
update_axes(ax, m, unit="[°K]")
80+
81+
# %%
82+
# Now, with eddy contours, and displaying SST anomaly
83+
sst.bessel_high_filter("analysed_sst", 400)
84+
85+
# %%
86+
# Eddy detection
87+
sst.bessel_high_filter("sla", 400)
88+
# ADT filtered
89+
ax = start_axes("SLA", extent=extent)
90+
m = sst.display(ax, "sla", vmin=-0.1, vmax=0.1)
91+
update_axes(ax, m, unit="[m]")
92+
a, c = sst.eddy_identification("sla", "u", "v", date, 0.002)
93+
94+
# %%
95+
kwargs_a = dict(lw=2, label="Anticyclonic", ref=-10, color="b")
96+
kwargs_c = dict(lw=2, label="Cyclonic", ref=-10, color="r")
97+
ax = start_axes("SST anomaly")
98+
m = sst.display(ax, "analysed_sst", vmin=-1, vmax=1)
99+
a.display(ax, **kwargs_a), c.display(ax, **kwargs_c)
100+
ax.legend()
101+
update_axes(ax, m, unit="[°K]")
102+
103+
# %%
104+
# Example of post-processing
105+
# --------------------------
106+
# Get mean of sst anomaly_high in each internal contour
107+
anom_a = a.interp_grid(sst, "analysed_sst", method="mean", intern=True)
108+
anom_c = c.interp_grid(sst, "analysed_sst", method="mean", intern=True)
109+
110+
# %%
111+
# Are cyclonic (resp. anticyclonic) eddies generally associated with positive (resp. negative) SST anomaly ?
112+
fig = plt.figure(figsize=(7, 5))
113+
ax = fig.add_axes([0.05, 0.05, 0.90, 0.90])
114+
ax.set_xlabel("SST anomaly")
115+
ax.set_xlim([-1, 1])
116+
ax.set_title("Histograms of SST anomalies")
117+
ax.hist(
118+
anom_a, 5, alpha=0.5, color="b", label="Anticyclonic (mean:%s)" % (anom_a.mean())
119+
)
120+
ax.hist(anom_c, 5, alpha=0.5, color="r", label="Cyclonic (mean:%s)" % (anom_c.mean()))
121+
ax.legend()
122+
123+
# %%
124+
# Not clearly so in that case ..

0 commit comments

Comments
 (0)