hgrecco / pint

Operate and manipulate physical quantities in Python
http://pint.readthedocs.org/
Other
2.39k stars 468 forks source link

Feature request: regex/wildcard supporting for unit conversion. #1152

Open hongyi-zhao opened 4 years ago

hongyi-zhao commented 4 years ago

Hi,

I want to convert between a_u_length and angstrom, and I find that I must use it as following exactly:

$ pint-convert bohr angstrom
1 bohr = 0.529177210904(81) Å
$ pint-convert a_u_length angstrom
1 bohr = 0.529177210904(81) Å

Could you please let pint support regex/wildcard for unit conversion?

Best regards HY

hgrecco commented 4 years ago

I don't quite follow. What would be the desired way to use it?

hongyi-zhao commented 4 years ago

Give all the possible conversions. Say, for the following query with the -r option, which means using regex for matching the unit names:

$ pint-convert -r 'a_u_.*' angstrom

Should give the results similar to the following command which is executed under the local git repo directory of pint:

$ grep -EohR 'a_u_[a-z_]+' . | xargs -I{} -P0 pint-convert {} angstrom 2>/dev/null
1 hartree = 455.6335252912(9) Å
1 electron_mass = 0.0242631023868(75) Å
1 bohr = 0.529177210904(81) Å
1 atomic_unit_of_temperature = 455.6335252912(9) Å

But I'm very confused on the above conversions. In detail, why should pint gives the conversions between energy/mass/temperature and length? This is obviously unreasonable.

hgrecco commented 4 years ago

I agree with this as a feature to pint-convert . Feel free to submit a PR

hongyi-zhao commented 4 years ago

But I must first understand/figure out the meaning of the following conversions given by pint, as I have mentioned above:

(datasci) werner@X10DAi-01:~$ pint-convert hartree atomic_unit_of_temperature
1 hartree = 1 a_u_temp
(datasci) werner@X10DAi-01:~$ pint-convert hartree electron_mass
1 hartree = 5.3251354521(16)e-05 m_e
(datasci) werner@X10DAi-01:~$ pint-convert hartree angstrom
1 hartree = 455.6335252912(9) Å

Why should the energy | temperature | mass | length (angstrom) be converted to each other like this way by pint? Conversions like this are obviously irrational. Is this a bug?