Repository: sunpy/sunpy

Issue:
Rename map function from `pixel_to_data` to `pixel_to_world`
This nomenclature is clearer as we are not dealing with data units but world coordinates. This also references WCS (world coordinate system).


Discussion:
👍 With deprecation of the current API.
What he said.

Resolving patch:
diff --git a/sunpy/map/mapbase.py b/sunpy/map/mapbase.py
--- a/sunpy/map/mapbase.py
+++ b/sunpy/map/mapbase.py
@@ -480,14 +480,14 @@ def bottom_left_coord(self):
         """
         The physical coordinate for the bottom left [0,0] pixel.
         """
-        return self.pixel_to_data(0*u.pix, 0*u.pix)
+        return self.pixel_to_world(0*u.pix, 0*u.pix)
 
     @property
     def top_right_coord(self):
         """
         The physical coordinate for the top left pixel.
         """
-        return self.pixel_to_data(*self.dimensions)
+        return self.pixel_to_world(*self.dimensions)
 
     @property
     def center(self):
@@ -495,7 +495,7 @@ def center(self):
         Return a coordinate object for the center pixel of the array.
         """
         center = u.Quantity(self.dimensions) / 2.
-        return self.pixel_to_data(*center)
+        return self.pixel_to_world(*center)
 
     @property
     def shifted_value(self):
@@ -772,9 +772,9 @@ def _validate_meta(self):
 
 
 # #### Data conversion routines #### #
-    def data_to_pixel(self, coordinate, origin=0):
+    def world_to_pixel(self, coordinate, origin=0):
         """
-        Convert a data (world) coordinate to a pixel coordinate by using
+        Convert a world (data) coordinate to a pixel coordinate by using
         `~astropy.wcs.WCS.wcs_world2pix`.
 
         Parameters
@@ -798,7 +798,7 @@ def data_to_pixel(self, coordinate, origin=0):
         """
         if not isinstance(coordinate, (SkyCoord,
                                        astropy.coordinates.BaseCoordinateFrame)):
-            raise ValueError("data_to_pixel takes a Astropy coordinate frame or SkyCoord instance.")
+            raise ValueError("world_to_pixel takes a Astropy coordinate frame or SkyCoord instance.")
 
         native_frame = coordinate.transform_to(self.coordinate_frame)
         lon, lat = u.Quantity(self._get_lon_lat(native_frame)).to(u.deg)
@@ -806,8 +806,16 @@ def data_to_pixel(self, coordinate, origin=0):
 
         return PixelPair(x * u.pixel, y * u.pixel)
 
+    # Thought it would be easier to create a copy this way.
+    @deprecated("0.8.0", alternative="sunpy.map.GenericMap.world_to_pixel")
+    def data_to_pixel(self, coordinate, origin=0):
+        """
+        See `~sunpy.map.mapbase.GenericMap.world_to_pixel`
+        """
+        return self.world_to_pixel(coordinate, origin=origin)
+
     @u.quantity_input(x=u.pixel, y=u.pixel)
-    def pixel_to_data(self, x, y, origin=0):
+    def pixel_to_world(self, x, y, origin=0):
         """
         Convert a pixel coordinate to a data (world) coordinate by using
         `~astropy.wcs.WCS.wcs_pix2world`.
@@ -846,6 +854,13 @@ def pixel_to_data(self, x, y, origin=0):
 
         return SkyCoord(x, y, frame=self.coordinate_frame)
 
+    # Thought it would be easier to create a copy this way.
+    @deprecated("0.8.0", alternative="sunpy.map.GenericMap.pixel_to_world")
+    def pixel_to_data(self, x, y, origin=0):
+        """
+        See `~sunpy.map.mapbase.GenericMap.pixel_to_world`
+        """
+        return self.pixel_to_world(x, y, origin=origin)
 
 # #### I/O routines #### #
 
