brukerapi 0.1.9__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
brukerapi/splitters.py CHANGED
@@ -1,20 +1,21 @@
1
- from .utils import index_to_slice
2
- from .dataset import Dataset
3
-
4
- import numpy as np
5
1
  import copy
2
+ import os
6
3
  from pathlib import Path
7
4
 
8
- SUPPORTED_FG = ['FG_ISA','FG_IRMODE','FG_ECHO']
5
+ import numpy as np
9
6
 
7
+ from .dataset import Dataset
8
+ from .exceptions import MissingProperty
9
+ from .utils import index_to_slice
10
10
 
11
- class Splitter(object):
11
+ SUPPORTED_FG = ["FG_ISA", "FG_IRMODE", "FG_ECHO"]
12
12
 
13
- def write(self, datasets, path_out=None):
14
13
 
14
+ class Splitter:
15
+ def write(self, datasets, path_out=None):
15
16
  for dataset in datasets:
16
17
  if path_out:
17
- dataset.write('{}/{}/{}'.format(Path(path_out), dataset.path.parents[0].name, dataset.path.name))
18
+ dataset.write(f"{Path(path_out)}/{dataset.path.parents[0].name}/{dataset.path.name}")
18
19
  else:
19
20
  dataset.write(dataset.path)
20
21
 
@@ -37,11 +38,11 @@ class Splitter(object):
37
38
  :param fg_index:
38
39
  :return:
39
40
  """
40
- VisuCoreDataMin = visu_pars['VisuCoreDataMin']
41
- value = np.reshape(VisuCoreDataMin.value, dataset.shape_final[dataset.encoded_dim:], order='F')
41
+ VisuCoreDataMin = visu_pars["VisuCoreDataMin"]
42
+ value = np.reshape(VisuCoreDataMin.value, dataset.shape_final[dataset.encoded_dim :], order="F")
42
43
  value = value[index_to_slice(select, value.shape, fg_rel_index)]
43
- VisuCoreDataMin.size = (np.prod(value.shape),)
44
- VisuCoreDataMin.value = value.flatten(order='F')
44
+ VisuCoreDataMin.size = (int(np.prod(value.shape)),)
45
+ VisuCoreDataMin.value = value.flatten(order="F")
45
46
 
46
47
  def _split_VisuCoreDataMax(self, dataset, visu_pars, select, fg_rel_index):
47
48
  """
@@ -51,11 +52,11 @@ class Splitter(object):
51
52
  :param fg_index:
52
53
  :return:
53
54
  """
54
- VisuCoreDataMax = visu_pars['VisuCoreDataMax']
55
- value = np.reshape(VisuCoreDataMax.value, dataset.shape_final[dataset.encoded_dim:], order='F')
55
+ VisuCoreDataMax = visu_pars["VisuCoreDataMax"]
56
+ value = np.reshape(VisuCoreDataMax.value, dataset.shape_final[dataset.encoded_dim :], order="F")
56
57
  value = value[index_to_slice(select, value.shape, fg_rel_index)]
57
- VisuCoreDataMax.size = (np.prod(value.shape),)
58
- VisuCoreDataMax.value = value.flatten(order='F')
58
+ VisuCoreDataMax.size = (int(np.prod(value.shape)),)
59
+ VisuCoreDataMax.value = value.flatten(order="F")
59
60
 
60
61
  def _split_VisuCoreDataOffs(self, dataset, visu_pars, select, fg_rel_index):
61
62
  """
@@ -65,11 +66,11 @@ class Splitter(object):
65
66
  :param fg_index:
66
67
  :return:
67
68
  """
68
- VisuCoreDataOffs = visu_pars['VisuCoreDataOffs']
69
- value = np.reshape(VisuCoreDataOffs.value, dataset.shape_final[dataset.encoded_dim:],order='F')
69
+ VisuCoreDataOffs = visu_pars["VisuCoreDataOffs"]
70
+ value = np.reshape(VisuCoreDataOffs.value, dataset.shape_final[dataset.encoded_dim :], order="F")
70
71
  value = value[index_to_slice(select, value.shape, fg_rel_index)]
71
- VisuCoreDataOffs.size = (np.prod(value.shape),)
72
- VisuCoreDataOffs.value = value.flatten(order='F')
72
+ VisuCoreDataOffs.size = (int(np.prod(value.shape)),)
73
+ VisuCoreDataOffs.value = value.flatten(order="F")
73
74
 
74
75
  def _split_VisuCoreDataSlope(self, dataset, visu_pars, select, fg_rel_index):
75
76
  """
