# Differentially rotate a Level 1.5 AIA map?

**URL:** <https://community.openastronomy.org/t/differentially-rotate-a-level-1-5-aia-map/531>\
**Category:** Development\
**Tags:** sunpy, question\
**Created:** [December 4, 2022, 6:34pm UTC](https://community.openastronomy.org/t/differentially-rotate-a-level-1-5-aia-map/531 "2022-12-04T18:34:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiuliaMRonca](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/giuliamronca/32/305_2.png) [@GiuliaMRonca](https://community.openastronomy.org/u/GiuliaMRonca)\
**Post date:** [December 4, 2022, 6:34pm UTC](https://community.openastronomy.org/t/differentially-rotate-a-level-1-5-aia-map/531/1 "2022-12-04T18:34:35Z")

</div>

Hello,  
I am trying to differentially rotate a full disk AIA map, which I upgraded to Level 1.5 with the use of aiapy.register (only this function, without using update\_pointing because I get an error otherwise)  
When applying the procedure in [Differentially rotating a map — SunPy 4.1.0 documentation](https://docs.sunpy.org/en/stable/generated/gallery/differential_rotation/reprojected_map.html#sphx-glr-generated-gallery-differential-rotation-reprojected-map-py) , I get an error when I try to plot the resulting map

I used to use this code until less than one year ago. Now, I need to rotate again some images, but the very same code gives this error  
My code is (I defined a function for differential rotation):

def diff\_rot\_new(mapname, time\_diff, basemap):

```
#NOTE: to go back in time, time_diff MUST be negative
in_time = mapname.date
out_time = in_time + time_diff
out_frame = Helioprojective(observer='earth', obstime= out_time, rsun= mapname.meta['rsun_ref']*u.m)
out_wcs = basemap.wcs

# Reproject the map from the input frame to the output frame.

with propagate_with_solar_surface():

    out_warp = mapname.reproject_to(out_wcs)

return out_warp

```

Then, the error I get is:

KeyError Traceback (most recent call last)  
Input In [39], in \<cell line: 10\>()  
78 ## Plotting event  
79 fig=plt.figure()  
—\> 80 out\_warp.plot(vmax= 3000, title=f’{map\_el.meta[“date-obs”]}‘)  
81 plt.colorbar()  
82 plt.savefig(event+’/images/Event evolution/event {time}.png’.format(time=time\_string),  
83 format=‘png’)

File ~\Miniconda\miniconda3\lib\site-packages\astropy\units\decorators.py:304, in QuantityInput. **call**..wrapper(\*func\_args, \*\*func\_kwargs)  
302 # Call the original function with any equivalencies in force.  
303 with add\_enabled\_equivalencies(self.equivalencies):  
 → 304 return\_ = wrapped\_function(\*func\_args, \*\*func\_kwargs)  
306 # Return  
307 ra = wrapped\_signature.return\_annotation

File ~\Miniconda\miniconda3\lib\site-packages\sunpy\map\mapbase.py:2413, in GenericMap.plot(self, annotate, axes, title, autoalign, clip\_interval, \*\*imshow\_kwargs)  
2410 if autoalign is True:  
2411 autoalign = ‘pcolormesh’  
 → 2413 axes = self.\_check\_axes(axes, warn\_different\_wcs=autoalign is False)  
2415 # Normal plot  
2416 plot\_settings = copy.deepcopy(self.plot\_settings)

File ~\Miniconda\miniconda3\lib\site-packages\sunpy\map\mapbase.py:2584, in GenericMap.\_check\_axes(self, axes, warn\_different\_wcs)  
2569 “”"  
2570 - If axes is None, get the current Axes object.  
2571 - Error if not a WCSAxes.  
(…)  
2581 WCSAxes.  
2582 “”"  
2583 if not axes:  
 → 2584 axes = wcsaxes\_compat.gca\_wcs(self.wcs)  
2586 if not wcsaxes\_compat.is\_wcsaxes(axes):  
2587 raise TypeError("The axes need to be an instance of WCSAxes. "  
2588 "To fix this pass set the `projection` keyword "  
2589 “to this map when creating the axes.”)

File ~\Miniconda\miniconda3\lib\site-packages\sunpy\util\decorators.py:371, in cached\_property\_based\_on..outer..inner(instance)  
369 cache[attr\_name] = new\_attr\_val  
370 # Recompute the property  
 → 371 new\_val = prop(instance)  
372 cache[prop\_key] = new\_val  
374 return cache[prop\_key]

File ~\Miniconda\miniconda3\lib\site-packages\sunpy\map\mapbase.py:569, in GenericMap.wcs(self)  
567 w2.wcs.crval = u.Quantity([self.\_reference\_longitude, self.\_reference\_latitude])  
568 w2.wcs.ctype = self.coordinate\_system  
 → 569 w2.wcs.pc = self.rotation\_matrix  
570 w2.wcs.set\_pv(self.\_pv\_values)  
571 # FITS standard doesn’t allow both PC\_ij _and_ CROTA keywords

File ~\Miniconda\miniconda3\lib\site-packages\sunpy\map\mapbase.py:1276, in GenericMap.rotation\_matrix(self)  
1260 r"“”  
1261 Matrix describing the transformation needed to align the reference  
1262 pixel with the coordinate axes.  
(…)  
1273 other transformations e.g., skews for non-orthgonal coordinate systems.  
1274 “”"  
1275 if ‘PC1\_1’ in self.meta:  
 → 1276 return np.array([[self.meta[‘PC1\_1’], self.meta[‘PC1\_2’]],  
1277 [self.meta[‘PC2\_1’], self.meta[‘PC2\_2’]]])  
1279 elif ‘CD1\_1’ in self.meta:  
1280 cd = np.array([[self.meta[‘CD1\_1’], self.meta[‘CD1\_2’]],  
1281 [self.meta[‘CD2\_1’], self.meta[‘CD2\_2’]]])

File ~\Miniconda\miniconda3\lib\site-packages\sunpy\util\metadata.py:161, in MetaDict. **getitem** (self, key)  
157 def **getitem** (self, key):  
158 “”"  
159 Override `[]` indexing.  
160 “”"  
 → 161 return OrderedDict. **getitem** (self, key.lower())

KeyError: ‘pc1\_2’

Could anyone be of help? Did you have the same problem?  
My sunpy version is 3.5.1

---

<div class="post-metadata">

**Author:** ![GiuliaMRonca](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/giuliamronca/32/305_2.png) [@GiuliaMRonca](https://community.openastronomy.org/u/GiuliaMRonca)\
**Post date:** [December 4, 2022, 7:05pm UTC](https://community.openastronomy.org/t/differentially-rotate-a-level-1-5-aia-map/531/2 "2022-12-04T19:05:50Z")

</div>

Hello everyone,  
it looks like I solved the issue by updating my sunpy version on Miniconda.

---

<div class="post-metadata">

**Author:** ![wtbarnes](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/wtbarnes/32/20_2.png) [@wtbarnes](https://community.openastronomy.org/u/wtbarnes)\
**Post date:** [December 8, 2022, 3:06am UTC](https://community.openastronomy.org/t/differentially-rotate-a-level-1-5-aia-map/531/3 "2022-12-08T03:06:13Z")

</div>

Hi Giulia. Glad that your original issue was solved!

I wanted to ask also about your comment that `update_pointing` in aiapy wasn’t working. What specifically is the issue?

---

<div class="post-metadata">

**Author:** ![GiuliaMRonca](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/giuliamronca/32/305_2.png) [@GiuliaMRonca](https://community.openastronomy.org/u/GiuliaMRonca)\
**Post date:** [December 8, 2022, 6:43am UTC](https://community.openastronomy.org/t/differentially-rotate-a-level-1-5-aia-map/531/4 "2022-12-08T06:43:22Z")

</div>

Hi Will,

Actually, I got an error when I was trying to use register after update\_pointing:  
_ValueError: could not broadcast input array from shape (2,2) into shape (2,)_  
Update\_pointing it self was fine, but I could not move on in the code because of the error I got.  
I asked about it here

> [@Aiapy.update\_pointing and aiapy.register error?](https://community.openastronomy.org/t/aiapy-update-pointing-and-aiapy-register-error/527):
>
> Hi, I am trying to follow the procedure indicated by Sunpy to register a map after having downloaded it and align the level 1 data (see here for the website: [Registering and aligning level 1 data — aiapy 0.7.1 documentation](https://aiapy.readthedocs.io/en/stable/generated/gallery/prepping_level_1_data.html#sphx-glr-generated-gallery-prepping-level-1-data-py)) However, when I use the aiapy.update\_pointing function and then try to use the aiapy-register function, this error occurs: ValueError: could not broadcast input array from shape (2,2) into shape (2,) I just follow the indicated procedure, so I can’t grasp where the error…

But it got solved as well by upgrading the aiapy and sunpy version.
