forked from AIM-Harvard/pyradiomics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This script takes a configuration file, a test name (must be unique) and the test case to use. It then generates the output and stores this in the baseline files. Update the test_features script to allow for tests that do not test all available features. (testing still fails if there are feature classes that are not tested). When a feature class is tested, all features must be enabled.
- Loading branch information
Showing
5 changed files
with
127 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import argparse | ||
import logging | ||
|
||
import six | ||
|
||
import radiomics | ||
from radiomics import featureextractor | ||
from testUtils import RadiomicsTestUtils | ||
|
||
|
||
def main(argv=None): | ||
logger = logging.getLogger('radiomics.addTest') | ||
|
||
logger.setLevel(logging.INFO) | ||
radiomics.setVerbosity(logging.INFO) | ||
|
||
handler = logging.FileHandler(filename='testLog.txt', mode='w') | ||
formatter = logging.Formatter("%(levelname)s:%(name)s: %(message)s") | ||
handler.setFormatter(formatter) | ||
|
||
radiomics.logger.addHandler(handler) | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('TestName', type=str, help='Name for the new test, must not be already present in the baseline') | ||
parser.add_argument('TestCase', type=str, choices=list(radiomics.testCases), help='Test image and segmentation to ' | ||
'use in the new test') | ||
parser.add_argument('Configuration', metavar='FILE', default=None, | ||
help='Parameter file containing the settings to be used in extraction') | ||
|
||
args = parser.parse_args(argv) | ||
|
||
logger.info('Input accepted, starting addTest...') | ||
|
||
try: | ||
|
||
testutils = RadiomicsTestUtils() | ||
|
||
try: | ||
assert args.TestName not in testutils.getTests() | ||
assert args.TestCase in radiomics.testCases | ||
except AssertionError as e: | ||
logger.error('Input not valid, cancelling addTest! (%s)', e.message) | ||
exit(1) | ||
|
||
logger.debug('Initializing extractor') | ||
extractor = featureextractor.RadiomicsFeaturesExtractor(args.Configuration) | ||
|
||
logger.debug('Starting extraction') | ||
featurevector = extractor.execute(*radiomics.getTestCase(args.TestCase)) | ||
|
||
configuration = {} | ||
baselines = {} | ||
|
||
for k, v in six.iteritems(featurevector): | ||
if 'general_info' in k: | ||
configuration[k] = v | ||
else: | ||
image_filter, feature_class, feature_name = k.split('_') | ||
if feature_class not in baselines: | ||
baselines[feature_class] = {} | ||
baselines[feature_class][k] = v | ||
|
||
configuration['general_info_TestCase'] = args.TestCase | ||
|
||
testutils.addTest(args.TestName, configuration, baselines) | ||
|
||
logger.info('addTest Done') | ||
|
||
except Exception: | ||
logger.error('Error running addTest!', exc_info=True) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters