You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there is not enought infrastructure in place to be able to do a code generating repr on a CRS. This would be a very useful feature and is something that we should certainly strive for.
The text was updated successfully, but these errors were encountered:
I looked into this and made the following changes to add a basic __repr__ (and _repr_html_ for a visual representation of a Projection in a jupyter notebook):
diff --git a/lib/cartopy/_crs.pyx b/lib/cartopy/_crs.pyx
index 81a321c..b4e3ae0 100644
--- a/lib/cartopy/_crs.pyx+++ b/lib/cartopy/_crs.pyx@@ -202,8 +202,23 @@ cdef class CRS:
"""
self.__init__(self, **state)
+ def __repr__(self):+ name = self.__class__.__name__+ str_params = {'lat_0': 'central_latitude',+ 'lon_0': 'central_longitude',+ 'h': 'height',+ 'ellps': 'ellipse',+ 'proj': 'projection'}+ str_items_dict = {}+ for param_name, param_desc in str_params.items():+ proj4_param = self.proj4_params.get(param_name, None)+ if proj4_param is not None:+ str_items_dict[param_desc] = proj4_param+ params_str = ', '.join(['{}={}'.format(k, v)+ for k, v in str_items_dict.items()])+ return '<{}: {}>'.format(name, params_str)+
# TODO
- #def __str__
#def _geod(self): # to return the pyproj.Geod
def _as_mpl_transform(self, axes=None):
diff --git a/lib/cartopy/crs.py b/lib/cartopy/crs.py
index 46d088e..1ba3187 100644
--- a/lib/cartopy/crs.py+++ b/lib/cartopy/crs.py@@ -146,6 +146,13 @@ class Projection(six.with_metaclass(ABCMeta, CRS)):
domain = self._domain = sgeom.Polygon(self.boundary)
return domain
+ def _repr_html_(self):+ import matplotlib.pyplot as plt+ ax = plt.axes(projection=self)+ ax.set_global()+ ax.coastlines('110m')+ plt.show()+
def _as_mpl_axes(self):
import cartopy.mpl.geoaxes as geoaxes
return geoaxes.GeoAxes, {'map_projection': self}
This exposes the following problems:
what information do we want to include in the repr of a CRS? If we miss key information from the repr it may make the repr less worthwhile than not having a repr at all.
Currently there is not enought infrastructure in place to be able to do a code generating repr on a CRS. This would be a very useful feature and is something that we should certainly strive for.
The text was updated successfully, but these errors were encountered: