NCPP / ocgis

OpenClimateGIS is a set of geoprocessing and calculation tools for CF-compliant climate datasets.
Other
70 stars 19 forks source link

Coordinate priority with non-spherical CRS #490

Open bekozi opened 5 years ago

bekozi commented 5 years ago

@mkmitchell reported an issue with a NARR dataset having a Lambert Conformal Conic projection. The lat/lon coordinate variables were marked with axis x/y attributes. The Cartesian x/y coordinate variables had no axis attributes. ocgis errored out during a subset as it chose the LCC projection correctly but picked the wrong coordinates because of axis attribute priority during coordinate selection. This was fixed by updating the dimension map prior to the subset.

To fix this, coordinate variable selection should attempt to match coordinate variable units against the units recommended by the coordinate system prior to using the axis attributes.

mkmitchell commented 5 years ago

I was able to bypass the error by using your suggestion

rdc = RequestDataset(uri, 'variable')
rdc.dimension_map.set_variable('x', 'x')
rdc.dimension_map.set_variable('y', 'y')

but it only worked for a bit. I'm getting the same error again.

ocgis.exc.ExtentError: A subset operation on variable "None" returned empty. This typically means the selection geometry falls outside the spatial domain of the target dataset.

I'm attempting to sum the variable by day/month/year for every shape in the shapefile using the following command:

ops = OcgOperations(dataset=rdc, output_format='shp', time_region={'month': [1,2,3,4,9,10,11,12]}, spatial_operation='clip', geom=shp, calc=calc,
                calc_raw=True, aggregate=True, calc_grouping=['day', 'month', 'year'], prefix=prefix)

Thanks in advance!

bekozi commented 5 years ago

Bummer! A few quick questions:

I cannot think of any recent changes that would cause this. It's possible (if the shapfile changed) that you do have some empty subsets in there. In that case, you can try setting allow_empty=True in the operations call.

mkmitchell commented 5 years ago

It must be the shapefile. I get the error I posted about with one. It succeeds with a few others.
I've also seen ValueError: Record's geometry type does not match collection schema's geometry type: 'Point' != 'MultiPoint' with a different one.

mkmitchell commented 5 years ago

It was definitely the shapefile. It appears very small features were giving me the error.

bekozi commented 5 years ago

Thanks for the update. Sorry for the slow reply - was taking some PTO.

Do you think this is a problem that needs to be fixed in ocgis? I could take a look at the shapefile if that would help.

mkmitchell commented 5 years ago

Take your much deserved PTO!

That's completely up to you. I ended up iterating through selections of my shapefile. If it worked I selected more and if it didn't I deselected a few I previously added.

It may be nice to have ocgis keep running the calculation and report a list of features that didn't process because of whatever exception.

bekozi commented 5 years ago

Done! :wink: Your approach makes sense. When you get a chance, could you pass along the shp and netcdf (or just the spatial resolution of the grid if that's easier)? What you described would be a nice feature.