Aiapy.update_pointing and aiapy.register error?

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)

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 lies.
Has anyone had the same problem and could help me?

Hello,

I feel like I’ve seen that error before.

Could you tell me a few items please:

  1. sunpy and aiapy versions: sunpy.__version__ and aiapy.__version__
  2. Could you copy and paste the entire error log?
  3. This errored on a full disk level 1 image?
  4. What does your script look like?

Hello,

sunpy version is: 3.1.5
aiapy version is: 0.6.3

The error appears on full disk level 1 images. The script is:

base_raw=sunpy.map.Map(basemap_file) # FITS file in a computer folder
base_updated_pointing= update_pointing(base_raw)
base_registered = register(base_updated_pointing)
basemap= normalize_exposure(base_registered)
new_dimensions = [2048, 2048] * u.pixel # Resampling
basemap = basemap.resample(new_dimensions)

And the error log is:

ValueError Traceback (most recent call last)
Input In [6], in <cell line: 18>()
31 base_updated_pointing= update_pointing(base_raw)
32 # print(base_updated_pointing.data.shape)
33 # print(base_updated_pointing.meta)
34 # base_observer_fixed= fix_observer_location(base_raw)
—> 35 base_registered = register(base_updated_pointing)
36 print(‘\n\n’, base_registered.meta)
38 # plt.figure()
39 # base_registered.plot()
40 # plt.colorbar()
(…)
44 # basemap = sunpy.map.Map(base_registered.data/base_registered.exposure_time.to(u.s).value,
45 # base_registered.meta)

File ~\Miniconda\miniconda3\lib\site-packages\aiapy\calibrate\prep.py:80, in register(smap, missing, order, use_scipy)
78 scale_factor = smap.scale[0] / scale
79 missing = smap.min() if missing is None else missing
—> 80 tempmap = smap.rotate(
81 recenter=True,
82 scale=scale_factor.value,
83 order=order,
84 missing=missing,
85 use_scipy=use_scipy
86 )
87 # extract center from padded smap.rotate output
88 # crpix1 and crpix2 will be equal (recenter=True), as prep does not
89 # work with submaps
90 center = np.floor(tempmap.meta[‘crpix1’])

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:1648, in GenericMap.rotate(self, angle, rmatrix, order, scale, recenter, missing, use_scipy)
1645 pixel_center = pixel_array_center
1647 # Apply the rotation to the image data
→ 1648 new_data = affine_transform(new_data.T,
1649 np.asarray(rmatrix),
1650 order=order, scale=scale,
1651 image_center=np.flipud(pixel_center),
1652 recenter=recenter, missing=missing,
1653 use_scipy=use_scipy).T
1655 if recenter:
1656 new_reference_pixel = pixel_array_center

File ~\Miniconda\miniconda3\lib\site-packages\sunpy\image\transform.py:94, in affine_transform(image, rmatrix, order, scale, image_center, recenter, missing, use_scipy)
91 else:
92 rot_center = image_center
—> 94 displacement = np.dot(rmatrix, rot_center)
95 shift = image_center - displacement
96 if not use_scipy:

File <array_function internals>:180, in dot(*args, **kwargs)

File ~\Miniconda\miniconda3\lib\site-packages\astropy\utils\masked\core.py:572, in MaskedNDArray.array_finalize(self, obj)
567 super_array_finalize(obj)
569 if self._mask is None:
570 # Got here after, e.g., a view of another masked class.
571 # Get its mask, or initialize ours.
→ 572 self._set_mask(getattr(obj, ‘_mask’, False))
574 if ‘info’ in obj.dict:
575 self.info = obj.info

File ~\Miniconda\miniconda3\lib\site-packages\astropy\utils\masked\core.py:228, in Masked._set_mask(self, mask, copy)
225 if ma.shape != self.shape:
226 # This will fail (correctly) if not broadcastable.
227 self._mask = np.empty(self.shape, dtype=mask_dtype)
→ 228 self._mask[…] = ma
229 elif ma is mask:
230 # Even if not copying use a view so that shape setting
231 # does not propagate.
232 self._mask = mask.copy() if copy else mask.view()

ValueError: could not broadcast input array from shape (2,2) into shape (2,)

