Skip to content

Commit f953256

Browse files
authored
Merge pull request #122 from bingli621/fix-utils-speed_energy_conversion
Fix: speed energy conversion in utils..py
2 parents 4c72f0b + a8f3fb8 commit f953256

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/tof/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
two_pi = sc.constants.pi * (2.0 * sc.units.rad)
1414

1515

16-
def speed_to_wavelength(x: sc.Variable, unit: str = 'angstrom') -> sc.Variable:
16+
def speed_to_wavelength(x: sc.Variable, unit: str = "angstrom") -> sc.Variable:
1717
"""
1818
Convert neutron speeds to wavelengths.
1919
@@ -27,7 +27,7 @@ def speed_to_wavelength(x: sc.Variable, unit: str = 'angstrom') -> sc.Variable:
2727
return (1.0 / (m_over_h * x)).to(unit=unit)
2828

2929

30-
def wavelength_to_speed(x: sc.Variable, unit: str = 'm/s') -> sc.Variable:
30+
def wavelength_to_speed(x: sc.Variable, unit: str = "m/s") -> sc.Variable:
3131
"""
3232
Convert neutron wavelengths to speeds.
3333
@@ -41,7 +41,7 @@ def wavelength_to_speed(x: sc.Variable, unit: str = 'm/s') -> sc.Variable:
4141
return (1.0 / (m_over_h * x)).to(unit=unit)
4242

4343

44-
def speed_to_energy(x: sc.Variable, unit='meV') -> sc.Variable:
44+
def speed_to_energy(x: sc.Variable, unit="meV") -> sc.Variable:
4545
"""
4646
Convert neutron speeds to energies.
4747
@@ -52,10 +52,10 @@ def speed_to_energy(x: sc.Variable, unit='meV') -> sc.Variable:
5252
unit:
5353
The unit of the output energies.
5454
"""
55-
return (const.m_n * x * x).to(unit=unit)
55+
return ((0.5 * const.m_n) * x * x).to(unit=unit)
5656

5757

58-
def energy_to_speed(x: sc.Variable, unit='m/s') -> sc.Variable:
58+
def energy_to_speed(x: sc.Variable, unit="m/s") -> sc.Variable:
5959
"""
6060
Convert neutron energies to speeds.
6161
@@ -66,7 +66,7 @@ def energy_to_speed(x: sc.Variable, unit='m/s') -> sc.Variable:
6666
unit:
6767
The unit of the output speeds.
6868
"""
69-
return sc.sqrt(x / const.m_n).to(unit=unit)
69+
return sc.sqrt(x / (0.5 * const.m_n)).to(unit=unit)
7070

7171

7272
def one_mask(
@@ -97,8 +97,8 @@ def var_to_dict(var: sc.Variable) -> dict:
9797
The variable to convert.
9898
"""
9999
return {
100-
'value': var.values.tolist() if var.ndim > 0 else float(var.value),
101-
'unit': str(var.unit),
100+
"value": var.values.tolist() if var.ndim > 0 else float(var.value),
101+
"unit": str(var.unit),
102102
}
103103

104104

0 commit comments

Comments
 (0)