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)
| 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. |