question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add unit of electron-volts that is specifically a temperature

See original GitHub issue

The electron-volt (eV) is an extremely common unit of temperature in plasma physics. Units of eV, keV, and so on are often used as a measure of the thermal energy per particle. A quantity with units of eV can be converted to temperature by dividing by the Boltzmann constant, kB.

Despite my honest opinion about this usage (see https://github.com/PlasmaPy/PlasmaPy/issues/131 for my grumblings), many in the plasma physics community would benefit from a unit of electron-volts that is specifically a temperature (perhaps called eV_temp). Including this unit would also allow us to clean up a lot of code within PlasmaPy.

The ways to currently do this are:

>>> kT = 1.4 * units.eV
>>> kT.to(units.K, equivalencies=units.temperature_energy())
<Quantity 11604.522060401008 K>

and

>>> units.set_enabled_equivalencies(units.temperature_energy())
>>> kT.to(units.K)
<Quantity 11604.522060401008 K>

The proposed usage would allow usage like:

>>> kT = 1.0 * units.eV_temp
>>> kT.to(units.K)
<Quantity 11604.522060401008 K>

One of the biggest benefits is that we would not need to explicitly do a conversion step before we put a quantity with these units into a formula. This would also greatly reduce the ambiguity for when units of eV are used as temperature.

However, units of eV can also correspond to mass, momentum, distance, and time as well as energy. This ambiguity is part of the reason why I generally recommend against using units of eV in general (along with having silent factors of kB, c, c2, etc.). If we decide to have units of eV_temp, then we might want to consider units of eV_mass and eV_momentum as well.

Thank you!
-Nick

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
mhvkcommented, Dec 19, 2017

It may be possible to repurpose some trickery I used for the functional units, which define their own equivalencies. This can solve one direction very easily:

eV_temp = u.Unit('eV_temp', u.eV)
eV_temp.equivalencies = [(eV_temp, u.K) + u.temperature_energy()[0][3:1:-1]]
(1*u.K).to(eV_temp)
# <Quantity 8.617330337217213e-05 eV_temp>

For the other direction, we’d either need to adjust UnitBase to start checking for equivalencies on itself, or eV_temp should subclass the base unit and add a new method. Just as a proof of concept:

eV_temp._normalize_equivalencies = lambda x: eV_temp.equivalencies
(1*eV_temp).to(u.K)
# <Quantity 11604.522060401008 K>

So, this is not difficult in itself, but needs thought of how best to implement it.

0reactions
pllimcommented, Aug 26, 2020

What is the package that specializes in Xray astronomy and use astropy? Maybe such a def_unit can live there?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert kelvin [K] to electron-volt [eV] • Energy and Work ...
Convert kelvin [K] to electron-volt [eV] • Energy and Work Converter • Common Unit Converters • Compact Calculator • Online Unit Converters.
Read more >
Electronvolt - wikidoc
The electronvolt (symbol eV) is a unit of energy. It is the amount of energy equivalent to that gained by a single unbound...
Read more >
A TeV, measured in chocolate and coffee - Quantum Diaries
We also use an electron volt as a unit of temperature. An atom in a monatomic (helium, argon, etc.) ideal gas has a...
Read more >
Electronvolt - Wikipedia
When used as a unit of energy, the numerical value of 1 eV in joules (symbol J) is equivalent to the numerical value...
Read more >
The total energy radiated increases rapidly ... - CLASS NOTES
Note that 1 eV is the kinetic energy acquired by an electron or a proton acted upon by a potential difference of 1...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found