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)
| 11 | class 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 | """ |
nothing calls this directly
no test coverage detected