Skip to content

Add DN as new unit - #11591

Merged
mhvk merged 1 commit into
astropy:mainfrom
jdavies-st:units-add-dn
Apr 19, 2021
Merged

mhvk merged 1 commit into
astropy:mainfrom
jdavies-st:units-add-dn

Conversation

@jdavies-st

Copy link
Copy Markdown
Contributor

Description

This pull request adds the name "DN" as a string that can generate a count unit, u.ct. "DN", or digital number, is a common name used for counts in the FITS header keyword BUNIT and in FITS binary table column units. In fact, an example in the existing Astropy documentation has this unit

https://docs.astropy.org/en/stable/io/fits/usage/table.html?highlight=DN

but that unit doesn't currently parse into a u.ct. This PR enables that.

@github-actions github-actions Bot added the units label Apr 17, 2021

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 in general, but a question about whether the unit should just be on its own, and whether prefixes are warranted.

Comment thread astropy/units/astrophys.py Outdated
# EVENTS

def_unit((['ct', 'count'], ['count']),
def_unit((['ct', 'count', 'DN'], ['count']),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 to adding DN. One question, though: should it really be the same as count? Or might it be better as an alias of adu (see below) or just be its own unit?

One reason I ask is that to me prefixes (like milliDN) do not really make sense, but for count` we're stuck with having them (which I think is a bit of a mistake, but too late to fix!).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question! I don't have a strong opinion. Generally DN is synonymous with counts in my experience. I think probably adu should be the same. It is a count. Same unit, different name. Any reason they are different units in astropy? Am I opening a can of worms? 😅

Agree prefixes don't make sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, and I see you can have millicounts but not picocounts? And I see why (%). 🤯

Would be nice to put that horse back into the stable. 😂

Anyway, if DN was on its own as a unit, could it least have an equivalency to u.ct and u.adu? That would seem useful. I see that currently u.ct != u.adu.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, I was wondering about removing the prefixes and seeing if anyone notices...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 for removing stupid prefixes. Maybe after a qiuck search on github for u.milicounts ;-)

Comment thread astropy/units/astrophys.py Resolved
@mhvk

mhvk commented Apr 18, 2021

Copy link
Copy Markdown
Contributor

(Taking this out of the code review since perhaps a discussion that should not be just "resolved away")

On equivalencies and/or whether the units should be the same, I'd be more inclined to go the equivalency route, since at least to me count suggests something with Poisson statistics, while that would not be true for ADU (would need to correct for gain). In that respect, perhaps DN should just be its own unit as well?

As for equivalencies, right now it is not easy for units to have built-in equivalencies (though it is possible; it is used for the magnitude units, and have been meaning to extend that, if only for Celsius and Fahrenheit). It would of course be quite easy to add an equivalency for all of them, say, u.equivalent_counts, though it is not too difficult as is:

c = 10*u.ct
print(c.to(u.adu, equivalencies=[(u.count, u.adu)]))
# 10.0 adu
u.add_enabled_equivalencies([(u.adu, u.ct)])
print(c.to(u.adu))
# 10.0 adu

@mhvk

mhvk commented Apr 18, 2021

Copy link
Copy Markdown
Contributor

p.s. Just to be sure that we don't let the discussion prevent a simple addition: for now, we could just stick with a simple addition of DN as its own unit (without prefixes!).

@jdavies-st

Copy link
Copy Markdown
Contributor Author

for now, we could just stick with a simple addition of DN as its own unit (without prefixes!).

That seems like a good solution to me. I'll update this PR. Thanks for the discussion and example u.add_enabled_equivalencies().

Would both "dn" and "DN" be useful mnemonics for what should be the base u.dn unit?

@pllim

pllim commented Apr 19, 2021

Copy link
Copy Markdown
Member

FWIW I don't think DN is the same as count. Even among HST instruments, that is not always true ("count" could be e/s!).

Yes to no prefix to DN. Removing prefix for count should be a separate PR.

@pllim pllim added this to the v4.3 milestone Apr 19, 2021
@mhvk

mhvk commented Apr 19, 2021

Copy link
Copy Markdown
Contributor

I think having both dn and DN as aliases makes sense.

@pllim

pllim commented Apr 19, 2021

Copy link
Copy Markdown
Member

While, u.N is taken, luckily it doesn't take D as prefix. 😌

Comment thread docs/changes/units/11591.feature.rst Outdated
@@ -0,0 +1 @@
Add a new "DN" unit, ``units.dn``, representing digital number.

@pllim pllim Apr 19, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add a new "DN" unit, ``units.dn``, representing digital number.
Add a new "DN" unit, ``units.dn`` or ``units.DN``, representing digital number for a detector.

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, except change log nitpick.

This doesn't need a test, does it, @mhvk ?

@pllim pllim changed the title Add DN as extra name to u.ct Add DN as new unit Apr 19, 2021
@pllim

pllim commented Apr 19, 2021

Copy link
Copy Markdown
Member

Note to reviewer: If you don't think we need What's New entry for this, please remove the label, thanks!

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good now! Would you mind terribly squashing the commits together? (I can do it too if you prefer)

@mhvk

mhvk commented Apr 19, 2021

Copy link
Copy Markdown
Contributor

Super, thanks! Will now merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants