syncopy.shared.parsers.io_parser#

syncopy.shared.parsers.io_parser(fs_loc, varname='', isfile=True, ext='', exists=True)[source]#

Parse file-system location strings for reading/writing files/directories

Parameters:
  • fs_loc (str) – String pointing to (hopefully valid) file-system location (absolute/relative path of file or directory ).

  • varname (str) – Local variable name used in caller, see Examples for details.

  • isfile (bool) – Indicates whether fs_loc points to a file (isfile = True) or directory (isfile = False)

  • ext (str or 1darray-like) – Valid filename extension(s). Can be a single string (e.g., ext = “lfp”) or a list/1darray of valid extensions (e.g., ext = [“lfp”, “mua”]).

  • exists (bool) – If exists = True ensure that file-system location specified by fs_loc exists (typically used when reading from fs_loc), otherwise (exists = False) check for already present conflicting files/directories (typically used when creating/writing to fs_loc).

Returns:

  • fs_path (str) – Absolute path of fs_loc.

  • fs_name (str (only if isfile = True)) – Name (including extension) of input file (without path).

Examples

To test whether “/path/to/dataset.lfp” points to an existing file, one might use

>>> io_parser("/path/to/dataset.lfp")
'/path/to', 'dataset.lfp'

The following call ensures that a folder called “mydata” can be safely created in the current working directory

>>> io_parser("mydata", isfile=False, exists=False)
'/path/to/cwd/mydata'

Suppose a routine wants to save data to a file with potential extensions “.lfp” or “.mua”. The following call may be used to ensure the user input dsetname = “relative/dir/dataset.mua” is a valid choice:

>>> abs_path, filename = io_parser(dsetname, varname="dsetname", ext=["lfp", "mua"], exists=False)
>>> abs_path
'/full/path/to/relative/dir/'
>>> filename
'dataset.mua'