@@ -79,34 +80,34 @@ class Splitter(object):
79
80
  :param fg_index:
80
81
  :return:
81
82
  """
82
- VisuCoreDataSlope = visu_pars['VisuCoreDataSlope']
83
- value = np.reshape(VisuCoreDataSlope.value, dataset.shape_final[dataset.encoded_dim:],order='F')
83
+ VisuCoreDataSlope = visu_pars["VisuCoreDataSlope"]
84
+ value = np.reshape(VisuCoreDataSlope.value, dataset.shape_final[dataset.encoded_dim :], order="F")
84
85
  value = value[index_to_slice(select, value.shape, fg_rel_index)]
85
- VisuCoreDataSlope.size = (np.prod(value.shape),)
86
- VisuCoreDataSlope.value = value.flatten(order='F')
86
+ VisuCoreDataSlope.size = (int(np.prod(value.shape)),)
87
+ VisuCoreDataSlope.value = value.flatten(order="F")
87
88
 
88
89
  def _split_VisuCoreTransposition(self, dataset, visu_pars, index, fg_index):
89
90
  try:
90
- VisuCoreTransposition = visu_pars['VisuCoreTransposition']
91
+ VisuCoreTransposition = visu_pars["VisuCoreTransposition"]
91
92
  except KeyError:
92
93
  return VisuCoreTransposition
93
94
 
94
- value = np.reshape(VisuCoreTransposition.value, dataset.shape_final[dataset.encoded_dim:], order='F')
95
+ value = np.reshape(VisuCoreTransposition.value, dataset.shape_final[dataset.encoded_dim :], order="F")
95
96
  value = value[index_to_slice(index, value.shape, fg_index - dataset.encoded_dim)]
96
- VisuCoreTransposition.size = (np.prod(value.shape),)
97
- VisuCoreTransposition.value = value.flatten(order='F')
97
+ VisuCoreTransposition.size = (int(np.prod(value.shape)),)
98
+ VisuCoreTransposition.value = value.flatten(order="F")
99
+ return None
98
100
 
99
101
 
100
102
  class FrameGroupSplitter(Splitter):
101
103
  def __init__(self, fg):
102
104
  if fg not in SUPPORTED_FG:
103
- raise NotImplemented('Split operation for {} is not implemented'.format(fg))
105
+ raise NotImplementedError(f"Split operation for {fg} is not implemented")
104
106
 
105
- super(FrameGroupSplitter, self).__init__()
107
+ super().__init__()
106
108
  self.fg = fg
107
109
 
108
-
109
- def split(self, dataset, select=None, write=False, path_out=None, **kwargs):
110
+ def split(self, dataset, select=None, write=None, path_out=None, **kwargs):
110
111
  """Split Bruker object along a dimension of specific frame group.
111
112
  Only the frame groups listed in SPLIT_FG_IMPLEMENTED can be used to split the object.
112
113
 
@@ -121,14 +122,17 @@ class FrameGroupSplitter(Splitter):
121
122
 
122
123
  """
123
124
 
124
- if "<{}>".format(self.fg) not in dataset.dim_type:
125
- raise ValueError(f'Dataset does not contain {self.fg} frame group')
125
+ if write is None:
126
+ write = False
127
+
128
+ if f"<{self.fg}>" not in dataset.dim_type:
129
+ raise ValueError(f"Dataset does not contain {self.fg} frame group")
126
130
 
127
131
  """
128
132
  CHECK if FG and index are valid
