本文整理汇总了Python中utils.Data类的典型用法代码示例。如果您正苦于以下问题:Python Data类的具体用法?Python Data怎么用?Python Data使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Data类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transmission_pixel_sinogram
def transmission_pixel_sinogram(rays, image, angles, pixel_i, pixel_j, rays_downsample=5, response_image=None):
if response_image is None:
response_image = Data(image.extent, np.zeros(image.data.shape, dtype=np.double))
response_image.data[pixel_i, pixel_j] = 1
response = rotation_sinogram(rays, response_image, angles)
response = response.reshape(response.shape[0], -1, rays_downsample).mean(axis=2)
return response
示例2: transmission_response_sinogram
def transmission_response_sinogram(rays, image, angles, rays_downsample=5):
nx, ny = image.data.shape
response = np.zeros((nx * ny, angles.shape[0], int(rays.shape[0] / rays_downsample)), dtype=np.double)
response_image = Data(image.extent, np.zeros(image.data.shape, dtype=np.double))
for i in range(nx * ny):
ix = i % image.data.shape[0]
iy = i // image.data.shape[0]
print(i, nx * ny, ix, iy)
response_image.data[ix, iy] = 1
response[i] = transmission_pixel_sinogram(rays, image, angles, ix, iy, rays_downsample, response_image)
response_image.data[ix, iy] = 0
return response
示例3: __init__
def __init__(self, parent, size, plot, msg):
self.parent = parent
self.plot2d = plot
self.msgwin = msg
self.data = Data()
x = Image.open(abs_path(photograph)) # Images are kept along with the python code
im = x.resize(size)
self.size[0] = float(im.size[0])
self.size[1] = float(im.size[1])
self.image = ImageTk.PhotoImage(im)
self.canvas = Canvas(parent, width = im.size[0], height = im.size[1])
self.canvas.create_image(0,0,image = self.image, anchor = NW)
self.adblock = self.canvas.create_rectangle(self.dotxy(self.adctl),fill='white')
for k in self.douts:
k[2] = self.canvas.create_oval(self.dotxy(k), outline="", fill = 'black')
for k in self.dins:
k[2] = self.canvas.create_oval(self.dotxy(k), outline="", fill = 'black')
for k in self.adcs:
k[2] = self.canvas.create_oval(self.dotxy(k), outline="", fill = 'black')
for k in self.ls_ins:
k[2] = self.canvas.create_oval(self.dotxy(k), outline="", fill = 'black')
self.led[2] = self.canvas.create_oval(self.dotxy(self.led), outline="", fill = 'black')
self.pwg[2] = self.canvas.create_oval(self.dotxy(self.pwg), outline="", fill = 'black')
self.dac[2] = self.canvas.create_oval(self.dotxy(self.dac), outline="", fill = 'black')
self.cntr[2] = self.canvas.create_oval(self.dotxy(self.cntr), outline="", fill = 'black')
self.cmp[2] = self.canvas.create_oval(self.dotxy(self.cmp), outline="", fill = 'black')
self.canvas.bind("<ButtonRelease-1>", self.mouse_click)
self.canvas.pack()
示例4: testSingleImg
def testSingleImg():
NetHelper.gpu()
#submission()
nh=NetHelper(deploy=cfgs.deploy_pt,model=cfgs.best_model_dir)
img=Data.imFromFile(os.path.join(cfgs.train_mask_path,"1_1_mask.tif"))
res=nh.bin_pred_map(img)
print(np.histogram(res))
示例5: extractParam
def extractParam(self):
"""Turn muti part encoded form into params."""
params = []
try:
environ = {
'CONTENT_TYPE': self.headers['content-type'],
'CONTENT_LENGTH': self.headers['content-length'],
'REQUEST_METHOD': 'POST',
}
except KeyError:
trace('# Warning: missing header content-type or content-length'
' in file: %s not an http request ?\n' % self.file_path)
return params
form = FieldStorage(fp=StringIO(self.body),
environ=environ,
keep_blank_values=True)
try:
keys = form.keys()
except TypeError:
trace('# Using custom data for request: %s ' % self.file_path)
params = Data(self.headers['content-type'], self.body)
return params
for item in form.list:
key = item.name
value = item.value
filename = item.filename
if filename is None:
params.append([key, value])
else:
# got a file upload
filename = filename or ''
params.append([key, 'Upload("%s")' % filename])
if filename:
if os.path.exists(filename):
trace('# Warning: uploaded file: %s already'
' exists, keep it.\n' % filename)
else:
trace('# Saving uploaded file: %s\n' % filename)
f = open(filename, 'w')
f.write(str(value))
f.close()
return params
示例6: readDataSetFile
def readDataSetFile(filename, F):
with open(filename) as f:
E = DataSet()
for line in f:
line =line.split()
if len(line) != len(F):
print("Number of attributes in the Training record:"+str(line)+"does not match the number in the attribute file")
raise Exception('DataValidation')
d = Data()
idx= 0
for value in ine:
if value in F[idx].values:
d.addValue(F[idx].name,value)
else:
print('Value='+value+' is not a valid value for attribute='+ F[idx].name)
idx += 1
E.addData(d)
f.close()
示例7: func
def func(filename, nh):
_,idx,ext=Data.splitPath(filename)
if ext!=".tif":
return None
cfgs.cnt+=1
print(cfgs.cnt)
#idx=int(idx)
img=Data.imFromFile(filename)
ready=prep(img,cfgs.inShape[1],cfgs.inShape[0])
# print(np.histogram(ready))
# ready*=0.00392156862745
ready-=128
ready*=0.0078431372549
pred_bin,pred, img=classifier(ready,nh)
# pred_bin,pred,output, img=classifier(ready,nh)
result=run_length_enc(pred_bin)
if debug:
# print('org',np.histogram(ready))
# print('data', np.histogram(img))
hist=np.histogram(img)
print(pd.DataFrame(hist[0],index=hist[1][1:]).T)
hist=np.histogram(pred)
print(pd.DataFrame(hist[0],index=hist[1][1:]).T)
mask=plt.imread(os.path.join(cfgs.train_mask_path,idx+"_mask.tif"))
plt.figure(1)
plt.subplot(221)
plt.title('mask')
plt.imshow(mask)
plt.subplot(222)
plt.title('prediction')
plt.imshow(pred_bin)
plt.subplot(223)
plt.title('img')
plt.imshow(img)
plt.subplot(224)
plt.title('heatmap ')
plt.imshow(pred)
plt.show()
# print(idx,result)
return (idx,result)
示例8: submission
def submission():
NetHelper.gpu(2)
#submission()
nh=NetHelper(deploy=cfgs.deploy_pt,model=cfgs.best_model_dir)
if debug:
l=Data.folder_opt(cfgs.train_data_path,func,nh)
else:
l=Data.folder_opt(cfgs.test_data_path,func,nh)
l=np.array(l,dtype=[('x',int),('y',object)])
l.sort(order='x')
first_row = 'img,pixels'
file_name = 'submission.csv'
with open(file_name, 'w+') as f:
f.write(first_row)
for i in l:
s = str(i[0]) + ',' + i[1]
f.write(('\n'+s))
示例9: __init__
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()
示例10: on_pubmsg
def on_pubmsg(self, c, e):
"""Hook for public not-prefixed written text inside a channel.
-> e.target() == channel
-> e.source() == [email protected]
"""
nick, hostname = nm_to_n(e.source()), nm_to_h(e.source())
if not nick in self.users:
self.users[nick] = User(nick, hostname, self.connection)
user, chan = self.users[nick], self.chans[e.target().lower()]
line_raw = e.arguments()[0]
data = Data(line_raw=line_raw, chan=chan, user=user)
# execute plugins
if line_raw.startswith(self.command_prefix):
data.line_raw = data.line_raw[len(self.command_prefix):]
data.reaction_type = "public_command"
self.dispatch(data)
else:
data.reaction_type = "public"
self.dispatch(data)
示例11: __init__
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)"
#.........这里部分代码省略.........
示例12: __init__
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
#.........这里部分代码省略.........
示例13: __init__
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)
#.........这里部分代码省略.........
示例14: __init__
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')
#.........这里部分代码省略.........
示例15: __init__
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):
#.........这里部分代码省略.........