Skip to content

Commit 729e17e

Browse files
committed
Apply black and test with flake8
1 parent 0d7f881 commit 729e17e

File tree

19 files changed

+659
-579
lines changed

19 files changed

+659
-579
lines changed

doc/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15-
import sys
16-
import os
15+
# import sys
16+
# import os
1717

1818
# If extensions (or modules to document with autodoc) are in another directory,
1919
# add these directories to sys.path here. If the directory is relative to the
@@ -39,7 +39,7 @@
3939
sphinx_gallery_conf = {
4040
'examples_dirs': '../examples', # path to your example scripts
4141
'gallery_dirs': 'python_module',
42-
'capture_repr': ('_repr_html_', '__repr__'),
42+
'capture_repr': ('_repr_html_'),
4343
'line_numbers': False,
4444
'filename_pattern': '/pet',
4545
}

examples/pet_display_id.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
c = EddiesObservations.load_file(data.get_path("Cyclonic_20190223.nc"))
1313

1414
# Plot
15-
fig = plt.figure(figsize=(15,8))
15+
fig = plt.figure(figsize=(15, 8))
1616
ax = fig.add_subplot(111)
17-
ax.set_aspect('equal')
17+
ax.set_aspect("equal")
1818
ax.set_xlim(0, 360)
1919
ax.set_ylim(-80, 80)
2020
a.display(ax, label="Anticyclonic", color="r", lw=1)

examples/pet_one_track.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313

1414
eddy = a.extract_ids([9672])
1515
eddy_f = a.extract_ids([9672])
16-
eddy_f.median_filter(1, 'time', 'lon').loess_filter(5, 'time', 'lon')
17-
eddy_f.median_filter(1, 'time', 'lat').loess_filter(5, 'time', 'lat')
16+
eddy_f.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
17+
eddy_f.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
1818
fig = plt.figure(figsize=(20, 8))
1919
ax = fig.add_subplot(111)
2020
ax.set_xlim(17, 22.5)
2121
ax.set_ylim(35, 36.5)
2222
ax.grid()
23-
eddy.plot(ax, color='r', lw=.5)
24-
eddy_f.plot(ax, color='g', lw=1)
25-
23+
eddy.plot(ax, color="r", lw=0.5)
24+
eddy_f.plot(ax, color="g", lw=1)

examples/tracking_diagnostics/pet_center_count.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@
99
import py_eddy_tracker_sample
1010

1111