129
133
  """
130
134
  # absolute index of FG_SLICE among dimensions of the dataset
131
- fg_abs_index = dataset.dim_type.index("<{}>".format(self.fg))
135
+ fg_abs_index = dataset.dim_type.index(f"<{self.fg}>")
132
136
 
133
137
  # index of FG_SLICE among frame group dimensions of the dataset
134
138
  fg_rel_index = fg_abs_index - dataset.encoded_dim
@@ -136,15 +140,17 @@ class FrameGroupSplitter(Splitter):
136
140
  # number of samples in self.fg dimension
137
141
  fg_size = dataset.shape[fg_abs_index]
138
142
 
139
- # If no index is specified, all elements of given dimension will be splited
143
+ # If no index is specified, all elements of given dimension will be split
140
144
  if select is None:
141
145
  select = list(range(0, fg_size))
142
146
 
143
147
  if isinstance(select, int):
144
- select = [select,]
148
+ select = [
149
+ select,
150
+ ]
145
151
 
146
152
  if max(select) >= fg_size:
147
- raise IndexError(f'Selection {select} out of bounds, size of {self.fg} dimension is {fg_size}')
153
+ raise IndexError(f"Selection {select} out of bounds, size of {self.fg} dimension is {fg_size}")
148
154
 
149
155
  """
150
156
  PERFORM splitting
@@ -153,10 +159,13 @@ class FrameGroupSplitter(Splitter):
153
159
 
154
160
  for select_ in select:
155
161
  # construct a new Dataset, without loading data, the data will be supplied later
156
- name = '{}_{}_{}/2dseq'.format(dataset.path.parents[0].name, self.fg, select_)
162
+ name = f"{dataset.path.parents[0].name}_{self.fg}_{select_}/2dseq"
163
+
164
+ dset_path = dataset.path.parents[1] / name
165
+ os.makedirs(dset_path, exist_ok=True)
157
166
 
158
167
  # construct a new Dataset, without loading data, the data will be supplied later
159
- dataset_ = Dataset(dataset.path.parents[1] / name, load=False)
168
+ dataset_ = Dataset(dataset.path.parents[1] / name, load=0)
160
169
 
161
170
  dataset_.parameters = self._split_params(dataset, select_, fg_abs_index, fg_rel_index, fg_size)
162
171
 
@@ -178,8 +187,7 @@ class FrameGroupSplitter(Splitter):
178
187
  return datasets
179
188
 
180
189
  def _split_params(self, dataset, select, fg_abs_index, fg_rel_index, fg_size):
181
-
182
- visu_pars = copy.deepcopy(dataset.parameters['visu_pars'])
190
+ visu_pars = copy.deepcopy(dataset.parameters["visu_pars"])
183
191
 
184
192
  self._split_VisuCoreFrameCount(visu_pars, fg_size)
185
193
  self._split_VisuFGOrderDescDim(visu_pars)
@@ -189,12 +197,12 @@ class FrameGroupSplitter(Splitter):
189
197
  self._split_VisuCoreDataMin(dataset, visu_pars, select, fg_rel_index)
190
198
  self._split_VisuCoreDataMax(dataset, visu_pars, select, fg_rel_index)
191
199
 
192
- if self.fg == 'FG_ECHO':
200
+ if self.fg == "FG_ECHO":
193
201
  self._split_params_FG_ECHO(dataset, select, fg_abs_index, fg_rel_index, fg_size, visu_pars)
194
- if self.fg == 'FG_ISA':
202
+ if self.fg == "FG_ISA":
195
203
  self._split_params_FG_ISA(dataset, select, fg_abs_index, fg_rel_index, fg_size, visu_pars)
196
204
 
197
- return {'visu_pars': visu_pars}
205
+ return {"visu_pars": visu_pars}
198
206
 
199
207
  def _split_params_FG_ISA(self, dataset, select, fg_abs_index, fg_rel_index, fg_size, visu_pars):
200
208
  self._split_VisuCoreDataUnits(visu_pars, dataset, select, fg_rel_index)
@@ -204,43 +212,42 @@ class FrameGroupSplitter(Splitter):
204
212
  self._split_VisuAcqEchoTime(visu_pars, select)
205
213
 
206
214
  def _split_VisuCoreFrameCount(self, visu_pars, fg_size):
207
- VisuCoreFrameCount = visu_pars['VisuCoreFrameCount']
215
+ VisuCoreFrameCount = visu_pars["VisuCoreFrameCount"]
208
216
  value = int(VisuCoreFrameCount.value / fg_size)
209
217
  VisuCoreFrameCount.value = value
210
218
 
