Skip to content

Commit

Permalink
feat: update to handle other data than nmr
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed Nov 3, 2023
1 parent 0499ee3 commit 1a9de00
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions nmrglue/fileio/jcampdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,10 @@ def read(filename, show_all_data=False, read_err=None):
# find and parse NMR data array from raw dic
data = _getdataarray(dic, show_all_data)

# remove data tables from dic
try:
dic['XYDATA_OLD'] = dic["XYDATA"]
del dic["XYDATA"]
except KeyError:
pass

try:
subdiclist = dic["_datatype_NMRSPECTRUM"]
for subdic in subdiclist:
data = _getdataarray(subdic)
data = _getdataarray(subdic, show_all_data)
if data is not None:
correctdic = subdic
break
Expand All @@ -654,7 +647,7 @@ def read(filename, show_all_data=False, read_err=None):
try:
subdiclist = dic["_datatype_NMRFID"]
for subdic in subdiclist:
data = _getdataarray(subdic)
data = _getdataarray(subdic, show_all_data)
if data is not None:
correctdic = subdic
break
Expand All @@ -667,7 +660,21 @@ def read(filename, show_all_data=False, read_err=None):
try:
subdiclist = dic["_datatype_NA"]
for subdic in subdiclist:
data = _getdataarray(subdic)
data = _getdataarray(subdic, show_all_data)
if data is not None:
correctdic = subdic
break
except KeyError:
pass

if data is None:
# finally try all non-typed data sections, since
# sometimes DATATYPE label may be missing
try:
dic_key = list(dic.keys())[0]
subdiclist = dic[dic_key]
for subdic in subdiclist:
data = _getdataarray(subdic, show_all_data)
if data is not None:
correctdic = subdic
break
Expand All @@ -688,6 +695,7 @@ def read(filename, show_all_data=False, read_err=None):
# clean correct dic:
# remove data tables
try:
correctdic['XYDATA_OLD'] = correctdic["XYDATA"]
del correctdic["XYDATA"]
except KeyError:
pass
Expand Down

0 comments on commit 1a9de00

Please sign in to comment.