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

Remove python equivalents for c functions #373

Merged
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
82 changes: 0 additions & 82 deletions bin/addClassToBaseline.py

This file was deleted.

Binary file added data/baseline/brain1_glcm.npy
Binary file not shown.
Binary file added data/baseline/brain1_gldm.npy
Binary file not shown.
Binary file added data/baseline/brain1_glrlm.npy
Binary file not shown.
Binary file added data/baseline/brain1_glszm.npy
Binary file not shown.
Binary file added data/baseline/brain1_ngtdm.npy
Binary file not shown.
Binary file added data/baseline/brain2_glcm.npy
Binary file not shown.
Binary file added data/baseline/brain2_gldm.npy
Binary file not shown.
Binary file added data/baseline/brain2_glrlm.npy
Binary file not shown.
Binary file added data/baseline/brain2_glszm.npy
Binary file not shown.
Binary file added data/baseline/brain2_ngtdm.npy
Binary file not shown.
Binary file added data/baseline/breast1_glcm.npy
Binary file not shown.
Binary file added data/baseline/breast1_gldm.npy
Binary file not shown.
Binary file added data/baseline/breast1_glrlm.npy
Binary file not shown.
Binary file added data/baseline/breast1_glszm.npy
Binary file not shown.
Binary file added data/baseline/breast1_ngtdm.npy
Binary file not shown.
Binary file added data/baseline/lung1_glcm.npy
Binary file not shown.
Binary file added data/baseline/lung1_gldm.npy
Binary file not shown.
Binary file added data/baseline/lung1_glrlm.npy
Binary file not shown.
Binary file added data/baseline/lung1_glszm.npy
Binary file not shown.
Binary file added data/baseline/lung1_ngtdm.npy
Binary file not shown.
Binary file added data/baseline/lung2_glcm.npy
Binary file not shown.
Binary file added data/baseline/lung2_gldm.npy
Binary file not shown.
Binary file added data/baseline/lung2_glrlm.npy
Binary file not shown.
Binary file added data/baseline/lung2_glszm.npy
Binary file not shown.
Binary file added data/baseline/lung2_ngtdm.npy
Binary file not shown.
9 changes: 3 additions & 6 deletions docs/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ Feature Extractor Level

*Miscellaneous*

- ``enableCExtensions`` [True]: Boolean, set to False to force calculation to full-python mode. See also
:py:func:`~radiomics.enableCExtensions()`.
- ``additionalInfo`` [True]: boolean, set to False to disable inclusion of additional information on the extraction in the
output. See also :py:func:`~radiomics.featureextractor.RadiomicsFeaturesExtractor.addProvenance()`.

Expand Down Expand Up @@ -284,12 +282,11 @@ Feature Class Level

- ``force2D`` [False]: Boolean, set to true to force a by slice texture calculation. Dimension that identifies
the 'slice' can be defined in ``force2Ddimension``. If input ROI is already a 2D ROI, features are automatically
extracted in 2D. See also :py:func:`~radiomics.imageoperations.generateAngles`
extracted in 2D.
- ``force2Ddimension`` [0]: int, range 0-2. Specifies the 'slice' dimension for a by-slice feature extraction. Value 0
identifies the 'z' dimension (axial plane feature extraction), and features will be extracted from the xy plane.
Similarly, 1 identifies the y dimension (coronal plane) and 2 the x dimension (saggital plane). if
``force2Dextraction`` is set to False, this parameter has no effect. See also
:py:func:`~radiomics.imageoperations.generateAngles`
``force2Dextraction`` is set to False, this parameter has no effect.

*Texture matrix weighting*

Expand All @@ -312,7 +309,7 @@ Feature Class Level
*Distance to neighbour*

- ``distances`` [[1]]: List of integers. This specifies the distances between the center voxel and the neighbor, for which
angles should be generated. See also :py:func:`~radiomics.imageoperations.generateAngles`
angles should be generated.

.. note::

