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)
| 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 |