|
1 | 1 | import functools |
2 | | -import importlib |
| 2 | +import importlib.resources |
3 | 3 | import os |
4 | 4 |
|
5 | 5 | import numpy as np |
6 | 6 |
|
7 | 7 |
|
| 8 | +_DATADIR = importlib.resources.files('pywt.data') |
| 9 | + |
| 10 | + |
8 | 11 | @functools.cache |
9 | 12 | def ascent(): |
10 | 13 | """ |
@@ -39,8 +42,7 @@ def ascent(): |
39 | 42 | >>> plt.show() # doctest: +SKIP |
40 | 43 |
|
41 | 44 | """ |
42 | | - _datadir = importlib.resources.files('pywt.data') |
43 | | - with importlib.resources.as_file(_datadir.joinpath('ascent.npz')) as f: |
| 45 | + with importlib.resources.as_file(_DATADIR.joinpath('ascent.npz')) as f: |
44 | 46 | ascent = np.load(f)['data'] |
45 | 47 |
|
46 | 48 | return ascent |
@@ -77,8 +79,7 @@ def aero(): |
77 | 79 | >>> plt.show() # doctest: +SKIP |
78 | 80 |
|
79 | 81 | """ |
80 | | - _datadir = importlib.resources.files('pywt.data') |
81 | | - with importlib.resources.as_file(_datadir.joinpath('aero.npz')) as f: |
| 82 | + with importlib.resources.as_file(_DATADIR.joinpath('aero.npz')) as f: |
82 | 83 | aero = np.load(f)['data'] |
83 | 84 |
|
84 | 85 | return aero |
@@ -126,8 +127,7 @@ def camera(): |
126 | 127 | >>> plt.show() # doctest: +SKIP |
127 | 128 |
|
128 | 129 | """ |
129 | | - _datadir = importlib.resources.files('pywt.data') |
130 | | - with importlib.resources.as_file(_datadir.joinpath('camera.npz')) as f: |
| 130 | + with importlib.resources.as_file(_DATADIR.joinpath('camera.npz')) as f: |
131 | 131 | camera = np.load(f)['data'] |
132 | 132 |
|
133 | 133 | return camera |
@@ -159,8 +159,7 @@ def ecg(): |
159 | 159 | [<matplotlib.lines.Line2D object at ...>] |
160 | 160 | >>> plt.show() # doctest: +SKIP |
161 | 161 | """ |
162 | | - _datadir = importlib.resources.files('pywt.data') |
163 | | - with importlib.resources.as_file(_datadir.joinpath('ecg.npz')) as f: |
| 162 | + with importlib.resources.as_file(_DATADIR.joinpath('ecg.npz')) as f: |
164 | 163 | ecg = np.load(f)['data'] |
165 | 164 |
|
166 | 165 | return ecg |
@@ -198,8 +197,7 @@ def nino(): |
198 | 197 | [<matplotlib.lines.Line2D object at ...>] |
199 | 198 | >>> plt.show() # doctest: +SKIP |
200 | 199 | """ |
201 | | - _datadir = importlib.resources.files('pywt.data') |
202 | | - with importlib.resources.as_file(_datadir.joinpath('sst_nino3.npz')) as f: |
| 200 | + with importlib.resources.as_file(_DATADIR.joinpath('sst_nino3.npz')) as f: |
203 | 201 | sst_csv = np.load(f)['data'] |
204 | 202 |
|
205 | 203 | # sst_csv = pd.read_csv("http://www.cpc.ncep.noaa.gov/data/indices/ersst4.nino.mth.81-10.ascii", sep=' ', skipinitialspace=True) |
|
0 commit comments