Beispiel #1
0
 def __init__(self, sorting, save_path=None):
     SortingExtractor.__init__(
         self)  # init tmp folder before constructing NpzSortingExtractor
     tmp_folder = self.get_tmp_folder()
     self._sorting = sorting
     if save_path is None:
         self._is_tmp = True
         self._tmp_file = tempfile.NamedTemporaryFile(suffix=".npz",
                                                      dir=tmp_folder).name
     else:
         save_path = Path(save_path)
         if save_path.suffix != '.npz':
             save_path = save_path.with_suffix('.npz')
         if not save_path.parent.is_dir():
             os.makedirs(save_path.parent)
         self._is_tmp = False
         self._tmp_file = save_path
     NpzSortingExtractor.write_sorting(self._sorting, self._tmp_file)
     NpzSortingExtractor.__init__(self, self._tmp_file)
     # keep Npz kwargs
     self._npz_kwargs = deepcopy(self._kwargs)
     self.set_tmp_folder(tmp_folder)
     self.copy_unit_properties(sorting)
     self.copy_unit_spike_features(sorting)
     self._kwargs = {'sorting': sorting}
Beispiel #2
0
 def move_to(self, save_path):
     save_path = Path(save_path)
     if save_path.suffix != '.npz':
         save_path = save_path.with_suffix('.npz')
     save_path.parent.mkdir(parents=True, exist_ok=True)
     shutil.move(self._tmp_file, str(save_path))
     self._tmp_file = str(save_path)
     self._kwargs['file_path'] = str(Path(self._tmp_file).absolute())
     self._npz_kwargs['file_path'] = str(Path(self._tmp_file).absolute())
     self._is_tmp = False
     tmp_folder = self.get_tmp_folder()
     # re-initialize with new file
     NpzSortingExtractor.__init__(self, self._tmp_file)
     # keep Npz kwargs
     self.set_tmp_folder(tmp_folder)
     self.copy_unit_properties(self._sorting)
     self.copy_unit_spike_features(self._sorting)