-
Notifications
You must be signed in to change notification settings - Fork 179
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
Understand NetCDF CF convention for projection info in .geobox
property
#837
Comments
I think demonstrating what this would look like would be the most useful I think. One benefit of writing the CRS this way is that it can be understood natively by software using GDAL such as QGIS or rasterio and it can also be understood by newer versions of ArcMap. More information about it can be found here: https://corteva.github.io/rioxarray/html/examples/crs_management.html Here is what a netcdf dataset with CRS information written to the dataset/dataarray with rio.write_crs would look like when opened up using
Here is what is inside the
When parsing the
Also, since the CRS information is in the coordinates, when performing some xarray operations, the CRS information is preserved:
But, to be able to retrieve the CRS information, you would have to have a standard coordinate to look for when the
From #835 (comment)
I agree. In |
@snowman2 thanks for detailed example. I didn't realise that I must say that I do not fully understand the coordinates vs dimensions model of xarray, kinda assume one-to-one mapping, but it's obviously not that simple. Having a special "empty" coordinate that gets propagated through various xarray operations looks like a good approach. I should play around with I should probably ping @andrewdhicks and @omad on this. |
Sounds good 👍. Here is the PLANET_SCOPE_3D.nc file. I think the main difference is that there is a global attribute called
If you write the netCDF file using Side note - I was using the latest (unreleased) version of rioxarray from GitHub as it supports loading in 1-D coordinates. |
Thanks @snowman2, I have some questions regarding this scheme.
Even if using CF supported projections, figuring out I feel like having a scheme that is similar to CF convention, but isn't actually, is worse than having a completely different representation. I do like non-dimension coordinate approach to store CRS metadata, just not sure about whole CF convention which seems to be very limited as far as availability of projections go. |
Some background on our choice for using the subset of CRS CF conventions. In the beginning of our search for a format to use in the netCDF file, we wanted to be able to write a netCDF that would be understood by GDAL and ArcGIS. The motivation for the format for the CRS being readable by GDAL is that it can be read in using So, we did some digging and found that if you add the Also since GDAL supported the WKT string representation, that meant that it would also support any projection GDAL can read in with the WKT representation. So, that worked for our needs as well. Not sure about ArcMap - didn't test it too extensively. This is very useful for our system as users can load in the data from You are indeed correct that the CF conventions for projections is limited. PROJ/GDAL developers say that WKT is the better format. Maybe this could be something to bring up for discussion here: https://github.com/cf-convention/cf-conventions. Side note: |
I see, so NetCDF CF files datacube produces don't use those names, instead we needed to follow CF spec more closely and actually run compliance checker tool on produced netcdf files. We still use GDAL (via rasterio) to read those, we do not do any special CRS processing, all of it is done by GDAL code. So, I assume GDAL does support CF convention for reading, but probably not for arbitrary WKT string. We do write files using netCDF4 library rather than GDAL, not sure what was the original reason for it, probably to do with the fact that we store dataset yaml text in one of the netcdf variables, or due to our need to be CF compliant more than what GDAL could produce at the time? Since CF spec does not mandate any particular name for a variable containing CRS info we can use So, what we have so far (at run-time level as opposed to storage level):
what a mess. |
I should clarify that this only works in GDAL when the
GDAL does support reading in an arbitrary WKT string in the
We use xarray's |
Brought this up on the CF conventions repo for discussion: cf-convention/cf-conventions#222 |
Expected behaviour
xr.open_dataset(<netcdf CF file>).geobox is not None
Actual behaviour
netcdf cf files loaded via
xr.open_dataset
are seen as not-georegistered by datcube.geobox
extension. Even for files produced by datacube itself.Also see comment thread in #835 (comment)
The text was updated successfully, but these errors were encountered: