Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.elastix_toolname = 'Elastix'
self.transformix_toolname = 'Transformix'
# self.Elastix = sitk.SimpleElastix()
self.create_network('pairwise')
self.FixedImage = []
self.MovingImage = []
self.FixedMask = []
self.MovingMask = []
self.ToTransform = []
self.ParameterMaps = [] # sitk.VectorOfParameterMap()
self.TransformedImage = 'vfs://tmp/WORC_Elastix/results/elastix_output_image_{sample_id}_{cardinality}.nii.gz'
self.TransformedSeg = 'vfs://tmp/WORC_Elastix/results/elastix_output_seg_{sample_id}_{cardinality}.nii.gz'
self.TransformParameters = 'vfs://tmp/WORC_Elastix/results/elastix_output_trans_{sample_id}_{cardinality}.txt'
self.fastr_tmpdir = os.path.join(fastr.config.mounts['tmp'], 'WORC_Elastix')
# TODO: Add initial transformation
----------
network: fastr network, default None
If you input a network, the evaluate network is added
to the existing network.
'''
if network is not None:
self.network = network
self.mode = 'WORC'
else:
self.mode = 'StandAlone'
self.fastr_plugin = fastr_plugin
self.name = 'WORC_Slicer_' + name
self.network = fastr.create_network(id=self.name)
self.fastr_tmpdir = os.path.join(fastr.config.mounts['tmp'], self.name)
if images is None and self.mode == 'StandAlone':
message = 'Either images and segmentations as input or a WORC' +\
'network is required for the Evaluate network.'
raise WORCexceptions.WORCIOError(message)
self.images = images
self.segmentations = segmentations
self.create_network()
def execute(self):
# this function is kind of like the build()-function in a builder, except it peforms execute on the object being built as well
self._validate() # do some final sanity checking before we execute the thing
if self._radiomix_feature_file:
# Convert radiomix features and use those as inputs
output_folder = os.path.join(fastr.config.mounts['tmp'],
'Radiomix_features')
# Check if output folder exists: otherwise create
if not os.path.exists(output_folder):
os.mkdir(output_folder)
# convert the features
convert_radiomix_features(self._radiomix_feature_file, output_folder)
# Set the newly created feature files as the WORC input
self.features_from_this_directory(output_folder)
# Training sources
if self.images_train:
self._worc.images_train = self.images_train
elif self._images_train:
def execute(self):
# this function is kind of like the build()-function in a builder, except it peforms execute on the object being built as well
self._validate() # do some final sanity checking before we execute the thing
if self._radiomix_feature_file:
# Convert radiomix features and use those as inputs
output_folder = os.path.join(fastr.config.mounts['tmp'],
'Radiomix_features')
# Check if output folder exists: otherwise create
if not os.path.exists(output_folder):
os.mkdir(output_folder)
# convert the features
convert_radiomix_features(self._radiomix_feature_file, output_folder)
# Set the newly created feature files as the WORC input
self.features_from_this_directory(output_folder)
self._worc.images_train = self._images_train
self._worc.features_train = self._features_train
self._worc.segmentations_train = self._segmentations_train
fitandscore.inputs['traintest'] = traintest_data.output
fitandscore.inputs['parameters'] = parameter_data.output
sink_output.input = fitandscore.outputs['fittedestimator']
source_data = {'estimator_source': estimatordata,
'traintest': traintest_files,
'parameters': parameter_files}
sink_data = {'output': f"vfs://tmp/GS/{name}/output_{{sample_id}}_{{cardinality}}{{ext}}"}
network.execute(source_data, sink_data,
tmpdir=os.path.join(tempfolder, 'tmp'),
execution_plugin=self.fastr_plugin)
# Read in the output data once finished
# TODO: expanding fastr url is probably a nicer way
sink_files = glob.glob(os.path.join(fastr.config.mounts['tmp'], 'GS', name) + '/output*.hdf5')
save_data = list()
for output in sink_files:
data = pd.read_hdf(output)
save_data.extend(list(data['RET']))
# if one choose to see train score, "out" will contain train score info
try:
if self.return_train_score:
(train_scores, test_scores, test_sample_counts,
fit_time, score_time, parameters_est, parameters_all) =\
zip(*save_data)
else:
(test_scores, test_sample_counts,
fit_time, score_time, parameters_est, parameters_all) =\
zip(*save_data)
except ValueError as e:
self.segmentations_test = list()
self.semantics_test = list()
self.labels_test = list()
self.masks_test = list()
self.masks_normalize_test = list()
self.features_test = list()
self.metadata_test = list()
self.Elastix_Para = list()
self.label_names = 'Label1, Label2'
# Set some defaults, name
self.fastr_plugin = 'LinearExecution'
if name == '':
name = [randint(0, 9) for p in range(0, 5)]
self.fastr_tmpdir = os.path.join(fastr.config.mounts['tmp'], self.name)
self.additions = dict()
self.CopyMetadata = True
self.segmode = []
self._add_evaluation = False
self.TrainTest = False
# Memory settings for all fastr nodes
self.fastr_memory_parameters = dict()
self.fastr_memory_parameters['FeatureCalculator'] = '14G'
self.fastr_memory_parameters['Classification'] = '12G'
self.fastr_memory_parameters['WORCCastConvert'] = '4G'
self.fastr_memory_parameters['Preprocessing'] = '4G'
self.fastr_memory_parameters['Elastix'] = '4G'
self.fastr_memory_parameters['Transformix'] = '4G'
self.fastr_memory_parameters['Segmentix'] = '6G'
If you input a network, the evaluate network is added
to the existing network.
"""
if parent is not None:
self.parent = parent
self.network = parent.network
self.mode = 'WORC'
self.name = parent.network.id
self.ensemble = parent.configs[0]['Ensemble']['Use']
else:
self.mode = 'StandAlone'
self.fastr_plugin = fastr_plugin
self.name = 'WORC_Evaluate_' + name
self.network = fastr.create_network(id=self.name)
self.fastr_tmpdir = os.path.join(fastr.config.mounts['tmp'], self.name)
self.ensemble = ensemble
if features is None and self.mode == 'StandAlone':
raise WORCexceptions.WORCIOError('Either features as input or a WORC network is required for the Evaluate network.')
self.features = features
self.label_type = label_type
self.create_network()