Skip to content

Commit

Permalink
maint: revise shebangs/attribution, add dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Feb 28, 2023
1 parent 017ef38 commit 2910d82
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 151 deletions.
114 changes: 0 additions & 114 deletions nireports/interfaces/reports.py

This file was deleted.

30 changes: 13 additions & 17 deletions nireports/interfaces/viz.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
# Copyright 2023 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,12 +20,15 @@
#
# https://www.nipreps.org/community/licensing/
#
# STATEMENT OF CHANGES: This file was ported carrying over full git history from MRIQC,
# another NiPreps project licensed under the Apache-2.0 terms, and has been changed since.
# The original file this work derives from is found at:
# https://github.com/nipreps/mriqc/blob/1ffd4c8d1a20b44ebfea648a7b12bb32a425d4ec/
# mriqc/interfaces/viz.py
"""Visualization interfaces."""
from io import open # pylint: disable=W0622
from pathlib import Path

import numpy as np
from mriqc.viz.utils import plot_mosaic, plot_segmentation, plot_spikes
from nipype.interfaces.base import (
BaseInterfaceInputSpec,
File,
Expand All @@ -35,16 +38,14 @@
traits,
)

from nireports.reportlets.mriqc.utils import plot_mosaic, plot_segmentation, plot_spikes


class PlotContoursInputSpec(BaseInterfaceInputSpec):
in_file = File(exists=True, mandatory=True, desc="File to be plotted")
in_contours = File(
exists=True, mandatory=True, desc="file to pick the contours from"
)
in_contours = File(exists=True, mandatory=True, desc="file to pick the contours from")
cut_coords = traits.Int(8, usedefault=True, desc="number of slices")
levels = traits.List(
[0.5], traits.Float, usedefault=True, desc="add a contour per level"
)
levels = traits.List([0.5], traits.Float, usedefault=True, desc="add a contour per level")
colors = traits.List(
["r"],
traits.Str,
Expand Down Expand Up @@ -159,9 +160,7 @@ def _run_interface(self, runtime):
cmap=self.inputs.cmap,
annotate=self.inputs.annotate,
)
self._results["out_file"] = str(
(Path(runtime.cwd) / self.inputs.out_file).resolve()
)
self._results["out_file"] = str((Path(runtime.cwd) / self.inputs.out_file).resolve())
return runtime


Expand All @@ -175,9 +174,7 @@ class PlotSpikesOutputSpec(TraitedSpec):


class PlotSpikes(SimpleInterface):
"""
Plot slices of a dataset with spikes
"""
"""Plot slices of a dataset with spikes."""

input_spec = PlotSpikesInputSpec
output_spec = PlotSpikesOutputSpec
Expand All @@ -189,8 +186,7 @@ def _run_interface(self, runtime):
spikes_list = np.loadtxt(self.inputs.in_spikes, dtype=int).tolist()
# No spikes
if not spikes_list:
with open(out_file, "w") as f:
f.write("<p>No high-frequency spikes were found in this dataset</p>")
Path(out_file).write_text("<p>No high-frequency spikes were found in this dataset</p>")
return runtime

spikes_list = [tuple(i) for i in np.atleast_2d(spikes_list).tolist()]
Expand Down
15 changes: 8 additions & 7 deletions nireports/reportlets/mriqc/svg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
# Copyright 2023 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,11 @@
#
# https://www.nipreps.org/community/licensing/
#
# STATEMENT OF CHANGES: This file was ported carrying over full git history from MRIQC,
# another NiPreps project licensed under the Apache-2.0 terms, and has been changed since.
# The original file this work derives from is found at:
# https://github.com/nipreps/mriqc/blob/1ffd4c8d1a20b44ebfea648a7b12bb32a425d4ec/
# mriqc/viz/svg.py
"""SVG handling utilities."""


Expand Down Expand Up @@ -59,9 +64,7 @@ def combine_svg(svg_list, axis="vertical"):
for i, els in enumerate(sizes):
scales[i] = ref_size[0] / els[0]

newsizes = [
tuple(size) for size in np.array(sizes) * np.array(scales)[..., np.newaxis]
]
newsizes = [tuple(size) for size in np.array(sizes) * np.array(scales)[..., np.newaxis]]
totalsize = [newsizes[0][0], np.sum(newsizes, axis=0)[1]]

elif axis == "horizontal":
Expand All @@ -72,9 +75,7 @@ def combine_svg(svg_list, axis="vertical"):
for i, els in enumerate(sizes):
scales[i] = ref_size[1] / els[1]

newsizes = [
tuple(size) for size in np.array(sizes) * np.array(scales)[..., np.newaxis]
]
newsizes = [tuple(size) for size in np.array(sizes) * np.array(scales)[..., np.newaxis]]
totalsize = [np.sum(newsizes, axis=0)[0], newsizes[0][1]]

# Compose the views panel: total size is the width of
Expand Down
23 changes: 10 additions & 13 deletions nireports/reportlets/mriqc/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
# Copyright 2023 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,11 @@
#
# https://www.nipreps.org/community/licensing/
#
# STATEMENT OF CHANGES: This file was ported carrying over full git history from MRIQC,
# another NiPreps project licensed under the Apache-2.0 terms, and has been changed since.
# The original file this work derives from is found at:
# https://github.com/nipreps/mriqc/blob/1ffd4c8d1a20b44ebfea648a7b12bb32a425d4ec/
# mriqc/viz/utils.py
"""Visualization utilities."""
import math
import os.path as op
Expand Down Expand Up @@ -396,9 +401,7 @@ def plot_mosaic(
)
naxis += 1

fig.subplots_adjust(
left=0.05, right=0.95, bottom=0.05, top=0.95, wspace=0.05, hspace=0.05
)
fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95, wspace=0.05, hspace=0.05)

if title:
fig.suptitle(title, fontsize="10")
Expand Down Expand Up @@ -516,9 +519,7 @@ def _calc_fd(fd_file, fd_radius):
translations = np.transpose(np.abs(np.diff(cols[0:3, :])))
rotations = np.transpose(np.abs(np.diff(cols[3:6, :])))

fd_power = np.sum(translations, axis=1) + (fd_radius * pi / 180) * np.sum(
rotations, axis=1
)
fd_power = np.sum(translations, axis=1) + (fd_radius * pi / 180) * np.sum(rotations, axis=1)

# FD is zero for the first time point
fd_power = np.insert(fd_power, 0, 0)
Expand Down Expand Up @@ -556,16 +557,12 @@ def plot_segmentation(anat_file, segmentation, out_file, **kwargs):

anat_ras = nb.as_closest_canonical(nb.load(anat_file))
anat_ras_plumb = anat_ras.__class__(
anat_ras.dataobj,
_dicom_real_to_card(anat_ras.affine),
anat_ras.header
anat_ras.dataobj, _dicom_real_to_card(anat_ras.affine), anat_ras.header
)

seg_ras = nb.as_closest_canonical(nb.load(segmentation))
seg_ras_plumb = seg_ras.__class__(
seg_ras.dataobj,
_dicom_real_to_card(seg_ras.affine),
seg_ras.header
seg_ras.dataobj, _dicom_real_to_card(seg_ras.affine), seg_ras.header
)

if kwargs.get("saturate", False):
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ classifiers =
[options]
python_requires = >= 3.7
install_requires =
matplotlib >= 3.4.2
nibabel >= 3.0.1
nipype
numpy
pybids
pyyaml
seaborn
svgutils >= 0.3.4
packages = find:

[options.package_data]
Expand Down

0 comments on commit 2910d82

Please sign in to comment.