syncopy.shared.parsers.filename_parser

syncopy.shared.parsers.filename_parser(filename, is_in_valid_container=None)[source]

Extract information from Syncopy file and folder names

Parameters
  • filename (str) – Syncopy data file (*.<dataclass>.info), Syncopy info file (*.<dataclass>) or Syncopy container folder (*.spy)

  • is_in_valid_container (bool) – If True, the filename must be inside a folder with a .spy extension. If False, filename must not be inside a .spy folder. If None, the extension of the parent folder is not checked.

Returns

fileinfo – Information extracted from filename and foldername with keys [‘filename’, ‘container’, ‘folder’, ‘tag’, ‘basename’, ‘extension’].

Return type

dict

Examples

>>> filename_parser('/home/user/monkeyB_20190709_rfmapping_1_amua-stimon.analog')
{'filename': 'monkeyB_20190709_rfmapping_1_amua-stimon.analog',
 'container': None,
 'folder': '/home/schmiedtj_it/Projects/SyNCoPy',
 'tag': None,
 'basename': 'monkeyB_20190709_rfmapping_1_amua-stimon',
 'extension': '.analog'}
>>> filename_parser('/home/user/monkeyB_20190709_rfmapping_1_amua-stimon.analog.info')
{'filename': 'monkeyB_20190709_rfmapping_1_amua-stimon.analog',
'container': None,
'folder': '/home/user',
'tag': None,
'basename': 'monkeyB_20190709_rfmapping_1_amua-stimon',
'extension': '.analog'}
>>> filename_parser('session_1.spy/session_1_amua-stimon.analog')
{'filename': 'session_1_amua-stimon.analog',
 'container': 'session_1.spy',
 'folder': '/home/user/session_1.spy',
 'tag': 'amua-stimon',
 'basename': 'session_1',
 'extension': '.analog'}
>>> filename_parser('session_1.spy')
{'filename': None,
 'container': 'session_1.spy',
 'folder': '/home/user',
 'tag': None,
 'basename': 'session_1',
 'extension': '.spy'}

See also

io_parser()

check file and folder names for existence