0

I have a netcdf that I want to slice by coordinates, but when I open it, the dataset appears not to have any coordinates associated. It has dimmensions and lat/lon variables, but any coordinates, so it looks like this:

<xarray.Dataset>
Dimensions:             (y: 10980, x: 10980)
Dimensions without coordinates: y, x
Data variables: (12/20)
    lon                 (y, x) float32 ...
    lat                 (y, x) float32 ...

But I need something like this:

<xarray.Dataset>
Dimensions:              (x: 7861, y: 7981)
Coordinates:
  * x                    (x) float64 1.992e+05 1.992e+05 ... 4.35e+05 4.35e+05
  * y                    (y) float64 4.586e+06 4.586e+06 ... 4.347e+06 4.347e+06
Data variables: (12/15)
    lon                  (y, x) float32 ...
    lat                  (y, x) float32 ...

I cannot upload the netcdf files as they're extremely heavy, sorry about that.

Any grasp of how it can possibly be done would be very appreciated!!

OlegRuskiy
  • 173
  • 2
  • 12
  • Do you know the projection / crs of the data? – Michael Delgado Mar 22 '22 at 16:33
  • 1
    I also think that the x,y are coordinates in some other projection than ordinary lon/lat... – msi_gerva Mar 22 '22 at 17:06
  • 1
    Yep exactly. If you have metadata associated with the file it might say the projection somewhere… like “EPSG: 5070” or something like that. If you have that then you could convert the lat lon values to a regular grid with pyproj but you do need to know the projection. – Michael Delgado Mar 23 '22 at 05:54
  • Thanks for your answer @MichaelDelgado ! The projection is EPSG: 32631. So now I need to use pyproj? Could you please provide a small example? I'm quite new to pyproj. Thank you very much!! – OlegRuskiy Mar 23 '22 at 10:44
  • Check out the [proj docs](https://pyproj4.github.io/pyproj/stable/api/proj.html#pyproj-proj) - it’s pretty straightforward - just initialize a proj transformer and then plug in lat and lon to get the transformed values. – Michael Delgado Mar 24 '22 at 04:44
  • Yeah I got that, but my problem is that I am unable to assign proper coordinates to my dataset @MichaelDelgado – OlegRuskiy Mar 24 '22 at 11:18
  • can you provide a [mre]? we don't really have much to work with here. – Michael Delgado Mar 24 '22 at 15:11
  • @MichaelDelgado I opened a new question where I explain in detail the problem, mre included! https://stackoverflow.com/q/71616481/16173560 – OlegRuskiy Mar 25 '22 at 11:48

0 Answers0