Commit e44e1f88 authored by William Clarke's avatar William Clarke
Browse files

Expanded range of field strengths to automatically identify.

parent 305b04a5
......@@ -158,12 +158,19 @@ class MRS(object):
cf_MHz = cf / 1e6
for key in GYRO_MAG_RATIO:
onefivet_range = GYRO_MAG_RATIO[key] * np.asarray([1.445, 1.505])
threet_range = GYRO_MAG_RATIO[key] * np.asarray([2.885, 3.005])
siemensthreet_range = GYRO_MAG_RATIO[key] * np.asarray([2.890, 2.895])
threet_range = GYRO_MAG_RATIO[key] * np.asarray([2.995, 3.005])
sevent_range = GYRO_MAG_RATIO[key] * np.asarray([6.975, 7.005])
ninefourt_range = GYRO_MAG_RATIO[key] * np.asarray([9.35, 9.45])
elevensevent_range = GYRO_MAG_RATIO[key] * np.asarray([11.74, 11.8])
if (cf_MHz > onefivet_range[0] and cf_MHz < onefivet_range[1]) or \
(cf_MHz > siemensthreet_range[0] and cf_MHz < siemensthreet_range[1]) or \
(cf_MHz > threet_range[0] and cf_MHz < threet_range[1]) or \
(cf_MHz > sevent_range[0] and cf_MHz < sevent_range[1]):
print(f'Identified as {key} nucleus data.')
(cf_MHz > sevent_range[0] and cf_MHz < sevent_range[1]) or \
(cf_MHz > ninefourt_range[0] and cf_MHz < ninefourt_range[1]) or \
(cf_MHz > elevensevent_range[0] and cf_MHz < elevensevent_range[1]):
print(f'Identified as {key} nucleus data.'
f' Esitmated field: {cf_MHz/GYRO_MAG_RATIO[key]} T.')
return key
raise ValueError(f'Unidentified nucleus,'
......
......@@ -6,6 +6,7 @@ import pytest
from fsl_mrs.utils import synthetic as syn
import numpy as np
from fsl_mrs.utils.misc import FIDToSpec, hz2ppm
from fsl_mrs.utils.constants import GYRO_MAG_RATIO
# Files
testsPath = Path(__file__).parent
......@@ -147,3 +148,46 @@ def test_basis_manipulations(synth_data):
mrs.add_MM_peaks(gamma=10, sigma=10)
assert mrs.basis.shape == (2048, 6)
assert mrs.numBasis == 6
def test_nucleus_identification():
rng = np.random.default_rng()
fid = rng.standard_normal(512) + 1j * rng.standard_normal(512)
hdr = {'centralFrequency': GYRO_MAG_RATIO['1H'] * 2.9,
'bandwidth': 4000.0}
mrs = MRS(FID=fid,
header=hdr,
nucleus='1H')
assert mrs.nucleus == '1H'
hdr = {'ResonantNucleus': '1H',
'centralFrequency': GYRO_MAG_RATIO['1H'] * 2.9,
'bandwidth': 4000.0}
mrs = MRS(FID=fid,
header=hdr)
assert mrs.nucleus == '1H'
hdr = {'json': {'ResonantNucleus': '1H'},
'centralFrequency': GYRO_MAG_RATIO['1H'] * 2.9,
'bandwidth': 4000.0}
mrs = MRS(FID=fid,
header=hdr)
assert mrs.nucleus == '1H'
# Test automatic identification
for nuc in ['1H', '13C', '31P']:
for field in [1.5, 2.894, 3.0, 7.0, 9.4, 11.755]:
hdr = {'centralFrequency': GYRO_MAG_RATIO[nuc] * field,
'bandwidth': 4000.0}
mrs = MRS(FID=fid,
header=hdr)
assert mrs.nucleus == nuc
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment