pysteps icon indicating copy to clipboard operation
pysteps copied to clipboard

lat/lon of grid points

Open juanpablosimarro opened this issue 5 years ago • 5 comments

Hello,

I wonder if there is a method to get the longitudes and latitudes of all grid points. From this code:

importer = io.get_method(importer_name, "importer") Z, _, metadata = io.read_timeseries(fns, importer, **importer_kwargs)

Given Z and metadata from the file (HDF5 or other format), is there a method to get the longitude and latitude of the grid points of Z given the information kept in metadata?

Thank you

Juan Simarro

juanpablosimarro avatar Jul 01 '20 16:07 juanpablosimarro

This feature has not been implemented in pysteps. Implementing an utility function for doing this could be useful.

In the meanwhile, you can use the following example:

import numpy as np import pyproj

xr = np.arange(geodata["x1"], geodata["x2"], geodata["xpixelsize"]) xr += 0.5 * (xr[1] - xr[0]) yr = np.arange(geodata["y1"], geodata["y2"], geodata["ypixelsize"]) yr += 0.5 * (yr[1] - yr[0]) grid_x, grid_y = np.meshgrid(xr, yr)

pr = pyproj.Proj(geodata["projection"]) grid_lon, grid_lat = pr(grid_x, grid_y, inverse=True)

pulkkins avatar Jul 02 '20 11:07 pulkkins

Correction: a similar piece of code is used in io.exporters.initialize_forecast_exporter_netcdf. It's not too much effort to implement that in a separate utility function.

pulkkins avatar Jul 02 '20 11:07 pulkkins

Hello @juanpablosimarro, @pulkkins already provided you with some good answers to your problem. Let us know should you need more support.

@pulkkins, maybe what you suggest could be flagged as a good first issue? @juanpablosimarro would you be interested in having a go at it?

dnerini avatar Jul 04 '20 09:07 dnerini

Hello, Thank you for your answers. I will try today to use those solutions. If I encounter any problem, I will report here. King regards Juan

juanpablosimarro avatar Jul 06 '20 11:07 juanpablosimarro

Hello again, I had problems with the exporters and OPERA. The code you provide above works well except that it is necessary to reverse the order of the y axis: grid_x, grid_y = np.meshgrid(xr, np.flip(yr)) Thanks again!

juanpablosimarro avatar Jul 07 '20 10:07 juanpablosimarro