-
Notifications
You must be signed in to change notification settings - Fork 415
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
ENH: Add dBZ as a unit in the registry #3343
Conversation
Thanks for putting this together! With some hand testing, this seems to cooperate with cross_section and quantification/dequantification. Given Pint's "beta" qualifier for log units (and their inherent quirks), I'm a little worried about how this could potentially interact with some of our other unit handling in calculations, eg >>> from metpy.units import units
>>> ref = 40 * units.dBZ
>>> ref
<Quantity(40, 'dBZ')>
>>> ref.magnitude
40
>>> ref.to_base_units()
<Quantity(10000.0, 'dimensionless')>
>>> ref.m_as('')
10000.00000000001 At first pass, I can't find anywhere we do this kind of handling that dBZ could even sneak into, but might be something to be mindful of or test for in the future. I'll leave that thought out there for other inputs. Actual review questions: Should there be a descriptive longname, |
@dcamron thanks for the thoughts here; dBZ is a dimensionless quantity so that behavior is expected, and according to the cf-conventions, dBZ is the proper units for this quantity.
It may be helpful to add BZ here as well, since that is mentioned as the "base unit" in this PR @dopplershift submitted a few years ago https://github.com/Unidata/UDUNITS-2/pull/42/files Any other thoughts here? |
I'm not sure I agree that Same thing would be true of My first question, though: why is this suddenly an issue with MetPy 1.6? |
To answer my question above, it's because I added a |
Ok, I think we can get what we want here with: units.define('dBz = 1e-18 m^3; logbase: 10; logfactor: 10 = dBZ') allows us to do: ref = 55 * units.dBz
ref.to('mm^6/m^3')
ref.to_base_units() and get Strong preference for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think with a few tweaks this will be a nice thing to include.
I should add that I tried to define the linear equivalent directly as a mm^6/m^3, but I kept getting
so I assume there's an issue with the more complicated units and the Pint parser. It's fine, we're still correct, the only downside is that This does show there's still work to do on the Pint side, since: 50 * units.dBZ + 10 * units.dB gives |
Co-authored-by: Ryan May <rmay31@gmail.com>
Thanks for the feedback here @dopplershift !! I added in those suggestions. Please let me know if you have any other comments/changes you would like to see :) |
@dopplershift I had actually tried this yesterday as well before I commented, and it works if you first define Z and then define dBz as a log-unit of Z, reg.define('reflectivity_factor = mm^6 / m^3 = _ = Z')
reg.define('dBZ = Z ; logbase: 10; logfactor: 10 = dBz') I had just abandoned the thought until the conversation headed that way anyway. |
@dcamron @dopplershift should I add this then?
|
@mgrover1 Don't worry about it. I'm really iffy on Z being listed as a formal unit, and I don't think the use cases justify having it. While this is definitely a good thing to add, the plan also is to push this off until 1.7.0. In the meanwhile, we're going to put out a 1.6.1 that more directly addresses the problem with |
This sounds great! Thank you so much! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
With 1.6.1 out the door, we can go ahead and put this in main and start the crawl towards 1.7. |
Description Of Changes
Fixes #3341
Adds "dBZ" as a unit within the unit registry, with this being equivalent to dB, while still being its own separate unit.
Checklist