fmridenoise.utils package¶
Subpackages¶
Submodules¶
fmridenoise.utils.entities module¶
-
fmridenoise.utils.entities.
assert_all_entities_equal
(entities: List[Dict[str, str]], *entities_names: str) → None¶
-
fmridenoise.utils.entities.
build_path
(entities, path_patterns, strict=False)¶ Extension of bids.build_path that throws exception instead of returning None :param entities: :param A dictionary mapping entity names to entity values.: :param Entities with
None
or empty-string value will be removed.: :param Otherwise: :param entities will be cast to string values: :param therefore: :param if any format is expected: :type if any format is expected: e.g., zero-padded integers :param value should be formatted.: :param path_patterns: :param A dictionary mapping entity names to entity values.: :param Entities withNone
or empty-string value will be removed.: :param Otherwise: :param entities will be cast to string values: :param therefore: :param if any format is expected: :type if any format is expected: e.g., zero-padded integers :param value should be formatted.: :param strict: :param If True: :param all passed entities must be matched inside a: :param pattern in order to be a valid match. If False: :param extra entities will: :param be ignored so long as all mandatory entities are found.:Returns: built path
-
fmridenoise.utils.entities.
is_entity_subset
(entity_superset: Dict[str, str], entity_subset: Dict[str, str]) → bool¶ Checks if all key values in subset are in superset :param entity_superset: bigger dict :param entity_subset: smaller dict
Returns: true if all key-values pairs from entity_subset are in entity_superset
-
fmridenoise.utils.entities.
parse_file_entities_with_pipelines
(filename, entities=None, config=None, include_unmatched=False) → Dict[str, str]¶ bids.extract_pipelines_from_path extended with ability to
fmridenoise.utils.error_data module¶
-
class
fmridenoise.utils.error_data.
ErrorData
(critical: bool, entities: dict, source_name: str, message: str)¶ Bases:
object
-
asdict
()¶
-
build_message
() → str¶
-
critical
: bool¶
-
entities
: dict¶
-
classmethod
error
(entities: dict, source: object, message: str) → fmridenoise.utils.error_data.ErrorData¶
-
message
: str¶
-
source_name
: str¶
-
classmethod
warning
(entities: dict, source: object, message: str) → fmridenoise.utils.error_data.ErrorData¶
-
fmridenoise.utils.json_validator module¶
-
fmridenoise.utils.json_validator.
is_valid
(pipeline: dict, silent=False) → bool¶ Returns decision if denoising pipeline is valid.
- Parameters
pipeline – Denoising pipeline dictionary.
silent (default False) – If silent is True, errors won’t be printed to the console.
-
fmridenoise.utils.json_validator.
validate
(pipeline: dict) → None¶ Checks if denoising pipeline is valied.
Checks if pipeline dictionary conforms to denoising pipeline schema. Denoising pipeline unambigously defines denoising strategy.
- Parameters
pipeline – Denoising pipeline dictionary.
- Returns
None if pipeline is valid.
- Raises
ValidationError or SchemaError if pipeline is not valid. –
fmridenoise.utils.numeric module¶
-
fmridenoise.utils.numeric.
check_symmetry
(matrix)¶ Checks if matrix is symmetrical.
fmridenoise.utils.plotting module¶
-
fmridenoise.utils.plotting.
make_carpetplot
(time_series: numpy.ndarray, out_fname: str, dpi=300, figsize=(8, 3), format='png')¶ Generates and saves carpet plot for rois timecourses.
- Parameters
time_series – Timecourse array of size N_timepoints x N_rois. Output of fit_transform() NiftiLabelsMasker method.
out_fname – Carpetplot output filename.
dpi (
int
, optional) – Dots per inch (default 300).figsize (
tuple
, optional) – Size of the figure in inches (default (3,8))format (
str
, optional) – Image format. Available options include ‘png’, ‘pdf’, ‘ps’, ‘eps’ and ‘svg’.
-
fmridenoise.utils.plotting.
make_catplot
(x, y, data, output_path, xlabel=None, ylabel=None)¶ Plot representing quality measure value for each pipeline.
- Parameters
x (str) – Column name of data corresponding to quality measure.
y (str) – Column name of data used to group values.
data (pd.DataFrame) – Table of quality measures. It should contain at least one one column representing quality measure and one column for grouping variable. Usually each row corresponds to one pipeline.
output_path (str) – Output path where plot is saved.
xlabel (str, optional) – Custom x-axis label.
ylabel (str, optional) – Custom y-axis label.
- Returns
Path for generated plot.
-
fmridenoise.utils.plotting.
make_corr_matrix_plot
(data, output_path, title=None, ylabel=None, correlation=True)¶ Plot representing correlation matrix.
- Parameters
data (numpy.ndarray) – N x N correlation matrix.
output_path (str) – Output path where plot is saved.
title (str, optional) – Plot title.
ylabel (str, optional) – Custom y-axis label.
correlation (bool, default True) – If this flag is true, values are treated as correlations ranging from -1 to 1 automatically rescaling colorbar to that range.
- Returns
Path for generated plot.
-
fmridenoise.utils.plotting.
make_kdeplot
(data, output_path, title=None)¶ Plot representing edge strenght distribution.
- Parameters
data (pd.DataFrame) – Each column corresponds to single denoising strategy, each row correspond to connection strength. Column names will be used to create legend. DataFrame shape is n_edges x n_pipelines.
output_path (str) – Output path where plot is saved.
title (str, optional) – Plot title.
- Returns
Path for generated plot.
-
fmridenoise.utils.plotting.
make_motion_plot
(group_conf_summary: pandas.core.frame.DataFrame, output_path: str, mean_fd_th: float = 0.2, max_fd_th: float = 5, perc_spikes_th: float = 20) → matplotlib.figure.Figure¶ Generates plot presenting number of subjects excluded with high motion according specified thresholds. :param group_conf_summary: dataframe, output from GroupConfounds :type group_conf_summary: DataFrame :param output_path: output path where plot is saved :type output_path: str :param mean_fd_th: mean frame displacement threshold :type mean_fd_th: float :param max_fd_th: max frame displacement threshold :type max_fd_th: float :param perc_spikes_th: maximum percentage of unusually high frame displacement threshold :type perc_spikes_th: float
- Returns
created figure, ready to save
-
fmridenoise.utils.plotting.
make_violinplot
(data, output_path, xlabel=None)¶ Plot representing quality measure distribution for each pipeline.
- Parameters
data (pd.DataFrame) – Table of quality measures. Each column represents single pipeline. Column names will be used as pipeline names. Values in each row correspond to quality measure used, usually there is one row for each network edge.
output_path (str) – Output path where plot is saved.
xlabel (str, optional) – Custom x-axis label.
- Returns
Path for generated plot.
fmridenoise.utils.report_creator module¶
-
fmridenoise.utils.report_creator.
create_report
(runtime_info, report_data, output_dir, report_name='report.html')¶
fmridenoise.utils.temps module¶
-
fmridenoise.utils.temps.
cleanup_tempdirs
() → None¶
-
fmridenoise.utils.temps.
mkdtemp
(name: str) → str¶
fmridenoise.utils.traits module¶
-
fmridenoise.utils.traits.
Optional
(trait: traits.trait_type.TraitType) → traits.trait_types.Union¶ Return Union of function argument and Instance(_Undefined) :param trait: optional trait :type trait: TraitType
- Returns
union with undefined instance
-
fmridenoise.utils.traits.
remove_undefined
(iterable: Iterable) → Iterable¶ Creates generator that ignores all instances of _Undefined :param iterable: objects iterable :type iterable: Iterable
- Returns
generator
fmridenoise.utils.utils module¶
-
fmridenoise.utils.utils.
cast_bool
(value) → bool¶ Tries to cast value to bool. Raises ValueError if value is ambiguous. Raises TypeError for unsupported types. :param value: value to cast :return: bool
-
fmridenoise.utils.utils.
copy_as_dummy_dataset
(source_bids_dir: str, new_path: str, ext_to_copy=()) → None¶ Walks trough BIDS dataset and recreates it’s structure but with empty files.
- Parameters
{str} -- source of BIDS dataset (source_bids_dir) –
{str} -- destination of new dummy_complete dataset (new_path) –
- Keyword Arguments
{tuple or str} -- files with given extensions (ext_to_copy) –
be copied instead of empty (default (will) – {tuple()})
- Returns
None
-
fmridenoise.utils.utils.
create_dataset_description_json_content
() → str¶
-
fmridenoise.utils.utils.
create_flatten_identity_join_node
(name: str, fields: List[str], joinsource: Union[nipype.pipeline.engine.nodes.Node, str], flatten_fields: List[str]) → nipype.pipeline.engine.nodes.JoinNode¶
-
fmridenoise.utils.utils.
create_identity_join_node
(name: str, fields: List[str], joinsource: Union[nipype.pipeline.engine.nodes.Node, str]) → nipype.pipeline.engine.nodes.JoinNode¶
-
fmridenoise.utils.utils.
is_booleanlike
(value) → bool¶ Checks if argument is bool or string with ‘true’ or ‘false’ value. :param value: argument to check :return: True if argument is booleanlike, false if not
-
fmridenoise.utils.utils.
swap_booleans
(dictionary: dict, inplace: bool = True) → dict¶ Recursively iterates on dictionary and swaps booleanlike values with proper booleans. :param dictionary: input dictionary :param inplace: if True modifies inplace, if False creates deepcopy before changes :return: dictionary with swaped values