1+ {
2+ "cells" : [
3+ {
4+ "cell_type" : " code" ,
5+ "execution_count" : null ,
6+ "metadata" : {
7+ "collapsed" : false
8+ },
9+ "outputs" : [],
10+ "source" : [
11+ " %matplotlib inline"
12+ ]
13+ },
14+ {
15+ "cell_type" : " markdown" ,
16+ "metadata" : {},
17+ "source" : [
18+ " \n Grid filtering in PET\n =====================\n\n How filter work in py eddy tracker. This implementation maybe doesn't respect state art, but ...\n\n We code a specific filter in order to filter grid with same wavelength at each pixel.\n "
19+ ]
20+ },
21+ {
22+ "cell_type" : " code" ,
23+ "execution_count" : null ,
24+ "metadata" : {
25+ "collapsed" : false
26+ },
27+ "outputs" : [],
28+ "source" : [
29+ " from py_eddy_tracker.dataset.grid import RegularGridDataset\n from py_eddy_tracker import data\n from matplotlib import pyplot as plt\n\n\n 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)\n return ax\n\n\n def update_axes(ax, mappable=None):\n ax.grid()\n if mappable:\n plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))"
30+ ]
31+ },
32+ {
33+ "cell_type" : " markdown" ,
34+ "metadata" : {},
35+ "source" : [
36+ " All information will be for regular grid\n\n "
37+ ]
38+ },
39+ {
40+ "cell_type" : " code" ,
41+ "execution_count" : null ,
42+ "metadata" : {
43+ "collapsed" : false
44+ },
45+ "outputs" : [],
46+ "source" : [
47+ " g = RegularGridDataset(\n data.get_path(\" dt_med_allsat_phy_l4_20160515_20190101.nc\" ), \" longitude\" , \" latitude\" ,\n )"
48+ ]
49+ },
50+ {
51+ "cell_type" : " markdown" ,
52+ "metadata" : {},
53+ "source" : [
54+ " Kernel\n ------\n Shape of kernel will increase in x when latitude increase\n\n "
55+ ]
56+ },
57+ {
58+ "cell_type" : " code" ,
59+ "execution_count" : null ,
60+ "metadata" : {
61+ "collapsed" : false
62+ },
63+ "outputs" : [],
64+ "source" : [
65+ " fig = plt.figure(figsize=(12, 8))\n for i, latitude in enumerate((15, 35, 55, 75)):\n k = g.kernel_bessel(latitude, 500, order=3).T\n ax0 = plt.subplot(\n 2,\n 2,\n i + 1,\n title=f\" Kernel at {latitude}\u00b0 of latitude\\ nfor 1/8\u00b0 grid, shape : {k.shape}\" ,\n aspect=\" equal\" ,\n )\n m = ax0.pcolormesh(k, vmin=-0.5, vmax=2, cmap=\" viridis_r\" )\n plt.colorbar(m, cax=fig.add_axes((0.92, 0.05, 0.01, 0.9)))"
66+ ]
67+ },
68+ {
69+ "cell_type" : " markdown" ,
70+ "metadata" : {},
71+ "source" : [
72+ " Kernel applying\n ---------------\n Original grid\n\n "
73+ ]
74+ },
75+ {
76+ "cell_type" : " code" ,
77+ "execution_count" : null ,
78+ "metadata" : {
79+ "collapsed" : false
80+ },
81+ "outputs" : [],
82+ "source" : [
83+ " ax = start_axes(\" ADT\" )\n m = g.display(ax, \" adt\" , vmin=-0.15, vmax=0.15)\n update_axes(ax, m)"
84+ ]
85+ },
86+ {
87+ "cell_type" : " markdown" ,
88+ "metadata" : {},
89+ "source" : [
90+ " We will select wavelength of 300 km\n\n Low frequency\n\n "
91+ ]
92+ },
93+ {
94+ "cell_type" : " code" ,
95+ "execution_count" : null ,
96+ "metadata" : {
97+ "collapsed" : false
98+ },
99+ "outputs" : [],
100+ "source" : [
101+ " ax = start_axes(\" ADT low frequency\" )\n g.copy(\" adt\" , \" adt_low\" )\n g.bessel_low_filter(\" adt_low\" , 300, order=3)\n m = g.display(ax, \" adt_low\" , vmin=-0.15, vmax=0.15)\n update_axes(ax, m)"
102+ ]
103+ },
104+ {
105+ "cell_type" : " markdown" ,
106+ "metadata" : {},
107+ "source" : [
108+ " High frequency\n\n "
109+ ]
110+ },
111+ {
112+ "cell_type" : " code" ,
113+ "execution_count" : null ,
114+ "metadata" : {
115+ "collapsed" : false
116+ },
117+ "outputs" : [],
118+ "source" : [
119+ " ax = start_axes(\" ADT high frequency\" )\n g.copy(\" adt\" , \" adt_high\" )\n g.bessel_high_filter(\" adt_high\" , 300, order=3)\n m = g.display(ax, \" adt_high\" , vmin=-0.15, vmax=0.15)\n update_axes(ax, m)"
120+ ]
121+ },
122+ {
123+ "cell_type" : " markdown" ,
124+ "metadata" : {},
125+ "source" : [
126+ " Clues\n -----\n wavelength : 80km\n\n "
127+ ]
128+ },
129+ {
130+ "cell_type" : " code" ,
131+ "execution_count" : null ,
132+ "metadata" : {
133+ "collapsed" : false
134+ },
135+ "outputs" : [],
136+ "source" : [
137+ " g.copy(\" adt\" , \" adt_high_80\" )\n g.bessel_high_filter(\" adt_high_80\" , 80, order=3)\n g.copy(\" adt\" , \" adt_low_80\" )\n g.bessel_low_filter(\" adt_low_80\" , 80, order=3)\n\n area = dict(llcrnrlon=11.75, urcrnrlon=21, llcrnrlat=33, urcrnrlat=36.75)"
138+ ]
139+ },
140+ {
141+ "cell_type" : " markdown" ,
142+ "metadata" : {},
143+ "source" : [
144+ " Spectrum\n\n "
145+ ]
146+ },
147+ {
148+ "cell_type" : " code" ,
149+ "execution_count" : null ,
150+ "metadata" : {
151+ "collapsed" : false
152+ },
153+ "outputs" : [],
154+ "source" : [
155+ " fig = plt.figure(figsize=(10, 6))\n ax = fig.add_subplot(111)\n ax.set_title(\" Spectrum\" )\n ax.set_xlabel(\" km\" )\n\n lon_spec, lat_spec = g.spectrum_lonlat(\" adt\" , area=area)\n mappable = ax.loglog(*lat_spec, label=\" lat raw\" )[0]\n ax.loglog(*lon_spec, label=\" lon raw\" , color=mappable.get_color(), linestyle=\" --\" )\n\n lon_spec, lat_spec = g.spectrum_lonlat(\" adt_high_80\" , area=area)\n mappable = ax.loglog(*lat_spec, label=\" lat high\" )[0]\n ax.loglog(*lon_spec, label=\" lon high\" , color=mappable.get_color(), linestyle=\" --\" )\n\n lon_spec, lat_spec = g.spectrum_lonlat(\" adt_low_80\" , area=area)\n mappable = ax.loglog(*lat_spec, label=\" lat low\" )[0]\n ax.loglog(*lon_spec, label=\" lon low\" , color=mappable.get_color(), linestyle=\" --\" )\n\n ax.set_xlim(10, 1000)\n ax.set_ylim(1e-6, 1)\n ax.set_xscale(\" log\" )\n ax.legend()\n ax.grid()"
156+ ]
157+ },
158+ {
159+ "cell_type" : " markdown" ,
160+ "metadata" : {},
161+ "source" : [
162+ " Spectrum ratio\n\n "
163+ ]
164+ },
165+ {
166+ "cell_type" : " code" ,
167+ "execution_count" : null ,
168+ "metadata" : {
169+ "collapsed" : false
170+ },
171+ "outputs" : [],
172+ "source" : [
173+ " fig = plt.figure(figsize=(10, 6))\n ax = fig.add_subplot(111)\n ax.set_title(\" Spectrum ratio\" )\n ax.set_xlabel(\" km\" )\n\n lon_spec, lat_spec = g.spectrum_lonlat(\n \" adt_high_80\" , area=area, ref=g, ref_grid_name=\" adt\"\n )\n mappable = ax.plot(*lat_spec, label=\" lat high\" )[0]\n ax.plot(*lon_spec, label=\" lon high\" , color=mappable.get_color(), linestyle=\" --\" )\n\n lon_spec, lat_spec = g.spectrum_lonlat(\n \" adt_low_80\" , area=area, ref=g, ref_grid_name=\" adt\"\n )\n mappable = ax.plot(*lat_spec, label=\" lat low\" )[0]\n ax.plot(*lon_spec, label=\" lon low\" , color=mappable.get_color(), linestyle=\" --\" )\n\n ax.set_xlim(10, 1000)\n ax.set_ylim(0, 1)\n ax.set_xscale(\" log\" )\n ax.legend()\n ax.grid()"
174+ ]
175+ },
176+ {
177+ "cell_type" : " markdown" ,
178+ "metadata" : {},
179+ "source" : [
180+ " Old filter\n ----------\n To do ...\n\n "
181+ ]
182+ }
183+ ],
184+ "metadata" : {
185+ "kernelspec" : {
186+ "display_name" : " Python 3" ,
187+ "language" : " python" ,
188+ "name" : " python3"
189+ },
190+ "language_info" : {
191+ "codemirror_mode" : {
192+ "name" : " ipython" ,
193+ "version" : 3
194+ },
195+ "file_extension" : " .py" ,
196+ "mimetype" : " text/x-python" ,
197+ "name" : " python" ,
198+ "nbconvert_exporter" : " python" ,
199+ "pygments_lexer" : " ipython3" ,
200+ "version" : " 3.7.7"
201+ }
202+ },
203+ "nbformat" : 4 ,
204+ "nbformat_minor" : 0
205+ }
0 commit comments