def _reconstruct(self, update): data_ll, data_lh, data_hl, data_hh = None, None, None, None node_ll, node_lh, node_hl, node_hh =\ self._get_node(self.LL), self._get_node(self.LH),\ self._get_node(self.HL), self._get_node(self.HH) if node_ll is not None: data_ll = node_ll.reconstruct() if node_lh is not None: data_lh = node_lh.reconstruct() if node_hl is not None: data_hl = node_hl.reconstruct() if node_hh is not None: data_hh = node_hh.reconstruct() if (data_ll is None and data_lh is None and data_hl is None and data_hh is None): raise ValueError( "Tree is missing data - all subnodes of `%s` node " "are None. Cannot reconstruct node." % self.path ) else: coeffs = data_ll, (data_lh, data_hl, data_hh) rec = idwt2(coeffs, self.wavelet, self.mode) if update: self.data = rec return rec
def _reconstruct(self, update): data_ll, data_lh, data_hl, data_hh = None, None, None, None node_ll, node_lh, node_hl, node_hh =\ self._get_node(self.LL), self._get_node(self.LH),\ self._get_node(self.HL), self._get_node(self.HH) if node_ll is not None: data_ll = node_ll.reconstruct() if node_lh is not None: data_lh = node_lh.reconstruct() if node_hl is not None: data_hl = node_hl.reconstruct() if node_hh is not None: data_hh = node_hh.reconstruct() if (data_ll is None and data_lh is None and data_hl is None and data_hh is None): raise ValueError( "Tree is missing data - all subnodes of `%s` node " "are None. Cannot reconstruct node." % self.path) else: coeffs = data_ll, (data_lh, data_hl, data_hh) rec = idwt2(coeffs, self.wavelet, self.mode) if update: self.data = rec return rec
def waverec2(coeffs, wavelet, mode='sym'): """ Multilevel 2D Inverse Discrete Wavelet Transform. coeffs - coefficients list [cAn, (cHn, cVn, cDn), ... (cH1, cV1, cD1)] wavelet - wavelet to use (Wavelet object or name string) mode - signal extension mode, see MODES Returns 2D array of reconstructed data. """ if not isinstance(coeffs, (list, tuple)): raise ValueError("Expected sequence of coefficient arrays.") if len(coeffs) < 2: raise ValueError("Coefficient list too short (minimum 2 arrays required).") a, ds = coeffs[0], coeffs[1:] for d in ds: a = idwt2((a, d), wavelet, mode) return a
def waverec2(coeffs, wavelet, mode='sym'): """ Multilevel 2D Inverse Discrete Wavelet Transform. coeffs - coefficients list [cAn, (cHn, cVn, cDn), ... (cH1, cV1, cD1)] wavelet - wavelet to use (Wavelet object or name string) mode - signal extension mode, see MODES Returns 2D array of reconstructed data. """ if not isinstance(coeffs, (list, tuple)): raise ValueError("Expected sequence of coefficient arrays.") if len(coeffs) < 2: raise ValueError( "Coefficient list too short (minimum 2 arrays required).") a, ds = coeffs[0], coeffs[1:] for d in ds: a = idwt2((a, d), wavelet, mode) return a