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 # Stastics on identification files\n\n Some statistics on raw identification without any tracking\n "
19
+ ]
20
+ },
21
+ {
22
+ "cell_type" : " code" ,
23
+ "execution_count" : null ,
24
+ "metadata" : {
25
+ "collapsed" : false
26
+ },
27
+ "outputs" : [],
28
+ "source" : [
29
+ " import numpy as np\n from matplotlib import pyplot as plt\n from matplotlib.dates import date2num\n\n from py_eddy_tracker import start_logger\n from py_eddy_tracker.data import get_remote_demo_sample\n from py_eddy_tracker.observations.observation import EddiesObservations\n\n start_logger().setLevel(\" ERROR\" )"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type" : " code" ,
34
+ "execution_count" : null ,
35
+ "metadata" : {
36
+ "collapsed" : false
37
+ },
38
+ "outputs" : [],
39
+ "source" : [
40
+ " 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(mappable, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type" : " markdown" ,
45
+ "metadata" : {},
46
+ "source" : [
47
+ " We load demo sample and take only first year.\n\n Replace by a list of filename to apply on your own dataset.\n\n "
48
+ ]
49
+ },
50
+ {
51
+ "cell_type" : " code" ,
52
+ "execution_count" : null ,
53
+ "metadata" : {
54
+ "collapsed" : false
55
+ },
56
+ "outputs" : [],
57
+ "source" : [
58
+ " file_objects = get_remote_demo_sample(\n \" eddies_med_adt_allsat_dt2018/Anticyclonic_2010_2011_2012\"\n )[:365]"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type" : " markdown" ,
63
+ "metadata" : {},
64
+ "source" : [
65
+ " Merge all identification dataset in one object\n\n "
66
+ ]
67
+ },
68
+ {
69
+ "cell_type" : " code" ,
70
+ "execution_count" : null ,
71
+ "metadata" : {
72
+ "collapsed" : false
73
+ },
74
+ "outputs" : [],
75
+ "source" : [
76
+ " all_a = EddiesObservations.concatenate(\n [EddiesObservations.load_file(i) for i in file_objects]\n )"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type" : " markdown" ,
81
+ "metadata" : {},
82
+ "source" : [
83
+ " We define polygon bound\n\n "
84
+ ]
85
+ },
86
+ {
87
+ "cell_type" : " code" ,
88
+ "execution_count" : null ,
89
+ "metadata" : {
90
+ "collapsed" : false
91
+ },
92
+ "outputs" : [],
93
+ "source" : [
94
+ " x0, x1, y0, y1 = 15, 20, 33, 38\n xs = np.array([[x0, x1, x1, x0, x0]], dtype=\" f8\" )\n ys = np.array([[y0, y0, y1, y1, y0]], dtype=\" f8\" )\n # Polygon object is create to be usable by match function.\n polygon = dict(contour_lon_e=xs, contour_lat_e=ys, contour_lon_s=xs, contour_lat_s=ys)"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type" : " markdown" ,
99
+ "metadata" : {},
100
+ "source" : [
101
+ " Geographic frequency of eddies\n\n "
102
+ ]
103
+ },
104
+ {
105
+ "cell_type" : " code" ,
106
+ "execution_count" : null ,
107
+ "metadata" : {
108
+ "collapsed" : false
109
+ },
110
+ "outputs" : [],
111
+ "source" : [
112
+ " step = 0.125\n ax = start_axes(\"\" )\n # Count pixel used for each contour\n g_a = all_a.grid_count(bins=((-10, 37, step), (30, 46, step)), intern=True)\n m = g_a.display(\n ax, cmap=\" terrain_r\" , vmin=0, vmax=0.75, factor=1 / all_a.nb_days, name=\" count\"\n )\n ax.plot(polygon[\" contour_lon_e\" ][0], polygon[\" contour_lat_e\" ][0], \" r\" )\n update_axes(ax, m)"
113
+ ]
114
+ },
115
+ {
116
+ "cell_type" : " markdown" ,
117
+ "metadata" : {},
118
+ "source" : [
119
+ " We use match function to count number of eddies which intersect the polygon defined previously.\n `p1_area` option allow to get in c_e/c_s output, precentage of area occupy by eddies in the polygon.\n\n "
120
+ ]
121
+ },
122
+ {
123
+ "cell_type" : " code" ,
124
+ "execution_count" : null ,
125
+ "metadata" : {
126
+ "collapsed" : false
127
+ },
128
+ "outputs" : [],
129
+ "source" : [
130
+ " i_e, j_e, c_e = all_a.match(polygon, p1_area=True, intern=False)\n i_s, j_s, c_s = all_a.match(polygon, p1_area=True, intern=True)"
131
+ ]
132
+ },
133
+ {
134
+ "cell_type" : " code" ,
135
+ "execution_count" : null ,
136
+ "metadata" : {
137
+ "collapsed" : false
138
+ },
139
+ "outputs" : [],
140
+ "source" : [
141
+ " dt = np.datetime64(\" 1970-01-01\" ) - np.datetime64(\" 1950-01-01\" )\n kw_hist = dict(\n bins=date2num(np.arange(21900, 22300).astype(\" datetime64\" ) - dt), histtype=\" step\"\n )\n # translate julian day in datetime64\n t = all_a.time.astype(\" datetime64\" ) - dt"
142
+ ]
143
+ },
144
+ {
145
+ "cell_type" : " markdown" ,
146
+ "metadata" : {},
147
+ "source" : [
148
+ " Count how many are in polygon\n\n "
149
+ ]
150
+ },
151
+ {
152
+ "cell_type" : " code" ,
153
+ "execution_count" : null ,
154
+ "metadata" : {
155
+ "collapsed" : false
156
+ },
157
+ "outputs" : [],
158
+ "source" : [
159
+ " ax = plt.figure(figsize=(12, 6)).add_subplot(111)\n ax.set_title(\" Different way to count eddies presence in a polygon\" )\n ax.set_ylabel(\" Count\" )\n m = all_a.mask_from_polygons(((xs, ys),))\n ax.hist(t[m], label=\" center in polygon\" , **kw_hist)\n ax.hist(t[i_s[c_s > 0]], label=\" intersect speed contour with polygon\" , **kw_hist)\n ax.hist(t[i_e[c_e > 0]], label=\" intersect extern contour with polygon\" , **kw_hist)\n ax.legend()\n ax.set_xlim(np.datetime64(\" 2010\" ), np.datetime64(\" 2011\" ))\n ax.grid()"
160
+ ]
161
+ },
162
+ {
163
+ "cell_type" : " markdown" ,
164
+ "metadata" : {},
165
+ "source" : [
166
+ " Percent of are of interest occupy by eddies\n\n "
167
+ ]
168
+ },
169
+ {
170
+ "cell_type" : " code" ,
171
+ "execution_count" : null ,
172
+ "metadata" : {
173
+ "collapsed" : false
174
+ },
175
+ "outputs" : [],
176
+ "source" : [
177
+ " ax = plt.figure(figsize=(12, 6)).add_subplot(111)\n ax.set_title(\" Percent of polygon occupy by an anticyclonic eddy\" )\n ax.set_ylabel(\" Percent of polygon\" )\n ax.hist(t[i_s[c_s > 0]], weights=c_s[c_s > 0] * 100.0, label=\" speed contour\" , **kw_hist)\n ax.hist(t[i_e[c_e > 0]], weights=c_e[c_e > 0] * 100.0, label=\" effective contour\" , **kw_hist)\n ax.legend(), ax.set_ylim(0, 25)\n ax.set_xlim(np.datetime64(\" 2010\" ), np.datetime64(\" 2011\" ))\n ax.grid()"
178
+ ]
179
+ }
180
+ ],
181
+ "metadata" : {
182
+ "kernelspec" : {
183
+ "display_name" : " Python 3" ,
184
+ "language" : " python" ,
185
+ "name" : " python3"
186
+ },
187
+ "language_info" : {
188
+ "codemirror_mode" : {
189
+ "name" : " ipython" ,
190
+ "version" : 3
191
+ },
192
+ "file_extension" : " .py" ,
193
+ "mimetype" : " text/x-python" ,
194
+ "name" : " python" ,
195
+ "nbconvert_exporter" : " python" ,
196
+ "pygments_lexer" : " ipython3" ,
197
+ "version" : " 3.7.7"
198
+ }
199
+ },
200
+ "nbformat" : 4 ,
201
+ "nbformat_minor" : 0
202
+ }
0 commit comments