Repository: sunpy/sunpy

Issue:
`Map.rotate` does not update `NAXISi` fields in the metadata
### Describe the bug

`resample()`, `submap()`, and `superpixel()` all update NAXISi, but `rotate` does not.

### To Reproduce

```python
from sunpy.map import Map, GenericMap
import astropy.units as u

# Prints the shape of the data array, and the naxis fields
def print_metadata_and_shape(label: str, map: GenericMap):
    print(f"---{label}---")
    print(f"Shape: {map.data.shape}")
    print(f"Naxis: ({map.meta["NAXIS1"]}, {map.meta["NAXIS2"]})")

# Using a helioviewer jp2 since you can't write a fits file out as jp2
# and read it back (different issue).
aia_map = Map("https://helioviewer.org/jp2/AIA/2024/03/12/304/2024_03_12__00_00_05_130__SDO_AIA_AIA_304.jp2")
print_metadata_and_shape("Original map", aia_map)

# Rotate the image and print info
aia_rotated = aia_map.rotate(45 * u.deg, missing=0)
print_metadata_and_shape("Rotated map", aia_rotated)

# Save rotated image
aia_rotated.save("aia.fits")
aia_rotated.save("aia.jp2")

# Read back rotated fits and look at metadata
aia_fits_readback = Map("aia.fits")
print_metadata_and_shape("FITS Readback", aia_fits_readback)

# Read back rotated jp2 and look at metadata
aia_jp2_readback = Map("aia.jp2")
print_metadata_and_shape("JP2 Readback", aia_jp2_readback)

```

Output from above code:
```
---Original map---
Shape: (4096, 4096)
Naxis: (4096, 4096)
---Rotated map---
Shape: (5794, 5794)
Naxis: (4096, 4096)
---FITS Readback---
Shape: (5794, 5794)
Naxis: (5794, 5794)
---JP2 Readback---
Shape: (5794, 5794)
Naxis: (4096, 4096)
```

### Screenshots

_No response_

### System Details

```
==============================
sunpy Installation Information
==============================

General
#######
OS: Mac OS 14.3.1
Arch: 64bit, (arm)
sunpy: 4.0.dev2573+gf79e5d92d
Installation path: /Users/dgarciab/miniforge3/envs/sunpy-dev/lib/python3.12/site-packages/sunpy-4.0.dev2573+gf79e5d92d.dist-info

Required Dependencies
#####################
astropy: 6.0.0
numpy: 1.26.4
packaging: 23.2
parfive: 2.0.2
pyerfa: 2.0.1.1
requests: 2.31.0

Optional Dependencies
#####################
sunpy: 4.0.dev2573+gf79e5d92d
```

### Installation method

git checkout

Discussion:

Patch:
diff --git a/changelog/7522.bugfix.rst b/changelog/7522.bugfix.rst
new file mode 100644
index 000000000..ce157bec9
--- /dev/null
+++ b/changelog/7522.bugfix.rst
@@ -0,0 +1,1 @@
+The :meth:`~sunpy.map.GenericMap.rotate` function now correctly updates the NAXISi.
diff --git a/sunpy/map/mapbase.py b/sunpy/map/mapbase.py
index 0bea831de..81ff4814c 100644
--- a/sunpy/map/mapbase.py
+++ b/sunpy/map/mapbase.py
@@ -1742,6 +1742,8 @@ class GenericMap(NDData):
         new_meta['crval2'] = rotation_center[1].value
         new_meta['crpix1'] = new_reference_pixel[0] + 1  # FITS pixel origin is 1
         new_meta['crpix2'] = new_reference_pixel[1] + 1  # FITS pixel origin is 1
+        new_meta['NAXIS1'] = new_data.shape[1]
+        new_meta['NAXIS2'] = new_data.shape[0]
 
         # Unpad the array if necessary
         if unpad_x > 0:


Test patch:
diff --git a/sunpy/map/tests/test_mapbase.py b/sunpy/map/tests/test_mapbase.py
index 31c579727..6c2e9fd1b 100644
--- a/sunpy/map/tests/test_mapbase.py
+++ b/sunpy/map/tests/test_mapbase.py
@@ -1355,6 +1355,13 @@ def test_non_str_key():
         sunpy.map.GenericMap(np.zeros((10, 10)), header)
 
 
+def test_updating_of_naxisi_on_rotate(aia171_test_map):
+    aia171_test_map_rotated = aia171_test_map.rotate(45 * u.deg, missing=0)
+    assert aia171_test_map.data.shape == (128, 128)
+    assert aia171_test_map_rotated.meta['NAXIS1'] == 182
+    assert aia171_test_map_rotated.meta['NAXIS2'] == 182
+
+
 def test_wcs_isot(aia171_test_map):
     # Check that a Map WCS returns the time as isot format
     assert aia171_test_map.wcs.to_header()['DATE-OBS'] == '2011-02-15T00:00:00.340'
@@ -1595,7 +1602,7 @@ def test_meta_modifications(aia171_test_map):
     assert aiamap_rot.meta.original_meta == aiamap.meta.original_meta
     assert set(aiamap_rot.meta.added_items.keys()) == set(['pc1_1', 'pc1_2', 'pc2_1', 'pc2_2'])
     assert set(aiamap_rot.meta.removed_items.keys()) == set(['crota2'])
-    assert set(aiamap_rot.meta.modified_items) == set(['cdelt1', 'crpix1', 'crpix2', 'crval1'])
+    assert set(aiamap_rot.meta.modified_items) == set(['cdelt1', 'crpix1', 'crpix2', 'crval1', 'naxis1', 'naxis2'])
 
 
 def test_no_wcs_observer_info(heliographic_test_map):