MCPcopy Create free account
hub / github.com/PyWavelets/pywt / get_level

Method get_level

pywt/_wavelet_packets.py:750–806  ·  view source on GitHub ↗

Returns all nodes on the specified level. Parameters ---------- level : int Specifies decomposition `level` from which the nodes will be collected. order : {'natural', 'freq'}, optional - "natural" - left to right in tree

(self, level, order="natural", decompose=True)

Source from the content-addressed store, hash-verified

748 return self.data # return original data
749
750 def get_level(self, level, order="natural", decompose=True):
751 """
752 Returns all nodes on the specified level.
753
754 Parameters
755 ----------
756 level : int
757 Specifies decomposition `level` from which the nodes will be
758 collected.
759 order : {'natural', 'freq'}, optional
760 - "natural" - left to right in tree (default)
761 - "freq" - band ordered
762 decompose : bool, optional
763 If set then the method will try to decompose the data up
764 to the specified `level` (default: True).
765
766 Notes
767 -----
768 If nodes at the given level are missing (i.e. the tree is partially
769 decomposed) and `decompose` is set to False, only existing nodes
770 will be returned.
771
772 Frequency order (``order="freq"``) is also known as sequency order
773 and "natural" order is sometimes referred to as Paley order. A detailed
774 discussion of these orderings is also given in [1]_, [2]_.
775
776 References
777 ----------
778 ..[1] M.V. Wickerhauser. Adapted Wavelet Analysis from Theory to
779 Software. Wellesley. Massachusetts: A K Peters. 1994.
780 ..[2] D.B. Percival and A.T. Walden. Wavelet Methods for Time Series
781 Analysis. Cambridge University Press. 2000.
782 DOI:10.1017/CBO9780511841040
783 """
784 if order not in ["natural", "freq"]:
785 raise ValueError(f"Invalid order: {order}")
786 if level > self.maxlevel:
787 raise ValueError("The level cannot be greater than the maximum"
788 " decomposition level value (%d)" % self.maxlevel)
789
790 result = []
791
792 def collect(node):
793 if node.level == level:
794 result.append(node)
795 return False
796 return True
797
798 self.walk(collect, decompose=decompose)
799 if order == "natural":
800 return result
801 elif order == "freq":
802 result = {node.path: node for node in result}
803 graycode_order = get_graycode_order(level)
804 return [result[path] for path in graycode_order if path in result]
805 else:
806 raise ValueError(f"Invalid order name - {order}.")
807

Callers 8

test_collecting_nodesFunction · 0.95
test_removing_nodesFunction · 0.95
test_wavelet_packet_axisFunction · 0.95
wp_scalogram.pyFile · 0.45
wp_2d.pyFile · 0.45
wp_nd.pyFile · 0.45

Calls 2

get_graycode_orderFunction · 0.85
walkMethod · 0.80

Tested by 4

test_collecting_nodesFunction · 0.76
test_removing_nodesFunction · 0.76
test_wavelet_packet_axisFunction · 0.76