211
219
  def _split_VisuFGOrderDescDim(self, visu_pars):
212
- VisuFGOrderDescDim = visu_pars['VisuFGOrderDescDim']
220
+ VisuFGOrderDescDim = visu_pars["VisuFGOrderDescDim"]
213
221
  value = VisuFGOrderDescDim.value - 1
214
222
 
215
223
  if value > 1:
216
224
  VisuFGOrderDescDim.value = value
217
225
  else:
218
- del visu_pars['VisuFGOrderDescDim']
226
+ del visu_pars["VisuFGOrderDescDim"]
219
227
 
220
228
  def _split_VisuCoreDataUnits(self, visu_pars, fg_scheme, index, fg_index):
221
- VisuCoreDataUnits = visu_pars['VisuCoreDataUnits']
229
+ VisuCoreDataUnits = visu_pars["VisuCoreDataUnits"]
222
230
  value = VisuCoreDataUnits.value
223
231
  VisuCoreDataUnits.value = value[index]
224
232
  VisuCoreDataUnits.size = (65,)
225
233
 
226
234
  def _split_VisuFGOrderDesc(self, visu_pars, fg):
227
- VisuFGOrderDesc = visu_pars['VisuFGOrderDesc']
235
+ VisuFGOrderDesc = visu_pars["VisuFGOrderDesc"]
228
236
 
229
237
  size = VisuFGOrderDesc.size[0] - 1
230
238
  VisuFGOrderDesc.size = size
231
239
 
232
240
  value = VisuFGOrderDesc.nested
233
241
  for fg_ in value:
234
- if fg_[1] == '<{}>'.format(fg):
242
+ if fg_[1] == f"<{fg}>":
235
243
  value.remove(fg_)
236
244
  if value:
237
245
  VisuFGOrderDesc.value = value
238
246
  else:
239
- del visu_pars['VisuFGOrderDesc']
247
+ del visu_pars["VisuFGOrderDesc"]
240
248
 
241
249
  def _split_VisuFGElemComment(self, visu_pars, fg_scheme, index, fg_index):
242
-
243
- VisuFGElemComment = visu_pars['VisuFGElemComment']
250
+ VisuFGElemComment = visu_pars["VisuFGElemComment"]
244
251
 
245
252
  value = VisuFGElemComment.value
246
253
 
@@ -249,9 +256,9 @@ class FrameGroupSplitter(Splitter):
249
256
  VisuFGElemComment.size = (65,)
250
257
 
251
258
  def _split_VisuAcqEchoTime(self, visu_pars, select):
252
- VisuAcqEchoTime = visu_pars['VisuAcqEchoTime']
253
- value = VisuAcqEchoTime.value
254
- VisuAcqEchoTime.size=(1,)
259
+ VisuAcqEchoTime = visu_pars["VisuAcqEchoTime"]
260
+ value = VisuAcqEchoTime.list
261
+ VisuAcqEchoTime.size = (1,)
255
262
  VisuAcqEchoTime.value = float(value[select])
256
263
 
257
264
 
@@ -259,31 +266,35 @@ class SlicePackageSplitter(Splitter):
259
266
  """
260
267
  Split 2dseq data set along individual slice packages
261
268
  """
262
- def split(self, dataset, write=False, path_out=None):
269
+
270
+ def split(self, dataset, write=None, path_out=None):
263
271
  """
264
272
  Split 2dseq data set containing multiple data sets into a list of 2dseq data sets containing individual slice packages.
265
273
 
266
274
  This functionality might be used for instance when converting data to a different data format.
267
275
 
268
276
  :param dataset: 2dseq dataset with multiple slice packages
269
- :param write: if True, splitted data sets will we writen to drive
277
+ :param write: if True, split data sets will be written to drive
270
278
  :param path_out: a path to store data sets (optional)
271
- :return: list of splitted data sets
279
+ :return: list of split data sets
272
280
  """
273
281
 
282
+ if write is None:
283
+ write = False
284
+
274
285
  try:
275
- VisuCoreSlicePacksSlices = dataset['VisuCoreSlicePacksSlices'].value
286
+ VisuCoreSlicePacksSlices = dataset["VisuCoreSlicePacksSlices"].nested
276
287
  except KeyError:
