class MatlabAdapter(ABCGroupAdapter):
    """
    Interface between Brain Connectivity Toolbox of Olaf Sporns and TVB Framework.
    This adapter requires BCT and Matlab deployed locally.
    """

    def __init__(self, xml_file_path):
        ABCGroupAdapter.__init__(self, xml_file_path)
        self.matlab_worker = MatlabWorker()

    @staticmethod
    def can_be_active():
        return not not TvbProfile.current.MATLAB_EXECUTABLE

    def get_required_memory_size(self, **kwargs):
        """
        Return the required memory to run this algorithm.
        """
        # Don't know how much memory is needed.
        return -1

    def get_required_disk_size(self, **kwargs):
        """
        Returns the required disk size to be able to run the adapter (in kB).
        """
        return 0

    def get_matlab_file_root(self):
        """
        Return the root folder in which the matlab files are stored.
        """
        return self.xml_reader.get_additional_path()

    def launch(self, **kwargs):
        """
        Pick the correct algorithm to use, and launch the MATLAB call. 
        After computation, make sure the correct results are returned.
        """
        # Read selected Algorithm identifier, from input arguments
        bct_storage = self.xml_reader.get_additional_path()
        if bct_storage is not None:
            self.matlab_worker.add_to_path(bct_storage)
        algorithm, kwargs = self.get_algorithm_and_attributes(**kwargs)

        # Execute MATLAB code
        mat_code = self.get_call_code(algorithm)
        self.log.info("Starting execution of MATLAB code:" + mat_code)
        runcode, matlablog, result = self.matlab_worker.matlab(mat_code, kwargs)
        self.log.debug("Code run in MATLAB: " + str(runcode))
        self.log.debug("MATLAB log: " + str(matlablog))
        self.log.debug("Finished MATLAB execution:" + str(result))

        # Now build PYTHON result objects
        return self.build_result(algorithm, result, kwargs)
示例#2
0
 def __init__(self):
     ABCAsynchronous.__init__(self)
     self.matlab_worker = MatlabWorker()
示例#3
0
class BaseBCT(ABCAsynchronous):
    """
    Interface between Brain Connectivity Toolbox of Olaf Sporns and TVB Framework.
    This adapter requires BCT deployed locally, and Matlab or Octave installed separately of TVB.
    """
    def __init__(self):
        ABCAsynchronous.__init__(self)
        self.matlab_worker = MatlabWorker()

    @staticmethod
    def can_be_active():
        return not not TvbProfile.current.MATLAB_EXECUTABLE

    def get_form_class(self):
        return BaseBCTForm

    def get_output(self):
        return [ConnectivityMeasureIndex, ValueWrapperIndex]

    def get_required_memory_size(self, view_model):
        # We do not know how much memory is needed.
        return -1

    def get_required_disk_size(self, view_model):
        return 0

    def get_connectivity(self, view_model):
        conn_index = load_entity_by_gid(view_model.connectivity.hex)
        return h5.load_from_index(conn_index)

    def execute_matlab(self, matlab_code, data):
        self.matlab_worker.add_to_path(BCT_PATH)
        self.log.info("Starting execution of MATLAB code:" + matlab_code)
        runcode, matlablog, result = self.matlab_worker.matlab(matlab_code,
                                                               data=data)
        self.log.debug("Code run in MATLAB: " + str(runcode))
        self.log.debug("MATLAB log: " + str(matlablog))
        self.log.debug("Finished MATLAB execution:" + str(result))
        return result

    def build_connectivity_measure(self,
                                   result,
                                   key,
                                   connectivity,
                                   title="",
                                   label_x="",
                                   label_y=""):
        measure = ConnectivityMeasure()
        measure.array_data = result[key]
        measure.connectivity = connectivity
        measure.title = title
        measure.label_x = label_x
        measure.label_y = label_y
        return h5.store_complete(measure, self.storage_path)

    def build_float_value_wrapper(self, result, key, title=""):
        value = ValueWrapperIndex()
        value.data_value = float(result[key])
        value.data_type = 'float'
        value.data_name = title
        return value

    def build_int_value_wrapper(self, result, key, title=""):
        value = ValueWrapperIndex()
        value.data_value = int(result[key])
        value.data_type = 'int'
        value.data_name = title
        return value

    @abstractmethod
    def launch(self, view_model):
        pass
示例#4
0
 def __init__(self):
     ABCAdapter.__init__(self)
     self.matlab_worker = MatlabWorker()
示例#5
0
 def __init__(self):
     ABCAsynchronous.__init__(self)
     self.matlab_worker = MatlabWorker()