Hello,
the Sunpy version is 3.1.5
the aiapy version is 0.6.3

The images I am using have been downloaded with Fido and saved in a folder in my PC, they are full disk level 1 AIA images
The script is:

base_raw=sunpy.map.Map(basemap_file)
base_updated_pointing= update_pointing(base_raw)
base_registered = register(base_updated_pointing)
basemap= normalize_exposure(base_registered)

new_dimensions = [2048, 2048] * u.pixel
basemap = basemap.resample(new_dimensions)

The error log is:

ValueError Traceback (most recent call last)
Input In [6], in <cell line: 18>()
31 base_updated_pointing= update_pointing(base_raw)
32 # print(base_updated_pointing.data.shape)
33 # print(base_updated_pointing.meta)
34 # base_observer_fixed= fix_observer_location(base_raw)
—> 35 base_registered = register(base_updated_pointing)
36 print(‘\n\n’, base_registered.meta)
38 # plt.figure()
39 # base_registered.plot()
40 # plt.colorbar()
(…)
44 # basemap = sunpy.map.Map(base_registered.data/base_registered.exposure_time.to(u.s).value,
45 # base_registered.meta)

File ~\Miniconda\miniconda3\lib\site-packages\aiapy\calibrate\prep.py:80, in register(smap, missing, order, use_scipy)
78 scale_factor = smap.scale[0] / scale
79 missing = smap.min() if missing is None else missing
—> 80 tempmap = smap.rotate(
81 recenter=True,
82 scale=scale_factor.value,
83 order=order,
84 missing=missing,
85 use_scipy=use_scipy
86 )
87 # extract center from padded smap.rotate output
88 # crpix1 and crpix2 will be equal (recenter=True), as prep does not
89 # work with submaps
90 center = np.floor(tempmap.meta[‘crpix1’])

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:1648, in GenericMap.rotate(self, angle, rmatrix, order, scale, recenter, missing, use_scipy)
1645 pixel_center = pixel_array_center
1647 # Apply the rotation to the image data
→ 1648 new_data = affine_transform(new_data.T,
1649 np.asarray(rmatrix),
1650 order=order, scale=scale,
1651 image_center=np.flipud(pixel_center),
1652 recenter=recenter, missing=missing,
1653 use_scipy=use_scipy).T
1655 if recenter:
1656 new_reference_pixel = pixel_array_center

File ~\Miniconda\miniconda3\lib\site-packages\sunpy\image\transform.py:94, in affine_transform(image, rmatrix, order, scale, image_center, recenter, missing, use_scipy)
91 else:
92 rot_center = image_center
—> 94 displacement = np.dot(rmatrix, rot_center)
95 shift = image_center - displacement
96 if not use_scipy:

File <array_function internals>:180, in dot(*args, **kwargs)

File ~\Miniconda\miniconda3\lib\site-packages\astropy\utils\masked\core.py:572, in MaskedNDArray.array_finalize(self, obj)
567 super_array_finalize(obj)
569 if self._mask is None:
570 # Got here after, e.g., a view of another masked class.
571 # Get its mask, or initialize ours.
→ 572 self._set_mask(getattr(obj, ‘_mask’, False))
574 if ‘info’ in obj.dict:
575 self.info = obj.info

File ~\Miniconda\miniconda3\lib\site-packages\astropy\utils\masked\core.py:228, in Masked._set_mask(self, mask, copy)
225 if ma.shape != self.shape:
226 # This will fail (correctly) if not broadcastable.
227 self._mask = np.empty(self.shape, dtype=mask_dtype)
→ 228 self._mask[…] = ma
229 elif ma is mask:
230 # Even if not copying use a view so that shape setting
231 # does not propagate.
232 self._mask = mask.copy() if copy else mask.view()

ValueError: could not broadcast input array from shape (2,2) into shape (2,)

Dear @nabobalis ,
it seems like I solved, by updating my sunpy and aiapy version

Thank you in any case for your time

Apologies that your response got flagged as spam. I suggest that you make use of the code blocks in the future as that should lessen the chance of it happening.

Glad you got it sorted!

Thank you for explaining!
Didn’t know of this issue.