Repository: sunpy/sunpy

Issue:
Show a warning when calling `reproject_to()` and there is a (minor) mismatch in `rsun`
People continue to get tripped up on a mismatch in `rsun` causing data to be lost in a reprojection (e.g., #7323 or https://community.openastronomy.org/t/derotate-hmi-map-at-carrington-rate-with-postel-projection/840/5).  Something like #7328 can help a user deal with an `rsun` mismatch, but only if they're aware that that's the problem.

We could emit a warning specific to `reproject_to()` such that it alerts a user if the `rsun` values of the map and the output header are not the same, since it might lead to unexpected results.  It should probably come with a tolerance parameter to control what level of `rsun` mismatch is considered a potential mistake.

Discussion:
nabobalis: Thanks for the PR @Mubin17, can you add changelog and a unit test? If you need help with these, we can proivde that.

Patch:
diff --git a/changelog/7370.feature.rst b/changelog/7370.feature.rst
new file mode 100644
index 000000000..a37830ee8
--- /dev/null
+++ b/changelog/7370.feature.rst
@@ -0,0 +1,1 @@
+Added a warning message for ``rsun`` mismatch in :meth:`~sunpy.map.GenericMap.reproject_to` method.
diff --git a/sunpy/map/mapbase.py b/sunpy/map/mapbase.py
index f07a2b4d9..4318046ab 100644
--- a/sunpy/map/mapbase.py
+++ b/sunpy/map/mapbase.py
@@ -2739,6 +2739,12 @@ class GenericMap(NDData):
         outmap = GenericMap(output_array, target_wcs.to_header(),
                             plot_settings=self.plot_settings)
 
+        # Check rsun mismatch
+        if self.rsun_meters != outmap.rsun_meters:
+            warn_user("rsun mismatch detected: "
+                      f"{self.name}.rsun_meters={self.rsun_meters}; {outmap.name}.rsun_meters={outmap.rsun_meters}. "
+                      "This might cause unexpected results during reprojection.")
+
         if return_footprint:
             return outmap, footprint
         return outmap


Test patch:
diff --git a/sunpy/map/tests/test_reproject_to.py b/sunpy/map/tests/test_reproject_to.py
index da2b9d636..0f3885e71 100644
--- a/sunpy/map/tests/test_reproject_to.py
+++ b/sunpy/map/tests/test_reproject_to.py
@@ -13,6 +13,7 @@ from astropy.wcs import WCS
 
 import sunpy.map
 from sunpy.tests.helpers import figure_test
+from sunpy.util.exceptions import SunpyUserWarning
 
 
 @pytest.fixture
@@ -119,3 +120,11 @@ def test_return_footprint(aia171_test_map, hpc_header):
 def test_invalid_inputs(aia171_test_map, hpc_header):
     with pytest.raises(ValueError, match="The specified algorithm must be one of"):
         aia171_test_map.reproject_to(hpc_header, algorithm='something')
+
+def test_rsun_mismatch_warning(aia171_test_map, hpc_header):
+    with pytest.warns(SunpyUserWarning, match="rsun mismatch detected: "):
+        # Modifying the `hpc_header` rsun value to create a mismatch
+        hpc_header["rsun_ref"] += 1
+
+        # Reproject with the mismatched rsun
+        aia171_test_map.reproject_to(hpc_header)