is chain transform possible ?

Asked by Stefano Borini

I was wondering if there's a better strategy to achieve the same

coordinates = [ 1.0, 2.0, 3.0] * angstrom
coordinates.units = meters
coordinates.magnitude.tolist() # should be a list of values in meters.

I was thinking something alike

coordinates = [ 1.0, 2.0, 3.0] * angstrom
coordinates.tounit(meters).magnitude.tolist()

Maybe it's there but I just don't see it.

btw... I like your library. I switched away from unum because of the GPL license, the dreaded as keyword issue and because it was unmaintained for a long time. I'd like to help you with the development, but I am really overloaded way beyond human limit. However, I will probably issue bug reports as I am going to use quantities considerably in the next months. Keep up the good work, I really depend on your library for my project.

Question information

Language:
English Edit question
Status:
Solved
For:
python-quantities Edit question
Assignee:
No assignee Edit question
Solved by:
Tony S Yu
Solved:
Last query:
Last reply:
Revision history for this message
Best Tony S Yu (tonysyu) said :
#1

I think the quantities method you're looking for is called `rescale`. In other words:

>>> import quantities as pq
>>> coordinates = [ 1.0, 2.0, 3.0] * pq.angstrom
>>> coordinates.rescale(pq.meter).magnitude.tolist()

Revision history for this message
Stefano Borini (stefano-borini) said :
#2

Thanks Tony S Yu, that solved my question.

Revision history for this message
Stefano Borini (stefano-borini) said :
#3

Yes! that's it. Thanks! My brain confused with reshape, so I passed by while scouting the dir()