277
- print('Parameter VisuCoreSlicePacksSlices not found')
288
+ raise MissingProperty("Parameter VisuCoreSlicePacksSlices not found") from KeyError
278
289
 
279
- # list of splitted data sets
290
+ # list of split data sets
280
291
  datasets = []
281
292
 
282
293
  # range of frames of given slice package
283
- frame_range = range(0,0)
294
+ frame_range = range(0, 0)
284
295
 
285
296
  # absolute index of FG_SLICE among dimensions of the dataset
286
- fg_rel_index = dataset['VisuFGOrderDesc'].sub_list(1).index('<FG_SLICE>')
297
+ fg_rel_index = dataset["VisuFGOrderDesc"].sub_list(1).index("<FG_SLICE>")
287
298
 
288
299
  # index of FG_SLICE among frame group dimensions of the dataset
289
300
  fg_abs_index = fg_rel_index + dataset.encoded_dim
@@ -291,31 +302,32 @@ class SlicePackageSplitter(Splitter):
291
302
  # slice package split loop
292
303
  for sp_index in range(len(VisuCoreSlicePacksSlices)):
293
304
  # set range
294
- frame_range= range(frame_range.stop, frame_range.stop + VisuCoreSlicePacksSlices[sp_index][1])
305
+ frame_range = range(frame_range.stop, frame_range.stop + VisuCoreSlicePacksSlices[sp_index][1])
295
306
 
296
307
  # number of frames contained in given slice package
297
308
  frame_count = frame_range.stop - frame_range.start
298
309
 
299
310
  # name of the data set created by the split
300
- name = '{}_sp_{}/2dseq'.format(dataset.path.parents[0].name, sp_index)
311
+ name = f"{dataset.path.parents[0].name}_sp_{sp_index}/2dseq"
301
312
 
313
+ os.makedirs(dataset.path.parents[1] / name, exist_ok=True)
302
314
 
303
315
  # construct a new Dataset, without loading data, the data will be supplied later
304
- dataset_ = Dataset(dataset.path.parents[1] / name, load=False)
316
+ dataset_ = Dataset(dataset.path.parents[1] / name, load=0)
305
317
 
306
- # SPLIT parameteres
318
+ # SPLIT parameters
307
319
  dataset_.parameters = self._split_parameters(dataset, frame_range, fg_rel_index, fg_abs_index, sp_index, frame_count)
308
320
 
309
321
  # construct properties from the new set of parameters
310
322
  dataset_.load_properties()
311
323
 
312
324
  # change id
313
- dataset_.id = '{}_sp_{}'.format(dataset_.id, sp_index)
325
+ dataset_.id = f"{dataset_.id}_sp_{sp_index}"
314
326
 
315
327
  # construct schema
316
328
  dataset_.load_schema()
317
329
 
318
- #SPLIT data
330
+ # SPLIT data
319
331
  dataset_.data = self._split_data(dataset, frame_range, fg_abs_index)
320
332
 
321
333
  # append to result
@@ -328,7 +340,7 @@ class SlicePackageSplitter(Splitter):
328
340
 
329
341
  def _split_parameters(self, dataset, frame_range, fg_rel_index, fg_abs_index, sp_index, frame_count):
330
342
  # create a copy of visu_pars of the original data set
331
- visu_pars_ = copy.deepcopy(dataset.parameters['visu_pars'])
343
+ visu_pars_ = copy.deepcopy(dataset.parameters["visu_pars"])
332
344
 
333
345
  # modify individual parameters so that the resulting data set is consistent
334
346
  self._split_VisuCorePosition(visu_pars_, frame_range, frame_count)
@@ -337,37 +349,38 @@ class SlicePackageSplitter(Splitter):
337
349
  self._split_VisuCoreDataMax(dataset, visu_pars_, frame_range, fg_rel_index)
338
350
  self._split_VisuCoreDataOffs(dataset, visu_pars_, frame_range, fg_rel_index)
339
351
  self._split_VisuCoreDataSlope(dataset, visu_pars_, frame_range, fg_rel_index)
