Repository navigation
Expand file tree
/
Copy pathplotting_images.py
More file actions
176 lines (140 loc) · 5.47 KB
/
Copy pathplotting_images.py
File metadata and controls
176 lines (140 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import numpy as np
import matplotlib.pyplot as plt
# N = 1000
# B = 750
# x = np.linspace(-3, 3, N)
# y = np.linspace(-3, 3, N)
# X, Y = np.meshgrid(x, y)
# f = 1/(1+ np.exp(-(X + 0.2 * Y) * 10))
# df = f**2 * np.exp(-(X + 0.2 * Y) *10) * 10
# fig, ax = plt.subplots(1,3, figsize = (12, 4))
# ax[0].pcolormesh(X, Y, f)
# ax[1].pcolormesh(X, Y, df, cmap = "binary")
# ax[2].plot(x, np.ones(len(x)) *(-3+6*(B/N)), 'g')
# ax[2].pcolormesh(X, Y, df, cmap = "binary")
# ax[2].plot(x[::15], -x[::15]/0.2, 'r-o', markerfacecolor = 'r', markeredgewidth = 0)#linestyle = 'b', marker = 'ro')
# #ax[2].plot(x[::15], -x[::15]/0.2, 'b-')
# ax[2].set_ylim(-3, 3)
# for a in ax:
# a.set_xticks([])
# a.set_yticks([])
# plt.savefig('line_detection.png', dpi = 1000)
# fig_, ax_ = plt.subplots(1,1,figsize = (1,1))
# ax_.plot(np.arange(0, len(df)), df[B, :], 'g')
# print(np.argmax(df[B, :]), np.max(df[B, :]))
# ax_.plot(np.argmax(df[B, :]), np.max(df[B, :]), 'r.')
# ax_.set_xticks([])
# ax_.set_yticks([])
# plt.savefig('line_cut.png', dpi = 1000)
from scipy.special import erf
def bi_gaussian(v, AS, AT, vS, vT, sS, sT):
return AS * np.exp(-(1/2)*((v - vS)/sS)**2) + AT * np.exp(-(1/2)*((v - vT)/sT)**2)
# v = np.linspace(-0.7, 0.4, 200)
# vS, vT, sS, sT = -0.4, 0.1, 0.1, 0.1
# bi_gauss = bi_gaussian(v, 200, 190, vS, vT, sS, sT)
# bi_gauss += np.random.normal(-10, 10, 200)
# V = lambda V_thres: (1/2) * (erf( (v - vS) / (np.sqrt(2) * sS) ) - erf( (v - vT) / (np.sqrt(2) * sT) ))
c_CA = 'indianred'
c_ML = 'royalblue'
# vis = V(v)
# max_vis = np.max(vis)
# VT_max = v[np.argmax(vis)]
# plt.figure(figsize=(6,4))
# plt.plot(v, vis, color = '#94c973')
# plt.axvline(x=VT_max, linestyle='--', color = c_ML)
# plt.plot(VT_max, max_vis, 'ro')
# plt.xlabel(r'$V_T$ (mV)')
# plt.ylabel('visibility V')
#plt.plot(v, bi_gauss, marker='o', color=c_ML, linestyle='None')
#plt.xlabel(r'$V_{out}$ (mV)')
#plt.ylabel('counts')
#plt.savefig('vis_measurmentExample.png', dpi = 1000)
#plt.show()
# print(max_vis, VT_max)
# v = np.linspace(-1.1, -0.1, 200)
# vS, vT, sS, sT = -0.6, -0.35, 0.15, 0.10
# bi_gauss = bi_gaussian(v, 200, 30, vS, vT, sS, sT)
# bi_gauss += np.random.uniform(-10, 10, 200)
# bi_gauss = np.where(bi_gauss < 0, np.random.uniform(0, 10), bi_gauss)
# plt.plot(v, bi_gauss, marker='o', color=c_ML, linestyle='None')
# #plt.plot(v, bi_gaussian(v, 200, 30, vS, vT, sS, sT), 'k--')
# plt.plot(v, gaussian(v, 200, vS, sS), 'r--')
# plt.plot(v, gaussian(v, 30, vT, sT),color = '#94c973', linestyle = '--')
# plt.xlabel(r'$V_{out}$ (mV)')
# plt.ylabel('counts')
# plt.show()
# from matplotlib.ticker import ScalarFormatter
# class ScalarFormatterClass(ScalarFormatter):
# def _set_format(self):
# self.format = "%1.1f"
# x = np.linspace(-10, 10, 500)
# y = 1/(1+np.exp(-x))
# fig, ax = plt.subplots(1, 2, figsize=(8, 4))
# yScalarFormatter = ScalarFormatterClass(useMathText=True)
# yScalarFormatter.set_powerlimits((0,0))
# ax[0].plot(x,y, color = c_ML)
# ax[0].set_title(r"$f(t)$")
# ax[0].set_xlabel('t')
# #ax[1].plot(x, np.gradient(np.gradient(y)))
# #ax[1].set_title(r"$d^2f(x)/dx^2$")
# #@ax[1].yaxis.set_major_formatter(yScalarFormatter)
# ax[1].plot(x, np.abs(np.gradient(np.gradient(y))), color = c_CA)
# ax[1].yaxis.set_major_formatter(yScalarFormatter)
# ax[1].set_title(r"$\left|\frac{d^2f(t)}{dt^2}\right|$")
# ax[1].set_xlabel('t')
# plt.savefig('ac_vis_second_deriv.png', dpi = 1000)
# #plt.tight_layout()
# plt.show()
# import os
# import json
# with open('configs.json', 'r') as file:
# configs = json.load(file)
# name = 'data_zoomed_out_expanded'
# IDS = ['47615_11_0.npy', '45526_19_0.npy', '45462_5_0.npy', '45442_2_0.npy']
# ls = []
# for ID in IDS:
# image = np.load(os.path.join(configs['DATASET_PATH'], name, 'images', ID))
# label = np.load(os.path.join(configs['DATASET_PATH'], name, 'labels', ID))
# ls.append((image, label))
# fig, ax = plt.subplots(2, 4, figsize = (20, 10))
# for i in range(4):
# ax[0, i].pcolormesh(ls[i][0])
# ax[0, i].plot(*ls[i][1], 'ro')
# ax[0, i].set_xticks([])
# ax[0, i].set_yticks([])
# name = 'labeled_data'
# IDS = [ '45402_9.npy', '45415_6.npy', '45481_10.npy', '45418_9.npy']
# ls = []
# for ID in IDS:
# image = np.load(os.path.join(configs['DATASET_PATH'], name, 'images', ID))
# label = np.load(os.path.join(configs['DATASET_PATH'], name, 'labels', ID))
# ls.append((image, label))
# for i in range(4):
# ax[1, i].pcolormesh(ls[i][0])
# ax[1, i].plot(*ls[i][1], 'ro')
# ax[1, i].set_xticks([])
# ax[1, i].set_yticks([])
# plt.savefig('data_examples', dpi = 1000)
# plt.show()
def gaussian(v, A, off, sig):
return A * np.exp(-(1/2)*((v - off)/sig)**2)
def plt_hist_example():
vmin, vmax = -0.8, 0.5
AS, AT, vS, vT, sS, sT = 150, 10, -0.5, 0.2, 0.1, 0.2
v = np.linspace(vmin, vmax, 60)
width = (abs(vmin) + abs(vmax)) / 60
y = bi_gaussian(v, AS, AT, vS, vT, sS, sT)
y += np.abs(np.random.normal(0, 20, 60))
c_ML = 'royalblue'
fig, ax = plt.subplots(1,1, figsize = (4, 4))
ax.bar(v,y, width=width, edgecolor='k', color=c_ML)
ax.set_xlim([vmin - width/2, vmax + width/2])
ax.set_xlabel(r'$V_{out}$ (mV)')
ax.set_ylabel(r'counts')
v = np.linspace(vmin, vmax, 200)
ax.plot(v, gaussian(v, AS, vS, sS), color = c_CA, linewidth = 3, label = 'singlet peak')
ax.plot(v, gaussian(v, AT, vT, sT), color = '#94c973', linewidth = 3, label = 'triplet peak')
ax.legend()
plt.savefig('histogram_fit_error2.png', dpi=800)
plt.show()
plt_hist_example()