Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow DN as a unit on GenericMap #7585

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

wtbarnes
Copy link
Member

Fixes #6566

@nabobalis nabobalis added map Affects the map submodule No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers) labels Apr 23, 2024
@nabobalis nabobalis added this to the 6.0.0 milestone May 8, 2024
@DanRyanIrish
Copy link
Member

I approve of the principle of this PR. I think that this is a case of the FITS standard being insufficient, rather than solar physicists not adhering to that standard. We need DN. It is not the same as counts.

@nabobalis nabobalis marked this pull request as ready for review May 16, 2024 00:39
@nabobalis nabobalis requested review from a team as code owners May 16, 2024 00:39
@nabobalis
Copy link
Contributor

The only tests I could not fix were the asdf ones.

sunpy/map/mapbase.py Outdated Show resolved Hide resolved
@wtbarnes
Copy link
Member Author

The figure test fails are real and are due to the unit label changing to "DN"

unit = None
# NOTE: Special case DN here as it is not part of the FITS standard, but
# is widely used and is also a recognized astropy unit
unit_str_components = unit.to_string().replace('/', ' ').replace('(', '').replace(')', '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What on earth caused you to need this line? This is great and I am here for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I removed the comment explaining this. Because anything with DN is not FITS-compliant, the whole unit becomes an UnrecognizedUnit and you cannot decompose it into individual Unit objects. Thus, you have to parse it as a string. The replace methods remove non unit characters that could be present in the string.

The goal here is to breakup the unit into components to check if one of them is DN. Just checking for "DN" in the unit string is ambiguous because it's possible some unit could include a contiguous "dn" in it somewhere.

If there is a better way to do this, I'm all for it. I don't like this approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I removed the comment explaining this. Because anything with DN is not FITS-compliant, the whole unit becomes an UnrecognizedUnit and you cannot decompose it into individual Unit objects. Thus, you have to parse it as a string. The replace methods remove non unit characters that could be present in the string.

The goal here is to breakup the unit into components to check if one of them is DN. Just checking for "DN" in the unit string is ambiguous because it's possible some unit could include a contiguous "dn" in it somewhere.

Ah!

I don't like this approach.

I do.

What kind of strings do we have to handle?
If I can see some examples, we could hopefully come up with another method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the updated _parse_fits_unit tests for some examples.

Copy link
Member

@Cadair Cadair May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than this abomination why not just do this:

unit = u.Unit(unit_str)
if u.DN not in unit.bases:
    warn_metadata(...)
    unit = None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
map Affects the map submodule No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of u.DN unit in place of u.count
4 participants