340
- self._split_VisuCoreTransposition(dataset, visu_pars_, frame_range, fg_rel_index)
352
+ if "VisuCoreTransposition" in dataset:
353
+ self._split_VisuCoreTransposition(dataset, visu_pars_, frame_range, fg_rel_index)
341
354
  self._split_VisuCoreFrameCount(dataset, visu_pars_, frame_count, fg_abs_index)
342
355
  self._split_VisuFGOrderDesc(visu_pars_, fg_rel_index, frame_count)
343
356
  self._split_VisuCoreSlicePacksDef(visu_pars_)
344
357
  self._split_VisuCoreSlicePacksSlices(visu_pars_, sp_index)
345
358
  self._split_VisuCoreSlicePacksSliceDist(visu_pars_, sp_index)
346
359
 
347
- return {"visu_pars":visu_pars_}
360
+ return {"visu_pars": visu_pars_}
348
361
 
349
362
  def _split_VisuCoreFrameCount(self, dataset, visu_pars, frame_count, fg_ind_abs):
350
- VisuCoreFrameCount = visu_pars['VisuCoreFrameCount']
363
+ VisuCoreFrameCount = visu_pars["VisuCoreFrameCount"]
351
364
 
352
365
  layout = np.array(dataset.shape_final)
353
- layout[0:dataset.encoded_dim] = 1
366
+ layout[0 : dataset.encoded_dim] = 1
354
367
  layout[fg_ind_abs] = 1
355
368
  frames = int(frame_count * np.prod(layout))
356
369
 
357
370
  VisuCoreFrameCount.value = frames
358
371
 
359
372
  def _split_VisuCoreOrientation(self, visu_pars, frame_range, frame_count):
360
- VisuCoreOrientation = visu_pars['VisuCoreOrientation']
361
- VisuCoreOrientation.value = VisuCoreOrientation.value[frame_range, :].flatten(order='C')
373
+ VisuCoreOrientation = visu_pars["VisuCoreOrientation"]
374
+ VisuCoreOrientation.value = VisuCoreOrientation.value[frame_range, :].flatten(order="C")
362
375
  VisuCoreOrientation.size = (frame_count, 9)
363
376
 
364
377
  def _split_VisuCorePosition(self, visu_pars, frame_range, frame_count):
365
- VisuCorePosition = visu_pars['VisuCorePosition']
366
- VisuCorePosition.value = VisuCorePosition.value[frame_range, :].flatten(order='C')
378
+ VisuCorePosition = visu_pars["VisuCorePosition"]
379
+ VisuCorePosition.value = VisuCorePosition.value[frame_range, :].flatten(order="C")
367
380
  VisuCorePosition.size = (frame_count, 3)
368
381
 
369
382
  def _split_VisuFGOrderDesc(self, visu_pars, fg_rel_ind, frame_count):
370
- VisuFGOrderDesc = visu_pars['VisuFGOrderDesc']
383
+ VisuFGOrderDesc = visu_pars["VisuFGOrderDesc"]
371
384
  value = VisuFGOrderDesc.value
372
385
 
373
386
  if isinstance(value[fg_rel_ind], list):
@@ -377,18 +390,18 @@ class SlicePackageSplitter(Splitter):
377
390
 
378
391
  VisuFGOrderDesc.value = value
379
392
 
380
- def _split_VisuCoreSlicePacksDef(self,visu_pars):
381
- VisuCoreSlicePacksDef = visu_pars['VisuCoreSlicePacksDef']
393
+ def _split_VisuCoreSlicePacksDef(self, visu_pars):
394
+ VisuCoreSlicePacksDef = visu_pars["VisuCoreSlicePacksDef"]
382
395
  value = VisuCoreSlicePacksDef.value
383
396
  value[1] = 1
384
397
  VisuCoreSlicePacksDef.value = value
385
398
 
386
399
  def _split_VisuCoreSlicePacksSlices(self, visu_pars_, sp_index):
387
- VisuCoreSlicePacksSlices = visu_pars_['VisuCoreSlicePacksSlices']
400
+ VisuCoreSlicePacksSlices = visu_pars_["VisuCoreSlicePacksSlices"]
388
401
  VisuCoreSlicePacksSlices.value = [VisuCoreSlicePacksSlices.value[sp_index]]
389
402
 
390
403
  def _split_VisuCoreSlicePacksSliceDist(self, visu_pars_, sp_index):
