MCPcopy Create free account
hub / github.com/ad12/DOSMA / load

Method load

dosma/cli.py:173–210  ·  view source on GitHub ↗

Command line interface loading scan data. ``self.scan_type`` must be set before calling this function. Args path (str): Path to pickle file or directory where data is stored. num_workers (int, optional): Number of workers to use to load data. Return

(self, path: str, num_workers: int = 0)

Source from the content-addressed store, hash-verified

171 return attr
172
173 def load(self, path: str, num_workers: int = 0):
174 """Command line interface loading scan data.
175
176 ``self.scan_type`` must be set before calling this function.
177
178 Args
179 path (str): Path to pickle file or directory where data is stored.
180 num_workers (int, optional): Number of workers to use to load data.
181
182 Returns:
183 ScanSequence: Scan of type ``self.scan_type``.
184
185 Raises:
186 ValueError: If path to load data from cannot be determined.
187
188 Examples:
189 >>> cli_scan.load("/path/to/pickle/file") # load data from pickle file
190 >>> cli_scan.load("/path/to/directory") # load data from directory
191 """
192 scan_type = self.scan_type
193
194 file_path = None
195 if os.path.isfile(path):
196 file_path = path
197 elif os.path.isdir(path) and scan_type.NAME:
198 fname = f"{scan_type.NAME}.data"
199 _paths = (
200 os.path.join(path, fname),
201 os.path.join(self._save_dir(path, create_dir=False), fname),
202 )
203 for _path in _paths:
204 if os.path.isfile(_path):
205 file_path = _path
206 break
207 if file_path is None:
208 raise ValueError(f"Cannot load {scan_type.__name__} data from path '{path}'")
209
210 return scan_type.load(file_path, num_workers)
211
212 def _save_dir(self, dir_path: str, create_dir: bool = True):
213 """Returns directory path specific to this scan.

Callers 15

__init__Method · 0.95
test_flipMethod · 0.45
test_transposeMethod · 0.45
test_from_nibMethod · 0.45
test_4dMethod · 0.45
test_mmap_numpyMethod · 0.45
test_mmap_niftiMethod · 0.45
test_dcm_nifti_loadMethod · 0.45
test_dcm_to_niftiMethod · 0.45
test_generic_loadMethod · 0.45
test_readFunction · 0.45

Calls 1

_save_dirMethod · 0.95

Tested by 15

test_flipMethod · 0.36
test_transposeMethod · 0.36
test_from_nibMethod · 0.36
test_4dMethod · 0.36
test_mmap_numpyMethod · 0.36
test_mmap_niftiMethod · 0.36
test_dcm_nifti_loadMethod · 0.36
test_dcm_to_niftiMethod · 0.36
test_generic_loadMethod · 0.36
test_readFunction · 0.36
test_nifti_readMethod · 0.36