Skip to content

Commit 7315b43

Browse files
import importlib.resources, mark /pywt/data/ as constant
1 parent dedac16 commit 7315b43

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

pywt/data/_readers.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import functools
2-
import importlib
2+
import importlib.resources
33
import os
44

55
import numpy as np
66

77

8+
_DATADIR = importlib.resources.files('pywt.data')
9+
10+
811
@functools.cache
912
def ascent():
1013
"""
@@ -39,8 +42,7 @@ def ascent():
3942
>>> plt.show() # doctest: +SKIP
4043
4144
"""
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:
4446
ascent = np.load(f)['data']
4547

4648
return ascent
@@ -77,8 +79,7 @@ def aero():
7779
>>> plt.show() # doctest: +SKIP
7880
7981
"""
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:
8283
aero = np.load(f)['data']
8384

8485
return aero
@@ -126,8 +127,7 @@ def camera():
126127
>>> plt.show() # doctest: +SKIP
127128
128129
"""
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:
131131
camera = np.load(f)['data']
132132

133133
return camera
@@ -159,8 +159,7 @@ def ecg():
159159
[<matplotlib.lines.Line2D object at ...>]
160160
>>> plt.show() # doctest: +SKIP
161161
"""
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:
164163
ecg = np.load(f)['data']
165164

166165
return ecg
@@ -198,8 +197,7 @@ def nino():
198197
[<matplotlib.lines.Line2D object at ...>]
199198
>>> plt.show() # doctest: +SKIP
200199
"""
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:
203201
sst_csv = np.load(f)['data']
204202

205203
# 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

Comments
 (0)