Skip to content

Commit 1ba589b

Browse files
committed
Manipulation of coordinates to set eddies in window
1 parent 4393c79 commit 1ba589b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/py_eddy_tracker/observations/observation.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,9 @@ def scatter(self, ax, name, ref=None, factor=1, **kwargs):
12561256
x = (x - ref) % 360 + ref
12571257
return ax.scatter(x, self.latitude, c=self[name] * factor, **kwargs)
12581258

1259-
def display(self, ax, ref=None, extern_only=False, intern_only=False, nobs=True, **kwargs):
1259+
def display(
1260+
self, ax, ref=None, extern_only=False, intern_only=False, nobs=True, **kwargs
1261+
):
12601262
if not extern_only:
12611263
lon_s = flatten_line_matrix(self.obs["contour_lon_s"])
12621264
lat_s = flatten_line_matrix(self.obs["contour_lat_s"])
@@ -1287,14 +1289,23 @@ def grid_count(self, bins, intern=False, center=False):
12871289

12881290
regular_grid = RegularGridDataset.with_array(
12891291
coordinates=("lon", "lat"),
1290-
datas=dict(count=grid, lon=x_bins[:-1], lat=y_bins[:-1],),
1292+
datas=dict(
1293+
count=grid,
1294+
lon=(x_bins[1:] + x_bins[:-1]) / 2,
1295+
lat=(y_bins[1:] + y_bins[:-1]) / 2,
1296+
),
1297+
variables_description=dict(
1298+
count=dict(long_name="Number of times pixel is in eddies")
1299+
),
1300+
centered=True,
12911301
)
12921302
if center:
12931303
x, y = (self.longitude - x0) % 360 + x0, self.latitude
12941304
grid[:] = histogram2d(x, y, (x_bins, y_bins))[0]
12951305
grid.mask = grid.data == 0
12961306
else:
1297-
x, y = (self[x_name] - x0) % 360 + x0, self[y_name]
1307+
x_ref = ((self.longitude - x0) % 360 + x0 - 180).reshape(-1, 1)
1308+
x, y = (self[x_name] - x_ref) % 360 + x_ref, self[y_name]
12981309
for x_, y_ in zip(x, y):
12991310
i, j = BasePath(create_vertice(x_, y_)).pixels_in(regular_grid)
13001311
grid_count_(grid, i, j)

0 commit comments

Comments
 (0)