def wavenumber_to_temp(wavenumber, units_in='cm-1', return_quantity=False, units_out='K'): """Converts wavenumbers (1/cm) to temperatures (K) Parameters ---------- wavenumber : float Wavenumber units_in : str, optional Units corresponding to ``wavenumber``. Default is 'cm-1'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``temp``. Default is 'K'. Returns ------- temperature : float or :class:`~vunits.quantity.Quantity` obj Temperature corresponding to ``units_out``. """ wavenumber_in = _force_get_quantity(obj=wavenumber, units=units_in) qty_out = wavenumber_in * c.c * c.h / c.kb return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def wavenumber_to_freq(wavenumber, units_in='cm-1', return_quantity=False, units_out='Hz'): """Converts wavenumber to frequency Parameters ---------- wavenumber : float Wavenumber units_in : str, optional Units corresponding to ``wavenumber``. Default is 'cm-1'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``freq``. Default is 'Hz'. Returns ------- freq : float or :class:`~vunits.quantity.Quantity` obj Frequency corresponding to ``units_out``. """ wavenumber_in = _force_get_quantity(obj=wavenumber, units=units_in) qty_out = wavenumber_in * c.c return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def wavenumber_to_inertia(wavenumber, units_in='cm-1', return_quantity=False, units_out='kg m2'): """Converts wavenumber (1/cm) to moment of inertia Parameters ---------- wavenumber : float Wavenumber units_in : str, optional Units corresponding to ``wavenumber``. Default is 'cm-1'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``inertia``. Default is 'kg m2'. Returns ------- mu : float or :class:`~vunits.quantity.Quantity` obj Moment of inertia corresponding to ``units_out``. """ wavenumber_in = _force_get_quantity(obj=wavenumber, units=units_in) qty_out = c.h / (8. * np.pi**2 * wavenumber_in * c.c) return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def temp_to_wavenumber(temp, units_in='K', return_quantity=False, units_out='cm-1'): """Converts vibrational/rotational temperature to wavenumber Parameters ---------- temp : float Temperature in K units_in : str, optional Units corresponding to ``temp``. Default is 'K'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``wavenumber``. Default is 'cm-1'. Returns ------- wavenumber : float or :class:`~vunits.quantity.Quantity` obj Wavenumber corresponding to ``units_out``. """ temp_in = _force_get_quantity(obj=temp, units=units_in) qty_out = temp_in * c.kb / c.c / c.h return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def wavenumber_to_energy(wavenumber, units_in='cm-1', return_quantity=False, units_out='J'): """Converts wavenumbers to energies Parameters ---------- wavenumber : float Wavenumber units_in : str, optional Units corresponding to ``wavenumber``. Default is '1/cm'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``energy``. Default is 'J'. Returns ------- energy : float or :class:`~vunits.quantity.Quantity` obj Energy corresponding to ``units_out``. """ wavenumber_in = _force_get_quantity(obj=wavenumber, units=units_in) qty_out = wavenumber_in * c.c * c.h return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def inertia_to_temp(inertia, units_in='kg m2', return_quantity=False, units_out='K'): """Converts moment of inertia into rotational temperature Parameters ---------- inertia : float Moment of inertia units_in : str, optional Units corresponding to ``inertia``. Default is 'kg m2'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``temp``. Default is 'K'. Returns ------- rot_temperature : float or :class:`~vunits.quantity.Quantity` obj Rotational temperature corresponding to ``units_out``. """ inertia_in = _force_get_quantity(obj=inertia, units=units_in) qty_out = c.h_bar**2 / 2. / c.kb / inertia_in return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def energy_to_wavenumber(energy, units_in='J', return_quantity=False, units_out='cm-1'): """Converts energy to wavenumber Parameters ---------- energy : float Energy units_in : str, optional Units corresponding to ``energy``. Default is 'J'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``wavenumber``. Default is 'cm-1'. Returns ------- wavenumber : float or :class:`~vunits.quantity.Quantity` obj Wavenumber corresponding to ``units_out``. """ energy_in = _force_get_quantity(obj=energy, units=units_in) qty_out = energy_in / c.h / c.c return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def freq_to_wavenumber(freq, units_in='Hz', return_quantity=False, units_out='cm-1'): """Converts frequency to wavenumber Parameters ---------- freq : float Frequency units_in : str, optional Units corresponding to ``freq``. Default is 'Hz'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``wavenumber``. Default is 'cm-1'. Returns ------- wavenumber : float or :class:`~vunits.quantity.Quantity` obj Wavenumber corresponding to ``units_out``. """ freq_in = _force_get_quantity(obj=freq, units=units_in) qty_out = freq_in / c.c return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def energy_to_freq(energy, units_in='J', return_quantity=False, units_out='Hz'): """Converts energy to frequency Parameters ---------- energy : float or :class:`~vunits.quantity.Quantity` obj Energy units_in : str, optional Units corresponding to ``energy``. Default is 'J'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``freq``. Default is 'Hz'. Returns ------- freq : float or :class:`~vunits.quantity.Quantity` obj Frequency corresponding to ``units_out``. """ energy_in = _force_get_quantity(obj=energy, units=units_in) qty_out = energy_in / c.h return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def temp_to_freq(temp, units_in='K', return_quantity=False, units_out='Hz'): """Converts temperature to frequency Parameters ---------- temp : float Temperature in K units_in : str, optional Units corresponding to ``temp``. Default is 'K'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``freq``. Default is 'Hz'. Returns ------- freq : float or :class:`~vunits.quantity.Quantity` obj Frequency corresponding to ``units_out``. """ temp_in = _force_get_quantity(obj=temp, units=units_in) qty_out = temp_in * c.kb / c.h return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def freq_to_temp(freq, units_in='Hz', return_quantity=False, units_out='K'): """Converts frequency to temperature Parameters ---------- freq : float Frequency units_in : str, optional Units corresponding to ``freq``. Default is 'Hz'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``temp``. Default is 'K'. Returns ------- temp : float or :class:`~vunits.quantity.Quantity` obj Temperature corresponding to ``units_out``. """ freq_in = _force_get_quantity(obj=freq, units=units_in) qty_out = freq_in * c.h / c.kb return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def freq_to_energy(freq, units_in='Hz', return_quantity=False, units_out='J'): """Converts frequency to energy Parameters ---------- freq : float Frequency units_in : str, optional Units corresponding to ``energy``. Default is 'Hz'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``energy``. Default is 'J'. Returns ------- energy : float or :class:`~vunits.quantity.Quantity` obj Energy corresponding to ``units_out``. """ freq_in = _force_get_quantity(obj=freq, units=units_in) qty_out = freq_in * c.h return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def energy_to_temp(energy, units_in='J', return_quantity=False, units_out='K'): """Converts energy to temperature Parameters ---------- energy : float Energy units_in : str, optional Units corresponding to ``energy``. Default is 'J'. return_quantity: bool, optional If True, returns :class:`~vunits.quantity.Quantity`. Otherwise, returns float. units_out : str, optional Units corresponding to ``temp``. Default is 'K'. Returns ------- temp : float or :class:`~vunits.quantity.Quantity` obj Temperature corresponding to ``units_out``. """ energy_in = _force_get_quantity(obj=energy, units=units_in) qty_out = energy_in / c.kb return _return_quantity(quantity=qty_out, return_quantity=return_quantity, units_out=units_out)
def test_return_quantity(self): vel1 = Quantity(mag=10., m=1., s=-1.) self.assertEqual(_return_quantity(vel1, True), vel1) self.assertEqual(_return_quantity(vel1, False, 'm/s'), vel1.mag) self.assertEqual(_return_quantity(vel1, False, 'cm/s'), vel1.mag*100.)