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

First Pint Support #475

ax3l opened this issue Feb 16, 2019 · 0 comments


1 participant
Copy link

commented Feb 16, 2019

Simple bindings to pint would be wonderful for dimensional analysis or records.

as drafted here

TODO: add pretty handlers, maybe some lookup DBs for typical quanitites, make useful.

import pint

ureg = pint.UnitRegistry()

# [E] = M L^2 T^-3 I^-1
E_pint = 1 * E_unitDim[api.Unit_Dimension.L] * ureg.m + \
E_unitDim[api.Unit_Dimension.M] * + \
E_unitDim[api.Unit_Dimension.T] * ureg.s + \
E_unitDim[api.Unit_Dimension.I] * ureg.A + \
E_unitDim[api.Unit_Dimension.theta] * ureg.K + \
E_unitDim[api.Unit_Dimension.N] * ureg.mol + \
E_unitDim[api.Unit_Dimension.J] *

# length L, mass M, time T, electric current I, thermodynamic temperature theta, amount of substance N, luminous intensity J

# False
E_pint.check('[length] * [mass] / [current] / [time]^3')
# True
# True

# <UnitsContainer({'[current]': -1.0, '[length]': 1.0, '[mass]': 1.0, '[time]': -3.0})>
# ^-- access just like a regular dictionary

# create:
pint.context.UnitsContainer({'[current]': -1.0, '[length]': 1.0, '[mass]': 1.0, '[time]': -3.0})
# <UnitsContainer({'[current]': -1.0, '[length]': 1.0, '[mass]': 1.0, '[time]': -3.0})>

As a first step, RecordComponent.unit_dimension should probably just return a dictionary that fits exactly those pint defaults:

  '[length]': L,
  '[mass]': M,
  '[time]': T,
  '[current]': I,
  '[temperature]': theta,
  '[substance]': N,
  '[luminosity]': J

# easy to pass:

@ax3l ax3l added this to To do in Unit Systems via automation Feb 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.