12-
a = TrackEddiesObservations.load_file(py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Anticyclonic.zarr"))
13-
c = TrackEddiesObservations.load_file(py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr"))
12+
a = TrackEddiesObservations.load_file(
13+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Anticyclonic.zarr")
14+
)
15+
c = TrackEddiesObservations.load_file(
16+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
17+
)
1418
a = a.merge(c)
1519
# Plot
1620
fig = plt.figure(figsize=(20, 8))
1721
ax = fig.add_subplot(111)
1822
ax.set_xlim(-5, 37)
1923
ax.set_ylim(30, 46)
20-
step = .1
24+
step = 0.1
2125
t0, t1 = a.period
2226
g = a.grid_count(((-5, 37, step), (30, 46, step)), center=True)
23-
g.vars['count'] = g.vars['count'] / (step ** 2 * (t1 - t0))
24-
m = g.display(ax, name='count', vmin=0, vmax=2)
27+
g.vars["count"] = g.vars["count"] / (step ** 2 * (t1 - t0))
28+
m = g.display(ax, name="count", vmin=0, vmax=2)
2529
ax.grid()
2630
cb = plt.colorbar(m, cax=fig.add_axes([0.95, 0.05, 0.01, 0.9]))
27-
cb.set_label('Eddies by 1°^2 by day')
28-
31+
cb.set_label("Eddies by 1°^2 by day")

examples/tracking_diagnostics/pet_lifetime.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,46 @@
88
import py_eddy_tracker_sample
99
from numpy import arange
1010

11-
a = TrackEddiesObservations.load_file(py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Anticyclonic.zarr"))
12-
c = TrackEddiesObservations.load_file(py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr"))
11+
a = TrackEddiesObservations.load_file(
12+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Anticyclonic.zarr")
13+
)
14+
c = TrackEddiesObservations.load_file(
15+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
16+
)
1317

1418
# Plot
1519
fig = plt.figure()
16-
ax_lifetime = fig.add_axes([0.05, 0.55, .4, .4])
17-
ax_cum_lifetime = fig.add_axes([0.55, 0.55, .4, .4])
18-
ax_ratio_lifetime = fig.add_axes([0.05, 0.05, .4, .4])
19-
ax_ratio_cum_lifetime = fig.add_axes([0.55, 0.05, .4, .4])
20+
ax_lifetime = fig.add_axes([0.05, 0.55, 0.4, 0.4])
21+
ax_cum_lifetime = fig.add_axes([0.55, 0.55, 0.4, 0.4])
22+
ax_ratio_lifetime = fig.add_axes([0.05, 0.05, 0.4, 0.4])
23+
ax_ratio_cum_lifetime = fig.add_axes([0.55, 0.05, 0.4, 0.4])
2024

2125

22-
cum_a, bins, _ = ax_cum_lifetime.hist(a['n'], histtype='step', bins=arange(0,800,1), label='Anticyclonic', color='r')
23-
cum_c, bins, _ = ax_cum_lifetime.hist(c['n'], histtype='step', bins=arange(0,800,1), label='Cyclonic', color='b')
26+
cum_a, bins, _ = ax_cum_lifetime.hist(
27+
a["n"], histtype="step", bins=arange(0, 800, 1), label="Anticyclonic", color="r"
28+
)
29+
cum_c, bins, _ = ax_cum_lifetime.hist(
30+
c["n"], histtype="step", bins=arange(0, 800, 1), label="Cyclonic", color="b"
31+
)
2432

25-
x = (bins[1:] + bins[:-1]) / 2.
26-
ax_ratio_cum_lifetime.plot(x, cum_c/cum_a)
33+
x = (bins[1:] + bins[:-1]) / 2.0
34+
ax_ratio_cum_lifetime.plot(x, cum_c / cum_a)
2735

2836
nb_a, nb_c = cum_a[:-1] - cum_a[1:], cum_c[:-1] - cum_c[1:]
29-
ax_lifetime.plot(x[1:], nb_a, label='Anticyclonic', color='r')
30-
ax_lifetime.plot(x[1:], nb_c, label='Cyclonic', color='b')
37+
ax_lifetime.plot(x[1:], nb_a, label="Anticyclonic", color="r")
38+
ax_lifetime.plot(x[1:], nb_c, label="Cyclonic", color="b")
3139

3240
ax_ratio_lifetime.plot(x[1:], nb_c / nb_a)
3341

3442

3543
for ax in (ax_lifetime, ax_cum_lifetime, ax_ratio_cum_lifetime, ax_ratio_lifetime):
36-
ax.set_xlim(0,365)
44+
ax.set_xlim(0, 365)
3745
if ax in (ax_lifetime, ax_cum_lifetime):
38-
ax.set_ylim(1,None)
39-
ax.set_yscale('log')
46+
ax.set_ylim(1, None)
47+
ax.set_yscale("log")
4048
ax.legend()
4149
else:
42-
ax.set_ylim(0,2)
43-
ax.set_ylabel('Ratio Cyclonic/Anticyclonic')
44-
ax.set_xlabel('Lifetime (days)')
50+
ax.set_ylim(0, 2)
51+
ax.set_ylabel("Ratio Cyclonic/Anticyclonic")
52+
ax.set_xlabel("Lifetime (days)")
4553
ax.grid()

examples/tracking_diagnostics/pet_pixel_used.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@
99
import py_eddy_tracker_sample
1010

1111

12-
a = TrackEddiesObservations.load_file(py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Anticyclonic.zarr"))
13-
c = TrackEddiesObservations.load_file(py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr"))
12+
a = TrackEddiesObservations.load_file(
13+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Anticyclonic.zarr")
14+
)
15+
c = TrackEddiesObservations.load_file(
16+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
17+
)
1418

1519
# Plot
1620
fig = plt.figure(figsize=(15, 20))
1721
ax_a = fig.add_subplot(311)
18-
ax_a.set_title('Anticyclonic frequency')
22+
ax_a.set_title("Anticyclonic frequency")
1923
ax_c = fig.add_subplot(312)
20-
ax_c.set_title('Cyclonic frequency')
24+
ax_c.set_title("Cyclonic frequency")
2125
ax_all = fig.add_subplot(313)
22-
ax_all.set_title('All eddies frequency')
26+
ax_all.set_title("All eddies frequency")
2327

2428
step = 0.1
25-
kwargs_pcolormesh = dict(cmap='terrain_r', vmin=0, vmax=.75)
29+
kwargs_pcolormesh = dict(cmap="terrain_r", vmin=0, vmax=0.75)
2630
g_a = a.grid_count(((-5, 37, step), (30, 46, step)), intern=True)
2731
t0, t1 = a.period
2832
g_a.vars["count"] = g_a.vars["count"] / (t1 - t0)

examples/tracking_diagnostics/pet_propagation.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,23 @@ def cum_distance_by_track(distance, track):
2626
new_distance[i + 1] = d_cum
2727
return new_distance
2828

29+
2930
a = TrackEddiesObservations.load_file(
3031
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Anticyclonic.zarr")
3132
)
3233
c = TrackEddiesObservations.load_file(
3334
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
3435
)
3536

36-
a.median_filter(1, 'time', 'lon').loess_filter(5, 'time', 'lon')
37-
a.median_filter(1, 'time', 'lat').loess_filter(5, 'time', 'lat')
38-
c.median_filter(1, 'time', 'lon').loess_filter(5, 'time', 'lon')
39-
c.median_filter(1, 'time', 'lat').loess_filter(5, 'time', 'lat')
37+
a.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
38+
a.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
39+
c.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
40+
c.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
4041

4142
d_a = distance(a.longitude[:-1], a.latitude[:-1], a.longitude[1:], a.latitude[1:])
4243
d_c = distance(c.longitude[:-1], c.latitude[:-1], c.longitude[1:], c.latitude[1:])
43-
d_a = cum_distance_by_track(d_a, a["track"]) / 1000.
44-
d_c = cum_distance_by_track(d_c, c["track"]) / 1000.
44+
d_a = cum_distance_by_track(d_a, a["track"]) / 1000.0
45+
d_c = cum_distance_by_track(d_c, c["track"]) / 1000.0
4546

4647
# Plot
4748
fig = plt.figure()
@@ -69,7 +70,12 @@ def cum_distance_by_track(distance, track):
6970
ax_ratio_propagation.plot(x[1:], nb_c / nb_a)
7071

7172

72-
for ax in (ax_propagation, ax_cum_propagation, ax_ratio_cum_propagation, ax_ratio_propagation):
73+
for ax in (
74+
ax_propagation,
75+
ax_cum_propagation,
76+
ax_ratio_cum_propagation,
77+
ax_ratio_propagation,
78+
):
7379
ax.set_xlim(0, 1000)
7480
if ax in (ax_propagation, ax_cum_propagation):
7581
ax.set_ylim(1, None)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
],
2828
zip_safe=False,
2929
entry_points=dict(
30-
console_scripts=["MergeEddies = py_eddy_tracker.appli:merge_eddies",]
30+
console_scripts=["MergeEddies = py_eddy_tracker.appli:merge_eddies"]
3131
),
3232
package_data={
3333
"py_eddy_tracker.featured_tracking": ["*.nc"],

share/fig.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
11
from matplotlib import pyplot as plt
22
from py_eddy_tracker.dataset.grid import RegularGridDataset
3-
grid_name, lon_name, lat_name = 'nrt_global_allsat_phy_l4_20190223_20190226.nc', 'longitude', 'latitude'
3+
4+
grid_name, lon_name, lat_name = (
5+
"nrt_global_allsat_phy_l4_20190223_20190226.nc",
6+
"longitude",
7+
"latitude",
8+
)
49
if False:
510

611
h = RegularGridDataset(grid_name, lon_name, lat_name)
7-
12+
813
fig = plt.figure(figsize=(14, 12))
9-
ax = fig.add_axes([.02, .51, .9, .45])
10-
ax.set_title('ADT (m)')
14+
ax = fig.add_axes([0.02, 0.51, 0.9, 0.45])
15+
ax.set_title("ADT (m)")
1116
ax.set_ylim(-75, 75)
12-
ax.set_aspect('equal')
13-
m = h.display(ax, name='adt', vmin=-1, vmax=1)
17+
ax.set_aspect("equal")
18+
m = h.display(ax, name="adt", vmin=-1, vmax=1)
1419
ax.grid(True)
15-
plt.colorbar(m, cax=fig.add_axes([.94, .51, .01, .45]))
20+
plt.colorbar(m, cax=fig.add_axes([0.94, 0.51, 0.01, 0.45]))
1621
h = RegularGridDataset(grid_name, lon_name, lat_name)
17-
h.bessel_high_filter('adt', 500, order=3)
18-
ax = fig.add_axes([.02, .02, .9, .45])
19-
ax.set_title('ADT Filtered (m)')
20-
ax.set_aspect('equal')
22+
h.bessel_high_filter("adt", 500, order=3)
23+
ax = fig.add_axes([0.02, 0.02, 0.9, 0.45])
24+
ax.set_title("ADT Filtered (m)")
25+
ax.set_aspect("equal")
2126
ax.set_ylim(-75, 75)
22-
m = h.display(ax, name='adt', vmin=-.1, vmax=.1)
27+
m = h.display(ax, name="adt", vmin=-0.1, vmax=0.1)
2328
ax.grid(True)
24-
plt.colorbar(m, cax=fig.add_axes([.94, .02, .01, .45]))
25-
fig.savefig('png/filter.png')
29+
plt.colorbar(m, cax=fig.add_axes([0.94, 0.02, 0.01, 0.45]))
30+
fig.savefig("png/filter.png")
2631

2732
if True:
2833
import logging
29-
logging.getLogger().setLevel('DEBUG') # Values: ERROR, WARNING, INFO, DEBUG
34+
35+
logging.getLogger().setLevel("DEBUG") # Values: ERROR, WARNING, INFO, DEBUG
3036
from datetime import datetime
37+
3138
h = RegularGridDataset(grid_name, lon_name, lat_name)
32-
h.bessel_high_filter('adt', 500, order=3)
39+
h.bessel_high_filter("adt", 500, order=3)
3340
# h.bessel_high_filter('adt', 300, order=1)
3441
date = datetime(2019, 2, 23)
3542
a, c = h.eddy_identification(
36-
'adt', 'ugos', 'vgos', # Variable to use for identification
37-
date, # Date of identification
38-
0.002, # step between two isolines of detection (m)
43+
"adt",
44+
"ugos",
45+
"vgos", # Variable to use for identification
46+
date, # Date of identification
47+
0.002, # step between two isolines of detection (m)
3948
# 0.02, # step between two isolines of detection (m)
40-
pixel_limit=(5, 2000), # Min and max of pixel can be include in contour
41-
shape_error=55, # Error maximal of circle fitting over contour to be accepted
42-
bbox_surface_min_degree=.125 ** 2, # degrees surface minimal to take in account contour
43-
)
44-
fig = plt.figure(figsize=(15,7))
45-
ax = fig.add_axes([.03,.03,.94,.94])
46-
ax.set_title('Eddies detected -- Cyclonic(red) and Anticyclonic(blue)')
47-
ax.set_ylim(-75,75)
48-
ax.set_xlim(0,360)
49-
ax.set_aspect('equal')
50-
a.display(ax, color='b', linewidth=.5)
51-
c.display(ax, color='r', linewidth=.5)
49+
pixel_limit=(5, 2000), # Min and max of pixel can be include in contour
50+
shape_error=55, # Error maximal of circle fitting over contour to be accepted
51+
bbox_surface_min_degree=0.125
52+
** 2, # degrees surface minimal to take in account contour
53+
)
54+
fig = plt.figure(figsize=(15, 7))
55+
ax = fig.add_axes([0.03, 0.03, 0.94, 0.94])
56+
ax.set_title("Eddies detected -- Cyclonic(red) and Anticyclonic(blue)")
57+
ax.set_ylim(-75, 75)
58+
ax.set_xlim(0, 360)
59+
ax.set_aspect("equal")
60+
a.display(ax, color="b", linewidth=0.5)
61+
c.display(ax, color="r", linewidth=0.5)
5262
ax.grid()
53-
fig.savefig('png/eddies.png')
63+
fig.savefig("png/eddies.png")

0 commit comments

Comments
 (0)