简体   繁体   English

如何使用python熊猫打开nxs文件?

[英]How can I open an nxs file with python pandas?

I have a Nexus file (foo.nxs) with direct data from measurements and I wish to open it with pandas. 我有一个Nexus文件(foo.nxs),其中包含来自测量的直接数据,我希望用熊猫打开它。 However, when I try the typical 但是,当我尝试典型的

HDFStore('foo.nxs') or read_hdf('foo.nxs','/group')

It just returns an empty Store: 它只是返回一个空的Store:

<class 'pandas.io.pytables.HDFStore'>
File path: /foo.nxs
Empty

or the TypeError: 或TypeError:

TypeError: cannot create a storer if the object is not existing nor a value are passed

All examples in the docs page start by creating a hdf file, storing data in it and then retrieving it, but this is done from the same pandas. docs页面中的所有示例都首先创建一个hdf文件,然后将数据存储在其中,然后再检索它,但这是通过同一只熊猫完成的。 I want to know whether it's possible to read an hdf file which was not previously generated with pandas. 我想知道是否可以读取以前不是用熊猫生成的hdf文件。

Here's a part of the output from ptdump, as requested by @Jeff: 这是@Jeff请求的ptdump输出的一部分:

/ (RootGroup) ''
  /._v_attrs (AttributeSet), 4 attributes:
    [HDF5_Version := '1.8.11',
    NeXus_version := '4.3.0',
    file_name := '/Messdaten/C9/20140423/messung_21h14m01.197.nxs',
    file_time := '2014-04-23T21:14:01+01:00']
/exp_root.Kerr.DoublePulse2D.SuperDuperScan_V2_00001 (Group) ''
  /exp_root.Kerr.DoublePulse2D.SuperDuperScan_V2_00001._v_attrs (AttributeSet), 1 attributes:
   [NX_class := 'NXentry']
/exp_root.Kerr.DoublePulse2D.SuperDuperScan_V2_00001/scan_data (Group) ''
  /exp_root.Kerr.DoublePulse2D.SuperDuperScan_V2_00001/scan_data._v_attrs (AttributeSet), 1 attributes:
   [NX_class := 'NXdata']
/exp_root.Kerr.DoublePulse2D.SuperDuperScan_V2_00001/scan_data/actuator_1_1 (CArray(5, 121), zlib(6)) ''
  atom := Float64Atom(shape=(), dflt=0.0)
  maindim := 0
  flavor := 'numpy'
  byteorder := 'little'
  chunkshape := (5, 121)

You have a plain vanilla PyTables store. 您有一个普通的香草PyTables商店。 So these are actually pretty easy to read (and don't need pandas), but this will show you how you can read them (as numpy arrays). 因此,它们实际上很容易阅读(不需要熊猫),但这将向您展示如何阅读(作为numpy数组)。

with pd.get_store('test.h5') as store:
     data = store.root.exp_root.Kerr.DoublePulse2D.SuperDuperScan_V2_00001/scan_data/actuator_1_1.read()

docs are here . 文档在这里

This just grabs the PyTables root node and reads the data in. This is in CArray format, and is a simple array. 这只是获取PyTables根节点并读取数据。这是CArray格式,是一个简单的数组。

HDFStore will be able to read plain-vanilla PyTables Table objects (with out the meta data), but simple enough to just read in arrays. HDFStore将能够读取普通的PyTables Table对象(不包含元数据),但足够简单,只需读取数组即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM