Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lat/lon of grid points #159

Open
juanpablosimarro opened this issue Jul 1, 2020 · 5 comments
Open

lat/lon of grid points #159

juanpablosimarro opened this issue Jul 1, 2020 · 5 comments
Assignees
Labels
good first issue Good for newcomers support User request for support

Comments

@juanpablosimarro
Copy link

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

@pulkkins
Copy link
Member

pulkkins commented Jul 2, 2020

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
Copy link
Member

pulkkins commented Jul 2, 2020

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.

@dnerini dnerini added good first issue Good for newcomers support User request for support labels Jul 4, 2020
@dnerini
Copy link
Member

dnerini commented Jul 4, 2020

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?

@juanpablosimarro
Copy link
Author

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
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers support User request for support
Projects
None yet
Development

No branches or pull requests

4 participants