Returns all nodes from specified level. Parameters ---------- level : int Decomposition `level` from which the nodes will be collected. order : {'natural', 'freq'}, optional If `natural` (default) a flat list is returned.
(self, level, order="natural", decompose=True)
| 874 | return self.data # return original data |
| 875 | |
| 876 | def get_level(self, level, order="natural", decompose=True): |
| 877 | """ |
| 878 | Returns all nodes from specified level. |
| 879 | |
| 880 | Parameters |
| 881 | ---------- |
| 882 | level : int |
| 883 | Decomposition `level` from which the nodes will be |
| 884 | collected. |
| 885 | order : {'natural', 'freq'}, optional |
| 886 | If `natural` (default) a flat list is returned. |
| 887 | If `freq`, a 2d structure with rows and cols |
| 888 | sorted by corresponding dimension frequency of 2d |
| 889 | coefficient array (adapted from 1d case). |
| 890 | decompose : bool, optional |
| 891 | If set then the method will try to decompose the data up |
| 892 | to the specified `level` (default: True). |
| 893 | |
| 894 | Notes |
| 895 | ----- |
| 896 | Frequency order (``order="freq"``) is also known as as sequency order |
| 897 | and "natural" order is sometimes referred to as Paley order. A detailed |
| 898 | discussion of these orderings is also given in [1]_, [2]_. |
| 899 | |
| 900 | References |
| 901 | ---------- |
| 902 | ..[1] M.V. Wickerhauser. Adapted Wavelet Analysis from Theory to |
| 903 | Software. Wellesley. Massachusetts: A K Peters. 1994. |
| 904 | ..[2] D.B. Percival and A.T. Walden. Wavelet Methods for Time Series |
| 905 | Analysis. Cambridge University Press. 2000. |
| 906 | DOI:10.1017/CBO9780511841040 |
| 907 | """ |
| 908 | if order not in ["natural", "freq"]: |
| 909 | raise ValueError(f"Invalid order: {order}") |
| 910 | if level > self.maxlevel: |
| 911 | raise ValueError("The level cannot be greater than the maximum" |
| 912 | " decomposition level value (%d)" % self.maxlevel) |
| 913 | |
| 914 | result = [] |
| 915 | |
| 916 | def collect(node): |
| 917 | if node.level == level: |
| 918 | result.append(node) |
| 919 | return False |
| 920 | return True |
| 921 | |
| 922 | self.walk(collect, decompose=decompose) |
| 923 | |
| 924 | if order == "freq": |
| 925 | nodes = {} |
| 926 | for (row_path, col_path), node in [ |
| 927 | (self.expand_2d_path(node.path), node) for node in result |
| 928 | ]: |
| 929 | nodes.setdefault(row_path, {})[col_path] = node |
| 930 | graycode_order = get_graycode_order(level, x='l', y='h') |
| 931 | nodes = [nodes[path] for path in graycode_order if path in nodes] |
| 932 | result = [] |
| 933 | for row in nodes: |