-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Modifications to CRS handling in xarray_.py provider #1578
Comments
I've started drafting a solution to this on our fork within grid_mapping = self.parse_grid_mapping()
if grid_mapping is not None:
crs_attrs = pyproj.CRS.to_cf(self._data[grid_mapping].attrs)
epsg_code = crs_attrs.to_epsg()
if epsg_code == 4326:
pass
elif epsg_code is None:
LOGGER.debug('No epsg code parsed. Default CRS used.')
else:
properties['bbox_crs'] = f'https://www.opengis.net/def/crs/EPSG/0/{epsg_code}' # noqa
properties['inverse_flattening'] = \
crs_attrs['inverse_flattening']
if crs_attrs['grid_mapping_name'] != 'latitude_longitude':
properties['crs_type'] = 'ProjectedCRS'
elif 'crs' in self._data.variables.keys():
try:
properties['bbox_crs'] = f'https://www.opengis.net/def/crs/EPSG/0/{self._data.crs.epsg_code}' # noqa
properties['inverse_flattening'] = self._data.crs.\
inverse_flattening
properties['crs_type'] = 'ProjectedCRS'
except KeyError:
LOGGER.debug('Unable to parse CRS. Assuming default WGS84.') Where def parse_grid_mapping(self):
spatiotemporal_dims = (self.time_field, self.y_field, self.x_field)
grid_mapping_name = None
for var_name, var in self._data.variables.items():
if all(dim in var.dims for dim in spatiotemporal_dims):
try:
grid_mapping_name = self._data[var_name].attrs['grid_mapping']
except KeyError:
LOGGER.debug()
return grid_mapping_name Some key changes / notes:
Question moving forward:
Would love thoughts/ideas/feedback on this solution @dblodgett-usgs @tomkralidis. Also tagging @ptomasula @aufdenkampe and @kieranbartels for input / visibility. |
Keep it simple is going to rule the day here. We should support a fairly narrow (yet common) set of conventions and allow a configuration override of either an epsg code or a WKT string. I think the current implementation is that fairly narrow (yet common) set of conventions atleast as a starting point. Re: ProjectedCRS -- we should not assume projected if there is a CRS -- only if it is not a lon/lat CRS. IMHO, 0-360 should nearly always be converted to -180 - 180 for use. If there isn't a set of utility functions that make that translation on the fly we'll either need to drop support for those datasets in EDR or get the utilities written. If we can't parse any CRS info, we have to assume that the data are WGS84 or fall back on a configuration element that supports an epsg code or WKT string. |
Great -- sounds good @dblodgett-usgs. I will continue down this path, and will add in that configuration functionality. I don't think utility functions exist to make the translation to -180-180, so those will need to get added. We can exclude 0-360 datasets in the short-term. |
@dblodgett-usgs pretty easy to implement that in python. def normalize(angle):
angle = angle % 360
return angle if angle < 180 else angle - 360 |
Description
These lines of code in the xarray provider are causing issues for some of the EDR datasets I'm trying to serve.
I'm working with CF-compliant zarrs/netCDFs, and I see a few issues as the current code base and its ability to work with a broad range of datasets.
epsg_code
is not a required attribute for CF compliance, so this section of the code can result in a failure to build if you're working with a dataset with a CRS variable that does not have this attribute.crs
variable. These lines of code would change thecrs_type
attribute to 'ProjectedCRS', even though it should remain as GeographicCRS.crs
), looking to see if any of the spatio-temporal variables have agrid_mapping
attribute, and use the information instead. This would allow us to dynamically search for the variable that contains coordinate reference system information, in case it is not namedcrs
.Screenshots/Tracebacks
Here's the error I got:
The text was updated successfully, but these errors were encountered: