pytables

13
Pytables等应用 Hdf5,numpy,matplotlib

Upload: gowell

Post on 11-Jun-2015

1.220 views

Category:

Technology


5 download

DESCRIPTION

python HDF5科学数据库等应用

TRANSCRIPT

Page 1: Pytables

Pytables等应用  

Hdf5,numpy,matplotlib  

Page 2: Pytables

需求  

•  可实时序列化的字典,无类型信息丢失  •  要有>  2GB的存储体积  •  要有矩阵(numpy)方式的存储接口  •  要有GUI工具方便增、删、查、改  •  快、免费、开源  

Page 3: Pytables

其他数据库  

• bsddb  Berkeley  DB  类型信息丢失  • Sqllite  sql接口不方便,类型信息与效率冲突  • Nosql  多余的服务器,实时序列不方便  

Page 4: Pytables

Pytables  •  流畅性能的坚实基础 上层numpy下层hdf5  •  简单、快捷的存取接口  

•  强劲运算  •  I/O速度超强优化  •  重复/回退  •  超大数据容量  •  数据分层,          数据项多维数组  

total=sum(row['energy']  for  row  in  mytable.where('(pressure>10)&(count<1e7)')])  

Page 5: Pytables

pytables结构  

class  ParScle(IsDescripSon):          idenSty  =  StringCol(itemsize=22,  dflt="  ",  pos=0)    #  character  String          。。。  fileh  =  openFile("objec]ree.h5",  mode  =  "w")  group1  =  fileh.createGroup(fileh.root,  "group1")  array1  =  fileh.createArray(fileh.root,  "array1",  ["string",  "array"],  "String  array")  table1  =  fileh.createTable(group1,  "table1",  ParScle)  

Page 6: Pytables

class  

•  File:内存表征文件  •  Group:逻辑分组  •  Table: 结构化数据hdf5表征  •  Array  :  数组化hdf5,  CArray\EArray  •  Link  •  A]ributeSet:h5f.root._v_a]rs.obj  =  myObject    •  Expr:tb.Expr("2*a+b*c”).eval()  #  array([14,  24,  36])  

Page 7: Pytables

HDF5  

•  NCSA研制,美国国家高级计算应用中心,风云卫星使用  

•  6种数据类型,栅格图像、调色板、多维数据、注释、数据表、数据组  

•  类似一个文件系统,          分层结构  

Page 8: Pytables

工具  

•  GUI工具:java编写  •  ptdump:  观察结构、数据  •  ptrepack:不同文件间拷贝、合并、删除等  

Page 9: Pytables

numpy  创建:np.arange(0,  60,  10).reshape(-­‐1,  1)  +  np.arange(0,  6)  

Page 10: Pytables

Numpy结构化数组  

import  numpy  as  np    persontype  =  np.dtype({  

 'names':['name',  'age',  'weight'],    'formats':['S32','i',  'f']})  

a  =  np.array([    ("Zhang",32,75.5),("Wang",24,65.2)],    dtype=persontype)  

Page 11: Pytables

Matplotlib图库  

Page 12: Pytables

Matplotlib例  

import  matplotlib.pyplot  as  plt    f,  ax  =  plt.subplots()  ax.plot(x[],  y[],‘r-­‐’,  label=’xxx’)  ax.grid()  ax.set_Slte(‘example’)  ax.legend()  plt.show()  

Page 13: Pytables

谢谢