NCPP / ocgis

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

Polar Stereographic standard_parallel #515

Closed aaschwanden closed 4 years ago

aaschwanden commented 4 years ago

in the master branch,

crs = ocgis.variable.crs.CFPolarStereographic(epsg=3413)

results in

`--------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~/Library/Python/3.8/lib/python/site-packages/ocgis-2.1.1-py3.8.egg/ocgis/variable/crs.py in init(self, **kwds) 917 try: --> 918 crs.update({self.map_parameters[k]: kwds[k]}) 919 except KeyError:

KeyError: 'standard_parallel'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)

in ----> 1 crs = ocgis.variable.crs.CFPolarStereographic(epsg=3413) ~/Library/Python/3.8/lib/python/site-packages/ocgis-2.1.1-py3.8.egg/ocgis/variable/crs.py in __init__(self, *args, **kwds) 1109 if 'scale_factor' not in kwds: 1110 kwds['scale_factor'] = 1.0 -> 1111 super(CFPolarStereographic, self).__init__(*args, **kwds) 1112 1113 ~/Library/Python/3.8/lib/python/site-packages/ocgis-2.1.1-py3.8.egg/ocgis/variable/crs.py in __init__(self, **kwds) 919 except KeyError: 920 # Attempt to load any default map parameter values. --> 921 crs.update({self.map_parameters[k]: self.map_parameters_defaults[k]}) 922 923 super(CFCoordinateReferenceSystem, self).__init__(value=crs, name=name) KeyError: 'standard_parallel'` I'm pretty sure I've used this previously. I am missing something?
bekozi commented 4 years ago

I don't think you are missing anything. This definitely looks like a bug. I'm not sure what would have changed to affect this. I'll get back to you!

bekozi commented 4 years ago

I understand what's going on. "CF" coordinate systems need to be created using CF parameters. In this case, it would look like (with the 999s replaced with correct parameters):

crs = ocgis.variable.crs.CFPolarStereographic(
  standard_parallel=999, 
  latitude_of_projection_origin=999, 
  straight_vertical_longitude_from_pole=999, 
  false_easting=999, 
  false_northing=999
)

To create a coordinate system from just an EPSG code use:

crs = ocgis.variable.crs.CoordinateReferenceSystem(epsg=3413)

I pushed a change that will raise an error when an EPSG code is used to create a CF coordinate system.

There may be other issues that occur when trying to do what you're aiming for, so let me know how it goes. I'm wondering if you want to create a CF-compatible coordinate system by translating from EPSG code / PROJ params.

aaschwanden commented 4 years ago

Thanks for the clarification and the warning.

This works for me.