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

Moved the QC assets into the spinalcordtoolbox package #1311

Merged
merged 7 commits into from
May 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
include LICENSE
include setup*
include README*
include Changelog
include CHANGES.md
include abstract.png
include version.txt
include batch_processing*

recursive-include testing *.py *.sh
recursive-exclude testing __MACOSX

recursive-include scripts *.py
recursive-exclude scripts __MACOSX
graft spinalcordtoolbox/reports/assets
prune dev
prune scripts
prune testing
2 changes: 1 addition & 1 deletion install_sct
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ fi


## Install the spinalcordtoolbox into conda
pip install -e ${SCT_SOURCE}
pip install ${SCT_SOURCE}


## Install binaries
Expand Down
4 changes: 1 addition & 3 deletions scripts/sct_label_vertebrae.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
# TODO: address the case when there is more than one max correlation

import sys
# import commands
import os
import shutil
# from glob import glob
import numpy as np
from sct_maths import mutual_information
from msct_parser import Parser
Expand Down Expand Up @@ -351,7 +349,7 @@ def test(qslice):
return qslice.single()

labeled_seg_file = path_output + file_seg + '_labeled' + ext_seg
test(qcslice.Sagittal(fname_in, labeled_seg_file))
test(qcslice.Sagittal(Image(fname_in), Image(labeled_seg_file)))
sct.printv('Sucessfully generated the QC results in %s' % qc_param.qc_results)
sct.printv('Use the following command to see the results in a browser:')
sct.printv('sct_qc -folder %s' % qc_path, type='info')
Expand Down
3 changes: 1 addition & 2 deletions scripts/sct_propseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,10 @@ def get_parser():
def test(qslice):
return qslice.mosaic()

test(qcslice.Axial(fname_input_data, fname_seg))
test(qcslice.Axial(Image(fname_input_data), Image(fname_seg)))
sct.printv('Sucessfully generated the QC results in %s' % param.qc_results)
sct.printv('Use the following command to see the results in a browser:')
sct.printv('sct_qc -folder %s' % qc_path, type='info')

sct.printv('\nDone! To view results, type:', verbose)
sct.printv("fslview " + fname_input_data + " " + fname_seg + " -l Red -b 0,1 -t 0.7 &\n", verbose, 'info')

13 changes: 10 additions & 3 deletions scripts/sct_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Copyright (c) 2017 Polytechnique Montreal <www.neuro.polymtl.ca>
# About the license: see the file LICENSE.TXT

"""Simple local http server to serve QC reports
"""

import os
import shutil
import sys
Expand All @@ -14,6 +17,8 @@
from msct_parser import Parser
from sct_utils import printv

import spinalcordtoolbox.reports as reports


def get_parser():
parser = Parser(__file__)
Expand All @@ -27,8 +32,7 @@ def get_parser():


def _copy_assets(dest_path):
home_dir = os.path.dirname(os.path.dirname(__file__))
assets_path = os.path.join(home_dir, 'assets')
assets_path = os.path.join(reports.__path__[0], 'assets')

shutil.copy2(os.path.join(assets_path, 'index.html'), dest_path)

Expand Down Expand Up @@ -63,4 +67,7 @@ def _copy_assets(dest_path):
printv('http://127.0.0.1:8888', type='info')
printv('Copy and paste the address into your web browser')
printv('Press "Ctrl" + "C" to stop sct_qc')
httpd.serve_forever()
try:
httpd.serve_forever()
except KeyboardInterrupt:
printv('QC viewer stopped')
4 changes: 2 additions & 2 deletions scripts/sct_register_to_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,12 @@ def main():
qc_param = qc.Params(fname_data, 'sct_register_to_template', args, 'Sagittal', qc_path)
report = qc.QcReport(qc_param, '')

@qc.QcImage(report, 'bicubic', [qc.QcImage.no_seg_seg])
@qc.QcImage(report, 'none', [qc.QcImage.no_seg_seg])
def test(qslice):
return qslice.single()

fname_template2anat = path_output + 'template2anat' + ext_data
test(qcslice.SagittalTemplate2Anat(fname_data, fname_template2anat, fname_seg))
test(qcslice.SagittalTemplate2Anat(Image(fname_data), Image(fname_template2anat), Image(fname_seg)))
sct.printv('Sucessfully generate the QC results in %s' % qc_param.qc_results)
sct.printv('Use the following command to see the results in a browser')
sct.printv('sct_qc -folder %s' % qc_path, type='info')
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ source = spinalcordtoolbox/

[flake8]
exclude = build,.git,.tox,
ignore = E501
ignore = E501,E402
max-line-length = 179

[isort]
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
requirements = f.read().splitlines()

with open(path.join(here, 'version.txt')) as f:
version = f.read().split()
version = f.read().strip()