391
- VisuCoreSlicePacksSliceDist = visu_pars_['VisuCoreSlicePacksSliceDist']
392
- value = int(VisuCoreSlicePacksSliceDist.value[sp_index])
404
+ VisuCoreSlicePacksSliceDist = visu_pars_["VisuCoreSlicePacksSliceDist"]
405
+ value = int(VisuCoreSlicePacksSliceDist.array[sp_index])
393
406
  VisuCoreSlicePacksSliceDist.value = value
394
- VisuCoreSlicePacksSliceDist.size = 1
407
+ VisuCoreSlicePacksSliceDist.size = 1
brukerapi/utils.py CHANGED
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
2
 
3
+
3
4
  def index_to_slice(index, data_shape, dim_index):
4
5
  out = []
5
6
 
6
7
  if isinstance(index, range):
7
8
  index = slice(index.start, index.stop)
8
9
 
9
-
10
10
  for i in range(len(data_shape)):
11
11
  if i != dim_index:
12
12
  out.append(slice(0, data_shape[i]))
@@ -15,48 +15,47 @@ def index_to_slice(index, data_shape, dim_index):
15
15
 
16
16
  return tuple(out)
17
17
 
18
+
18
19
  def simple_measurement(dataset):
20
+ if dataset.encoded_dim == 1:
21
+ axes = (0,)
22
+ elif dataset.encoded_dim == 2:
23
+ axes = (0, 1)
24
+ elif dataset.encoded_dim == 3:
25
+ axes = (0, 1, 2)
19
26
 
20
- if dataset.encoded_dim == 1:
21
- axes = (0,)
22
- elif dataset.encoded_dim == 2:
23
- axes = (0,1)
24
- elif dataset.encoded_dim == 3:
25
- axes = (0,1,2)
27
+ return np.fft.fftshift(np.fft.fft2(dataset.data, axes=axes), axes=axes)
26
28
 
27
- return np.fft.fftshift(np.fft.fft2(dataset.data,axes=axes),axes=axes)
28
29
 
29
30
  def simple_reconstruction(dataset, **kwargs):
30
- """
31
- Simple Fourier reconstruction
32
- :return: image
33
- """
34
- if dataset.encoded_dim == 1:
35
- axes = (0,)
36
- elif dataset.encoded_dim == 2:
37
- axes = (0,1)
38
- elif dataset.encoded_dim == 3:
39
- axes = (0,1,2)
40
-
41
- data = np.fft.fftshift(np.fft.ifft2(dataset.data, axes=axes),
42
- axes=axes)
43
-
44
- if kwargs.get("COMBINE_CHANNELS") is True:
45
- return combine_channels(data=data)
46
- else:
47
- return data
31
+ """
32
+ Simple Fourier reconstruction
33
+ :return: image
34
+ """
35
+ if dataset.encoded_dim == 1:
36
+ axes = (0,)
37
+ elif dataset.encoded_dim == 2:
38
+ axes = (0, 1)
39
+ elif dataset.encoded_dim == 3:
40
+ axes = (0, 1, 2)
48
41
 
49
- def combine_channels(dataset, data=None):
42
+ data = np.fft.fftshift(np.fft.ifft2(dataset.data, axes=axes), axes=axes)
50
43
 
51
- if dataset.scheme is not None:
52
- channel_dim = dataset.scheme.dim_type.index('channel')
53
- else:
54
- raise NotImplemented
44
+ if kwargs.get("COMBINE_CHANNELS") is True:
45
+ return combine_channels(data=data)
46
+ return data
47
+
48
+
49
+ def combine_channels(dataset, data=None):
50
+ if dataset.scheme is not None:
51
+ channel_dim = dataset.scheme.dim_type.index("channel")
52
+ else:
53
+ raise NotImplementedError
55
54
 
56
- if data is None:
57
- data = dataset.data
55
+ if data is None:
56
+ data = dataset.data
58
57
 
59
- data = data ** 2
60
- data = np.expand_dims(np.sum(data, channel_dim), channel_dim)
58
+ data = data**2
59
+ data = np.expand_dims(np.sum(data, channel_dim), channel_dim)
61
60
 
62
- return np.sqrt(data)
61
+ return np.sqrt(data)