Skip to content

Commit 61b1b4f

Browse files
dbkhoutDaan Buekenhout
andauthored
Fix grid coordinates in plots (#340)
* Update utils.py * fix-typo * fix reproject_geodata --------- Co-authored-by: Daan Buekenhout <daan.buekenhout@kuleuven.be>
1 parent 89824c4 commit 61b1b4f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

pysteps/visualization/utils.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,14 @@ def reproject_geodata(geodata, t_proj4str, return_grid=None):
237237
# Reproject grid on fall-back projection
238238
if return_grid is not None:
239239
if return_grid == "coords":
240-
y_coord = np.linspace(y1, y2, shape[0]) + geodata["ypixelsize"] / 2.0
241-
x_coord = np.linspace(x1, x2, shape[1]) + geodata["xpixelsize"] / 2.0
240+
y_coord = (
241+
np.linspace(y1, y2, shape[0], endpoint=False)
242+
+ geodata["ypixelsize"] / 2.0
243+
)
244+
x_coord = (
245+
np.linspace(x1, x2, shape[1], endpoint=False)
246+
+ geodata["xpixelsize"] / 2.0
247+
)
242248
elif return_grid == "quadmesh":
243249
y_coord = np.linspace(y1, y2, shape[0] + 1)
244250
x_coord = np.linspace(x1, x2, shape[1] + 1)
@@ -327,7 +333,7 @@ def get_geogrid(nlat, nlon, geodata=None):
327333
Four-element tuple specifying the extent of the domain according to
328334
(lower left x, upper right x, lower left y, upper right y).
329335
regular_grid: bool
330-
True is the grid is regular. False otherwise.
336+
True if the grid is regular. False otherwise.
331337
origin: str
332338
Place the [0, 0] index of the array to plot in the upper left or lower left
333339
corner of the axes.
@@ -337,13 +343,15 @@ def get_geogrid(nlat, nlon, geodata=None):
337343
regular_grid = geodata.get("regular_grid", True)
338344

339345
x_lims = sorted((geodata["x1"], geodata["x2"]))
340-
x = np.linspace(x_lims[0], x_lims[1], nlon)
341-
xpixelsize = np.abs(x[1] - x[0])
346+
x, xpixelsize = np.linspace(
347+
x_lims[0], x_lims[1], nlon, endpoint=False, retstep=True
348+
)
342349
x += xpixelsize / 2.0
343350

344351
y_lims = sorted((geodata["y1"], geodata["y2"]))
345-
y = np.linspace(y_lims[0], y_lims[1], nlat)
346-
ypixelsize = np.abs(y[1] - y[0])
352+
y, ypixelsize = np.linspace(
353+
y_lims[0], y_lims[1], nlat, endpoint=False, retstep=True
354+
)
347355
y += ypixelsize / 2.0
348356

349357
extent = (geodata["x1"], geodata["x2"], geodata["y1"], geodata["y2"])

0 commit comments

Comments
 (0)