Expand Down
14 changes: 11 additions & 3 deletions docs/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ the module a class should be defined that fits the following signature::
* Documentation is required! Both at the class level (Feature class docstring) and at the level of the individual
features (Feature docstring).
* If the feature class uses C extensions for matrix calculation enhancement, which should be tested using
``test_cmatrices``, matrix calculation should be implemented as follows:
``test_matrices``, matrix calculation should be implemented as follows:

* The function calculating the matrix in python should be defined in a function called ``_calculateMatrix``.
* The function calculating the matrix using the C extension should be defined in a function called ``_calculateCMatrix``.
* The function calculating the matrix using the C extension should be defined in a function called ``_calculateMatrix``.
* The functions to calculate the matrix accept no additional input arguments other than the ``self`` argument, and
return the fully processed matrix as a numpy array.
* The fully processed matrix should be assigned to a variable in the feature class named ``P_[Name]``, where
Expand All @@ -66,6 +65,15 @@ the module a class should be defined that fits the following signature::
generated by the feature class should make use of this logger to ensure that the hierarchy of classes is correctly
reflected in generated logs (i.e. ``self.logger.debug('message')`` to generate a debug log message).

-------------------
Adding the baseline
-------------------

During testing, calculated features are compared to a fixed baseline. If you implement a new class, it must be added to
the baseline, otherwise testing will fail. Fortunately, adding a new class to the baseline is fairly easy: just run the
``add_baseline.py`` script located in the ``tests`` folder. In case you change a feature and need to rebuild the
baseline for that class, run the script with the class name as an argument (e.g. ``python add_baseline.py glcm``).

.. _radiomics-developers-feature:

--------------------------------
Expand Down
30 changes: 16 additions & 14 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ for python `here <https://wiki.python.org/moin/WindowsCompilers>`_.
Error loading C extensions.
###########################

I installed PyRadiomics successfully from the repository, but when I run the notebook, I get ``Error loading C extensions, switching to python calculation``
When I try to run PyRadiomics, I get ``Error loading C extensions``

When PyRadiomics is installed, the C extensions are compiled and copied to the installation folder, by default the
``site-packages`` folder. However, when the notebook is run form the repository, it is possible that PyRadiomics uses
the source code directly (i.e. runs in development mode). You can check this by checking the ``radiomics.__path__``
field, which will be something like ``['radiomics']`` when it is running in development mode and
``['path/to/python/Lib/site-packages']`` when running from the installed folder. If running in development mode, the C
extensions are not available by default. To make them available in development mode, run ``python setup.py develop``
from the commandline, which is similar to the ``install`` command, but installs pyradiomics to the source folder
instead (i.e. does nothing to the python files, but compiles the C extensions and copies them to the source folder).
extensions are not available by default. To make them available in development mode, run
``python setup.py build_ext --inplace`` from the commandline, which is similar to the ``install`` command, but just
compiles the C extensions end copies them to the source folder (making them available when running from the source tree).

Which python versions is PyRadiomics compatible with?
#####################################################

PyRadiomics is compatible with both python 2 and python 3. The automated testing uses python versions 2.7, 3.4 and 3.5
(only 64 bits architecture). Python < 2.6 is not supported. Other python versions may be compatible with PyRadiomics, but this
is not actively tested and therefore not guaranteed to work.
(only 64 bits architecture). Python < 2.6 is not supported. Other python versions may be compatible with PyRadiomics,
but this is not actively tested and therefore not guaranteed to work.

Input / Customization
---------------------
Expand Down Expand Up @@ -110,10 +110,10 @@ PyRadiomics does not support DICOM-RT struct as input directly. We recommend to
Usage
-----

How should the input file for ``pyradiomicsbatch`` be structured?
How should the input file for ``pyradiomics`` in batch-mode be structured?
#################################################################

Currently, the input file for ``pyradiomicsbatch`` is a csv file specifying the combinations of images and masks for
Currently, the batch input file for ``pyradiomics`` is a csv file specifying the combinations of images and masks for
which to extract features. It must contain a header line, where at least header "Image" and "Mask" should be specified
(capital sensitive). These identify the columns that contain the file location of the image and the mask, respectively.
Each subsequent line represents one combination of an image and a mask. Additional columns are also allowed, these are
Expand All @@ -125,11 +125,13 @@ Radiomics module not found in jupyter notebook

