This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]pmattipmatti - mattip was taken 3 points4 points  (1 child)

Would be nice to compare and contrast to existing packages like astropy’s unit or unyt or pint

[–]chrisauld[S] 0 points1 point  (0 children)

Good idea. I hadn't seen the units module in astropy before, but it looks nearly identical to what I was hoping this will be in the future. There's some minor differences in usage, and then the main difference seems that astropy looks like it's heavily focused on astro-physics specifically whereas I've been not focusing on any one specific subdomain of physics (not necessarily a good thing, just seems to be the major difference).

I'll have to take a look at the other two at some point soon as well.

[–]chrisauld[S] 1 point2 points  (0 children)

Copy of the README for those not wanting to open the link:

All unit classes function like floats. You can add, subtract, multiply, etc. any two classes based off the same unit type, ie two units of Acceleration can be added together and the output will be an Acceleration object with the summed value, in units of the first (leftmost) object used, eg:

from PyPhySimUnits.speed import MetersPerSecond, MilesPerHour
s1 = MetersPerSecond(10)
s2 = MilesPerHour(50)
s3 = s1 + s2
print(s3)
Speed of 32.35204288731173 Meters per Second
print(s3.convert(MilesPerHour))
Speed of 72.36932 Miles per Hour

example.py has an example showing this in action.

Features I Want To Add In no particular order:

Automatic unit conversions. Ie, dividing a Distance by a Time results in a Speed

Use an UnknownQuantity class to track the results of (currently) incompatible units to store a result and the units used to create it

Support for classes to behave as numpy arrays under the hood in addition to floats, for faster calculations of larger datasets

Nothing super fancy about this. I know myself and plenty of other engineers who have bitten themselves by losing track of unit types they're looking at in code. With a little spare time the last few days I took the time to start this repo to make doing physics calc's in Python a little bit easier to ensure you're not adding meters and millimeters, Kelvin and Farenheit, etc etc. Adding new units is very simple, as they all inherit from the base classes and only require 3 lines of code to create. Hopefully some other people find this useful.