Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply new ruff rules #139

Merged
merged 11 commits into from
Nov 23, 2024
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 @@
if self.generate_report:
self.inputs.mask = True

return super(BETRPT, self)._run_interface(runtime)
return super()._run_interface(runtime)

Check warning on line 62 in nireports/interfaces/reporting/masks.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/masks.py#L62

Added line #L62 was not covered by tests

def _post_run_hook(self, runtime):
"""generates a report showing slices from each axis of an arbitrary
Expand All @@ -76,7 +76,7 @@
self._mask_file,
)

return super(BETRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 79 in nireports/interfaces/reporting/masks.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/masks.py#L79

Added line #L79 was not covered by tests


class _BrainExtractionInputSpecRPT(
Expand Down Expand Up @@ -114,7 +114,7 @@
self._mask_file,
)

return super(BrainExtractionRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 117 in nireports/interfaces/reporting/masks.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/masks.py#L117

Added line #L117 was not covered by tests


class _ACompCorInputSpecRPT(nrb._SVGReportCapableInputSpec, confounds.CompCorInputSpec):
Expand Down Expand Up @@ -148,7 +148,7 @@
self._mask_file,
)

return super(ACompCorRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 151 in nireports/interfaces/reporting/masks.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/masks.py#L151

Added line #L151 was not covered by tests


class _TCompCorInputSpecRPT(nrb._SVGReportCapableInputSpec, confounds.TCompCorInputSpec):
Expand Down Expand Up @@ -184,7 +184,7 @@
self.aggregate_outputs(runtime=runtime).high_variance_masks,
)

return super(TCompCorRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 187 in nireports/interfaces/reporting/masks.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/masks.py#L187

Added line #L187 was not covered by tests


class _SimpleShowMaskInputSpec(nrb._SVGReportCapableInputSpec):
Expand All @@ -201,7 +201,7 @@
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 @@
self._moving_image,
)

return super(ApplyTOPUPRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 70 in nireports/interfaces/reporting/registration.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/registration.py#L70

Added line #L70 was not covered by tests


class _FUGUEInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.preprocess.FUGUEInputSpec):
Expand All @@ -94,7 +94,7 @@
self._moving_image,
)

return super(FUGUERPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 97 in nireports/interfaces/reporting/registration.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/registration.py#L97

Added line #L97 was not covered by tests


class _FLIRTInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.preprocess.FLIRTInputSpec):
Expand All @@ -119,7 +119,7 @@
self._moving_image,
)

return super(FLIRTRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 122 in nireports/interfaces/reporting/registration.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/registration.py#L122

Added line #L122 was not covered by tests


class _ApplyXFMInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.preprocess.ApplyXFMInputSpec):
Expand Down Expand Up @@ -183,7 +183,7 @@
self._moving_image,
)

return super(BBRegisterRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 186 in nireports/interfaces/reporting/registration.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/registration.py#L186

Added line #L186 was not covered by tests


class _MRICoregInputSpecRPT(nrb._SVGReportCapableInputSpec, fs.registration.MRICoregInputSpec):
Expand Down Expand Up @@ -230,7 +230,7 @@
self._moving_image,
)

return super(MRICoregRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 233 in nireports/interfaces/reporting/registration.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/registration.py#L233

Added line #L233 was not covered by tests


class _SimpleBeforeAfterInputSpecRPT(nrb._SVGReportCapableInputSpec):
Expand Down Expand Up @@ -259,7 +259,7 @@
self._moving_image,
)

return super(SimpleBeforeAfterRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 262 in nireports/interfaces/reporting/registration.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/registration.py#L262

Added line #L262 was not covered by tests


class _ResampleBeforeAfterInputSpecRPT(_SimpleBeforeAfterInputSpecRPT):
Expand Down Expand Up @@ -291,7 +291,7 @@
self._moving_image,
)

runtime = super(ResampleBeforeAfterRPT, self)._post_run_hook(runtime)
runtime = super()._post_run_hook(runtime)

Check warning on line 294 in nireports/interfaces/reporting/registration.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/registration.py#L294

Added line #L294 was not covered by tests
_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 @@
if self.generate_report:
self.inputs.segments = True

return super(FASTRPT, self)._run_interface(runtime)
return super()._run_interface(runtime)

Check warning on line 53 in nireports/interfaces/reporting/segmentation.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/segmentation.py#L53

Added line #L53 was not covered by tests

def _post_run_hook(self, runtime):
"""generates a report showing nine slices, three per axis, of an
Expand All @@ -72,7 +72,7 @@
outputs.tissue_class_files,
)

return super(FASTRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 75 in nireports/interfaces/reporting/segmentation.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/segmentation.py#L75

Added line #L75 was not covered by tests


class _ReconAllInputSpecRPT(
Expand Down Expand Up @@ -104,14 +104,14 @@

_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)

Check warning on line 107 in nireports/interfaces/reporting/segmentation.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/segmentation.py#L107

Added line #L107 was not covered by tests


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 @@
_out_report = None

def __init__(self, generate_report=False, **kwargs):
super(MELODICRPT, self).__init__(**kwargs)
super().__init__(**kwargs)

Check warning on line 132 in nireports/interfaces/reporting/segmentation.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/segmentation.py#L132

Added line #L132 was not covered by tests
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)

Check warning on line 137 in nireports/interfaces/reporting/segmentation.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/segmentation.py#L137

Added line #L137 was not covered by tests
# leave early if there's nothing to do
if not self.generate_report:
return runtime
Expand Down Expand Up @@ -163,7 +163,7 @@

def _list_outputs(self):
try:
outputs = super(MELODICRPT, self)._list_outputs()
outputs = super()._list_outputs()

Check warning on line 166 in nireports/interfaces/reporting/segmentation.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/segmentation.py#L166

Added line #L166 was not covered by tests
except NotImplementedError:
outputs = {}
if self._out_report is not None:
Expand All @@ -187,7 +187,7 @@
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 @@

_LOGGER.info("Generating report for ICA AROMA")

return super(ICA_AROMARPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)

Check warning on line 224 in nireports/interfaces/reporting/segmentation.py

View check run for this annotation

Codecov / codecov/patch

nireports/interfaces/reporting/segmentation.py#L224

Added line #L224 was not covered by tests
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
Loading