@@ -1070,7 +1085,7 @@ def rotate(self, angle=None, rmatrix=None, order=4, scale=1.0,
         temp_map = self._new_instance(new_data, new_meta, self.plot_settings)
 
         # Convert the axis of rotation from data coordinates to pixel coordinates
-        pixel_rotation_center = u.Quantity(temp_map.data_to_pixel(self.reference_coordinate,
+        pixel_rotation_center = u.Quantity(temp_map.world_to_pixel(self.reference_coordinate,
                                                                   origin=0)).value
         del temp_map
 
@@ -1239,7 +1254,7 @@ def submap(self, bottom_left, top_right=None):
 
             corners = u.Quantity([bottom_left, bottom_right, top_left, top_right])
             coord = SkyCoord(corners, frame=self.coordinate_frame)
-            pixel_corners = self.data_to_pixel(coord)
+            pixel_corners = self.world_to_pixel(coord)
 
             # Round the pixel values, we use floor+1 so that we always have at
             # least one pixel width of data.
diff --git a/sunpy/wcs/__init__.py b/sunpy/wcs/__init__.py
--- a/sunpy/wcs/__init__.py
+++ b/sunpy/wcs/__init__.py
@@ -3,8 +3,8 @@
 .. warning::
     As of version 0.8.0 the `sunpy.wcs` package is deprecated and will be
     removed in a future version, you should now transition to using
-    `sunpy.coordinates` and `sunpy.map.GenericMap.data_to_pixel` /
-    `sunpy.map.GenericMap.pixel_to_data` (or `astropy.wcs` directly) for the
+    `sunpy.coordinates` and `sunpy.map.GenericMap.world_to_pixel` /
+    `sunpy.map.GenericMap.pixel_to_world` (or `astropy.wcs` directly) for the
     functionality provided in this module.
 
 The WCS package provides functions to parse World Coordinate System (WCS)
diff --git a/sunpy/wcs/wcs.py b/sunpy/wcs/wcs.py
--- a/sunpy/wcs/wcs.py
+++ b/sunpy/wcs/wcs.py
@@ -29,7 +29,7 @@ def _convert_angle_units(unit='arcsec'):
     else:
         raise ValueError("The units specified are either invalid or is not supported at this time.")
 
-@deprecated("0.8.0", alternative="sunpy.map.GenericMap.pixel_to_data")
+@deprecated("0.8.0", alternative="sunpy.map.GenericMap.pixel_to_world")
 def convert_pixel_to_data(size, scale, reference_pixel,
                           reference_coordinate, x=None, y=None):
     """
@@ -105,7 +105,7 @@ def get_center(size, scale, reference_pixel, reference_coordinate):
     return scale * (size - 1 * u.pix) / 2. + reference_coordinate - (reference_pixel - 1 * u.pix) * scale
 
 
-@deprecated("0.8.0", alternative="sunpy.map.GenericMap.data_to_pixel")
+@deprecated("0.8.0", alternative="sunpy.map.GenericMap.world_to_pixel")
 def convert_data_to_pixel(x, y, scale, reference_pixel, reference_coordinate):
     """
     Calculate the pixel indices for a given data coordinate.


Test patch:
diff --git a/sunpy/map/tests/test_mapbase.py b/sunpy/map/tests/test_mapbase.py
--- a/sunpy/map/tests/test_mapbase.py
+++ b/sunpy/map/tests/test_mapbase.py
@@ -91,14 +91,13 @@ def test_wcs(aia171_test_map):
     wcs = aia171_test_map.wcs
     assert isinstance(wcs, astropy.wcs.WCS)
 
-    assert all(wcs.wcs.crpix == [
-        aia171_test_map.reference_pixel.x.value, aia171_test_map.reference_pixel.y.value
-    ])
+    assert all(wcs.wcs.crpix ==
+               [aia171_test_map.reference_pixel.x.value, aia171_test_map.reference_pixel.y.value])
+    assert all(wcs.wcs.cdelt == [aia171_test_map.scale.axis1.value,
+                                 aia171_test_map.scale.axis1.value])
     assert all(
-        wcs.wcs.cdelt == [aia171_test_map.scale.axis1.value, aia171_test_map.scale.axis1.value])
-    assert all(wcs.wcs.crval == [
-        aia171_test_map._reference_longitude.value, aia171_test_map._reference_latitude.value
-    ])
+        wcs.wcs.crval ==
+        [aia171_test_map._reference_longitude.value, aia171_test_map._reference_latitude.value])
     assert set(wcs.wcs.ctype) == set(
         [aia171_test_map.coordinate_system.axis1, aia171_test_map.coordinate_system.axis2])
     np.testing.assert_allclose(wcs.wcs.pc, aia171_test_map.rotation_matrix)
@@ -262,24 +261,24 @@ def test_swap_cd():
 
 def test_data_range(generic_map):
     """Make sure xrange and yrange work"""
-    assert_quantity_allclose((generic_map.xrange[1] - generic_map.xrange[0]).to(u.arcsec).value,
-                             generic_map.meta['cdelt1'] * generic_map.meta['naxis1'])
-    assert_quantity_allclose((generic_map.yrange[1] - generic_map.yrange[0]).to(u.arcsec).value,
-                             generic_map.meta['cdelt2'] * generic_map.meta['naxis2'])
+    assert_quantity_allclose((generic_map.xrange[1] - generic_map.xrange[0]
+            ).to(u.arcsec).value, generic_map.meta['cdelt1'] * generic_map.meta['naxis1'])
+    assert_quantity_allclose((generic_map.yrange[1] - generic_map.yrange[0]
+            ).to(u.arcsec).value, generic_map.meta['cdelt2'] * generic_map.meta['naxis2'])
 
     # the weird unit-de-unit thing here is to work around and inconsistency in
     # the way np.average works with astropy 1.3 and 2.0dev
-    assert_quantity_allclose(
-        np.average(u.Quantity(generic_map.xrange).value) * u.deg, generic_map.center.Tx)
-    assert_quantity_allclose(
-        np.average(u.Quantity(generic_map.yrange).value) * u.deg, generic_map.center.Ty)
+    assert_quantity_allclose(np.average(u.Quantity(generic_map.xrange).value) * u.deg,
+                             generic_map.center.Tx)
+    assert_quantity_allclose(np.average(u.Quantity(generic_map.yrange).value) * u.deg,
+                             generic_map.center.Ty)
 
 
-def test_data_to_pixel(generic_map):
+def test_world_to_pixel(generic_map):
     """Make sure conversion from data units to pixels is internally
     consistent"""
     # Note: FITS pixels start from 1,1
-    test_pixel = generic_map.data_to_pixel(generic_map.reference_coordinate, origin=1)
+    test_pixel = generic_map.world_to_pixel(generic_map.reference_coordinate, origin=1)
     assert_quantity_allclose(test_pixel, generic_map.reference_pixel)
 
 
@@ -481,7 +480,8 @@ def test_rotate(aia171_test_map):
 
     # Rotation of a rectangular map by a large enough angle will change which dimension is larger
     aia171_test_map_crop = aia171_test_map.submap(
-        SkyCoord([[0, 0], [1000, 400]] * u.arcsec, frame=aia171_test_map.coordinate_frame))
+        SkyCoord(
+            [[0, 0], [1000, 400]] * u.arcsec, frame=aia171_test_map.coordinate_frame))
 
     aia171_test_map_crop_rot = aia171_test_map_crop.rotate(60 * u.deg)
     assert aia171_test_map_crop.data.shape[0] < aia171_test_map_crop.data.shape[1]
@@ -489,19 +489,19 @@ def test_rotate(aia171_test_map):
 
     # Same test as above, to test the other direction
     aia171_test_map_crop = aia171_test_map.submap(
-        SkyCoord([[0, 0], [400, 1000]] * u.arcsec, frame=aia171_test_map.coordinate_frame))
+        SkyCoord(
+            [[0, 0], [400, 1000]] * u.arcsec, frame=aia171_test_map.coordinate_frame))
     aia171_test_map_crop_rot = aia171_test_map_crop.rotate(60 * u.deg)
     assert aia171_test_map_crop.data.shape[0] > aia171_test_map_crop.data.shape[1]
     assert aia171_test_map_crop_rot.data.shape[0] < aia171_test_map_crop_rot.data.shape[1]
 
 
 def test_rotate_pad_crpix(generic_map):
