I aim to reproject values from two arrays, ‘longitude’ and ‘latitude’ and treating each corresponding value as a coordinate pair reproject to a local map projection. I’m just wondering about the approach I use, and whether there’s a more idiomatic Python way to do this.
Here is a notebook that achieves my aim:
The NetCDF file in the notebook with longitude,latitude arrays shape = (2030, 1354)
is downloaded from NASA ocean colour.
There’s code to open the file, and isolate the ‘/navigation_data’ group which has longitude and latitude.
Then
- reshape the values into a matrix of longitude,latitude pairs
- define a local projection from a central coordinate
- reproject with pyproj in a function
project_array()
- set up ‘x’ and ‘y’ DataArrays with the same properties as ‘longitude’ and ‘latitude’ and fill with the projected values
My questions are, what is the most xarray-idiomatic way to do this? Is there anything especially wrong with the style here of how the reprojection is done?
I know that copying the longitude,latitude to fill with x,y is not ideal but I’m less concerned about that. Is there a better way to do the raw coordinate reprojection, but if there’s input into how the new arrays are added that will also help a lot.
Any feedback welcome, thanks! Michael Sumner