本文整理汇总了Python中utils.Data.save方法的典型用法代码示例。如果您正苦于以下问题:Python Data.save方法的具体用法?Python Data.save怎么用?Python Data.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Data
的用法示例。
在下文中一共展示了Data.save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class rad:
xmax = 255
ymax = 100
xlabel = "Channel Number"
ylabel = "Count"
size = [100, 100]
running = False
scale = None
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width=size[0], height=size[1])
self.canvas.create_image(0, 0, image=self.image, anchor=NW)
self.data = Data()
def enter(self, p):
self.ph = p
self.ph.clear_hist()
self.intro_msg()
self.plot2d.setWorld(0, 0, self.xmax, self.ymax)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
self.plot2d.markerval = None # Clear Markers
self.calibrated = False
try:
self.plot2d.canvas.delete(self.plot2d.markertext)
except:
pass
def exit(self):
self.running = False
def clear(self, e):
self.plot2d.delete_lines()
self.data.clear()
def set_ymax(self, w):
d = self.scale.get()
self.ymax = float(d)
self.plot2d.setWorld(0, 0, self.xmax, self.ymax)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
def collect_hist(self, e):
if self.running == False:
return
phdata = self.ph.read_hist()
self.plot2d.setWorld(0, 0, self.xmax, self.ymax)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
self.data.points = []
for k in phdata:
energy = k[0] * self.xmax / 255.0
self.data.points.append((energy, k[1]))
self.plot2d.delete_lines()
self.plot2d.line(self.data.points, "black")
# self.data.traces.append(self.data.points)
self.last_read_time = time.time()
def update(self):
if self.running == False:
return
self.collect_hist(0)
def start(self, w):
self.ph.start_hist()
self.running = True
self.msgwin.msg("Started Collecting Data")
def stop(self, w):
self.running = False
self.ph.stop_hist()
self.msgwin.msg("Stopped Collecting Data")
def clear_hist(self, w):
self.ph.clear_hist()
self.plot2d.delete_lines()
self.msgwin.msg("Cleared Histogram Data")
def save(self, e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg("Data saved to " + fname)
def calibrate(self, e):
if self.plot2d.markerval == None:
self.msgwin.msg("Mark a Peak before calibration", "red")
return
try:
chan = self.plot2d.markerval[0]
s = self.energytext.get()
energy = float(s)
self.xmax = self.xmax * energy / chan
self.xlabel = "Energy (MeV)"
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class pend:
NP = 400
tmax = 5.0 # We digitize oscillations for 10 seconds
looping = False
xlabel = 'Seconds'
ylabel = 'Volts'
size = [100,100]
scale = None
delay = 0.0
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, p):
self.ph = p
self.ph.select_adc(0)
self.ph.set_adc_size(2)
self.intro_msg()
self.plot2d.setWorld(0, -5, self.tmax, 5)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
def exit(self):
self.looping = False
def set_tmax(self,w):
d = self.scale.get()
self.tmax = float(d)
self.plot2d.setWorld(0, -5, self.tmax, 5)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
def clear(self,e):
if self.looping == True:
return
self.plot2d.delete_lines()
self.data.clear()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def calc_g(self,e):
if self.data.points == []:
return
x = self.lentext.get()
try:
L = float(x)
except:
self.msgwin.msg('Set the length of the rod', 'red')
return
import phmath, math
dat = []
for k in self.data.points:
dat.append([k[0], k[1]])
res = phmath.fit_dsine(dat)
fit = []
exp = []
for k in res[0]:
fit.append([k[0],k[2]])
exp.append([k[0],k[3]])
self.data.traces.append(fit)
self.col = self.data.get_col()
self.plot2d.line(fit, self.col)
self.col = self.data.get_col()
self.plot2d.line(exp, self.col)
D = res[1][4]
T = 1.0 / res[1][1]
r = 0.14 # radius of the rod
R = 1.27 # radius of the ball
density = 7.8 # density of iron
m_rod = math.pi * r**2 * L * density
m_ball = math.pi * 4 / 3 * R**3 * density
# print m_rod,'',m_ball
Lprime = ( (m_rod * L**2)/3 + (m_ball * 2/5 * R**2) + m_ball * \
(L+R)**2 ) / ( (m_rod * L)/2 + m_ball*(L+R) )
g = 4.0 * math.pi**2 * Lprime / (T * T)
# print T, Lprime, g, D
ss = 'T = %4.3f seconds. Length = %4.2f | g = %4.0f \
cm/sec2 | Damping factor = %4.3f\n'%(T,L,g,D)
self.msgwin.showtext(ss)
# g2 = 4.0 * math.pi**2 * L / (T * T)
def analyze(self,e):
self.data.analyze(self.xlabel, self.ylabel)
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class sound:
NP = 200
adc_delay = 10
delay_vals = [10,20,50,100,200,500,1000]
looping = False
xlabel = 'milli seconds'
ylabel = 'Volts'
adc_scale = None
size = [100,100]
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, fd): #Phoenix handler set by the caller
self.ph = fd
self.ph.select_adc(0)
self.ph.set_adc_size(1)
self.ph.write_outputs(0)
self.ph.set_pulse_width(13)
self.plot2d.setWorld(0, -5, self.NP * self.adc_delay/1000.0, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
self.msg_intro()
def exit(self): # Do cleanup here
self.ph.disable_set()
def update(self):
pass
def clear(self,e):
self.data.clear()
self.plot2d.delete_lines()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_waveform(self,w):
self.ph.enable_pulse_high(3)
data = self.ph.read_block(self.NP, self.adc_delay, 1)
self.data.points = []
for k in data:
self.data.points.append( (k[0]/1000.0, k[1]/1000.0) )
self.plot2d.line(self.data.points, self.data.get_col())
self.data.traces.append(self.data.points)
self.ph.write_outputs(0);
def set_adc_delay(self,w):
d = self.adc_scale.get()
self.adc_delay = self.delay_vals[d]
if self.ph == None:
return
self.ph.set_adc_delay(self.adc_delay)
self.plot2d.setWorld(0, -5, self.NP * self.adc_delay/1000.0, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
def ms_delay(self,e):
self.ph.write_outputs(0)
self.ph.set_pulse_width(13)
self.ph.set_pulse_polarity(0)
t = self.ph.pulse2rtime(3,3)
if t < 0:
self.msgwin.showtext('\nTime out on Input D3','red')
return
self.msgwin.showtext('%4.0f'%t)
def refresh(self,e):
self.msg_intro()
def msg_intro(self):
self.clear(None)
self.msgwin.clear()
self.msgwin.showtext('Connect the Transmitter Piezo between Digital '+\
'output D3 and Ground. Connect the Receiver Piezo between Ground '+\
'and the Inverting Amplifier Input. Set a gain resistor of 100. '+\
'Connect the Output of the amplifier to the level shifter and '+\
'level shifter output to Ch0. If the Amplitude is less, use one '+\
'more Inverting amplifier in series.')
self.msgwin.showlink('View Waveform', self.show_waveform)
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class rad:
xmax = 255
ymax = 100
xlabel = 'Channel Number'
ylabel = 'Count'
size = [100,100]
running = False
scale = None
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, p):
self.ph = p
self.ph.clear_hist()
self.intro_msg()
self.plot2d.setWorld(0, 0, self.xmax, self.ymax)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
self.plot2d.markerval = None # Clear Markers
self.calibrated = False
try:
self.plot2d.canvas.delete(self.plot2d.markertext)
except:
pass
def exit(self):
self.running = False
def clear(self,e):
self.plot2d.delete_lines()
self.data.clear()
def set_ymax(self,w):
d = self.scale.get()
self.ymax = float(d)
self.plot2d.setWorld(0, 0, self.xmax, self.ymax)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
def collect_hist(self, e):
if self.running == False:
return
phdata = self.ph.read_hist()
self.plot2d.setWorld(0, 0, self.xmax, self.ymax)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
self.data.points = []
for k in phdata:
energy = k[0] * self.xmax / 255.0
self.data.points.append( (energy, k[1]) )
self.plot2d.delete_lines()
self.plot2d.line(self.data.points, 'black')
# self.data.traces.append(self.data.points)
self.last_read_time = time.time()
def update(self):
if self.running == False:
return
self.collect_hist(0)
def start(self,w):
self.ph.start_hist()
self.running = True
self.msgwin.msg('Started Collecting Data')
def stop(self,w):
self.running = False
self.ph.stop_hist()
self.msgwin.msg('Stopped Collecting Data')
def clear_hist(self,w):
self.ph.clear_hist()
self.plot2d.delete_lines()
self.msgwin.msg('Cleared Histogram Data')
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def calibrate(self,e):
if self.plot2d.markerval == None:
self.msgwin.msg('Mark a Peak before calibration','red')
return
try:
chan = self.plot2d.markerval[0]
s = self.energytext.get()
energy = float(s)
self.xmax = self.xmax * energy / chan
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class pt100:
NP = 400
delay = 0.03 # minimum delay between voltage reads
tmax = 12.0 # Number of seconds for NP reads
looping = False
xlabel = 'Seconds'
ylabel = 'Kelvin'
gain = 11.0 # Assume PT100 output is amplified by 11
ccval = 1.0 # CCS nominal value is 1 mA
maxtemp = 800.0
size = [100,100]
del_scale = None
np_scale = None
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, p):
self.ph = p
self.ph.select_adc(0)
self.ph.set_adc_size(2)
self.intro_msg()
self.tmax = self.delay * self.NP
self.plot2d.setWorld(0, 0, self.tmax, self.maxtemp)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
def exit(self):
self.looping = False
def set_delay(self,w):
if self.looping:
return
d = self.del_scale.get()
self.delay = float(d)/1000.0
self.plot2d.setWorld(0, 0, self.NP * self.delay, self.maxtemp)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
if len(self.data.points) < 2:
return
self.plot2d.delete_lines()
self.plot2d.line(self.data.points, self.col)
def set_NP(self,w):
d = self.np_scale.get()
self.NP = d
self.plot2d.setWorld(0, 0, self.NP * self.delay, self.maxtemp)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
if len(self.data.points) < 2:
return
self.plot2d.delete_lines()
self.plot2d.line(self.data.points, self.col)
def clear(self,e):
self.plot2d.delete_lines()
self.data.clear()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def analyze(self,e):
self.data.analyze(self.xlabel, self.ylabel)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_all(self,e):
self.plot2d.delete_lines()
self.data.index = 0
for tr in self.data.traces:
self.plot2d.line(tr,self.data.get_col())
#------------------------------------------------------------------
def start(self,e):
if self.ph == None:
self.msgwin.msg('Connection not made yet', 'red')
return
if self.looping == False: # Same color if restarted
self.col = self.data.get_col()
self.msgwin.msg('Started Temperature Recording')
self.looping = True
self.data.points = []
def stop(self,e):
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class osc:
NP = 200
adc_delay = 20
delay_vals = [10,20,50,100,200,500,1000]
looping = False
xlabel = 'milli seconds'
ylabel = 'Volts'
adc_scale = None
size = [100,100]
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, fd): #Phoenix handler set by the caller
self.ph = fd
self.ph.select_adc(0)
self.ph.set_adc_size(1)
self.plot2d.setWorld(0, 0, self.NP * self.adc_delay/1000.0, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
self.msg_intro()
def exit(self): # Do cleanup here
self.ph.disable_set()
def update(self):
pass
def clear(self,e):
self.data.clear()
self.plot2d.delete_lines()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_waveform(self,w):
data = self.ph.read_block(self.NP, self.adc_delay, 0)
self.data.points = []
for k in data:
self.data.points.append( (k[0]/1000.0, k[1]/1000.0) )
self.plot2d.line(self.data.points, self.data.get_col())
self.data.traces.append(self.data.points)
def set_adc_delay(self,w):
d = self.adc_scale.get()
self.adc_delay = self.delay_vals[d]
if self.ph == None:
return
self.ph.set_adc_delay(self.adc_delay)
self.plot2d.setWorld(0, -5, self.NP * self.adc_delay/1000.0, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
def duty_cycle(self,e):
sum = 0.0
for k in range(100):
t = self.ph.r2ftime(4,4)
if t < 0:
self.msgwin.showtext('\nTime out on CMP','red')
return
else:
sum = sum + t
hi = sum / 100
self.msgwin.showtext('\nHIGH = ' + '%4.1f'%(hi) + ' usec. ')
sum = 0.0
for k in range(100):
t = self.ph.f2rtime(4,4)
if t < 0:
self.msgwin.showtext('\nTime out on CMP','red')
return
else:
sum = sum + t
low = sum / 100
self.msgwin.showtext('LOW = ' + '%4.1f'%(low) + ' usec. ')
ds = hi * 100 / (low + hi)
self.msgwin.showtext('Duty Cycle = ' + '%4.1f'%(ds)+ ' %. ')
def frequency(self,e):
fr = self.ph.measure_frequency()
self.msgwin.showtext('\nFrequency = ' + '%4.0f'%(fr) + ' Hz')
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class cap:
NP = 200
adc_delay = 20
delay_vals = [10,20,50,100,200,500,1000]
xlabel = 'milli seconds'
ylabel = 'Volts'
size = [100,100]
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, fd): #Phoenix handler 'ph' is set by the caller
self.intro_msg()
self.ph = fd
try:
self.ph.select_adc(0)
self.ph.set_adc_size(2)
except:
self.msgwin.msg('Connection NOT Established','red')
def exit(self): # Do cleanup here
try:
self.ph.disable_set()
except:
pass
def update(self):
pass
def clear(self,e):
self.data.clear()
self.plot2d.delete_lines()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def analyze(self,e):
self.data.analyze(self.xlabel, self.ylabel)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def capture_trace(self): # Collect data and store in object 'data'
# All conversion to be done here. setWorld according to 'trace'
# xscale and yscale are specified
# if axes are shown in different units
phdata = self.ph.read_block(self.NP, self.adc_delay, 0)
self.data.points = []
for k in phdata:
self.data.points.append( (k[0]/1000.0, k[1]/1000.0) )
#microsec -> millisec ; millivolts -> volts
self.data.traces.append(self.data.points)
last = self.data.points[-1][0]
second = self.data.points[-2][0]
xmax = last + (last-second)
self.plot2d.setWorld(0, 0, xmax, 5) # Set scale factors
self.plot2d.mark_axes(self.xlabel, self.ylabel) # axes & labels
self.plot2d.line(self.data.points, self.data.get_col())
def discharge(self,w):
self.ph.write_outputs(8)
time.sleep(1)
self.ph.enable_set_low(3)
self.capture_trace()
def charge(self,w):
self.ph.write_outputs(0)
time.sleep(1)
self.ph.enable_set_high(3)
self.capture_trace()
def set_adc_delay(self,w):
d = self.adc_scale.get()
self.adc_delay = self.delay_vals[d]
if self.ph == None:
return
self.ph.set_adc_delay(self.adc_delay)
self.plot2d.setWorld(0, 0, self.NP * self.adc_delay/1000.0, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
def calc_cap(self,e):
#.........这里部分代码省略.........
示例8: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class rodpend:
NP = 400
tmax = 10.0 # We digitize oscillations for 10 seconds
maxcount = 10
looping = False
xlabel = 'Number'
ylabel = 'g'
size = [100,100]
scale = None
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, p):
self.ph = p
self.ph.select_adc(0)
self.ph.set_adc_size(2)
self.intro_msg()
self.plot2d.setWorld(0, -5, self.tmax, 5)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
def exit(self):
self.looping = False
def clear(self,e):
self.plot2d.delete_lines()
self.data.clear()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def analyze(self,e):
self.data.analyze(self.xlabel, self.ylabel)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_all(self,e):
self.plot2d.delete_lines()
self.data.index = 0
for tr in self.data.traces:
self.plot2d.line(tr,self.data.get_col())
#------------------------------------------------------------------
def start(self,e):
x = self.lentext.get()
try:
self.length = float(x)
except:
self.msgwin.msg('Set the length of the Pendulum', 'red')
return
x = self.numtext.get()
try:
self.maxcount = int(x)
except:
self.maxcount = 10
self.tmax = self.maxcount
if self.ph == None:
self.msgwin.msg('Connection not made yet', 'red')
return
if self.looping == False: # Same color if restarted
self.col = self.data.get_col()
self.msgwin.msg('Starting Measurement of gravity using Rod Pendulum')
self.count = 0
t = self.ph.pendulum_period(3) # Every alternate rising edge
# t = self.ph.multi_r2rtime(3,1)
if t < 0:
self.msgwin.msg('Pendulum Period Timeout Error', 'red')
return
t = t/1000000.0
self.pisqr = math.pi ** 2
g = 4.0 * self.pisqr * 2.0 * self.length / (3.0 * t * t)
self.msgwin.showtext('\nPeriod Gravity')
self.msgwin.showtext('\n%6.5f\t%4.1f'%(t,g))
# print self.pisqr, self.length, t, g
self.data.points = [(self.count, g)]
self.plot2d.setWorld(0, 0, self.tmax, g*1.2)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
self.looping = True
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class induction:
NP = 200
adc_delay = 500
delay_vals = [200,500,1000]
looping = False
xlabel = 'milli seconds'
ylabel = 'Volts'
size = [100,100]
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self,fd):
self.plot2d.setWorld(0, -5, self.NP * self.adc_delay/1000.0, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
self.intro_msg()
self.ph = fd
try:
self.ph.select_adc(0)
self.ph.set_adc_size(2)
except:
self.msgwin.msg('Connection NOT Established','red')
def exit(self):
self.looping = False
def clear(self,e):
self.data.clear()
self.plot2d.delete_lines()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def analyze(self,e):
self.data.analyze(self.xlabel, self.ylabel)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_all(self,e):
self.plot2d.delete_lines()
self.data.index = 0
for tr in self.data.traces:
self.plot2d.line(tr,self.data.get_col())
def set_adc_delay(self,w):
d = self.adc_scale.get()
self.adc_delay = self.delay_vals[d]
if self.ph == None:
return
self.ph.set_adc_delay(self.adc_delay)
self.plot2d.setWorld(0, -5, self.NP * self.adc_delay/1000, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
#------------------------------------------------------------------
def start(self,e):
if self.ph == None:
self.msgwin.msg('Connection not made yet', 'red')
return
phdata = self.ph.read_block(self.NP, self.adc_delay, 1)
if phdata == None:
return
self.data.points = []
for k in phdata:
self.data.points.append( (k[0]/1000.0, k[1]/1000.0) ) # scale & copy
self.limit = 0.0 # Find the present signal level
for p in self.data.points:
if abs(p[1]) > self.limit:
self.limit = abs(p[1]) + 0.1
self.looping = True
self.msgwin.msg('Scanning for Waveform (amplitude > %4.3f V)'%self.limit)
# print self.limit
def get_peaks(self):
vmin = 5.0
vmax = -5.0
t1 = t2 = 0
for p in self.data.points:
if p[1] < vmin:
vmin = p[1]
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class gravity:
NP = 400
tmax = 10.0 # We digitize oscillations for 10 seconds
maxcount = 10
looping = False
xlabel = 'Number'
ylabel = 'g'
size = [100,100]
scale = None
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, p):
self.ph = p
self.intro_msg()
self.plot2d.setWorld(0, -5, self.tmax, 5)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
def exit(self):
self.looping = False
def update(self):
pass
def clear(self,e):
self.plot2d.delete_lines()
self.data.clear()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def analyze(self,e):
self.data.analyze(self.xlabel, self.ylabel)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_all(self,e):
self.plot2d.delete_lines()
self.data.index = 0
for tr in self.data.traces:
self.plot2d.line(tr,self.data.get_col())
#------------------------------------------------------------------
def attach(self,e):
x = self.lentext.get()
try:
self.length = float(x)
except:
self.msgwin.msg('Set the Height', 'red')
return
if self.ph == None:
self.msgwin.msg('Connection not made yet', 'red')
return
self.ph.write_outputs(1)
self.msgwin.msg('Powered the Electromagnet')
def measure(self,e):
t = self.ph.clr2rtime(0,0)
if t < 0:
self.msgwin.msg('Timeout Error', 'red')
return
elif t < 20:
self.msgwin.msg('Connection Error', 'red')
return
t = t + 4000.0 # 4 ms correction for magnetic retention
t = t * 1.0e-6 # usec to sec
print t, self.length
g = 2.0 * self.length / t ** 2
self.msgwin.showtext('\n%7.6f\t%4.1f'%(t,g))
self.msgwin.msg('Done')
def refresh(self,e):
self.intro_msg()
def intro_msg(self):
self.msgwin.clear()
self.msgwin.showtext('Connect the Electromagnet between Digital '+\
'Output D0 and GND. '+\
'Connect the loudspeaker between GND and the input of the inverting '+\
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class diode:
NP = 500
looping = False
xlabel = 'Volts'
ylabel = 'mA'
size = [100,100]
dac_voltage = 0.0
adc_voltage = 0.0
step = 39.0
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, p):
self.ph = p
self.ph.select_adc(0)
self.ph.set_adc_size(2)
self.plot2d.setWorld(0, 0, 5, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
self.intro_msg()
def exit(self):
self.looping = False
def clear(self,e):
self.data.clear()
self.plot2d.delete_lines()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def analyze(self,e):
self.data.analyze(self.xlabel, self.ylabel)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_all(self,e):
self.plot2d.delete_lines()
self.data.index = 0
for tr in self.data.traces:
self.plot2d.line(tr,self.data.get_col())
#------------------------------------------------------------------
def start(self,e):
if self.ph == None:
self.msgwin.msg('Connection not made yet', 'red')
return
if self.looping == False: # Same color if restarted in between
self.col = self.data.get_col()
self.msgwin.msg('Starting Diode IV measurement')
self.data.points = []
self.looping = True
self.dac_voltage = 0.0
def accept_trace(self):
self.data.traces.append(self.data.points)
def update(self):
if self.ph == None:
return
if self.looping != True:
return
self.ph.set_voltage(self.dac_voltage)
time.sleep(0.05)
self.adc_voltage = self.ph.get_voltage()[1]
# voltage and current converted into volts
current = (self.dac_voltage - self.adc_voltage)/1000.0
self.data.points.append( (self.adc_voltage/1000.0, current))
if len(self.data.points) < 2:
return
self.plot2d.delete_lines()
self.plot2d.line(self.data.points, self.col)
self.dac_voltage = self.dac_voltage + self.step
if self.dac_voltage > 5000:
self.msgwin.msg('IV Plot Done')
self.accept_trace()
self.looping = False
def intro_msg(self):
self.clear(None)
self.msgwin.clear()
self.msgwin.showtext('Make the connections as shown above. The '+\
#.........这里部分代码省略.........
示例12: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class gm:
NP = 400
countrate = 100.0 # Assume a 100 Hz count rate
numtrials = 5 # 5 trials default
duration = 1 # count for one second
tube_voltage = 0.0
VMIN = 300.0
VOPT = 500.0
VMAX = 902.0
looping = False
xlabel = 'Trial'
ylabel = 'Count'
size = [100,100]
scale = None
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, p):
self.ph = p
self.ph.select_adc(0)
self.ph.set_adc_size(2)
self.plot2d.setWorld(0, 0, self.countrate, self.numtrials)
self.plot2d.mark_axes(self.xlabel,self.ylabel)
self.tube_voltage = self.ph.gm_set_voltage(self.VOPT)
self.intro_msg()
def exit(self):
self.looping = False
def clear(self,e):
if self.looping == True: return
self.plot2d.delete_lines()
self.data.clear()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def analyze(self,e):
self.data.analyze(self.xlabel, self.ylabel)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_all(self,e):
self.plot2d.delete_lines()
self.data.index = 0
for tr in self.data.traces:
self.plot2d.line(tr,self.data.get_col())
#------------------------------------------------------------------
def start(self,e):
x = self.durationtext.get()
try:
self.duration = int(x)
except:
self.msgwin.msg('Set the Duration of Counting', 'red')
return
x = self.trialstext.get()
try:
self.numtrials = int(x)
except:
self.numtrials = 5
if self.ph == None:
self.msgwin.msg('Connection not made yet', 'red')
return
if self.looping == False: # Same color if restarted
self.col = self.data.get_col()
self.tube_voltage = self.ph.gm_set_voltage(self.tube_voltage)
self.msgwin.msg('GM tube Counting Radiation.')
self.msgwin.label.update()
self.count = 0
gmc = self.ph.gm_get_count(self.duration)
self.msgwin.showtext('\nCounts : %d '%(gmc))
self.data.points = [(self.count, gmc)]
self.plot2d.setWorld(0, 0, self.numtrials, gmc * 1.5 + 5)
self.xlabel = 'Trial'
self.plot2d.mark_axes(self.xlabel,self.ylabel)
self.count = self.count + 1
#.........这里部分代码省略.........
示例13: __init__
# 需要导入模块: from utils import Data [as 别名]
# 或者: from utils.Data import save [as 别名]
class mono:
NP = 200
adc_delay = 20
delay_vals = [10,20,50,100,200,500,1000]
looping = False
xlabel = 'milli seconds'
ylabel = 'Volts'
adc_scale = None
size = [100,100]
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
x = Image.open(abs_path(photograph))
im = x.resize(size)
self.size[0] = float(size[0])
self.size[1] = float(size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = size[0], height = size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.data = Data()
def enter(self, fd): #Phoenix handler set by the caller
self.ph = fd
self.ph.select_adc(0)
self.ph.set_adc_size(1)
self.ph.set_pulse_width(1)
self.plot2d.setWorld(0, 0, self.NP * self.adc_delay/1000.0, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
self.msg_intro()
def exit(self): # Do cleanup here
self.ph.disable_set()
def update(self):
pass
def clear(self,e):
self.data.clear()
self.plot2d.delete_lines()
def save(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save(fname)
self.msgwin.msg('Data saved to '+ fname)
def save_all(self,e):
fname = self.fntext.get()
if fname == None:
return
self.data.save_all(fname)
self.msgwin.msg('Data saved to '+ fname)
def show_waveform(self,w):
self.ph.enable_pulse_low(3)
data = self.ph.read_block(self.NP, self.adc_delay, 0)
self.data.points = []
for k in data:
self.data.points.append( (k[0]/1000.0, k[1]/1000.0) )
self.plot2d.line(self.data.points, self.data.get_col())
self.data.traces.append(self.data.points)
self.ph.write_outputs(8);
def set_adc_delay(self,w):
d = self.adc_scale.get()
self.adc_delay = self.delay_vals[d]
if self.ph == None:
return
self.ph.set_adc_delay(self.adc_delay)
self.plot2d.setWorld(0, -5, self.NP * self.adc_delay/1000.0, 5)
self.plot2d.mark_axes(self.xlabel, self.ylabel)
def ms_delay(self,e):
self.ph.write_outputs(8)
self.ph.set_pulse_width(1)
self.ph.set_pulse_polarity(1)
t = self.ph.pulse2ftime(3,3)
if t < 0:
self.msgwin.showtext('\nTime out on Input D3','red')
return
self.msgwin.showtext('\nMonoshot Delay = ' + '%4.0f'%(t) + ' usec.')
def refresh(self,e):
self.msg_intro()
def msg_intro(self):
self.clear(None)
self.msgwin.clear()
self.msgwin.showtext('Power the Monostable Multivibrator circuit '+\
'made using IC555 from the 5V Output socket. Connect the Trigger '+\
'Input of 555 (pin number 2) to Digital Output D3.\n')
self.msgwin.showlink('View Waveform', self.show_waveform)
self.msgwin.showtext(' View the output of the circuit.\n')
self.adc_scale = Scale(None, command = self.set_adc_delay, \
from_ = 0, to=6, orient=HORIZONTAL, length=100, showvalue=0)
self.adc_scale.set(1)
#.........这里部分代码省略.........