setup(
name='spinalcordtoolbox',
version=version,
description='Library of analysis tools for MRI of the spinal cord',
long_description=long_description,
url='http://www.neuro.polymtl.ca/home',
Expand All @@ -37,12 +38,13 @@
'Programming Language :: Python :: 2.7',
],
keywords='Magnetic Resonance Imaging MRI spinal cord analysis template',
packages=find_packages(exclude=['dev', 'install']),
packages=find_packages(exclude=['scripts', 'dev', 'dev.*', 'install', 'testing']),
package_data={},
install_requires=requirements,
include_package_data=True,

# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
entry_points={'console_scripts': ['sct=spinalcordtoolbox.qc.serve:spinalcordtoolbox'], },
# entry_points={'console_scripts': ['sct=spinalcordtoolbox.qc.serve:spinalcordtoolbox'], },
)
Empty file removed spinalcordtoolbox/qc/__init__.py
Empty file.
51 changes: 0 additions & 51 deletions spinalcordtoolbox/qc/serve.py

This file was deleted.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
21 changes: 5 additions & 16 deletions spinalcordtoolbox/reports/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import subprocess

import warnings

import shutil

warnings.filterwarnings("ignore")

import datetime
import matplotlib
matplotlib.use('Agg')
Expand Down Expand Up @@ -202,7 +200,7 @@ def _save(self, img_path, format='png', bbox_inches='tight', pad_inches=0.00):
class Params(object):
"""Parses and stores the variables that will included into the QC details

We derive the value of the contrast and subject name from the `input_file` path,
We derive the value of the contrast and subject name from the `input_file` path,
by splitting it into `[subject]/[contrast]/input_file`
"""

Expand All @@ -211,7 +209,7 @@ def __init__(self, input_file, command, args, orientation, dest_folder):
Parameters
----------
input_file : str
the input nifti file name
the input nifti file name
command : str
the command name
args : str
Expand Down Expand Up @@ -294,28 +292,19 @@ def update_description_file(self, dimension):

Parameters
----------
unparsed_args : list of str
the commands used in the Terminal of the process
description : str
quick description of current usage of the process
sct_commit : str
commit version of the code being currently used to generate the images
"""
# get path of the toolbox
path_script = os.path.dirname(__file__)
path_sct = os.path.dirname(path_script)
with open(os.path.join(path_sct, '..', 'version.txt')) as file_handle:
sct_version = file_handle.read().strip()

try:
cmd = 'git log -n 1 --pretty=format:"%H"'.split()
cmd = 'git rev-parse --short HEAD'.split()
git_hash = subprocess.check_output(cmd).strip('"')
except subprocess.CalledProcessError:
git_hash = "N/A"

output = {
'command': self.qc_params.command,
'version': "{}({})".format(sct_version, git_hash),
'version': git_hash,
'args': ' '.join(self.qc_params.args),
'subject': self.qc_params.subject,
'contrast': self.qc_params.contrast,
Expand Down
15 changes: 7 additions & 8 deletions spinalcordtoolbox/reports/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import numpy as np
from scipy import ndimage

import scripts.msct_image as msct_image

logger = logging.getLogger(__name__)

Expand All @@ -34,13 +33,13 @@ def __init__(self, image_name, seg_image_name):
"""
Parameters
----------
image_name : str
image_name : msct_image.Image
Input 3D MRI to be separated into slices.
seg_image_name : str
seg_image_name : msct_image.Image
Output name for the 3D MRI to be produced.
"""
self.image = msct_image.Image(image_name)
self.image_seg = msct_image.Image(seg_image_name)
self.image = image_name
self.image_seg = seg_image_name
self.image.change_orientation('SAL')
self.image_seg.change_orientation('SAL')

Expand Down Expand Up @@ -118,7 +117,7 @@ def crop(matrix, x, y, width, height):
returns the cropped matrix
"""
if width * 2 > matrix.shape[0]:
width = matrix.shape[0] // 2
width = matrix.shape[0] // 2
if height * 2 > matrix.shape[1]:
height = matrix.shape[1] // 2

Expand Down Expand Up @@ -347,7 +346,7 @@ class AxialTemplate2Anat(AxialTemplate):
"""The axial template to anat representation of a slice"""
def __init__(self, image_name, template2anat_image_name, seg_image_name):
super(AxialTemplate2Anat, self).__init__(image_name, template2anat_image_name)
self.image_seg2 = msct_image.Image(seg_image_name) # transformed input the one segmented
self.image_seg2 = seg_image_name # transformed input the one segmented
self.image_seg2.change_orientation('SAL') # reorient to SAL

def get_center(self):
Expand Down Expand Up @@ -410,7 +409,7 @@ class SagittalTemplate2Anat(Sagittal):

def __init__(self, image_name, template2anat_name, seg_image_name):
super(SagittalTemplate2Anat, self).__init__(image_name, template2anat_name)
self.image_seg2 = msct_image.Image(seg_image_name) # transformed input the one segmented
self.image_seg2 = seg_image_name # transformed input the one segmented
self.image_seg2.change_orientation('SAL') # reorient to SAL

def get_center(self):
Expand Down