From 1045512bc7d06aa11ec34e6663aa9c953946f8ab Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:11:30 +0100 Subject: [PATCH 01/11] Apply ruff/flake8-comprehensions rule C409 C409 Unnecessary list comprehension passed to `tuple()` (rewrite as a generator) --- nireports/assembler/report.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nireports/assembler/report.py b/nireports/assembler/report.py index 65aa6fb8..c06915a6 100644 --- a/nireports/assembler/report.py +++ b/nireports/assembler/report.py @@ -493,9 +493,9 @@ def _process_orderings(orderings, hits): tuple(bids_file.get_entities().get(k, None) for k in orderings) for bids_file in hits } # remove the all None member if it exists - none_member = tuple([None for k in orderings]) + none_member = tuple(None for k in orderings) if none_member in all_value_combos: - all_value_combos.remove(tuple([None for k in orderings])) + all_value_combos.remove(tuple(None for k in orderings)) # see what values exist for each entity unique_values = [ {value[idx] for value in all_value_combos} for idx in range(len(orderings)) From 013ab0f4a5263cedf2721f8732e65a64ab20dd01 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:12:14 +0100 Subject: [PATCH 02/11] Apply ruff/flake8-comprehensions rule C419 C419 Unnecessary list comprehension --- nireports/assembler/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nireports/assembler/misc.py b/nireports/assembler/misc.py index 6677fb35..6688d654 100644 --- a/nireports/assembler/misc.py +++ b/nireports/assembler/misc.py @@ -144,7 +144,7 @@ def dict2html(indict, table_id): if not rows: return None - width = max([len(row) for row in rows]) + width = max(len(row) for row in rows) result_str = '\n' % table_id td = "{0}".format From 31d7b4d5ee32800ee229912fb932069b1da8b5dc Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:16:32 +0100 Subject: [PATCH 03/11] Apply ruff/pyupgrade rule UP008 UP008 Use `super()` instead of `super(__class__, self)` --- nireports/interfaces/reporting/masks.py | 12 ++++++------ nireports/interfaces/reporting/registration.py | 14 +++++++------- nireports/interfaces/reporting/segmentation.py | 14 +++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/nireports/interfaces/reporting/masks.py b/nireports/interfaces/reporting/masks.py index 4dba645c..9d9343b7 100644 --- a/nireports/interfaces/reporting/masks.py +++ b/nireports/interfaces/reporting/masks.py @@ -59,7 +59,7 @@ def _run_interface(self, runtime): if self.generate_report: self.inputs.mask = True - return super(BETRPT, self)._run_interface(runtime) + return super()._run_interface(runtime) def _post_run_hook(self, runtime): """generates a report showing slices from each axis of an arbitrary @@ -76,7 +76,7 @@ def _post_run_hook(self, runtime): self._mask_file, ) - return super(BETRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _BrainExtractionInputSpecRPT( @@ -114,7 +114,7 @@ def _post_run_hook(self, runtime): self._mask_file, ) - return super(BrainExtractionRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _ACompCorInputSpecRPT(nrb._SVGReportCapableInputSpec, confounds.CompCorInputSpec): @@ -148,7 +148,7 @@ def _post_run_hook(self, runtime): self._mask_file, ) - return super(ACompCorRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _TCompCorInputSpecRPT(nrb._SVGReportCapableInputSpec, confounds.TCompCorInputSpec): @@ -184,7 +184,7 @@ def _post_run_hook(self, runtime): self.aggregate_outputs(runtime=runtime).high_variance_masks, ) - return super(TCompCorRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _SimpleShowMaskInputSpec(nrb._SVGReportCapableInputSpec): @@ -201,7 +201,7 @@ def _post_run_hook(self, runtime): self._seg_files = [self.inputs.mask_file] self._masked = True - return super(SimpleShowMaskRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _ROIsPlotInputSpecRPT(nrb._SVGReportCapableInputSpec): diff --git a/nireports/interfaces/reporting/registration.py b/nireports/interfaces/reporting/registration.py index 4b817db2..2d0fe983 100644 --- a/nireports/interfaces/reporting/registration.py +++ b/nireports/interfaces/reporting/registration.py @@ -67,7 +67,7 @@ def _post_run_hook(self, runtime): self._moving_image, ) - return super(ApplyTOPUPRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _FUGUEInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.preprocess.FUGUEInputSpec): @@ -94,7 +94,7 @@ def _post_run_hook(self, runtime): self._moving_image, ) - return super(FUGUERPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _FLIRTInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.preprocess.FLIRTInputSpec): @@ -119,7 +119,7 @@ def _post_run_hook(self, runtime): self._moving_image, ) - return super(FLIRTRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _ApplyXFMInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.preprocess.ApplyXFMInputSpec): @@ -183,7 +183,7 @@ def _post_run_hook(self, runtime): self._moving_image, ) - return super(BBRegisterRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _MRICoregInputSpecRPT(nrb._SVGReportCapableInputSpec, fs.registration.MRICoregInputSpec): @@ -230,7 +230,7 @@ def _post_run_hook(self, runtime): self._moving_image, ) - return super(MRICoregRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _SimpleBeforeAfterInputSpecRPT(nrb._SVGReportCapableInputSpec): @@ -259,7 +259,7 @@ def _post_run_hook(self, runtime): self._moving_image, ) - return super(SimpleBeforeAfterRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _ResampleBeforeAfterInputSpecRPT(_SimpleBeforeAfterInputSpecRPT): @@ -291,7 +291,7 @@ def _post_run_hook(self, runtime): self._moving_image, ) - runtime = super(ResampleBeforeAfterRPT, self)._post_run_hook(runtime) + runtime = super()._post_run_hook(runtime) _LOGGER.info("Successfully created report (%s)", self._out_report) os.unlink(fname) diff --git a/nireports/interfaces/reporting/segmentation.py b/nireports/interfaces/reporting/segmentation.py index d1213322..bcff725f 100644 --- a/nireports/interfaces/reporting/segmentation.py +++ b/nireports/interfaces/reporting/segmentation.py @@ -50,7 +50,7 @@ def _run_interface(self, runtime): if self.generate_report: self.inputs.segments = True - return super(FASTRPT, self)._run_interface(runtime) + return super()._run_interface(runtime) def _post_run_hook(self, runtime): """generates a report showing nine slices, three per axis, of an @@ -72,7 +72,7 @@ def _post_run_hook(self, runtime): outputs.tissue_class_files, ) - return super(FASTRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _ReconAllInputSpecRPT( @@ -104,7 +104,7 @@ def _post_run_hook(self, runtime): _LOGGER.info("Generating report for ReconAll (subject %s)", outputs.subject_id) - return super(ReconAllRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _MELODICInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.model.MELODICInputSpec): @@ -129,12 +129,12 @@ class MELODICRPT(fsl.MELODIC): _out_report = None def __init__(self, generate_report=False, **kwargs): - super(MELODICRPT, self).__init__(**kwargs) + super().__init__(**kwargs) self.generate_report = generate_report def _post_run_hook(self, runtime): # Run _post_run_hook of super class - runtime = super(MELODICRPT, self)._post_run_hook(runtime) + runtime = super()._post_run_hook(runtime) # leave early if there's nothing to do if not self.generate_report: return runtime @@ -163,7 +163,7 @@ def _post_run_hook(self, runtime): def _list_outputs(self): try: - outputs = super(MELODICRPT, self)._list_outputs() + outputs = super()._list_outputs() except NotImplementedError: outputs = {} if self._out_report is not None: @@ -221,4 +221,4 @@ def _post_run_hook(self, runtime): _LOGGER.info("Generating report for ICA AROMA") - return super(ICA_AROMARPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) From 41afb70eec21a909f4ee5ab5d1404297e05f315a Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:17:33 +0100 Subject: [PATCH 04/11] Apply ruff rule RUF022 RUF022 `__all__` is not sorted --- nireports/interfaces/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nireports/interfaces/__init__.py b/nireports/interfaces/__init__.py index 7445a1ac..5b637635 100644 --- a/nireports/interfaces/__init__.py +++ b/nireports/interfaces/__init__.py @@ -33,9 +33,9 @@ __all__ = ( "CompCorVariancePlot", "ConfoundsCorrelationPlot", - "RaincloudPlot", "FMRISummary", "PlotContours", "PlotMosaic", "PlotSpikes", + "RaincloudPlot", ) From cdbf03b78944e5c44c5319605eeeb4558e833def Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:18:01 +0100 Subject: [PATCH 05/11] Apply ruff rule RUF023 RUF023 `__slots__` is not sorted --- nireports/reportlets/modality/func.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nireports/reportlets/modality/func.py b/nireports/reportlets/modality/func.py index 385d9039..558b56f8 100644 --- a/nireports/reportlets/modality/func.py +++ b/nireports/reportlets/modality/func.py @@ -36,14 +36,14 @@ class fMRIPlot: """Generates the fMRI Summary Plot.""" __slots__ = ( - "timeseries", - "segments", - "tr", "confounds", - "spikes", "nskip", - "sort_carpet", "paired_carpet", + "segments", + "sort_carpet", + "spikes", + "timeseries", + "tr", ) def __init__( From fe1c3f10de5472c1bc1157b85283f57f6835a3b6 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:19:16 +0100 Subject: [PATCH 06/11] Apply ruff/Perflint rule PERF401 PERF401 Use a list comprehension to create a transformed list --- nireports/reportlets/xca.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nireports/reportlets/xca.py b/nireports/reportlets/xca.py index 6826f0cb..823b37bf 100644 --- a/nireports/reportlets/xca.py +++ b/nireports/reportlets/xca.py @@ -105,9 +105,7 @@ def plot_melodic_components( else: mask_img = nb.load(report_mask) - mask_sl = [] - for j in range(3): - mask_sl.append(transform_to_2d(mask_img.get_fdata(), j)) + mask_sl = [transform_to_2d(mask_img.get_fdata(), j) for j in range(3)] timeseries = np.loadtxt(os.path.join(melodic_dir, "melodic_mix")) power = np.loadtxt(os.path.join(melodic_dir, "melodic_FTmix")) From 92ff3be9e906bdda3a8c46bb8ec39de4ef8957ca Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:20:32 +0100 Subject: [PATCH 07/11] Apply ruff/refurb rule FURB188 FURB188 Prefer `removeprefix` over conditionally replacing with slice. --- nireports/assembler/report.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nireports/assembler/report.py b/nireports/assembler/report.py index c06915a6..4bc386e1 100644 --- a/nireports/assembler/report.py +++ b/nireports/assembler/report.py @@ -255,15 +255,11 @@ def __init__( if bids_filters.get("subject"): subject_id = bids_filters["subject"] - bids_filters["subject"] = ( - subject_id[4:] if subject_id.startswith("sub-") else subject_id - ) + bids_filters["subject"] = subject_id.removeprefix("sub-") if bids_filters.get("session"): session_id = bids_filters["session"] - bids_filters["session"] = ( - session_id[4:] if session_id.startswith("ses-") else session_id - ) + bids_filters["session"] = session_id.removeprefix("ses-") if bids_filters and out_filename == "report.html": out_filename = build_path(bids_filters, OUTPUT_NAME_PATTERN) From 2a32a269bb50abb6d62fc6ea34e07116c0f44aa0 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:27:35 +0100 Subject: [PATCH 08/11] Apply ruff/flake8-simplify rule SIM401 SIM401 Use `.get()` instead of an `if` block --- nireports/tools/timeseries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nireports/tools/timeseries.py b/nireports/tools/timeseries.py index cd2d6060..0a5bf468 100644 --- a/nireports/tools/timeseries.py +++ b/nireports/tools/timeseries.py @@ -73,7 +73,7 @@ def cifti_timeseries(dataset): } seg = {label: [] for label in list(labels.values()) + ["Other"]} for bm in matrix.get_index_map(1).brain_models: - label = "Other" if bm.brain_structure not in labels else labels[bm.brain_structure] + label = labels.get(bm.brain_structure, "Other") seg[label] += list(range(bm.index_offset, bm.index_offset + bm.index_count)) return dataset.get_fdata(dtype="float32").T, seg From 58fbf885e28effb91ee8fc5b4096c94dc326f16f Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:29:40 +0100 Subject: [PATCH 09/11] Apply ruff/flake8-implicit-str-concat rule ISC001 ISC001 Implicitly concatenated string literals on one line --- .maint/update_authors.py | 4 ++-- nireports/interfaces/nuisance.py | 2 +- nireports/interfaces/reporting/segmentation.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.maint/update_authors.py b/.maint/update_authors.py index 3b8658e1..15266b71 100755 --- a/.maint/update_authors.py +++ b/.maint/update_authors.py @@ -188,7 +188,7 @@ def zenodo( misses = set(miss_creators).intersection(miss_contributors) if misses: print( - "Some people made commits, but are missing in .maint/ " f"files: {', '.join(misses)}", + f"Some people made commits, but are missing in .maint/ files: {', '.join(misses)}", file=sys.stderr, ) @@ -268,7 +268,7 @@ def _aslist(value): if misses: print( - "Some people made commits, but are missing in .maint/ " f"files: {', '.join(misses)}", + f"Some people made commits, but are missing in .maint/ files: {', '.join(misses)}", file=sys.stderr, ) diff --git a/nireports/interfaces/nuisance.py b/nireports/interfaces/nuisance.py index bbb032b1..47f27a46 100644 --- a/nireports/interfaces/nuisance.py +++ b/nireports/interfaces/nuisance.py @@ -109,7 +109,7 @@ class _ConfoundsCorrelationPlotInputSpec(BaseInterfaceInputSpec): ignore_initial_volumes = traits.Int( 0, usedefault=True, - desc="Number of non-steady-state volumes at the beginning of the scan " "to ignore.", + desc="Number of non-steady-state volumes at the beginning of the scan to ignore.", ) diff --git a/nireports/interfaces/reporting/segmentation.py b/nireports/interfaces/reporting/segmentation.py index bcff725f..fe0365cc 100644 --- a/nireports/interfaces/reporting/segmentation.py +++ b/nireports/interfaces/reporting/segmentation.py @@ -111,7 +111,7 @@ class _MELODICInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.model.MELODICInpu out_report = File( "melodic_reportlet.svg", usedefault=True, - desc="Filename for the visual" " report generated " "by Nipype.", + desc="Filename for the visual report generated by Nipype.", ) report_mask = File( desc="Mask used to draw the outline on the reportlet. " @@ -187,7 +187,7 @@ class _ICA_AROMAInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.aroma.ICA_AROMA out_report = File( "ica_aroma_reportlet.svg", usedefault=True, - desc="Filename for the visual" " report generated " "by Nipype.", + desc="Filename for the visual report generated by Nipype.", ) report_mask = File( desc="Mask used to draw the outline on the reportlet. " From afab176177b31ce601f60eccce0340cf2b17d9b0 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 23 Nov 2024 17:19:46 +0100 Subject: [PATCH 10/11] Update nireports/assembler/report.py Co-authored-by: Chris Markiewicz --- nireports/assembler/report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nireports/assembler/report.py b/nireports/assembler/report.py index 4bc386e1..65eb9e02 100644 --- a/nireports/assembler/report.py +++ b/nireports/assembler/report.py @@ -489,7 +489,7 @@ def _process_orderings(orderings, hits): tuple(bids_file.get_entities().get(k, None) for k in orderings) for bids_file in hits } # remove the all None member if it exists - none_member = tuple(None for k in orderings) + none_member = (None,) * len(orderings) if none_member in all_value_combos: all_value_combos.remove(tuple(None for k in orderings)) # see what values exist for each entity From d28a5c961d2e45905b1583b2eb872da6099d0ada Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 23 Nov 2024 17:19:53 +0100 Subject: [PATCH 11/11] Update nireports/assembler/report.py Co-authored-by: Chris Markiewicz --- nireports/assembler/report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nireports/assembler/report.py b/nireports/assembler/report.py index 65eb9e02..774c2db4 100644 --- a/nireports/assembler/report.py +++ b/nireports/assembler/report.py @@ -491,7 +491,7 @@ def _process_orderings(orderings, hits): # remove the all None member if it exists none_member = (None,) * len(orderings) if none_member in all_value_combos: - all_value_combos.remove(tuple(None for k in orderings)) + all_value_combos.remove(none_member) # see what values exist for each entity unique_values = [ {value[idx] for value in all_value_combos} for idx in range(len(orderings))