跳转到主要内容

读取符合NXmx应用定义的NeXus格式的HDF5数据

项目描述

在Python中读取符合NXmx风格的NeXus HDF5数据

PyPI release Supported Python versions Code style: black

此包提供了一个整洁的Python接口,用于读取符合HDF5文件的结构,这些文件按照NXmx应用定义NeXus标准

安装

python-nxmx在PyPI上作为nxmx提供,因此您只需要Pip。

$ pip install nxmx

入门

如果您有一个NXmx格式的HDF5文件,使用h5ls检查它将类似于以下内容

$ h5ls -r my-nxmx-file.h5 
/                        Group
/entry                   Group
/entry/data              Group
/entry/definition        Dataset {SCALAR}
/entry/end_time          Dataset {SCALAR}
/entry/end_time_estimated Dataset {SCALAR}
/entry/instrument        Group
/entry/instrument/beam   Group
/entry/instrument/beam/incident_beam_size Dataset {2}
/entry/instrument/beam/incident_wavelength Dataset {SCALAR}
/entry/instrument/beam/total_flux Dataset {SCALAR}
/entry/instrument/detector Group

... etc. ...

使用nxmx,您可以在Python中这样访问NXmx数据

import h5py
import nxmx

with h5py.File("my-nxmx-file.h5") as f:
    nxmx_data = nxmx.NXmx(f)

一个更详细的示例

import h5py
import nxmx

with h5py.File("my-nxmx-file.h5") as f:
    nxmx_data = nxmx.NXmx(f)
    # Explore the NXmx data structure.
    entry, *_ = nxmx_data.entries
    print(entry.definition)  # Prints "NXmx".
    instrument, *_ = entry.instruments
    detector, *_ = instrument.detectors
    
    # Get the h5py object underlying an instance of a NX class.
    entry_group = entry._handle  # entry_group == f["entry"]

    # Find instances of a given NX class in a h5py.Group.
    beams = nxmx.find_class(instrument._handle, "NXbeam")
    # The equivalent for more than one NX class.
    beams, detectors = nxmx.find_classes(instrument._handle, "NXbeam", "NXdetector")

    # Query attributes of an object in the normal h5py way.
    # Suppose out detector has a transformation called "det_z".
    transformations, *_ = nxmx.find_class(detector._handle, "NXtransformations")
    attrs = transformations["det_z"].attrs  # Get the attributes of the "det_z" dataset.

项目详情


下载文件

下载适用于您的平台文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

nxmx-0.0.4.tar.gz (22.9 kB 查看哈希值)

上传时间

构建分发

nxmx-0.0.4-py3-none-any.whl (15.9 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面