-    rotated_map = generic_map.rotate(30 * u.deg)
+    rotated_map = generic_map.rotate(30*u.deg)
     # This tests that the reference pixel of the map is in the expected place.
     assert rotated_map.data.shape != generic_map.data.shape
-    assert_quantity_allclose(
-        u.Quantity(rotated_map.reference_pixel),
-        u.Quantity((6.049038105675565, 7.5490381056760265), u.pix))
+    assert_quantity_allclose(u.Quantity(rotated_map.reference_pixel),
+                             u.Quantity((6.049038105675565, 7.5490381056760265), u.pix))
 
 
 def test_rotate_recenter(generic_map):
@@ -594,7 +594,7 @@ def test_hg_coord(heliographic_test_map):
 
 
 def test_hg_pix_to_data(heliographic_test_map):
-    out = heliographic_test_map.pixel_to_data(180 * u.pix, 90 * u.pix)
+    out = heliographic_test_map.pixel_to_world(180 * u.pix, 90 * u.pix)
     assert isinstance(out, SkyCoord)
     assert isinstance(out.frame, sunpy.coordinates.HeliographicCarrington)
     assert_quantity_allclose(out.lon, 0 * u.deg)
@@ -602,12 +602,12 @@ def test_hg_pix_to_data(heliographic_test_map):
 
 
 def test_hg_data_to_pix(heliographic_test_map):
-    out = heliographic_test_map.data_to_pixel(
-        SkyCoord(0 * u.deg, 0 * u.deg, frame=heliographic_test_map.coordinate_frame))
+    out = heliographic_test_map.world_to_pixel(
+        SkyCoord(
+            0 * u.deg, 0 * u.deg, frame=heliographic_test_map.coordinate_frame))
     assert_quantity_allclose(out[0], 180 * u.pix)
     assert_quantity_allclose(out[1], 90 * u.pix)
 
-
 # Heliocentric Map Tests
 
 
@@ -640,7 +640,6 @@ def test_hc_warn():
     with pytest.warns(UserWarning):
         sunpy.map.Map((data, header))
 
-
 # Dimension testing