`reproject_to` does not preserve metadata

Open
#5,627 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start at the implementation of the reproject_to method and inspect how it reconstructs the data and header. Done means the reprojected map preserves the relevant original metadata, including units, and returns the appropriate map instance rather than always a GenericMap.

Written by the indexing model from the issue text.

Description

Discussion map

This is not a bug as I'm quite sure this is the intended behavior, but when using the new reproject_to method, the resulting map does not have much of the associated metadata of the original map as the resulting map is reconstructed from a data-header pair where the header is reconstructed only from the WCS.

For example, after reprojecting a map, the resulting map has no units,

>>> import sunpy.map
>>> import sunpy.data.sample
>>> m = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
>>> m.unit
Unit("ct")
>>> m.reproject_to(m.wcs).unit is None
True

One possible solution would be to instead create a header using the header helper and then creating the resulting map from a (data,header) pair instead.

Furthermore, I just noticed that this returns a GenericMap instance explicitly. Given the approach described above, could we instead return map with _new_instance?

Dominant language
Python
Stars
1k
Forks
682
Avg merge
1d 17h
Merged PRs (30d)
17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sunpy/sunpy

All issues in sunpy/sunpy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.