I have a NetCDF file which has swapped latitude and longitude positions.
The standard way a Netcdf I normally use is defined as follows:
<xarray.DataArray 'pev' (time: 365, latitude: 480, longitude: 1440)>
Coordinates:
* time (time) datetime64[ns] 2001-01-01T11:30:00 ... 2001-12-31T11:30:00
* longitude (longitude) float32 0.0 0.25 0.5 0.75 ... 359.25 359.5 359.75
* latitude (latitude) float32 59.75 59.5 59.25 59.0 ... -59.5 -59.75 -60.0
But the specifications of the NetCDF I am dealing with is as following:
<xarray.DataArray 'ETa' (time: 12, longitude: 720, latitude: 360)>
Coordinates:
* latitude (latitude) float64 89.75 89.25 88.75 ... -88.75 -89.25 -89.75
* longitude (longitude) float64 -179.8 -179.2 -178.8 ... 178.8 179.2 179.8
Dimensions without coordinates: time

Since the position of latitude and longitude is swapped, it's a bit difficult to do analysis without modifying the code at several steps.
Does anyone has come across such a problem and know how to resolve this issue early on using xarray?
Use the ds.transpose() function.
data.transpose('time', 'latitude', 'longitude')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With