cellpy.readers.filefinder#

Module Contents#

Functions#

find_in_raw_file_directory([raw_file_dir, ...])

Dumps the raw-file directory to a list.

list_raw_file_directory([raw_file_dir, project_dir, ...])

Dumps the raw-file directory to a list.

search_for_files(→ Tuple[List[str], str])

Searches for files (raw-data files and cellpy-files).

find_in_raw_file_directory(raw_file_dir: cellpy.internals.core.OtherPath | pathlib.Path | str | None = None, project_dir: cellpy.internals.core.OtherPath | pathlib.Path | str | None = None, extension: str | None = None, glob_txt: str | None = None)[source]#

Dumps the raw-file directory to a list.

Parameters:
  • raw_file_dir (path) – optional, directory where to look for run-files (default: read prm-file)

  • project_dir (path) – optional, subdirectory in raw_file_dir to look for run-files

  • extension (str) – optional, extension of run-files (without the ‘.’). If not given, all files will be listed.

  • glob_txt (str, optional) – optional, glob pattern to use when searching for files.

Returns:

list of file paths.

Return type:

list of str

Examples

>>> # find all files in your raw-file directory:
>>> filelist_1 = filefinder.find_in_raw_file_directory()
>>> # find all files in your raw-file directory in the subdirectory 'MY-PROJECT':
>>> filelist_2 = filefinder.find_in_raw_file_directory(raw_file_dir=rawdatadir/"MY-PROJECT")
>>> # find all files in your raw-file directory with the extension '.raw' in the subdirectory 'MY-PROJECT':
>>> filelist_3 = filefinder.find_in_raw_file_directory(raw_file_dir=rawdatadir/"MY-PROJECT", extension="raw")
>>> # find all files in your raw-file directory with the extension '.raw' in the subdirectory 'MY-PROJECT'
>>> # that contains the string 'good' in the file name
>>> filelist_4 = filefinder.find_in_raw_file_directory(
>>>     raw_file_dir=rawdatadir/"MY-PROJECT",
>>>     glob_txt="*good*",
>>>     extension="raw"
>>>)

Notes

Uses ‘find’ and ‘ssh’ to search for files.

list_raw_file_directory(raw_file_dir: cellpy.internals.core.OtherPath | pathlib.Path | str | None = None, project_dir: cellpy.internals.core.OtherPath | pathlib.Path | str | None = None, extension: str | None = None, levels: int | None = 1, only_filename: bool | None = False, with_prefix: bool | None = True)[source]#

Dumps the raw-file directory to a list.

Parameters:
  • raw_file_dir (path) – optional, directory where to look for run-files (default: read prm-file)

  • project_dir (path) – optional, subdirectory in raw_file_dir to look for run-files

  • extension (str) – optional, extension of run-files (without the ‘.’). If not given, all files will be listed.

  • levels (int, optional) – How many sublevels to list. Defaults to 1. If you want to list all sublevels, use listdir(levels=-1). If you want to list only the current level (no subdirectories), use listdir(levels=0).

  • only_filename (bool, optional) – If True, only the file names will be returned. Defaults to False.

  • with_prefix (bool, optional) – If True, the full path to the files including the prefix and the location (e.g. ‘scp://user@server.com/…’) will be returned. Defaults to True.

Returns:

list of file paths (only the actual file names).

Return type:

list of str

Notes

This function might be rather slow and memory consuming if you have a lot of files in your raw-file directory. If you have a lot of files, you might want to consider running this function in a separate process (e.g. in a separate python script or using multiprocessing).

The function currently returns the full path to the files from the root directory. It does not include the prefix (e.g. ssh://). Future versions might change this to either include the prefix or return the files relative to the raw_file_dir directory.

search_for_files(run_name: str, raw_extension: str | None = None, cellpy_file_extension: str | None = None, raw_file_dir: cellpy.internals.core.OtherPath | pathlib.Path | str | None = None, project_dir: cellpy.internals.core.OtherPath | pathlib.Path | str | None = None, cellpy_file_dir: cellpy.internals.core.OtherPath | pathlib.Path | str | None = None, prm_filename: pathlib.Path | str | None = None, file_name_format: str | None = None, reg_exp: str | None = None, sub_folders: bool | None = True, file_list: List[str] | None = None, with_prefix: bool | None = True, pre_path: cellpy.internals.core.OtherPath | pathlib.Path | str | None = None) Tuple[List[str], str][source]#

Searches for files (raw-data files and cellpy-files).

Parameters:
  • run_name (str) – run-file identification.

  • raw_extension (str) – optional, extension of run-files (without the ‘.’).

  • cellpy_file_extension (str) – optional, extension for cellpy files (without the ‘.’).

  • raw_file_dir (path) – optional, directory where to look for run-files (default: read prm-file)

  • project_dir (path) – optional, subdirectory in raw_file_dir to look for run-files

  • cellpy_file_dir (path) – optional, directory where to look for cellpy-files (default: read prm-file)

  • prm_filename (path) – optional parameter file can be given.

  • file_name_format (str) – format of raw-file names or a glob pattern (default: YYYYMMDD_[name]EEE_CC_TT_RR).

  • reg_exp (str) – use regular expression instead (defaults to None).

  • sub_folders (bool) – perform search also in sub-folders.

  • file_list (list of str) – perform the search within a given list of filenames instead of searching the folder(s). The list should not contain the full filepath (only the actual file names). If you want to provide the full path, you will have to modify the file_name_format or reg_exp accordingly.

  • with_prefix (bool) – if True, the file list contains full paths to the files (including the prefix and the location).

  • pre_path (path or str) – path to prepend the list of files selected from the file_list.

Returns:

run-file names (list of strings) and cellpy-file-name (str of full path).