How to use the fastr.create_network function in fastr

To help you get started, we’ve selected a few fastr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MStarmans91 / WORC / WORC / classification / SearchCV.py View on Github external
estimator_data = pd.Series([X, y, self.scoring,
                                    False,
                                    self.fit_params, self.return_train_score,
                                    True, True, True,
                                    self.error_score],
                                   index=estimator_labels,
                                   name='estimator Data')
        fname = 'estimatordata.hdf5'
        estimatorname = os.path.join(tempfolder, fname)
        estimator_data.to_hdf(estimatorname, 'Estimator Data')

        estimatordata = f"vfs://tmp/GS/{name}/{fname}"

        # Create the fastr network
        network = fastr.create_network('WORC_GridSearch_' + name)
        estimator_data = network.create_source('HDF5', id='estimator_source')
        traintest_data = network.create_source('HDF5', id='traintest')
        parameter_data = network.create_source('JsonFile', id='parameters')
        sink_output = network.create_sink('HDF5', id='output')

        fitandscore = network.create_node('worc/fitandscore:1.0', tool_version='1.0', id='fitandscore', resources=ResourceLimit(memory='2G'))
        fitandscore.inputs['estimatordata'].input_group = 'estimator'
        fitandscore.inputs['traintest'].input_group = 'traintest'
        fitandscore.inputs['parameters'].input_group = 'parameters'

        fitandscore.inputs['estimatordata'] = estimator_data.output
        fitandscore.inputs['traintest'] = traintest_data.output
        fitandscore.inputs['parameters'] = parameter_data.output
        sink_output.input = fitandscore.outputs['fittedestimator']

        source_data = {'estimator_source': estimatordata,
github MStarmans91 / WORC / WORC / tools / Slicer.py View on Github external
Parameters
        ----------

        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()
github MStarmans91 / WORC / WORC / tools / Elastix.py View on Github external
# self.link_trans.collapse = 'FixedImage'
            # self.link_trans.expand = True

            # Co[y metadata from image to segmentation as Elastix uses this
            self.copymetadata_node = self.network.create_node('itktools/0.3.2/CopyMetadata:1.0', tool_version='1.0', id='copymetadata')
            self.copymetadata_node.inputs['source'] = self.MovingImageSource.output
            self.copymetadata_node.inputs['destination'] = self.ToTransformSource.output

            # Then transform the segmentation
            self.transformix_node_seg = self.network.create_node('self.transformix_toolname', tool_version='unknown', id='transformix_seg')
            self.transformix_node_seg.inputs['image'] = self.copymetadata_node.outputs['output']
            self.transformix_node_seg.inputs['transform'] = self.changeorder_node.outputs['transform'][-1]
            self.outseg.inputs['input'] = self.transformix_node_seg.outputs['image']
        else:
            # Create the network
            self.network = fastr.create_network(id="elastix_group")

            # Create Sources
            self.FixedImageSource = self.network.create_source('ITKImageFile', id='FixedImage')
            self.FixedMaskSource = self.network.create_source('ITKImageFile', id='FixedMask')
            self.ToTransformSource = self.network.create_source('ITKImageFile', id='ToTransform')
            self.ParameterMapSource = self.network.create_source('ElastixParameterFile', id='ParameterMaps', node_group='par')
            # Elastix requires the output folder as a sink
            # self.OutputFolderSource = self.network.create_sink('Directory', id_='Out')

            # Create Elastix node and links
            self.elastix_node = self.network.create_node('self.elastix_toolname', tool_version='unknown', id='elastix')
            self.elastix_node.inputs['fixed_image'] = self.FixedImageSource.output
            self.elastix_node.inputs['fixed_mask'] = self.FixedMaskSource.output
            self.elastix_node.inputs['moving_image'] = self.FixedImageSource.output
            self.elastix_node.inputs['moving_mask'] = self.FixedMaskSource.output
            # self.OutputFolderSource.input = self.elastix_node.outputs['directory']
github MStarmans91 / WORC / WORC / tools / Evaluate.py View on Github external
network: fastr network, default None
                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()
github MStarmans91 / WORC / WORC / WORC.py View on Github external
"""Build the training network based on the given attributes."""
        # We either need images or features for Radiomics
        if self.images_test or self.features_test:
            self.TrainTest = True

        if self.images_train or self.features_train:
            print('Building training network...')
            # We currently require labels for supervised learning
            if self.labels_train:
                if not self.configs:
                    print("No configuration given, assuming default")
                    if self.images_train:
                        self.configs = [self.defaultconfig()] * len(self.images_train)
                    else:
                        self.configs = [self.defaultconfig()] * len(self.features_train)
                self.network = fastr.create_network(self.name)

                # BUG: We currently use the first configuration as general config
                image_types = list()
                for c in range(len(self.configs)):
                    if type(self.configs[c]) == str:
                        # Probably, c is a configuration file
                        self.configs[c] = config_io.load_config(self.configs[c])
                    image_types.append(self.configs[c]['ImageFeatures']['image_type'])

                # Create config source
                self.source_class_config = self.network.create_source('ParameterFile', id='config_classification_source', node_group='conf')

                # Classification tool and label source
                self.source_patientclass_train = self.network.create_source('PatientInfoFile', id='patientclass_train', node_group='pctrain')
                if self.labels_test:
                    self.source_patientclass_test = self.network.create_source('PatientInfoFile', id='patientclass_test', node_group='pctest')

fastr

Workflow creation and batch execution environment.

Apache-2.0
Latest version published 6 months ago

Package Health Score

47 / 100
Full package analysis