You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Check for units on parameters
Raise exception on missing units which allows us to be more explicit in what's wrong
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.
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.
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
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?
The text was updated successfully, but these errors were encountered: