Repository: yt-project/yt

Issue:
Geographic coordinate handler unit issues
In plots that use the geographic coordinate handler, we should be specifying the units for `extent` as `code_length` (i.e., lat / lon) but it's converting them to `cm`.  This is done for completely understandable reasons (and is the confluence of pushing lat/lon into a mono-unit array) but results in cartopy returning a `MULTISTRING EMPTY` projection for the bounds.

This can likely be handled at the level of the coordinate handler.

This bug isn't actionable yet, but I will update it as I continue digging.
Geographic coordinate handler unit issues
In plots that use the geographic coordinate handler, we should be specifying the units for `extent` as `code_length` (i.e., lat / lon) but it's converting them to `cm`.  This is done for completely understandable reasons (and is the confluence of pushing lat/lon into a mono-unit array) but results in cartopy returning a `MULTISTRING EMPTY` projection for the bounds.

This can likely be handled at the level of the coordinate handler.

This bug isn't actionable yet, but I will update it as I continue digging.


Discussion:
Thanks for digging into this. I'm all for investing time strengthening the geographic coordinate handlers. 
Thanks for digging into this. I'm all for investing time strengthening the geographic coordinate handlers. 

Resolving patch:
diff --git a/yt/data_objects/static_output.py b/yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -570,10 +570,13 @@ def _setup_coordinate_handler(self):
             cls = PolarCoordinateHandler
         elif self.geometry == "spherical":
             cls = SphericalCoordinateHandler
+            self.no_cgs_equiv_length = True
         elif self.geometry == "geographic":
             cls = GeographicCoordinateHandler
+            self.no_cgs_equiv_length = True
         elif self.geometry == "internal_geographic":
             cls = InternalGeographicCoordinateHandler
+            self.no_cgs_equiv_length = True
         elif self.geometry == "spectral_cube":
             cls = SpectralCubeCoordinateHandler
         else:
diff --git a/yt/visualization/plot_window.py b/yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -868,8 +868,12 @@ def _setup_plots(self):
             axis_index = self.data_source.axis
 
             xc, yc = self._setup_origin()
-            if self.ds.unit_system.name.startswith("us"):
-                # this should happen only if the dataset was initialized with argument unit_system="code"
+            if self.ds.unit_system.name.startswith("us") or self.ds.no_cgs_equiv_length:
+                # this should happen only if the dataset was initialized with
+                # argument unit_system="code" or if it's set to have no CGS
+                # equivalent.  This only needs to happen here in the specific
+                # case that we're doing a computationally intense operation
+                # like using cartopy, but it prevents crashes in that case.
                 (unit_x, unit_y) = ('code_length', 'code_length')
             elif self._axes_unit_names is None:
                 unit = self.ds.get_smallest_appropriate_unit(
@@ -1262,7 +1266,7 @@ def __init__(self, ds, axis, fields, center='c', width=None, axes_unit=None,
         if field_parameters is None:
             field_parameters = {}
 
-        if ds.geometry == "spherical" or ds.geometry == "cylindrical":
+        if ds.geometry in ("spherical", "cylindrical", "geographic", "internal_geographic"):
             mylog.info("Setting origin='native' for %s geometry." % ds.geometry)
             origin = 'native'
 
@@ -1437,6 +1441,9 @@ def __init__(self, ds, axis, fields, center='c', width=None, axes_unit=None,
                  method = "integrate", proj_style = None, window_size=8.0,
                  aspect=None):
         axis = fix_axis(axis, ds)
+        if ds.geometry in ("spherical", "cylindrical", "geographic", "internal_geographic"):
+            mylog.info("Setting origin='native' for %s geometry." % ds.geometry)
+            origin = 'native'
         # proj_style is deprecated, but if someone specifies then it trumps
         # method.
         if proj_style is not None:


Test patch:
diff --git a/yt/visualization/tests/test_geo_projections.py b/yt/visualization/tests/test_geo_projections.py
--- a/yt/visualization/tests/test_geo_projections.py
+++ b/yt/visualization/tests/test_geo_projections.py
@@ -29,7 +29,7 @@ def setup():
 def compare(ds, field, idir, test_prefix, test_name, projection,
             decimals=12, annotate=False):
     def slice_image(filename_prefix):
-        sl = yt.SlicePlot(ds, idir, field)
+        sl = yt.SlicePlot(ds, idir, field, origin = "native")
         sl.set_mpl_projection(projection)
         if annotate:
             sl._setup_plots()
@@ -75,7 +75,7 @@ def test_geo_projection_setup(self):
 
         from yt.utilities.on_demand_imports import _cartopy as cartopy
         axis = "altitude"
-        self.slc = yt.SlicePlot(self.ds, axis, "Density")
+        self.slc = yt.SlicePlot(self.ds, axis, "Density", origin = "native")
 
         assert isinstance(self.slc._projection, cartopy.crs.Mollweide)
         assert isinstance(self.slc._transform, cartopy.crs.PlateCarree)
@@ -87,7 +87,7 @@ def test_geo_projection_setup(self):
     @requires_module("cartopy")
     def test_geo_projections(self):
         from yt.utilities.on_demand_imports import _cartopy as cartopy
-        self.slc = yt.SlicePlot(self.ds, "altitude", "Density")
+        self.slc = yt.SlicePlot(self.ds, "altitude", "Density", origin = "native")
 
         for transform in transform_list:
             if transform == 'UTM':
@@ -112,7 +112,7 @@ def test_projection_object(self):
         for transform in shortlist:
             projection = get_mpl_transform(transform)
             proj_type = type(projection)
-            self.slc = yt.SlicePlot(self.ds, "altitude", "Density")
+            self.slc = yt.SlicePlot(self.ds, "altitude", "Density", origin = "native")
             self.slc.set_mpl_projection(projection)
 
             assert isinstance(self.slc._projection, proj_type)
@@ -125,7 +125,7 @@ def test_nondefault_transform(self):
         from yt.utilities.on_demand_imports import _cartopy as cartopy
         axis = "altitude"
         self.ds.coordinates.data_transform[axis] = "Miller"
-        self.slc = yt.SlicePlot(self.ds, axis, "Density")
+        self.slc = yt.SlicePlot(self.ds, axis, "Density", origin = "native")
 
         shortlist = ['Orthographic', 'PlateCarree', 'Mollweide']
 
@@ -152,7 +152,7 @@ def tearDown(self):
 
     def test_projection_setup(self):
         axis = "x"
-        self.slc = yt.SlicePlot(self.ds, axis, "Density")
+        self.slc = yt.SlicePlot(self.ds, axis, "Density", origin = "native")
 
         assert self.ds.coordinates.data_projection[axis] is None
         assert self.ds.coordinates.data_transform[axis] is None