Exemple #1
0
    def build():
        data = numpy.random.random((10, 10, 10, 10))
        time_series_index = time_series_index_factory(data=data)
        time_series = h5.load_from_index(time_series_index)
        n_comp = 5
        ica = mode_decompositions.IndependentComponents(source=time_series,
                                    component_time_series=numpy.random.random((10, n_comp, 10, 10)),
                                    prewhitening_matrix=numpy.random.random((n_comp, 10, 10, 10)),
                                    unmixing_matrix=numpy.random.random((n_comp, n_comp, 10, 10)),
                                    n_components=n_comp)
        ica.compute_norm_source()
        ica.compute_normalised_component_time_series()

        op = operation_factory()

        ica_index = IndependentComponentsIndex()
        ica_index.fk_from_operation = op.id
        ica_index.fill_from_has_traits(ica)

        independent_components_h5_path = h5.path_for_stored_index(ica_index)
        with IndependentComponentsH5(independent_components_h5_path) as f:
            f.store(ica)

        ica_index = dao.store_entity(ica_index)
        return ica_index
Exemple #2
0
    def launch(self, time_series, n_components=None):
        """ 
        Launch algorithm and build results. 
        """
        # --------- Prepare a IndependentComponents object for result ----------##
        ica_index = IndependentComponentsIndex()
        ica_index.source_gid = time_series.gid

        time_series_h5 = h5.h5_file_for_index(time_series)

        result_path = h5.path_for(self.storage_path, IndependentComponentsH5, ica_index.gid)
        ica_h5 = IndependentComponentsH5(path=result_path)
        ica_h5.gid.store(uuid.UUID(ica_index.gid))
        ica_h5.source.store(time_series_h5.gid.load())
        ica_h5.n_components.store(self.algorithm.n_components)

        # ------------- NOTE: Assumes 4D, Simulator timeSeries. --------------##
        input_shape = time_series_h5.data.shape
        node_slice = [slice(input_shape[0]), None, slice(input_shape[2]), slice(input_shape[3])]

        # ---------- Iterate over slices and compose final result ------------##
        small_ts = TimeSeries()
        for var in range(input_shape[1]):
            node_slice[1] = slice(var, var + 1)
            small_ts.data = time_series_h5.read_data_slice(tuple(node_slice))
            self.algorithm.time_series = small_ts
            partial_ica = self.algorithm.evaluate()
            ica_h5.write_data_slice(partial_ica)
        ica_h5.close()
        time_series_h5.close()

        return ica_index
Exemple #3
0
    def launch(self, view_model):
        # type: (ICAAdapterModel) -> [IndependentComponentsIndex]
        """
        Launch algorithm and build results.
        :param view_model: the ViewModel keeping the algorithm inputs
        :return: the ica index for the specified time series
        """
        # --------------------- Prepare result entities ---------------------##
        ica_index = IndependentComponentsIndex()
        result_path = h5.path_for(self.storage_path, IndependentComponentsH5,
                                  ica_index.gid)
        ica_h5 = IndependentComponentsH5(path=result_path)

        # ------------- NOTE: Assumes 4D, Simulator timeSeries. --------------##
        time_series_h5 = h5.h5_file_for_index(self.input_time_series_index)
        input_shape = time_series_h5.data.shape
        node_slice = [
            slice(input_shape[0]), None,
            slice(input_shape[2]),
            slice(input_shape[3])
        ]

        # ---------- Iterate over slices and compose final result ------------##
        small_ts = TimeSeries()
        for var in range(input_shape[1]):
            node_slice[1] = slice(var, var + 1)
            small_ts.data = time_series_h5.read_data_slice(tuple(node_slice))
            partial_ica = compute_ica_decomposition(small_ts,
                                                    view_model.n_components)
            ica_h5.write_data_slice(partial_ica)

        time_series_h5.close()

        partial_ica.source.gid = view_model.time_series
        partial_ica.gid = uuid.UUID(ica_index.gid)

        ica_h5.store(partial_ica, scalars_only=True)
        ica_h5.close()

        ica_index.fill_from_has_traits(partial_ica)

        return ica_index
    def launch(self, view_model):
        # type: (ICAAdapterModel) -> [IndependentComponentsIndex]
        """ 
        Launch algorithm and build results. 
        """
        # --------- Prepare a IndependentComponents object for result ----------##
        ica_index = IndependentComponentsIndex()
        ica_index.fk_source_gid = view_model.time_series.hex

        time_series_h5 = h5.h5_file_for_index(self.input_time_series_index)

        result_path = h5.path_for(self.storage_path, IndependentComponentsH5,
                                  ica_index.gid)
        ica_h5 = IndependentComponentsH5(path=result_path)
        ica_h5.gid.store(uuid.UUID(ica_index.gid))
        ica_h5.source.store(view_model.time_series)
        ica_h5.n_components.store(self.algorithm.n_components)

        # ------------- NOTE: Assumes 4D, Simulator timeSeries. --------------##
        input_shape = time_series_h5.data.shape
        node_slice = [
            slice(input_shape[0]), None,
            slice(input_shape[2]),
            slice(input_shape[3])
        ]

        # ---------- Iterate over slices and compose final result ------------##
        small_ts = TimeSeries()
        for var in range(input_shape[1]):
            node_slice[1] = slice(var, var + 1)
            small_ts.data = time_series_h5.read_data_slice(tuple(node_slice))
            self.algorithm.time_series = small_ts
            partial_ica = self.algorithm.evaluate()
            ica_h5.write_data_slice(partial_ica)
        array_metadata = ica_h5.unmixing_matrix.get_cached_metadata()
        ica_index.array_has_complex = array_metadata.has_complex
        ica_index.shape = json.dumps(ica_h5.unmixing_matrix.shape)
        ica_index.ndim = len(ica_h5.unmixing_matrix.shape)
        ica_h5.close()
        time_series_h5.close()

        return ica_index