I installed PyRadiomics, but when I run the jupyter notebook, I get ``ImportError: No module named radiomics``

This can have two possible causes: 1) When installing PyRadiomics from the repository, your python path variable will be
updated to enable python to find the package. However, this value is only updated in commandline windows when they are
restarted. If your jupyter notebook was running during installation, you first need to restart it. 2) Multiple versions
of python can be installed on your machine simultaneously. Ensure PyRadiomics is installed on the same version you are
using in your Jupyter notebook.
This can have two possible causes:

1) When installing PyRadiomics from the repository, your python path variable will be updated to enable python to find
the package. However, this value is only updated in commandline windows when they are restarted. If your jupyter
notebook was running during installation, you first need to restart it.
2) Multiple versions of python can be installed on your machine simultaneously. Ensure PyRadiomics is installed on the
same version you are using in your Jupyter notebook.

I'm missing features from my output. How can I see what went wrong?
###################################################################
Expand All @@ -140,7 +142,7 @@ out, or stored in a separate log file. The output is regulated by :py:func:`radi
logger can be accessed via ``radiomics.logger``. See also :ref:`here <radiomics-logging-label>` and the examples
included in the repository on how to set up logging.

I'm able to extract features, but many are NaN, 0 or 1. What happend?
I'm able to extract features, but many are NaN, 0 or 1. What happened?
#####################################################################

It is possible that the segmentation was too small to extract a valid texture. Check the value of ``VoxelNum``, which is
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ There are three ways you can use pyradiomics:
* ``python setup.py install``

To use your build for interactive use and development:
* ``python setup.py develop``
* ``python setup.py build_ext --inplace``

* If you don't have sudo/admin rights on your machine, you need to locally install numpy, nose, tqdm, PyWavelets, SimpleITK (specified in requirements.txt).
In a bash shell::
Expand Down
63 changes: 0 additions & 63 deletions examples/helloRadiomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,6 @@
import radiomics
from radiomics import featureextractor

def tqdmProgressbar():
"""
This function will setup the progress bar exposed by the 'tqdm' package.
Progress reporting is only used in PyRadiomics for the calculation of GLCM and GLSZM in full python mode, therefore
enable GLCM and full-python mode to show the progress bar functionality

N.B. This function will only work if the 'click' package is installed (not included in the PyRadiomics requirements)
"""
global extractor
extractor.kwargs['enableCExtensions'] = False
# Enable the GLCM class to show the progress bar
extractor.enableFeatureClassByName('glcm')

radiomics.setVerbosity(logging.INFO) # Verbosity must be at least INFO to enable progress bar

import tqdm
radiomics.progressReporter = tqdm.tqdm

def clickProgressbar():
"""
This function will setup the progress bar exposed by the 'click' package.
Progress reporting is only used in PyRadiomics for the calculation of GLCM and GLSZM in full python mode, therefore
enable GLCM and full-python mode to show the progress bar functionality.

Because the signature used to instantiate a click progress bar is different from what PyRadiomics expects, we need to
write a simple wrapper class to enable use of a click progress bar. In this case we only need to change the 'desc'
keyword argument to a 'label' keyword argument.

N.B. This function will only work if the 'click' package is installed (not included in the PyRadiomics requirements)
"""
global extractor

extractor.kwargs['enableCExtensions'] = False
# Enable the GLCM class to show the progress bar
extractor.enableFeatureClassByName('glcm')

radiomics.setVerbosity(logging.INFO) # Verbosity must be at least INFO to enable progress bar

import click

class progressWrapper():
def __init__(self, iterable, desc=''):
# For a click progressbar, the description must be provided in the 'label' keyword argument.
self.bar = click.progressbar(iterable, label=desc)

def __iter__(self):
return self.bar.__iter__() # Redirect to the __iter__ function of the click progressbar

def __enter__(self):
return self.bar.__enter__() # Redirect to the __enter__ function of the click progressbar

def __exit__(self, exc_type, exc_value, tb):
return self.bar.__exit__(exc_type, exc_value, tb) # Redirect to the __exit__ function of the click progressbar

radiomics.progressReporter = progressWrapper


# Get some test data

# Download the test case to temporary files and return it's location. If already downloaded, it is not downloaded again,
Expand Down Expand Up @@ -111,12 +54,6 @@ def __exit__(self, exc_type, exc_value, tb):
# Only enable mean and skewness in firstorder
extractor.enableFeaturesByName(firstorder=['Mean', 'Skewness'])

# Uncomment one of these functions to show how PyRadiomics can use the 'tqdm' or 'click' package to report progress when
# running in full python mode. Assumes the respective package is installed (not included in the requirements)

# tqdmProgressbar()
# clickProgressbar()

print("Calculating features")
featureVector = extractor.execute(imageName, maskName)

Expand Down
63 changes: 0 additions & 63 deletions examples/helloRadiomicsWithSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,6 @@
import radiomics
from radiomics import featureextractor

def tqdmProgressbar():
"""
This function will setup the progress bar exposed by the 'tqdm' package.
Progress reporting is only used in PyRadiomics for the calculation of GLCM and GLSZM in full python mode, therefore
enable GLCM and full-python mode to show the progress bar functionality

N.B. This function will only work if the 'click' package is installed (not included in the PyRadiomics requirements)
"""
global extractor
extractor.kwargs['enableCExtensions'] = False
# Enable the GLCM class to show the progress bar
extractor.enableFeatureClassByName('glcm')

radiomics.setVerbosity(logging.INFO) # Verbosity must be at least INFO to enable progress bar

import tqdm
radiomics.progressReporter = tqdm.tqdm

def clickProgressbar():
"""
This function will setup the progress bar exposed by the 'click' package.
Progress reporting is only used in PyRadiomics for the calculation of GLCM and GLSZM in full python mode, therefore
enable GLCM and full-python mode to show the progress bar functionality.

Because the signature used to instantiate a click progress bar is different from what PyRadiomics expects, we need to
write a simple wrapper class to enable use of a click progress bar. In this case we only need to change the 'desc'
keyword argument to a 'label' keyword argument.

N.B. This function will only work if the 'click' package is installed (not included in the PyRadiomics requirements)
"""
global extractor

extractor.kwargs['enableCExtensions'] = False
# Enable the GLCM class to show the progress bar
extractor.enableFeatureClassByName('glcm')

radiomics.setVerbosity(logging.INFO) # Verbosity must be at least INFO to enable progress bar

import click

class progressWrapper():
def __init__(self, iterable, desc=''):
# For a click progressbar, the description must be provided in the 'label' keyword argument.
self.bar = click.progressbar(iterable, label=desc)

def __iter__(self):
return self.bar.__iter__() # Redirect to the __iter__ function of the click progressbar

def __enter__(self):
return self.bar.__enter__() # Redirect to the __enter__ function of the click progressbar

def __exit__(self, exc_type, exc_value, tb):
return self.bar.__exit__(exc_type, exc_value, tb) # Redirect to the __exit__ function of the click progressbar

radiomics.progressReporter = progressWrapper


# Get some test data

# Download the test case to temporary files and return it's location. If already downloaded, it is not downloaded again,
Expand Down Expand Up @@ -96,12 +39,6 @@ def __exit__(self, exc_type, exc_value, tb):
# Initialize feature extractor using the settings file
extractor = featureextractor.RadiomicsFeaturesExtractor(paramsFile)

# Uncomment one of these functions to show how PyRadiomics can use the 'tqdm' or 'click' package to report progress when
# running in full python mode. Assumes the respective package is installed (not included in the requirements)

# tqdmProgressbar()
# clickProgressbar()

print("Active features:")
for cls, features in six.iteritems(extractor._enabledFeatures):
if len(features) == 0:
Expand Down
Loading