1616
1717from .globals import get_global_tmp_folder , is_set_global_tmp_folder
1818from .core_tools import (
19- check_json ,
19+ is_path_remote ,
2020 clean_zarr_folder_name ,
2121 is_dict_extractor ,
2222 SIJsonEncoder ,
@@ -673,7 +673,7 @@ def dump_to_json(
673673 ) -> None :
674674 """
675675 Dump recording extractor to json file.
676- The extractor can be re-loaded with load_extractor (json_file)
676+ The extractor can be re-loaded with load (json_file)
677677
678678 Parameters
679679 ----------
@@ -715,7 +715,7 @@ def dump_to_pickle(
715715 ):
716716 """
717717 Dump recording extractor to a pickle file.
718- The extractor can be re-loaded with load_extractor (pickle_file)
718+ The extractor can be re-loaded with load (pickle_file)
719719
720720 Parameters
721721 ----------
@@ -752,7 +752,9 @@ def dump_to_pickle(
752752 file_path .write_bytes (pickle .dumps (dump_dict ))
753753
754754 @staticmethod
755- def load (file_path : Union [str , Path ], base_folder : Optional [Union [Path , str , bool ]] = None ) -> "BaseExtractor" :
755+ def load (
756+ file_or_folder_path : Union [str , Path ], base_folder : Optional [Union [Path , str , bool ]] = None
757+ ) -> "BaseExtractor" :
756758 """
757759 Load extractor from file path (.json or .pkl)
758760
@@ -761,62 +763,10 @@ def load(file_path: Union[str, Path], base_folder: Optional[Union[Path, str, boo
761763 * save (...) a folder which contain data + json (or pickle) + metadata.
762764
763765 """
766+ # use loading.py and keep backward compatibility
767+ from .loading import load
764768
765- file_path = Path (file_path )
766- if base_folder is True :
767- base_folder = file_path .parent
768-
769- if file_path .is_file ():
770- # standard case based on a file (json or pickle)
771- if str (file_path ).endswith (".json" ):
772- with open (file_path , "r" ) as f :
773- d = json .load (f )
774- elif str (file_path ).endswith (".pkl" ) or str (file_path ).endswith (".pickle" ):
775- with open (file_path , "rb" ) as f :
776- d = pickle .load (f )
777- else :
778- raise ValueError (f"Impossible to load { file_path } " )
779- if "warning" in d :
780- print ("The extractor was not serializable to file" )
781- return None
782-
783- extractor = BaseExtractor .from_dict (d , base_folder = base_folder )
784- return extractor
785-
786- elif file_path .is_dir ():
787- # case from a folder after a calling extractor.save(...)
788- folder = file_path
789- file = None
790-
791- if folder .suffix == ".zarr" :
792- from .zarrextractors import read_zarr
793-
794- extractor = read_zarr (folder )
795- else :
796- # the is spikeinterface<=0.94.0
797- # a folder came with 'cached.json'
798- for dump_ext in ("json" , "pkl" , "pickle" ):
799- f = folder / f"cached.{ dump_ext } "
800- if f .is_file ():
801- file = f
802-
803- # spikeinterface>=0.95.0
804- f = folder / f"si_folder.json"
805- if f .is_file ():
806- file = f
807-
808- if file is None :
809- raise ValueError (f"This folder is not a cached folder { file_path } " )
810- extractor = BaseExtractor .load (file , base_folder = folder )
811-
812- return extractor
813-
814- else :
815- error_msg = (
816- f"{ file_path } is not a file or a folder. It should point to either a json, pickle file or a "
817- "folder that is the result of extractor.save(...)"
818- )
819- raise ValueError (error_msg )
769+ return load (file_or_folder_path , base_folder = base_folder )
820770
821771 def __reduce__ (self ):
822772 """
@@ -1167,50 +1117,6 @@ def _check_same_version(class_string, version):
11671117 return "unknown"
11681118
11691119
1170- def load_extractor (file_or_folder_or_dict , base_folder = None ) -> BaseExtractor :
1171- """
1172- Instantiate extractor from:
1173- * a dict
1174- * a json file
1175- * a pickle file
1176- * folder (after save)
1177- * a zarr folder (after save)
1178-
1179- Parameters
1180- ----------
1181- file_or_folder_or_dict : dictionary or folder or file (json, pickle)
1182- The file path, folder path, or dictionary to load the extractor from
1183- base_folder : str | Path | bool (optional)
1184- The base folder to make relative paths absolute.
1185- If True and file_or_folder_or_dict is a file, the parent folder of the file is used.
1186-
1187- Returns
1188- -------
1189- extractor: Recording or Sorting
1190- The loaded extractor object
1191- """
1192- if isinstance (file_or_folder_or_dict , dict ):
1193- assert not isinstance (base_folder , bool ), "`base_folder` must be a string or Path when loading from dict"
1194- return BaseExtractor .from_dict (file_or_folder_or_dict , base_folder = base_folder )
1195- else :
1196- return BaseExtractor .load (file_or_folder_or_dict , base_folder = base_folder )
1197-
1198-
1199- def load_extractor_from_dict (d , base_folder = None ) -> BaseExtractor :
1200- warnings .warn ("Use load_extractor(..) instead" )
1201- return BaseExtractor .from_dict (d , base_folder = base_folder )
1202-
1203-
1204- def load_extractor_from_json (json_file , base_folder = None ) -> "BaseExtractor" :
1205- warnings .warn ("Use load_extractor(..) instead" )
1206- return BaseExtractor .load (json_file , base_folder = base_folder )
1207-
1208-
1209- def load_extractor_from_pickle (pkl_file , base_folder = None ) -> "BaseExtractor" :
1210- warnings .warn ("Use load_extractor(..) instead" )
1211- return BaseExtractor .load (pkl_file , base_folder = base_folder )
1212-
1213-
12141120class BaseSegment :
12151121 def __init__ (self ):
12161122 self ._parent_extractor = None
0 commit comments