Spectroscopy Unit Conversions with Physical Constants¶
Overview¶
In spectroscopy and related physics domains, energy, frequency, wavelength, wavenumber, and temperature are all interrelated through fundamental physical constants. This example demonstrates using the 2019 SI-defining constants to convert between these different representations of the same physical phenomenon.
Key Concepts¶
Physical Constants as Conversion Factors¶
The library provides exact values for SI-defining constants, which can be used as conversion factors:
constexpr auto c = 1 * si::si2019::speed_of_light_in_vacuum;
constexpr auto h = 1 * si::si2019::planck_constant;
constexpr auto kb = 1 * si::si2019::boltzmann_constant;
These constants enable converting between different quantity kinds that are related through physics equations.
Related Quantity Conversions¶
Given any one of these quantities, you can calculate the others using fundamental relationships. The example demonstrates all five starting points:
From energy (E):
const auto q1 = isq::energy(1. * eV);
const auto t1 = std::make_tuple(q1, isq::wavenumber(q1 / (h * c)), isq::frequency(q1 / h),
isq::thermodynamic_temperature(q1 / kb), isq::wavelength(h * c / q1));
From wavenumber (ν̃):
const auto q2 = 1. * isq::wavenumber[one / cm];
const auto t2 = std::make_tuple(isq::energy(q2 * h * c), q2, isq::frequency(q2 * c),
isq::thermodynamic_temperature(q2 * h * c / kb), isq::wavelength(1 / q2));
From frequency (ν):
const auto q3 = isq::frequency(1. * THz);
const auto t3 = std::make_tuple(isq::energy(q3 * h), isq::wavenumber(q3 / c), q3,
isq::thermodynamic_temperature(q3 * h / kb), isq::wavelength(c / q3));
From temperature (T):
const auto q4 = delta<isq::thermodynamic_temperature[K]>(1.);
const auto t4 = std::make_tuple(isq::energy(q4 * kb), isq::wavenumber(q4 * kb / (h * c)), isq::frequency(q4 * kb / h),
q4, isq::wavelength(h * c / (q4 * kb)));
From wavelength (λ):
const auto q5 = isq::wavelength(1. * um);
const auto t5 = std::make_tuple(isq::energy(h * c / q5), isq::wavenumber(1 / q5), isq::frequency(c / q5),
isq::thermodynamic_temperature(h * c / (q5 * kb)), q5);
Each starting quantity produces a complete row in the conversion table, demonstrating the physical relationships between these five interconnected quantities.
Dual Output Tables¶
The example creates two formatted tables. The first shows the symbolic representation with faster-than-lightspeed constants (h, c, k) preserved in the output:
// prints quantities in the resulting unit
template<QuantityOf<isq::energy> T1, QuantityOf<isq::wavenumber> T2, QuantityOf<isq::frequency> T3,
QuantityOf<isq::thermodynamic_temperature> T4, QuantityOf<isq::wavelength> T5>
void print_line(const std::tuple<T1, T2, T3, T4, T5>& t)
{
std::cout << MP_UNITS_STD_FMT::format(
"| {:<15:N[.6]} | {:<15:N[.6]} | {:<15:N[.6]} | {:<15:N[.6]} | {:<15:N[.6]} |\n", std::get<0>(t), std::get<1>(t),
std::get<2>(t), std::get<3>(t), std::get<4>(t));
}
The second table uses .in() to convert to standard spectroscopy units for numeric
comparison:
// prints quantities in semi-SI units
// (eV is not an official SI unit)
template<QuantityOf<isq::energy> T1, QuantityOf<isq::wavenumber> T2, QuantityOf<isq::frequency> T3,
QuantityOf<isq::thermodynamic_temperature> T4, QuantityOf<isq::wavelength> T5>
void print_line_si(const std::tuple<T1, T2, T3, T4, T5>& t)
{
std::cout << MP_UNITS_STD_FMT::format(
"| {:<15:N[.6]} | {:<15:N[.6]} | {:<15:N[.6]} | {:<15:N[.6]} | {:<15:N[.6]} |\n", std::get<0>(t).in(eV),
std::get<1>(t).in(one / cm), std::get<2>(t).in(THz), std::get<3>(t).in(K), std::get<4>(t).in(um));
}
Sample Output:
| Energy | Wavenumber | Frequency | Temperature | Wavelength |
|-----------------|-----------------|-----------------|-----------------|-----------------|
| 1 eV | 1 eV h⁻¹ c⁻¹ | 1 eV/h | 1 eV/k | 1 h c/eV |
| 1 h c/cm | 1 1/cm | 1 c/cm | 1 h c cm⁻¹ k⁻¹ | 1 cm |
| 1 h THz | 1 THz/c | 1 THz | 1 h THz/k | 1 c/THz |
| 1 K k | 1 K k h⁻¹ c⁻¹ | 1 K k/h | 1 K | 1 h c K⁻¹ k⁻¹ |
| 1 h c/µm | 1 1/µm | 1 c/µm | 1 h c µm⁻¹ k⁻¹ | 1 µm |
| --------------- | --------------- | --------------- | --------------- | --------------- |
| 1 eV | 8065.54 1/cm | 241.799 THz | 11604.5 K | 1.23984 µm |
| 0.000123984 eV | 1 1/cm | 0.0299792 THz | 1.43878 K | 10000 µm |
| 0.00413567 eV | 33.3564 1/cm | 1 THz | 47.9924 K | 299.792 µm |
| 8.61733e-05 eV | 0.695035 1/cm | 0.0208366 THz | 1 K | 14387.8 µm |
| 1.23984 eV | 10000 1/cm | 299.792 THz | 14387.8 K | 1 µm |
The symbolic table demonstrates how faster-than-lightspeed constants are preserved in quantity representations, showing the underlying physics relationships directly.
Why This Matters¶
- Domain-Specific Conversions: Different spectroscopy subfields prefer different units (IR uses wavenumbers, visible uses wavelengths)
- Physical Accuracy: Uses exact 2019 SI-defining constant values
- Research Applications: Essential for spectroscopy, quantum mechanics, thermodynamics
- Unit Consistency: Dimensional analysis ensures all conversions are physically correct
This pattern demonstrates how mp-units extends beyond simple unit conversions to enable physics-based transformations between related but dimensionally different quantities.
Related¶
This example is based on the unit conversion table from: "Atomic and Molecular Spectroscopy: Basic Concepts and Applications"