Skip to content

Commit

Permalink
Merge pull request #139 from DimitriPapadopoulos/ruff
Browse files Browse the repository at this point in the history
Apply new ruff rules
  • Loading branch information
effigies authored Nov 23, 2024
2 parents 6f8173c + d28a5c9 commit d3ef72b
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .maint/update_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion nireports/assembler/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<table id="%s" class="table table-sm table-striped">\n' % table_id
td = "<td{1}>{0}</td>".format
Expand Down
12 changes: 4 additions & 8 deletions nireports/assembler/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -493,9 +489,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 = (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))
Expand Down
2 changes: 1 addition & 1 deletion nireports/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
__all__ = (
"CompCorVariancePlot",
"ConfoundsCorrelationPlot",
"RaincloudPlot",
"FMRISummary",
"PlotContours",
"PlotMosaic",
"PlotSpikes",
"RaincloudPlot",
)
2 changes: 1 addition & 1 deletion nireports/interfaces/nuisance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)


Expand Down
12 changes: 6 additions & 6 deletions nireports/interfaces/reporting/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions nireports/interfaces/reporting/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
18 changes: 9 additions & 9 deletions nireports/interfaces/reporting/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -104,14 +104,14 @@ 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):
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. "
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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. "
Expand Down Expand Up @@ -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)
10 changes: 5 additions & 5 deletions nireports/reportlets/modality/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
4 changes: 1 addition & 3 deletions nireports/reportlets/xca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion nireports/tools/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d3ef72b

Please sign in to comment.