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

Improve units behavior for new users #175

Closed
dopplershift opened this issue Jun 30, 2016 · 2 comments
Closed

Improve units behavior for new users #175

dopplershift opened this issue Jun 30, 2016 · 2 comments
Assignees
Labels
Area: Calc Pertains to calculations Type: Enhancement Enhancement to existing functionality
Milestone

Comments

@dopplershift
Copy link
Member

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:

  1. Check for units on parameters
  2. 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.

@deeplycloudy, @kpozsonyi any thoughts to add here?

@dopplershift dopplershift added Type: Enhancement Enhancement to existing functionality Area: Calc Pertains to calculations labels Jun 30, 2016
@kpozsonyi
Copy link
Contributor

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

@deeplycloudy
Copy link
Collaborator

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
#175 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ABQ6y3qRNQ6hyI1E8N4-qp3jvZWSBSScks5qRCxugaJpZM4JCkCQ
.

@dopplershift dopplershift modified the milestone: Winter 2017 Release (0.5) Jul 31, 2016
@dopplershift dopplershift modified the milestone: Spring 2017 Mar 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations Type: Enhancement Enhancement to existing functionality
Projects
None yet
Development

No branches or pull requests

3 participants