From d36e47e619c6e3d99f2f0492d8979c8fc50169d7 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 19 Mar 2024 13:25:56 -0400 Subject: [PATCH] fix several flaek8 errors --- .flake8 | 8 ++------ .pre-commit-config.yaml | 2 +- HCP_resting_state_analysis/functions/dFC_funcs.py | 11 ++++------- .../functions/post_analysis_funcs.py | 4 ++-- HCP_resting_state_analysis/post_analysis.py | 2 +- pydfc/comparison/plotting.py | 2 +- pydfc/dfc_utils.py | 4 ++-- pydfc/multi_analysis.py | 3 --- pydfc/task_utils.py | 2 +- tests/test_data_loader.py | 2 +- 10 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.flake8 b/.flake8 index d4a0b42..7f73516 100644 --- a/.flake8 +++ b/.flake8 @@ -31,14 +31,10 @@ ignore = E401, F401, F811, - F841, F821, - FS001 W503, - W504, - W605, - F541, - E902 + + # for compatibility with black # https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8 extend-ignore = E203 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e94151..9a7fe62 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,5 +56,5 @@ repos: rev: 7.0.0 hooks: - id: flake8 - args: [--config, .flake8, --verbose, pydfc, rest_dFC, task_dFC] + args: [--config, .flake8, --verbose, pydfc, HCP_resting_state_analysis, task_dFC] additional_dependencies: [flake8-use-fstring] diff --git a/HCP_resting_state_analysis/functions/dFC_funcs.py b/HCP_resting_state_analysis/functions/dFC_funcs.py index 8f6c18b..5102972 100755 --- a/HCP_resting_state_analysis/functions/dFC_funcs.py +++ b/HCP_resting_state_analysis/functions/dFC_funcs.py @@ -708,7 +708,7 @@ def visualize_conn_mat_dict( cb_ax = fig.add_axes([0.91, b, 0.007, h]) else: cb_ax = fig.add_axes([0.91, b, 0.01, h]) - cbar = fig.colorbar(im, cax=cb_ax, shrink=0.8) # shrink=0.8?? + fig.colorbar(im, cax=cb_ax, shrink=0.8) # shrink=0.8?? if save_image: folder = output_root[: output_root.rfind("/")] @@ -880,12 +880,12 @@ def visualize_conn_mat_2D_dict( if not node_networks is None: fig.subplots_adjust(wspace=0.45, hspace=0.50) - l, b, w, h = axs[-1][-1].get_position().bounds + _, _, _, h = axs[-1][-1].get_position().bounds if node_networks is None: cb_ax = fig.add_axes([0.91, 0.5 - h / 2, 0.007, h]) else: cb_ax = fig.add_axes([0.91, 0.5 - h / 2, 0.015, h]) - cbar = fig.colorbar(im, cax=cb_ax, shrink=0.8) # shrink=0.8?? + fig.colorbar(im, cax=cb_ax, shrink=0.8) # shrink=0.8?? if save_image: folder = output_root[: output_root.rfind("/")] @@ -1415,9 +1415,6 @@ def estimate_group_FCS(self, time_series_dict): def group_dFCM_assess(self, time_series_dict): # time_series_dict is a dict of time_series - - SUBJ_s_dFCM_dict = {} - SUBJECTs = common_subj_lst(time_series_dict) if self.params["n_jobs"] is None: @@ -2103,7 +2100,7 @@ def visualize_TPM(self, normalize=True, save_image=False, output_root=None): plt.figure(figsize=(5, 5)) plt.imshow(np.squeeze(C), interpolation="nearest", aspect="equal", cmap="jet") - cb = plt.colorbar(shrink=0.8) + plt.colorbar(shrink=0.8) plt.title(self.measure_name + " TPM") if save_image: diff --git a/HCP_resting_state_analysis/functions/post_analysis_funcs.py b/HCP_resting_state_analysis/functions/post_analysis_funcs.py index 2fc806e..d542a2d 100644 --- a/HCP_resting_state_analysis/functions/post_analysis_funcs.py +++ b/HCP_resting_state_analysis/functions/post_analysis_funcs.py @@ -174,7 +174,7 @@ def plot_rois(node_networks, nodes_locs, save_image=False, output_root=None): axes=axes[i], ) - title = f"Resting State Networks" + title = "Resting State Networks" # set subplot titles for i, network in enumerate(networks): axes[i].title.set_text(f"{network} network") @@ -1123,7 +1123,7 @@ def plot_TSNE( ax = fig.add_subplot(projection="3d") sample_measure_array = np.array(sample_measure_lst) for measure in measures_lst: - scatter = ax.scatter( + ax.scatter( X_embedded[sample_measure_array == measure, 0], X_embedded[sample_measure_array == measure, 1], X_embedded[sample_measure_array == measure, 2], diff --git a/HCP_resting_state_analysis/post_analysis.py b/HCP_resting_state_analysis/post_analysis.py index 64274f4..b24a674 100644 --- a/HCP_resting_state_analysis/post_analysis.py +++ b/HCP_resting_state_analysis/post_analysis.py @@ -41,7 +41,7 @@ if not num_subj2include is None: ALL_RECORDS = ALL_RECORDS[:num_subj2include] - print("*** %d subjects were included." % (num_subj2include)) + print(f"*** {num_subj2include} subjects were included.") FILTERS = [key for key in output] print(FILTERS) diff --git a/pydfc/comparison/plotting.py b/pydfc/comparison/plotting.py index d87dff6..4b48ef4 100644 --- a/pydfc/comparison/plotting.py +++ b/pydfc/comparison/plotting.py @@ -993,7 +993,7 @@ def plot_TSNE( ax = fig.add_subplot(projection="3d") sample_measure_array = np.array(sample_measure_lst) for measure in measures_lst: - scatter = ax.scatter( + ax.scatter( X_embedded[sample_measure_array == measure, 0], X_embedded[sample_measure_array == measure, 1], X_embedded[sample_measure_array == measure, 2], diff --git a/pydfc/dfc_utils.py b/pydfc/dfc_utils.py index 3e58c5e..c22e548 100644 --- a/pydfc/dfc_utils.py +++ b/pydfc/dfc_utils.py @@ -742,7 +742,7 @@ def visualize_conn_mat_dict( cb_ax = fig.add_axes([0.91, b, 0.007, h]) else: cb_ax = fig.add_axes([0.91, b, 0.01, h]) - cbar = fig.colorbar(im, cax=cb_ax, shrink=0.8) # shrink=0.8?? + fig.colorbar(im, cax=cb_ax, shrink=0.8) # shrink=0.8?? if save_image: folder = output_root[: output_root.rfind("/")] @@ -919,7 +919,7 @@ def visualize_conn_mat_2D_dict( cb_ax = fig.add_axes([0.91, 0.5 - h / 2, 0.007, h]) else: cb_ax = fig.add_axes([0.91, 0.5 - h / 2, 0.015, h]) - cbar = fig.colorbar(im, cax=cb_ax, shrink=0.8) # shrink=0.8?? + fig.colorbar(im, cax=cb_ax, shrink=0.8) # shrink=0.8?? if save_image: folder = output_root[: output_root.rfind("/")] diff --git a/pydfc/multi_analysis.py b/pydfc/multi_analysis.py index d370d18..3a28a6b 100644 --- a/pydfc/multi_analysis.py +++ b/pydfc/multi_analysis.py @@ -205,9 +205,6 @@ def estimate_group_FCS(self, time_series_dict): def group_dFC_assess(self, time_series_dict): # time_series_dict is a dict of time_series - - SUBJ_s_dFC_dict = {} - SUBJECTs = common_subj_lst(time_series_dict) if self.params["n_jobs"] is None: diff --git a/pydfc/task_utils.py b/pydfc/task_utils.py index 3d5d768..4970e00 100644 --- a/pydfc/task_utils.py +++ b/pydfc/task_utils.py @@ -69,7 +69,7 @@ def plot_task_dFC(task_labels, dFC_lst, event_types, Fs_mri, TR_step=12): scale_task_plot = 20 # plot task_data['event_labels'] - fig = plt.figure(figsize=(50, 200)) + plt.figure(figsize=(50, 200)) ax = plt.gca() diff --git a/tests/test_data_loader.py b/tests/test_data_loader.py index c2313f4..4c1f3db 100644 --- a/tests/test_data_loader.py +++ b/tests/test_data_loader.py @@ -25,7 +25,7 @@ def simulated_bold_data(tmp_path): def test_load(simulated_bold_data): - timeseries = nifti2timeseries( + nifti2timeseries( nifti_file=str(simulated_bold_data), n_rois=100, Fs=1 / 0.75,