Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab04a8a

Browse files
committed
handles partially acquired datasets in bruker
1 parent 0bbdcc6 commit ab04a8a

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

nmrglue/fileio/bruker.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,15 @@ def read(dir=".", bin_file=None, acqus_files=None, pprog_file=None, shape=None,
438438
# also fails silently when acqus file is absent.
439439
pass
440440

441+
estimated_dims = 1
442+
for i in (2, 3, 4):
443+
if f'acqu{i}s' in dic.keys():
444+
estimated_dims += 1
445+
441446
# read the binary file
442447
f = os.path.join(dir, bin_file)
443448
_, data = read_binary(f, shape=shape, cplex=cplex, big=big,
444-
isfloat=isfloat)
449+
isfloat=isfloat, estimated_dims=estimated_dims)
445450

446451

447452
return dic, data
@@ -1529,7 +1534,7 @@ def reorder_submatrix(data, shape, submatrix_shape, reverse=False):
15291534

15301535
# Bruker binary (fid/ser) reading and writing
15311536

1532-
def read_binary(filename, shape=(1), cplex=True, big=True, isfloat=False):
1537+
def read_binary(filename, shape=(1), cplex=True, big=True, isfloat=False, estimated_dims=None):
15331538
"""
15341539
Read Bruker binary data from file and return dic,data pair.
15351540
@@ -1578,7 +1583,18 @@ def read_binary(filename, shape=(1), cplex=True, big=True, isfloat=False):
15781583
return dic, data.reshape(shape)
15791584

15801585
except ValueError:
1581-
warn(f"{data.shape} cannot be shaped into {shape}")
1586+
try:
1587+
data = data.reshape(-1, shape[-1])
1588+
if estimated_dims and (estimated_dims > 2):
1589+
warn(
1590+
"Data is inconsistent with acquistion parameters. "
1591+
"This usually happens with partially acquired datasets with dims >2. "
1592+
"A 2D dataset will be returned. This will requires further reshaping before processing."
1593+
)
1594+
return dic, data
1595+
except ValueError:
1596+
warn(f"{data.shape} cannot be shaped into {shape} or a consistent 2D array. A 1D array will be returned.")
1597+
15821598
return dic, data
15831599

15841600

0 commit comments

Comments
 (0)