@@ -846,43 +846,63 @@ def save_to_memory(self, sharedmem=True, **save_kwargs) -> "BaseExtractor":
846846 return cached
847847
848848 # TODO rename to saveto_binary_folder
849- def save_to_folder (self , name = None , folder = None , overwrite = False , verbose = True , ** save_kwargs ):
849+ def save_to_folder (
850+ self ,
851+ name : str | None = None ,
852+ folder : str | Path | None = None ,
853+ overwrite : str = False ,
854+ verbose : bool = True ,
855+ ** save_kwargs ,
856+ ):
850857 """
851- Save extractor to folder.
858+ Save the extractor and its data to a folder.
852859
853- The save consist of:
854- * extracting traces by calling get_trace() method in chunks
855- * saving data into file (memmap with BinaryRecordingExtractor)
856- * dumping to json/pickle the original extractor for provenance
857- * dumping to json/pickle the cached extractor (memmap with BinaryRecordingExtractor)
860+ This method extracts trace data, saves it to a file (using a memory-mapped approach),
861+ and stores both the original extractor's provenance
862+ and the extractor's metadata in JSON format.
858863
859- This replaces the use of the old CacheRecordingExtractor and CacheSortingExtractor.
864+ The folder's final location and name can be specified in a couple of ways ways:
860865
861- There are 2 option for the "folder" argument :
862- * explicit folder: `extractor.save(folder="/path-for-saving/") `
863- * explicit sub-folder, implicit base-folder : ` extractor.save(name="extarctor_name")`
864- * generated: `extractor.save() `
866+ 1. Explicitly providing the full path :
867+ `` `
868+ extractor.save_to_folder(folder="/path/to/save/")
869+ `` `
865870
866- The second option saves to subfolder "extractor_name" in
867- "get_global_tmp_folder()". You can set the global tmp folder with:
868- "set_global_tmp_folder("path-to-global-folder")"
871+ 2. Providing a subfolder name, with the base folder being determined automatically:
872+ ```
873+ extractor.save_to_folder(name="my_extractor_data")
874+ ```
875+ In this case, the data is saved in a subfolder named "my_extractor_data"
876+ within the global temporary folder (set using `set_global_tmp_folder`). If no
877+ global temporary folder is set, one will be generated automatically.
869878
870- The folder must not exist. If it exists, remove it before.
879+ 3. If neither `name` nor `folder` is provided, a random name will be generated
880+ for the subfolder within the global temporary folder.
871881
872882 Parameters
873883 ----------
874- name: None str or Path
875- Name of the subfolder in get_global_tmp_folder()
876- If "name" is given, "folder" must be None.
877- folder: None str or Path
878- Name of the folder.
879- If "folder" is given, "name" must be None.
880- overwrite: bool, default: False
881- If True, the folder is removed if it already exists
884+ name : str , optional
885+ The name of the subfolder within the global temporary folder. If `folder`
886+ is provided, this argument must be None.
887+ folder : str or Path, optional
888+ The full path of the folder where the data should be saved. If `name` is
889+ provided, this argument must be None.
890+ overwrite : bool, default: False
891+ If True, an existing folder at the specified path will be deleted before saving.
892+ verbose : bool, default: True
893+ If True, print information about the cache folder being used.
894+ **save_kwargs
895+ Additional keyword arguments to be passed to the underlying save method.
882896
883897 Returns
884898 -------
885- cached: saved copy of the extractor.
899+ cached_extractor
900+ A saved copy of the extractor in the specified format.
901+
902+ Raises
903+ ------
904+ AssertionError
905+ If the folder already exists and `overwrite` is False.
886906 """
887907
888908 if folder is None :
@@ -925,7 +945,6 @@ def save_to_folder(self, name=None, folder=None, overwrite=False, verbose=True,
925945 self .copy_metadata (cached )
926946
927947 # dump
928- # cached.dump(folder / f'cached.json', relative_to=folder, folder_metadata=folder)
929948 cached .dump (folder / f"si_folder.json" , relative_to = folder )
930949
931950 return cached
0 commit comments