MCPcopy
hub / github.com/nitrain/nitrain / __init__

Method __init__

nitrain/datasets/dataset.py:13–45  ·  view source on GitHub ↗

Create a nitrain dataset from data in memory or on the local filesystem. Examples -------- import nitrain as nt from nitrain import readers dataset = nt.Dataset( inputs = readers.ImageReader('~/desktop/ds004711/sub-*/anat/*_T1w.ni

(self, inputs, outputs, transforms=None, base_dir=None, base_file=None)

Source from the content-addressed store, hash-verified

11class Dataset:
12
13 def __init__(self, inputs, outputs, transforms=None, base_dir=None, base_file=None):
14 """
15 Create a nitrain dataset from data in memory or on the local filesystem.
16
17 Examples
18 --------
19 import nitrain as nt
20 from nitrain import readers
21 dataset = nt.Dataset(
22 inputs = readers.ImageReader('~/desktop/ds004711/sub-*/anat/*_T1w.nii.gz'),
23 outputs = readers.ColumnReader('~/desktop/ds004711/participants.tsv', 'age'),
24 )
25 """
26
27 inputs = infer_reader(inputs)
28 outputs = infer_reader(outputs)
29
30 self._base_dir = base_dir
31 self._base_file = base_file
32
33 if base_dir:
34 base_dir = os.path.expanduser(base_dir)
35
36 inputs.map_values(base_dir=base_dir, base_file=base_file, base_label='inputs')
37 outputs.map_values(base_dir=base_dir, base_file=base_file, base_label='outputs')
38
39 # ensure alignment
40 if len(inputs.values) != len(outputs.values):
41 warnings.warn('Inputs and outputs do not have same length. This could be misalignment between mappings.')
42
43 self.inputs = inputs
44 self.outputs = outputs
45 self.transforms = transforms
46
47 def select(self, n, random=False):
48 """

Callers

nothing calls this directly

Calls 2

infer_readerFunction · 0.85
map_valuesMethod · 0.45

Tested by

no test coverage detected