CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
_readers.py213 linesDownload Raw Back to data
1import functools
2import importlib.resources
3import os
4
5import numpy as np
6
7_DATADIR = importlib.resources.files('pywt.data')
8
9
10@functools.cache
11def ascent():
12    """
13    Get an 8-bit grayscale bit-depth, 512 x 512 derived image for
14    easy use in demos
15
16    The image is derived from accent-to-the-top.jpg at
17    http://www.public-domain-image.com/people-public-domain-images-pictures/
18
19    Parameters
20    ----------
21    None
22
23    Returns
24    -------
25    ascent : ndarray
26       convenient image to use for testing and demonstration
27
28    Examples
29    --------
30    >>> import pywt.data
31    >>> ascent = pywt.data.ascent()
32    >>> ascent.shape == (512, 512)
33    True
34    >>> ascent.max()
35    255
36
37    >>> import matplotlib.pyplot as plt
38    >>> plt.gray()
39    >>> plt.imshow(ascent)
40    <matplotlib.image.AxesImage object at ...>
41    >>> plt.show()
42
43    """
44    with importlib.resources.as_file(_DATADIR.joinpath('ascent.npz')) as f:
45        ascent = np.load(f)['data']
46
47    return ascent
48
49
50@functools.cache
51def aero():
52    """
53    Get an 8-bit grayscale bit-depth, 512 x 512 derived image for
54    easy use in demos
55
56    Parameters
57    ----------
58    None
59
60    Returns
61    -------
62    aero : ndarray
63       convenient image to use for testing and demonstration
64
65    Examples
66    --------
67    >>> import pywt.data
68    >>> aero = pywt.data.ascent()
69    >>> aero.shape == (512, 512)
70    True
71    >>> aero.max()
72    255
73
74    >>> import matplotlib.pyplot as plt
75    >>> plt.gray()
76    >>> plt.imshow(aero)
77    <matplotlib.image.AxesImage object at ...>
78    >>> plt.show()
79
80    """
81    with importlib.resources.as_file(_DATADIR.joinpath('aero.npz')) as f:
82        aero = np.load(f)['data']
83
84    return aero
85
86
87@functools.cache
88def camera():
89    """
90    Get an 8-bit grayscale bit-depth, 512 x 512 derived image for
91    easy use in demos
92
93    Parameters
94    ----------
95    None
96
97    Returns
98    -------
99    camera : ndarray
100       convenient image to use for testing and demonstration
101
102    Notes
103    -----
104    No copyright restrictions. CC0 by the photographer (Lav Varshney).
105
106    .. versionchanged:: 0.18
107        This image was replaced due to copyright restrictions. For more
108        information, please see [1]_, where the same change was made in
109        scikit-image.
110
111    References
112    ----------
113    .. [1] https://github.com/scikit-image/scikit-image/issues/3927
114
115    Examples
116    --------
117    >>> import pywt.data
118    >>> camera = pywt.data.ascent()
119    >>> camera.shape == (512, 512)
120    True
121
122    >>> import matplotlib.pyplot as plt
123    >>> plt.gray()
124    >>> plt.imshow(camera)
125    <matplotlib.image.AxesImage object at ...>
126    >>> plt.show()
127
128    """
129    with importlib.resources.as_file(_DATADIR.joinpath('camera.npz')) as f:
130        camera = np.load(f)['data']
131
132    return camera
133
134
135@functools.cache
136def ecg():
137    """
138    Get 1024 points of an ECG timeseries.
139
140    Parameters
141    ----------
142    None
143
144    Returns
145    -------
146    ecg : ndarray
147       convenient timeseries to use for testing and demonstration
148
149    Examples
150    --------
151    >>> import pywt.data
152    >>> ecg = pywt.data.ecg()
153    >>> ecg.shape == (1024,)
154    True
155
156    >>> import matplotlib.pyplot as plt
157    >>> plt.plot(ecg)
158    [<matplotlib.lines.Line2D object at ...>]
159    >>> plt.show()
160    """
161    with importlib.resources.as_file(_DATADIR.joinpath('ecg.npz')) as f:
162        ecg = np.load(f)['data']
163
164    return ecg
165
166
167@functools.cache
168def nino():
169    """
170    This data contains the averaged monthly sea surface temperature in degrees
171    Celsius of the Pacific Ocean, between 0-10 degrees South and 90-80 degrees West, from 1950 to 2016.
172    This dataset is in the public domain and was obtained from NOAA.
173    National Oceanic and Atmospheric Administration's National Weather Service
174    ERSSTv4 dataset, nino 3, http://www.cpc.ncep.noaa.gov/data/indices/
175
176    Parameters
177    ----------
178    None
179
180    Returns
181    -------
182    time : ndarray
183       convenient timeseries to use for testing and demonstration
184    sst : ndarray
185       convenient timeseries to use for testing and demonstration
186
187    Examples
188    --------
189    >>> import pywt.data
190    >>> time, sst = pywt.data.nino()
191    >>> sst.shape == (264,)
192    True
193
194    >>> import matplotlib.pyplot as plt
195    >>> plt.plot(time,sst)
196    [<matplotlib.lines.Line2D object at ...>]
197    >>> plt.show()
198    """
199    with importlib.resources.as_file(_DATADIR.joinpath('sst_nino3.npz')) as f:
200        sst_csv = np.load(f)['data']
201
202    # sst_csv = pd.read_csv("http://www.cpc.ncep.noaa.gov/data/indices/ersst4.nino.mth.81-10.ascii", sep=' ', skipinitialspace=True)
203    # take only full years
204    n = int(np.floor(sst_csv.shape[0]/12.)*12.)
205    # Building the mean of three months
206    # the 4. column is nino 3
207    sst = np.mean(np.reshape(np.array(sst_csv)[:n, 4], (n//3, -1)), axis=1)
208    sst = (sst - np.mean(sst)) / np.std(sst, ddof=1)
209
210    dt = 0.25
211    time = np.arange(len(sst)) * dt + 1950.0  # construct time array
212    return time, sst
213 
Aluode/PerceptionLabPortable · CoolFace