示例#6
0
class BaseBCT(ABCAsynchronous):
    """
    Interface between Brain Connectivity Toolbox of Olaf Sporns and TVB Framework.
    This adapter requires BCT deployed locally, and Matlab or Octave installed separately of TVB.
    """
    _ui_connectivity_label = "Connection matrix:"


    def __init__(self):
        ABCAsynchronous.__init__(self)
        self.matlab_worker = MatlabWorker()


    @staticmethod
    def can_be_active():
        return not not TvbProfile.current.MATLAB_EXECUTABLE


    def get_input_tree(self):
        return [dict(name="connectivity", label=self._ui_connectivity_label, type=Connectivity, required=True)]


    def get_output(self):
        return [ConnectivityMeasure, ValueWrapper]


    def get_required_memory_size(self, **kwargs):
        # We do not know how much memory is needed.
        return -1


    def get_required_disk_size(self, **kwargs):
        return 0


    def execute_matlab(self, matlab_code, **kwargs):
        self.matlab_worker.add_to_path(BCT_PATH)
        self.log.info("Starting execution of MATLAB code:" + matlab_code)
        runcode, matlablog, result = self.matlab_worker.matlab(matlab_code, kwargs)
        self.log.debug("Code run in MATLAB: " + str(runcode))
        self.log.debug("MATLAB log: " + str(matlablog))
        self.log.debug("Finished MATLAB execution:" + str(result))
        return result


    def build_connectivity_measure(self, result, key, connectivity, title="", label_x="", label_y=""):
        measure = ConnectivityMeasure(storage_path=self.storage_path)
        measure.array_data = result[key]
        measure.connectivity = connectivity
        measure.title = title
        measure.label_x = label_x
        measure.label_y = label_y
        return measure


    def build_float_value_wrapper(self, result, key, title=""):
        value = ValueWrapper(storage_path=self.storage_path)
        value.data_value = float(result[key])
        value.data_type = 'float'
        value.data_name = title
        return value


    def build_int_value_wrapper(self, result, key, title=""):
        value = ValueWrapper(storage_path=self.storage_path)
        value.data_value = int(result[key])
        value.data_type = 'int'
        value.data_name = title
        return value


    @abstractmethod
    def launch(self, connectivity, **kwargs):
        pass
示例#7
0
class BaseBCT(ABCAsynchronous):
    """
    Interface between Brain Connectivity Toolbox of Olaf Sporns and TVB Framework.
    This adapter requires BCT deployed locally, and Matlab or Octave installed separately of TVB.
    """
    _ui_connectivity_label = "Connection matrix:"

    def __init__(self):
        ABCAsynchronous.__init__(self)
        self.matlab_worker = MatlabWorker()

    @staticmethod
    def can_be_active():
        return not not TvbProfile.current.MATLAB_EXECUTABLE

    def get_input_tree(self):
        return [
            dict(name="connectivity",
                 label=self._ui_connectivity_label,
                 type=Connectivity,
                 required=True)
        ]

    def get_output(self):
        return [ConnectivityMeasure, ValueWrapper]

    def get_required_memory_size(self, **kwargs):
        # We do not know how much memory is needed.
        return -1

    def get_required_disk_size(self, **kwargs):
        return 0

    def execute_matlab(self, matlab_code, **kwargs):
        self.matlab_worker.add_to_path(BCT_PATH)
        self.log.info("Starting execution of MATLAB code:" + matlab_code)
        runcode, matlablog, result = self.matlab_worker.matlab(
            matlab_code, kwargs)
        self.log.debug("Code run in MATLAB: " + str(runcode))
        self.log.debug("MATLAB log: " + str(matlablog))
        self.log.debug("Finished MATLAB execution:" + str(result))
        return result

    def build_connectivity_measure(self,
                                   result,
                                   key,
                                   connectivity,
                                   title="",
                                   label_x="",
                                   label_y=""):
        measure = ConnectivityMeasure(storage_path=self.storage_path)
        measure.array_data = result[key]
        measure.connectivity = connectivity
        measure.title = title
        measure.label_x = label_x
        measure.label_y = label_y
        return measure

    def build_float_value_wrapper(self, result, key, title=""):
        value = ValueWrapper(storage_path=self.storage_path)
        value.data_value = float(result[key])
        value.data_type = 'float'
        value.data_name = title
        return value

    def build_int_value_wrapper(self, result, key, title=""):
        value = ValueWrapper(storage_path=self.storage_path)
        value.data_value = int(result[key])
        value.data_type = 'int'
        value.data_name = title
        return value

    @abstractmethod
    def launch(self, connectivity, **kwargs):
        pass
 def __init__(self, xml_file_path):
     ABCGroupAdapter.__init__(self, xml_file_path)
     self.matlab_worker = MatlabWorker()