py2ls 0.1.4.9__py3-none-any.whl → 0.1.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py2ls/stdshade.py
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
from scipy.signal import savgol_filter
|
2
|
+
import numpy as np
|
3
|
+
import matplotlib.pyplot as plt
|
4
|
+
|
5
|
+
def stdshade(ax=None,*args, **kwargs):
|
6
|
+
|
7
|
+
def hue2rgb(hex_colors):
|
8
|
+
def hex_to_rgb(hex_color):
|
9
|
+
"""Converts a hexadecimal color code to RGB values."""
|
10
|
+
if hex_colors.startswith("#"):
|
11
|
+
hex_color = hex_color.lstrip("#")
|
12
|
+
return tuple(int(hex_color[i : i + 2], 16) / 255.0 for i in (0, 2, 4))
|
13
|
+
if isinstance(hex_colors, str):
|
14
|
+
return hex_to_rgb(hex_colors)
|
15
|
+
elif isinstance(hex_colors, (list)):
|
16
|
+
"""Converts a list of hexadecimal color codes to a list of RGB values."""
|
17
|
+
rgb_values = [hex_to_rgb(hex_color) for hex_color in hex_colors]
|
18
|
+
return rgb_values
|
19
|
+
if (
|
20
|
+
isinstance(ax, np.ndarray)
|
21
|
+
and ax.ndim == 2
|
22
|
+
and min(ax.shape) > 1
|
23
|
+
and max(ax.shape) > 1
|
24
|
+
):
|
25
|
+
y = ax
|
26
|
+
ax = plt.gca()
|
27
|
+
if ax is None:
|
28
|
+
ax = plt.gca()
|
29
|
+
alpha = 0.5
|
30
|
+
acolor = "k"
|
31
|
+
paraStdSem = "sem"
|
32
|
+
plotStyle = "-"
|
33
|
+
plotMarker = "none"
|
34
|
+
smth = 1
|
35
|
+
l_c_one = ["r", "g", "b", "m", "c", "y", "k", "w"]
|
36
|
+
l_style2 = ["--", "-."]
|
37
|
+
l_style1 = ["-", ":"]
|
38
|
+
l_mark = ["o", "+", "*", ".", "x", "_", "|", "s", "d", "^", "v", ">", "<", "p", "h"]
|
39
|
+
# Check each argument
|
40
|
+
for iarg in range(len(args)):
|
41
|
+
if (
|
42
|
+
isinstance(args[iarg], np.ndarray)
|
43
|
+
and args[iarg].ndim == 2
|
44
|
+
and min(args[iarg].shape) > 1
|
45
|
+
and max(args[iarg].shape) > 1
|
46
|
+
):
|
47
|
+
y = args[iarg]
|
48
|
+
# Except y, continuous data is 'F'
|
49
|
+
if (isinstance(args[iarg], np.ndarray) and args[iarg].ndim == 1) or isinstance(
|
50
|
+
args[iarg], range
|
51
|
+
):
|
52
|
+
x = args[iarg]
|
53
|
+
if isinstance(x, range):
|
54
|
+
x = np.arange(start=x.start, stop=x.stop, step=x.step)
|
55
|
+
# Only one number( 0~1), 'alpha' / color
|
56
|
+
if isinstance(args[iarg], (int, float)):
|
57
|
+
if np.size(args[iarg]) == 1 and 0 <= args[iarg] <= 1:
|
58
|
+
alpha = args[iarg]
|
59
|
+
if isinstance(args[iarg], (list, tuple)) and np.size(args[iarg]) == 3:
|
60
|
+
acolor = args[iarg]
|
61
|
+
acolor = tuple(acolor) if isinstance(acolor, list) else acolor
|
62
|
+
# Color / plotStyle /
|
63
|
+
if (
|
64
|
+
isinstance(args[iarg], str)
|
65
|
+
and len(args[iarg]) == 1
|
66
|
+
and args[iarg] in l_c_one
|
67
|
+
):
|
68
|
+
acolor = args[iarg]
|
69
|
+
else:
|
70
|
+
if isinstance(args[iarg], str):
|
71
|
+
if args[iarg] in ["sem", "std"]:
|
72
|
+
paraStdSem = args[iarg]
|
73
|
+
if args[iarg].startswith("#"):
|
74
|
+
acolor=hue2rgb(args[iarg])
|
75
|
+
if str2list(args[iarg])[0] in l_c_one:
|
76
|
+
if len(args[iarg]) == 3:
|
77
|
+
k = [i for i in str2list(args[iarg]) if i in l_c_one]
|
78
|
+
if k != []:
|
79
|
+
acolor = k[0]
|
80
|
+
st = [i for i in l_style2 if i in args[iarg]]
|
81
|
+
if st != []:
|
82
|
+
plotStyle = st[0]
|
83
|
+
elif len(args[iarg]) == 2:
|
84
|
+
k = [i for i in str2list(args[iarg]) if i in l_c_one]
|
85
|
+
if k != []:
|
86
|
+
acolor = k[0]
|
87
|
+
mk = [i for i in str2list(args[iarg]) if i in l_mark]
|
88
|
+
if mk != []:
|
89
|
+
plotMarker = mk[0]
|
90
|
+
st = [i for i in l_style1 if i in args[iarg]]
|
91
|
+
if st != []:
|
92
|
+
plotStyle = st[0]
|
93
|
+
if len(args[iarg]) == 1:
|
94
|
+
k = [i for i in str2list(args[iarg]) if i in l_c_one]
|
95
|
+
if k != []:
|
96
|
+
acolor = k[0]
|
97
|
+
mk = [i for i in str2list(args[iarg]) if i in l_mark]
|
98
|
+
if mk != []:
|
99
|
+
plotMarker = mk[0]
|
100
|
+
st = [i for i in l_style1 if i in args[iarg]]
|
101
|
+
if st != []:
|
102
|
+
plotStyle = st[0]
|
103
|
+
if len(args[iarg]) == 2:
|
104
|
+
st = [i for i in l_style2 if i in args[iarg]]
|
105
|
+
if st != []:
|
106
|
+
plotStyle = st[0]
|
107
|
+
# smth
|
108
|
+
if (
|
109
|
+
isinstance(args[iarg], (int, float))
|
110
|
+
and np.size(args[iarg]) == 1
|
111
|
+
and args[iarg] >= 1
|
112
|
+
):
|
113
|
+
smth = args[iarg]
|
114
|
+
|
115
|
+
if "x" not in locals() or x is None:
|
116
|
+
x = np.arange(1, y.shape[1] + 1)
|
117
|
+
elif len(x) < y.shape[1]:
|
118
|
+
y = y[:, x]
|
119
|
+
nRow = y.shape[0]
|
120
|
+
nCol = y.shape[1]
|
121
|
+
print(f"y was corrected, please confirm that {nRow} row, {nCol} col")
|
122
|
+
else:
|
123
|
+
x = np.arange(1, y.shape[1] + 1)
|
124
|
+
|
125
|
+
if x.shape[0] != 1:
|
126
|
+
x = x.T
|
127
|
+
yMean = np.nanmean(y, axis=0)
|
128
|
+
if smth > 1:
|
129
|
+
yMean = savgol_filter(np.nanmean(y, axis=0), smth, 1)
|
130
|
+
else:
|
131
|
+
yMean = np.nanmean(y, axis=0)
|
132
|
+
if paraStdSem == "sem":
|
133
|
+
if smth > 1:
|
134
|
+
wings = savgol_filter(np.nanstd(y, axis=0) / np.sqrt(y.shape[0]), smth, 1)
|
135
|
+
else:
|
136
|
+
wings = np.nanstd(y, axis=0) / np.sqrt(y.shape[0])
|
137
|
+
elif paraStdSem == "std":
|
138
|
+
if smth > 1:
|
139
|
+
wings = savgol_filter(np.nanstd(y, axis=0), smth, 1)
|
140
|
+
else:
|
141
|
+
wings = np.nanstd(y, axis=0)
|
142
|
+
|
143
|
+
fill_kws = kwargs.get('fill_kws', {})
|
144
|
+
line_kws = kwargs.get('line_kws', {})
|
145
|
+
fill = ax.fill_between(x, yMean + wings, yMean - wings, color=acolor, alpha=alpha, lw=0,**fill_kws)
|
146
|
+
if line_kws != {} and not any(key.lower() in ['lw', 'linewidth'] for key in line_kws.keys()):
|
147
|
+
line = ax.plot(x, yMean, color=acolor, lw=1.5, ls=plotStyle, marker=plotMarker, **line_kws)
|
148
|
+
else:
|
149
|
+
line = ax.plot(x, yMean, color=acolor, ls=plotStyle, marker=plotMarker, **line_kws)
|
150
|
+
return line[0], fill
|
151
|
+
# =============================================================================
|
152
|
+
# # for plot figures {Qiu et al.2023}
|
153
|
+
# =============================================================================
|
154
|
+
# =============================================================================
|
155
|
+
# plt.rcParams.update({'figure.max_open_warning': 0})
|
156
|
+
# # Output matplotlib figure to SVG with text as text, not curves
|
157
|
+
# plt.rcParams['svg.fonttype'] = 'none'
|
158
|
+
# plt.rcParams['pdf.fonttype'] = 42
|
159
|
+
#
|
160
|
+
# plt.rc('text', usetex=False)
|
161
|
+
# # plt.style.use('ggplot')
|
162
|
+
# plt.style.use('science')
|
163
|
+
# plt.rc('font', family='serif')
|
164
|
+
# plt.rcParams.update({
|
165
|
+
# "font.family": "serif", # specify font family here
|
166
|
+
# "font.serif": ["Arial"], # specify font here
|
167
|
+
# "font.size": 11})
|
168
|
+
# # plt.tight_layout()
|
169
|
+
# =============================================================================
|
170
|
+
# =============================================================================
|
171
|
+
# # axis spine
|
172
|
+
# # use it like: adjust_spines(ax, ['left', 'bottom'])
|
173
|
+
# =============================================================================
|
@@ -108,7 +108,7 @@ py2ls/.gitattributes,sha256=Gh2-F2vCM7SZ01pX23UT8pQcmauXWfF3gwyRSb6ZAFs,66
|
|
108
108
|
py2ls/.gitignore,sha256=y7GvbD_zZkjPVVIue8AyiuFkDMuUbvMaV65Lgu89To8,2763
|
109
109
|
py2ls/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
|
110
110
|
py2ls/README.md,sha256=CwvJWAnSXnCnrVHlnEbrxxi6MbjbE_MT6DH2D53S818,11572
|
111
|
-
py2ls/__init__.py,sha256=
|
111
|
+
py2ls/__init__.py,sha256=R5OBEeK0uOULvUsY1YjIj-EAQKlVPW32uh_hQHuN5Bg,109
|
112
112
|
py2ls/brain_atlas.py,sha256=w1o5EelRjq89zuFJUNSz4Da8HnTCwAwDAZ4NU4a-bAY,5486
|
113
113
|
py2ls/correlators.py,sha256=RbOaJIPLCHJtUm5SFi_4dCJ7VFUPWR0PErfK3K26ad4,18243
|
114
114
|
py2ls/data/.DS_Store,sha256=1lFlJ5EFymdzGAUAaI30vcaaLHt3F1LwpG7xILf9jsM,6148
|
@@ -116,12 +116,14 @@ py2ls/data/db2ls_sql_chtsht.json,sha256=ls9d7Sm8TLeujanWHfHlWhU85Qz1KnAizO_9X3wU
|
|
116
116
|
py2ls/data/lang_code_iso639.json,sha256=qZiU7H2RLJjDMXK22C-jhwzLJCI5vKmampjB1ys4ek4,2157
|
117
117
|
py2ls/db2ls.py,sha256=MMfFX47aIPIyu7fU9aPvX9lbPRPYOpJ_VXwlnWk-8qo,13615
|
118
118
|
py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
|
119
|
-
py2ls/ips.py,sha256=
|
119
|
+
py2ls/ips.py,sha256=6E_GBIyzMeWbdP3XoEQtyP3_IilDIFOylaxDuu4m3-4,95266
|
120
120
|
py2ls/netfinder.py,sha256=ZsLWGYMeRuGvxj2nqE0Z8ANoaVl18Necfw0HQfh2q7I,45548
|
121
121
|
py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
|
122
122
|
py2ls/sleep_events_detectors.py,sha256=36MCuRrpurn0Uvzpo3p3b3_JlVsRNHSWCXbJxCGM3mg,51546
|
123
|
+
py2ls/stats.py,sha256=Wd9yCKQ_61QD29WMEgMuEcreFxF91NmlPW65iWT2B5w,39041
|
124
|
+
py2ls/stdshade.py,sha256=lK9H98oEVLV14cYfB4BHYT5ptAI4Oia87MF86FqbPOg,6987
|
123
125
|
py2ls/translator.py,sha256=6S7MmTZmjj8NljVmj0W5uEauu4ePxso3AMf2LvGVRQA,30516
|
124
126
|
py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
|
125
|
-
py2ls-0.1.
|
126
|
-
py2ls-0.1.
|
127
|
-
py2ls-0.1.
|
127
|
+
py2ls-0.1.5.0.dist-info/METADATA,sha256=oM0BHs6W_KAa52S4XXVGvrIxE3JBWqv5rMzNGtWhhzs,17943
|
128
|
+
py2ls-0.1.5.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
129
|
+
py2ls-0.1.5.0.dist-info/RECORD,,
|
File without changes
|