I have two xarray data arrays (1. land_data, 2. climate_data) that I want to reproject and match (rio.reproject_match()):
climate_data_matched = climate_data.rio.reproject_match(land_data)
- Land data is a geotiff file with
land_data.rio.crs
=EPSG:4326
. The crs attribute is accepted byrio.reproject_match()
. - Climate data is a netcdf file with
climate_data.rio.crs
=
GEOGCRS["undefined",BASEGEOGCRS["undefined",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ID["EPSG",6326]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]],DERIVINGCONVERSION["Pole rotation (netCDF CF convention)",METHOD["Pole rotation (netCDF CF convention)"],PARAMETER["Grid north pole latitude (netCDF CF convention)",39.25,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],PARAMETER["Grid north pole longitude (netCDF CF convention)",198,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],PARAMETER["North pole grid longitude (netCDF CF convention)",0,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]],CS[ellipsoidal,2],AXIS["longitude",east,ORDER1,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],AXIS["latitude",north,ORDER2,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]]
However, rio.reproject_match()
does
only support OGC WKT (from spatialreference.org).
PROBLEM: If I run the code as described above, the climate_data array is empty (NaN values).
My assumption is that the prefix GEOGCRS cannot be interpreted and instead I need to convert the wkt to a string starting with GEOGCS (in line with OGC WKT). How can I convert them? I converted crs = climate_data.rio.crs.to_proj4()
and then wanted to use pycrs to crs = pycrs.parse.from_proj4(crs)
and crs = pycrs.parse.from_ogc_wkt(crs)
. But I got an error parsing the proj4 string: "The specified projection name 'ob_tran' could not be found in the list of supported projections."
If I manually modify the crs of climate_data climate_data = climate_data.rio.write_crs("epsg:4326", inplace=True)
and then run the code from above rio.reproject_match()
works perfectly fine. But I do not know whether 'EPSG:4326'
is actually to right code for the climate_data. How can I get the EPSG code from the wkt string starting with GEOGCRS?
Furthermore, I found this issue that proj4 failed in the past with GEOGCRS. And GEOGCRS is also defined in opengeospatial.org.