def launch(self, view_model): """ Launch algorithm and build results. """ # --------- Prepare a WaveletCoefficients object for result ----------## frequencies_array = numpy.array([]) if self.algorithm.frequencies is not None: frequencies_array = self.algorithm.frequencies.to_array() time_series_h5 = h5.h5_file_for_index(self.input_time_series_index) assert isinstance(time_series_h5, TimeSeriesH5) wavelet_index = WaveletCoefficientsIndex() dest_path = h5.path_for(self.storage_path, WaveletCoefficientsH5, wavelet_index.gid) wavelet_h5 = WaveletCoefficientsH5(path=dest_path) wavelet_h5.gid.store(uuid.UUID(wavelet_index.gid)) wavelet_h5.source.store(time_series_h5.gid.load()) wavelet_h5.mother.store(self.algorithm.mother) wavelet_h5.q_ratio.store(self.algorithm.q_ratio) wavelet_h5.sample_period.store(self.algorithm.sample_period) wavelet_h5.frequencies.store(frequencies_array) wavelet_h5.normalisation.store(self.algorithm.normalisation) # ------------- NOTE: Assumes 4D, Simulator timeSeries. --------------## node_slice = [ slice(self.input_shape[0]), slice(self.input_shape[1]), None, slice(self.input_shape[3]) ] # ---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries() small_ts.sample_period = time_series_h5.sample_period.load() small_ts.sample_period_unit = time_series_h5.sample_period_unit.load() for node in range(self.input_shape[2]): node_slice[2] = slice(node, node + 1) small_ts.data = time_series_h5.read_data_slice(tuple(node_slice)) self.algorithm.time_series = small_ts partial_wavelet = self.algorithm.evaluate() wavelet_h5.write_data_slice(partial_wavelet) wavelet_h5.close() time_series_h5.close() wavelet_index.fk_source_gid = self.input_time_series_index.gid wavelet_index.mother = self.algorithm.mother wavelet_index.normalisation = self.algorithm.normalisation wavelet_index.q_ratio = self.algorithm.q_ratio wavelet_index.sample_period = self.algorithm.sample_period wavelet_index.number_of_scales = frequencies_array.shape[0] wavelet_index.frequencies_min, wavelet_index.frequencies_max, _ = from_ndarray( frequencies_array) return wavelet_index
def launch(self, view_model): # type: (WaveletAdapterModel) -> (WaveletCoefficientsIndex) """ Launch algorithm and build results. :param view_model: the ViewModel keeping the algorithm inputs :return: the wavelet coefficients for the specified time series """ frequencies_array = numpy.array([]) if view_model.frequencies is not None: frequencies_array = view_model.frequencies.to_array() time_series_h5 = h5.h5_file_for_index(self.input_time_series_index) assert isinstance(time_series_h5, TimeSeriesH5) # --------------------- Prepare result entities ----------------------## wavelet_index = WaveletCoefficientsIndex() dest_path = self.path_for(WaveletCoefficientsH5, wavelet_index.gid) wavelet_h5 = WaveletCoefficientsH5(path=dest_path) # ------------- NOTE: Assumes 4D, Simulator timeSeries. --------------## node_slice = [ slice(self.input_shape[0]), slice(self.input_shape[1]), None, slice(self.input_shape[3]) ] # ---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries() small_ts.sample_period = time_series_h5.sample_period.load() small_ts.sample_period_unit = time_series_h5.sample_period_unit.load() for node in range(self.input_shape[2]): node_slice[2] = slice(node, node + 1) small_ts.data = time_series_h5.read_data_slice(tuple(node_slice)) partial_wavelet = compute_continuous_wavelet_transform( small_ts, view_model.frequencies, view_model.sample_period, view_model.q_ratio, view_model.normalisation, view_model.mother) wavelet_h5.write_data_slice(partial_wavelet) time_series_h5.close() partial_wavelet.source.gid = view_model.time_series partial_wavelet.gid = uuid.UUID(wavelet_index.gid) wavelet_index.fill_from_has_traits(partial_wavelet) self.fill_index_from_h5(wavelet_index, wavelet_h5) wavelet_h5.store(partial_wavelet, scalars_only=True) wavelet_h5.frequencies.store(frequencies_array) wavelet_h5.close() return wavelet_index