Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/tof/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
two_pi = sc.constants.pi * (2.0 * sc.units.rad)


def speed_to_wavelength(x: sc.Variable, unit: str = 'angstrom') -> sc.Variable:
def speed_to_wavelength(x: sc.Variable, unit: str = "angstrom") -> sc.Variable:
"""
Convert neutron speeds to wavelengths.

Expand All @@ -27,7 +27,7 @@ def speed_to_wavelength(x: sc.Variable, unit: str = 'angstrom') -> sc.Variable:
return (1.0 / (m_over_h * x)).to(unit=unit)


def wavelength_to_speed(x: sc.Variable, unit: str = 'm/s') -> sc.Variable:
def wavelength_to_speed(x: sc.Variable, unit: str = "m/s") -> sc.Variable:
"""
Convert neutron wavelengths to speeds.

Expand All @@ -41,7 +41,7 @@ def wavelength_to_speed(x: sc.Variable, unit: str = 'm/s') -> sc.Variable:
return (1.0 / (m_over_h * x)).to(unit=unit)


def speed_to_energy(x: sc.Variable, unit='meV') -> sc.Variable:
def speed_to_energy(x: sc.Variable, unit="meV") -> sc.Variable:
"""
Convert neutron speeds to energies.

Expand All @@ -52,10 +52,10 @@ def speed_to_energy(x: sc.Variable, unit='meV') -> sc.Variable:
unit:
The unit of the output energies.
"""
return (const.m_n * x * x).to(unit=unit)
return ((0.5 * const.m_n) * x * x).to(unit=unit)


def energy_to_speed(x: sc.Variable, unit='m/s') -> sc.Variable:
def energy_to_speed(x: sc.Variable, unit="m/s") -> sc.Variable:
"""
Convert neutron energies to speeds.

Expand All @@ -66,7 +66,7 @@ def energy_to_speed(x: sc.Variable, unit='m/s') -> sc.Variable:
unit:
The unit of the output speeds.
"""
return sc.sqrt(x / const.m_n).to(unit=unit)
return sc.sqrt(x / (0.5 * const.m_n)).to(unit=unit)


def one_mask(
Expand Down Expand Up @@ -97,8 +97,8 @@ def var_to_dict(var: sc.Variable) -> dict:
The variable to convert.
"""
return {
'value': var.values.tolist() if var.ndim > 0 else float(var.value),
'unit': str(var.unit),
"value": var.values.tolist() if var.ndim > 0 else float(var.value),
"unit": str(var.unit),
}


Expand Down
Loading