Repository: yt-project/yt

Issue:
Axes labels always in code for spherical datasets, independent of "unit_system"
### Bug report

**Bug summary**

@neutrinoceros discovered this when we went over #2728, what is happening is that the axes units are always in code units, independent of `unit_system`. It turns out that this is only the case for spherical datasets, and that it is not amrvac frontend-related. I managed to reproduce this issue with the [KeplerianDisk](https://girder.hub.yt/#item/5e17944f68085e00016c308b) dataset on the yt Hub as well, which is the athena_pp frontend.

**Code for reproduction**
```python
blast = "amrvac/bw_2d0000.dat"
disk = "KeplerianDisk/disk.out1.00000.athdf"
for file, name in zip((blast, disk), ("amrvac", "athenapp")):
    ds = yt.load(file, unit_system="cgs")
    p = yt.SlicePlot(ds, "phi", "density")
    p.save(f"slice_cgs_{name}.png")
```

**Actual outcome**
AMRVAC dataset:
<img width="500" alt="slice_cgs_amrvac" src="https://user-images.githubusercontent.com/43474374/93447205-70f2c380-f8d2-11ea-9670-87015c12dd10.png">
AthenaPP dataset:
<img width="500" alt="slice_cgs_athenapp" src="https://user-images.githubusercontent.com/43474374/93447373-9ed80800-f8d2-11ea-9124-58d184cafb7c.png">

**Expected outcome**
R and z axis labels in `"cm"`.
For reference, this is a 3D Cartesian dataset (`"amrvac/bw_3d0000.dat"`)  sliced along `y`, same code as above:
<img width="500" alt="slice_cgs_amrvac_cart" src="https://user-images.githubusercontent.com/43474374/93447757-1148e800-f8d3-11ea-94fc-00faa9436ecf.png">
which behaves as it should.




Discussion:
Reporting that the images produced by the example script have gotten better since #3533

![slice_cgs_amrvac](https://user-images.githubusercontent.com/14075922/138244000-c1fa3f26-718d-4eb7-be46-41d819f50bde.png)
![slice_cgs_athenapp](https://user-images.githubusercontent.com/14075922/138244012-3856febc-6558-4f2b-972a-60c6e1df7add.png)

... but this issue is still relevant.


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
@@ -689,7 +689,10 @@ def _setup_coordinate_handler(self):
             cls = PolarCoordinateHandler
         elif self.geometry == "spherical":
             cls = SphericalCoordinateHandler
-            self.no_cgs_equiv_length = True
+            # It shouldn't be required to reset self.no_cgs_equiv_length
+            # to the default value (False) here, but it's still necessary
+            # see https://github.com/yt-project/yt/pull/3618
+            self.no_cgs_equiv_length = False
         elif self.geometry == "geographic":
             cls = GeographicCoordinateHandler
             self.no_cgs_equiv_length = True
@@ -1151,11 +1154,19 @@ def _assign_unit_system(self, unit_system):
         if unit_system != "code":
             us = unit_system_registry[str(unit_system).lower()]
 
-        us._code_flag = unit_system == "code"
+        self._unit_system_name: str = unit_system
 
         self.unit_system = us
         self.unit_registry.unit_system = self.unit_system
 
+    @property
+    def _uses_code_length_unit(self) -> bool:
+        return self._unit_system_name == "code" or self.no_cgs_equiv_length
+
+    @property
+    def _uses_code_time_unit(self) -> bool:
+        return self._unit_system_name == "code"
+
     def _create_unit_registry(self, unit_system):
         from yt.units import dimensions
 
diff --git a/yt/visualization/plot_modifications.py b/yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -2505,7 +2505,7 @@ def __call__(self, plot):
         if self.time:
             # If no time_units are set, then identify a best fit time unit
             if self.time_unit is None:
-                if plot.ds.unit_system._code_flag:
+                if plot.ds._uses_code_time_unit:
                     # if the unit system is in code units
                     # we should not convert to seconds for the plot.
                     self.time_unit = plot.ds.unit_system.base_units[dimensions.time]
@@ -2530,7 +2530,7 @@ def __call__(self, plot):
                 un = self.time_unit.latex_representation()
                 time_unit = r"$\ \ (" + un + r")$"
             except AttributeError as err:
-                if plot.ds.unit_system._code_flag == "code":
+                if plot.ds._uses_code_time_unit:
                     raise RuntimeError(
                         "The time unit str repr didn't match expectations, something is wrong."
                     ) from err
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
@@ -998,7 +998,7 @@ def _setup_plots(self):
             axis_index = self.data_source.axis
 
             xc, yc = self._setup_origin()
-            if self.ds.unit_system._code_flag or self.ds.no_cgs_equiv_length:
+            if self.ds._uses_code_length_unit:
                 # 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
@@ -1009,7 +1009,15 @@ def _setup_plots(self):
                 unit = self.ds.get_smallest_appropriate_unit(
                     self.xlim[1] - self.xlim[0]
                 )
-                (unit_x, unit_y) = (unit, unit)
+                unit_x = unit_y = unit
+                coords = self.ds.coordinates
+                if hasattr(coords, "image_units"):
+                    # this should detect angular coordinates
+                    image_units = coords.image_units[coords.axis_id[axis_index]]
+                    if image_units[0] in ("deg", "rad"):
+                        unit_x = "code_length"
+                    if image_units[1] in ("deg", "rad"):
+                        unit_y = "code_length"
             else:
                 (unit_x, unit_y) = self._axes_unit_names
 


Test patch:
diff --git a/tests/tests.yaml b/tests/tests.yaml
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -170,7 +170,7 @@ answer_tests:
   local_cylindrical_background_010:  # PR 3520
     - yt/geometry/coordinates/tests/test_cylindrical_coordinates.py:test_noise_plots
 
-  local_spherical_background_002:  # PR 3533 + 3520
+  local_spherical_background_003:  # PR 3618
     - yt/geometry/coordinates/tests/test_spherical_coordinates.py:test_noise_plots
 
   #local_particle_trajectory_001: