Closed dopplershift closed 7 years ago
I feel like attaching default units could be tricky and cause issues, but could also be a good thing as well. I like the idea of checking for units on parameters though, since that is something I personally forget about when using units in functions
Once I learned how to use the units support and tried it for a meaningful project, I got excited about it and started to use it for peace of mind. But I was initially tripped up by it, too. It's almost entirely without precedent in common practice.
I like the idea of checking and raising. If the decorator were passed the necessary unit hints (@hasunits('length/time', 'length/time'), that error message could dynamically generate instructions that would get the user over the hump, perhaps like so:
Argument 2 to function get_wind_speed requires units with dimensions length/time. Any variable x can be assigned a unit as follows: from metpy.units import units x = x*units.meter/units.second
For more deeply nested function calls, the disconnect between the raising function and the user code could be lengthy, so it won't be possible to instruct the user as to the exact steps, but I bet something lengthly like the above could go a long way.
On Thu, Jun 30, 2016 at 3:51 PM, kpozsonyi notifications@github.com wrote:
I feel like attaching default units could be tricky and cause issues, but could also be a good thing as well. I like the idea of checking for units on parameters though, since that is something I personally forget about when using units in functions
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/metpy/MetPy/issues/175#issuecomment-229785232, or mute the thread https://github.com/notifications/unsubscribe/ABQ6y3qRNQ6hyI1E8N4-qp3jvZWSBSScks5qRCxugaJpZM4JCkCQ .
Units, while a good way to enforce correctness (especially where, unlike GEMPAK, we're trying to bring in data from many different sources), can really trip up new users and get in the way.
One way to improve things might be to have the calculations (via decorator of course) issue better diagnostics:
Another option would be to issue a warning and attach some default units, but I'd have to be convinced--from the zen of Python "in the face of ambiguity, resist the temptation to guess". Functions we add this to would lose the ability to work with unit-free values, but that might be good regardless.
@deeplycloudy, @kpozsonyi any thoughts to add here?