io
Common building-block functions for handling module input and output.
check_exists(fns, dir)
Checks if the files in fns
exist in dir
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fns |
list[str]
|
The list of files to check. |
required |
dir |
Path
|
The directory the files should exist in. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If any of the files in |
Source code in src/nhssynth/common/io.py
consistent_ending(fn, ending='.pkl', suffix='')
Ensures that the filename fn
ends with ending
. If not, removes any existing ending and appends ending
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
str
|
The filename to check. |
required |
ending |
str
|
The desired ending to check for. Default is ".pkl". |
'.pkl'
|
suffix |
str
|
A suffix to append to the filename before the ending. |
''
|
Returns:
Type | Description |
---|---|
str
|
The filename with the correct ending and potentially an inserted suffix. |
Source code in src/nhssynth/common/io.py
consistent_endings(args)
Wrapper around consistent_ending
to apply it to a list of filenames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
list[Union[str, tuple[str, str], tuple[str, str, str]]]
|
The list of filenames to check. Can take the form of a single filename, a pair of a filename and an ending, or a triple of a filename, an ending and a suffix. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
The list of filenames with the correct endings. |
Source code in src/nhssynth/common/io.py
experiment_io(experiment_name, dir_experiments='experiments')
Create an experiment's directory and return the path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
experiment_name |
str
|
The name of the experiment. |
required |
dir_experiments |
str
|
The name of the directory containing all experiments. |
'experiments'
|
Returns:
Type | Description |
---|---|
str
|
The path to the experiment directory. |
Source code in src/nhssynth/common/io.py
potential_suffix(fn, fn_base)
Checks if fn
is a suffix (starts with an underscore) to append to fn_base
, or a filename in its own right.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
str
|
The filename / potential suffix to append to |
required |
fn_base |
str
|
The name of the file the suffix would attach to. |
required |
Returns:
Type | Description |
---|---|
str
|
The appropriately processed |
Source code in src/nhssynth/common/io.py
potential_suffixes(fns, fn_base)
Wrapper around potential_suffix
to apply it to a list of filenames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fns |
list[str]
|
The list of filenames / potential suffixes to append to |
required |
fn_base |
str
|
The name of the file the suffixes would attach to. |
required |
Source code in src/nhssynth/common/io.py
warn_if_path_supplied(fns, dir)
Warns if the files in fns
include directory separators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fns |
list[str]
|
The list of files to check. |
required |
dir |
Path
|
The directory the files should exist in. |
required |
Warns:
Type | Description |
---|---|
UserWarning
|
when the path to any of the files in |