Skip to content

Commit b569aee

Browse files
committed
Get a more compact and quicker display status of observations files
1 parent d6f954a commit b569aee

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

src/py_eddy_tracker/appli/eddies.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,20 @@ def get_frequency_grid():
9090

9191
def display_infos():
9292
parser = EddyParser("Display General inforamtion")
93-
parser.add_argument("observations", nargs='+', help="Input observations to compute frequency")
93+
parser.add_argument(
94+
"observations", nargs="+", help="Input observations to compute frequency"
95+
)
9496
args = parser.parse_args()
95-
array_vars = [
96-
"speed_contour_longitude",
97-
"speed_contour_latitude",
98-
"effective_contour_longitude",
99-
"effective_contour_latitude",
100-
"uavg_profile",
97+
vars = [
98+
"amplitude",
99+
"speed_radius",
100+
"speed_area",
101+
"effective_radius",
102+
"effective_area",
103+
"time",
104+
"latitude",
101105
]
102106
for filename in args.observations:
103107
print(f"-- {filename} --")
104-
e = EddiesObservations.load_file(filename, remove_vars=array_vars)
105-
print(e.__repr__())
108+
e = EddiesObservations.load_file(filename, include_vars=vars)
109+
print(e)

src/py_eddy_tracker/observations/observation.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def shifted_ellipsoid_degrees_mask2(lon0, lat0, lon1, lat1, minor=1.5, major=1.5
112112
return m
113113

114114

115+
@njit(cache=True)
116+
def hist_numba(x, bins):
117+
return histogram(x, bins)
118+
119+
115120
class EddiesObservations(object):
116121
"""
117122
Class to hold eddy properties *amplitude* and counts of
@@ -199,6 +204,22 @@ def sign_legend(self):
199204
def shape(self):
200205
return self.observations.shape
201206

207+
def get_infos(self):
208+
infos = dict(
209+
bins_lat=(-90, -60, -15, 15, 60, 90),
210+
bins_amplitude=array((0, 1, 2, 3, 4, 5, 10, 500)),
211+
bins_radius=array((0, 15, 30, 45, 60, 75, 100, 200, 2000)),
212+
nb_obs=self.observations.shape[0],
213+
)
214+
t0, t1 = self.period
215+
infos["t0"], infos["t1"] = t0, t1
216+
infos["period"] = t1 - t0 + 1
217+
return infos
218+
219+
def _repr_html_(self):
220+
infos = self.get_infos()
221+
return f"""<b>{infos['nb_obs']} observations from {infos['t0']} to {infos['t1']} </b>"""
222+
202223
def __repr__(self):
203224
"""
204225
return general informations on dataset as a string
@@ -225,13 +246,13 @@ def hist(varname, x="lat", bins=bins_lat, percent=False, mean=False, nb=False):
225246
:rtype: array
226247
"""
227248
if nb:
228-
v = histogram(self[x], bins=bins)[0]
249+
v = hist_numba(self[x], bins=bins)[0]
229250
else:
230251
v = histogram(self[x], bins=bins, weights=self[varname])[0]
231252
if percent:
232253
v = v.astype("f4") / v.sum() * 100
233254
elif mean:
234-
v /= histogram(self[x], bins=bins)[0]
255+
v /= hist_numba(self[x], bins=bins)[0]
235256
return v
236257

237258
def box_display(value):
@@ -241,25 +262,20 @@ def box_display(value):
241262
return f"""{nb_obs} observations from {t0} to {t1} ({period} days, ~{nb_obs / period:.0f} obs/day)
242263
Speed area : {self["speed_area"].sum() / period / 1e12:.2f} Mkm²/day
243264
Effective area : {self["effective_area"].sum() / period / 1e12:.2f} Mkm²/day
244-
245-
Distribution in Amplitude:
265+
----Distribution in Amplitude:
246266
Amplitude bounds (cm) {box_display(bins_amplitude)}
247267
Percent of eddies : {box_display(hist('time', 'amplitude', bins_amplitude / 100., percent=True, nb=True))}
248-
249-
Distribution in Radius:
268+
----Distribution in Radius:
250269
Speed radius (km) {box_display(bins_radius)}
251270
Percent of eddies : {box_display(hist('time', 'radius_s', bins_radius * 1000., percent=True, nb=True))}
252-
253-
Distribution in Latitude
271+
----Distribution in Latitude
254272
Latitude bounds {box_display(bins_lat)}
255273
Percent of eddies : {box_display(hist('time', percent=True, nb=True))}
256274
Percent of speed area : {box_display(hist('speed_area', percent=True))}
257275
Percent of effective area : {box_display(hist('effective_area', percent=True))}
258-
259276
Mean speed radius (km) : {box_display(hist('radius_s', mean=True) / 1000.)}
260277
Mean effective radius (km): {box_display(hist('radius_e', mean=True) / 1000.)}
261-
Mean amplitude (cm) : {box_display(hist('amplitude', mean=True) * 100.)}
262-
"""
278+
Mean amplitude (cm) : {box_display(hist('amplitude', mean=True) * 100.)}"""
263279

264280
def __getitem__(self, attr):
265281
if attr in self.elements:
@@ -1367,9 +1383,10 @@ def grid_count(self, bins, intern=False, center=False):
13671383
grid.mask = grid.data == 0
13681384
else:
13691385
x_ref = ((self.longitude - x0) % 360 + x0 - 180).reshape(-1, 1)
1370-
x, y = (self[x_name] - x_ref) % 360 + x_ref, self[y_name]
1386+
# x, y = (self[x_name] - x_ref) % 360 + x_ref, self[y_name]
13711387
nb = x_ref.shape[0]
1372-
for i_, (x_, y_) in enumerate(zip(x, y)):
1388+
for i_, (x, y_) in enumerate(zip(self[x_name], self[y_name])):
1389+
x_ = (x - x_ref[i_]) % 360 + x_ref[i_]
13731390
if debug_active and i_ % 10000 == 0:
13741391
print(f"{i_}/{nb}", end="\r")
13751392
i, j = BasePath(create_vertice(x_, y_)).pixels_in(regular_grid)

0 commit comments

Comments
 (0)