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
Quantities or Pint #92
Comments
Replacing this: import quantities by from pint import _DEFAULT_REGISTRY as quantities and import quantities as pq by from pint import _DEFAULT_REGISTRY as pq will get you half way there to see. It is not clean but will help you to see if there is any other issue. In any case (if you choose to keep quantities or switch to pint), I would suggest that you create a |
Oh wow, thanks for the protip! And yes I definitely agree changing
units.py to be the point of reference for all the rest of IK. I'll have to
give this a try asap
|
I played around with that for a bit today, and it looks like the bulk of it will be pretty manageable! I was able to bring test errors and failures down to < 50 with just a few changes. A lot of the rest just have to do with some temperatures. I'm sure a good portion of the rest are some basic fixes here and there. |
Great!. Then my suggestion would be. Create the import pint
ureg = UnitRegistry(autoconvert_offset_to_baseunit = True)
# You can also define here units that you want to import from the module
meter = ureg.meter And then write everywhere (you can search and replace!) from instruments.units import ureg as quantities or from instruments.units import ureg as pq That should do it. In the long run you might want to clean up to remove the prefix |
We even already have a What are your recommended best practices for how the end users are suppose to supply units if they were using IK? Should they define their own unit registry, or should they use the one defined in |
The suggested way is to define one single registry and then make all applications use that one. This has served us well, but it fails when you try to put multiple independent projects using Pint together. I have recently prototyped a way to ask Pint for the most recently instantiated Registry, I am still thinking the API and the interaction with |
Gotcha. I'll plug away at this as I have time and see where I get! |
All the more reason to switch to |
@scasagrande do you have your work on this so far in a public branch somewhere? |
I do not, specifically because this body of work is going to be a large breaking change. I want all the breaking changes that I have in flight to be done for this year. And then hopefully drop Py2.7 support 💃 |
Pint has been shipped to master! 🎉 |
In light of the discussions in issue #91 I think we should also take a look at if we want to continue to use
quantities
over alternatives likepint
.quantities
is what we've been using, but that's mostly just because it was the best option we found.Keeping Quantities Pros
Keeping Quantities Cons
Switching to Pint Pros
dBm
numpy
as a dependencySwitching to Pint Cons
quantities
quantities
all you need to do isimport quantities as pq
and you're good to go. Withpint
you have two lines you need to execute, along with a parameter in the second line if you want easy-to-use temperature unitsisn't going to work. That's because addition/multiplication of non-absolute units are non-trivial. Their docs go into detail about this, and it makes sense after you read it. For example, if you have 10C + 10C, do you get 20C, or do you get 313C (293K+293K)? So instead, you have to do either:
or
where this will automatically convert these units to
kelvin
when doing addition/multiplication.More about that can be read at https://pint.readthedocs.org/en/0.7.2/nonmult.html
The text was updated successfully, but these errors were encountered: