9. Nexus数据文件

DASC小组正在实施跨所有光束线的Nexus文件写入。对于MX光束线,这将作为档案格式。

9.1. 概述

Nexus文件的结构非常灵活,既可以存储简单的数据集,例如单个数据阵列及其轴,也可以存储高度复杂的数据,例如整个多组件仪器的仿真结果。这种灵活性是通过分层结构实现的,将相关数据项收集到组中,即使没有任何文档也可以轻松导航Nexus文件。Nexus文件是自我描述的,应该很容易理解,至少对于那些熟悉实验技术的人来说是这样。

9.2. 在钻石上使用Nexus。

9.2.1. 配置GDA以生成Nexus。

为了配置GDA以生成Nexus文件,需要设置几个配置设置。首先,在java.properties文件中,确保数据写入器的格式设置为NexusDataWriter,即::

gda.data.scan.datawriter.dataFormat=NexusDataWriter

接下来,我们需要确保GDA可以找到所需的相关Nexus库。因此,对于需要访问Nexus文件的任何进程(通常仅为命令服务器),我们需要向启动命令添加以下参数:

-Djava.library.path=$GDA_ROOT/lib/Linux-i386

在哪里? GDA_ROOT 定义为安装GDA的位置。我们还假设我们在一台32位Linux机器上运行。

最后,我们需要确保 LD_LIBRARY_PATH 还包含库路径(例如 $GDA_ROOT/lib/Linux-i386 )。对于Microsoft Windows,我们只需确保库目录(例如 %GDA_ROOT%/lib/win32 )位于系统路径中。

重要

如果您使用标准的GDA启动脚本,那么这些修改已经就绪,您需要设置的只是java属性。

9.3. 相关的Java属性

下面是为了配置DataWriter行为的某些方面而可以定义的Java属性的摘要。

Nexus Java属性

Java属性名称

违约

可能的

描述

gda.nexus.backend

HDF5

HDF5、XML

要使用的磁盘格式。

gda.nexus.beamlinePrefix

对,错

是否对数据文件使用“iXX-”前缀。

gda.nexus.createSRS

对,错

是否还要创建ASCII数据文件。

9.4. 有用的Java接口

如果可扫描对象实现 INeXusInfoWriteable 接口之后,它将能够将附加信息写入该可扫描Nexus组中的Nexus文件,该组通常是NX定位器(可扫描对象)或NX检测器(检测器)。

作为示例,下面是来自 ScannableMotionBase 设备:

public void writeNeXusInformation(GdaNexusFile file) {
    try {
        NeXusUtils.writeNexusDoubleArray(file, "soft_limit_min", getUpperGdaLimits());
        NeXusUtils.writeNexusDoubleArray(file, "soft_limit_max", getLowerGdaLimits());
        NeXusUtils.writeNexusDoubleArray(file, "tolerance", getTolerance());
        NeXusUtils.writeNexusInteger(file, "gda_level", getLevel());  // Non-official field
    } catch (NexusException e) {
        logger.debug("ScannableMotionBase: Problem writing additional info to NeXus file.");
    }
}

另外,这里有一个来自 CounterTimerBase

public void writeNeXusInformation(GdaNexusFile file) {
    try {
        NeXusUtils.writeNexusString(file, "description", getDescription());
        NeXusUtils.writeNexusString(file, "type", getDetectorType());
        NeXusUtils.writeNexusString(file, "id", getDetectorID());
    } catch (NexusException e) {
        logger.debug("CounterTimerBase: Problem writing additional info to NeXus file.");
    } catch (DeviceException e) {
        logger.debug("CounterTimerBase: Problem writing additional info to NeXus file.");
    }
}

您可以看到,通过实现此接口,您还可以将所需的任何信息写入Nexus文件。

9.5. 在扫描之外使用Nexus。

目前,Nexus写入主要与扫描机制捆绑在一起。这就是大部分测试已经进行的地方。可以在Jython脚本中使用NexusDataWriter,但目前这被认为是“试验性的”。

9.6. 捕获其他信息

9.6.1. 元数据

默认情况下,将在所有光束线上捕获多个项目。这些主要是与机器(源)相关的项目。所有元数据都使用GdaMetadata类读出。

基本上,为了记录特定值,您需要在服务器XML文件中定义一个具有特定名称的MetadataEntry。它们可以使用任何受支持的来源来实际获取数据,例如scannable、epics pv、java property、ICAT值等。

目前仅在扫描开始时捕获这些值,这将扩展到允许在各种“触发点”捕获,例如:

  • 开始扫描。

  • 扫描结束。

  • 在扫描开始和结束时。

  • 在每个扫描点。

  • 在指定的时间段(长期发展)

9.6.2. 元数据项到Nexus类的映射

本节列出了Nexus类中各种项之间的映射,以及需要调用哪些元数据项才能填充它们。

NXsource

字段名

元数据名称

资料型态

描述

名称

facility.name

名字

类型

instrument.source.type

设施类型(例如“同步加速器X射线源”)

探头

instrument.source.probe

辐射类型(如x射线、红外线等)

模式

source.fillMode

同步加速器运行模式

facility_mode

facility.mode

设施运行模式(例如“用户”、“机器日”等)

笔记

instrument.source.notes

MCR消息

频率

instrument.source.frequency

双重的

同步加速器频率(赫兹)

电压

instrument.source.energy

双重的

GeV中的同步加速器能量

权力

instrument.source.power

双重的

功率

current

instrument.source.current

双重的

当前

top_up

instrument.source.top_up

布尔

同步加速器是否处于充值模式?

NXmonochromator

字段名

元数据名称

资料型态

描述

名称

instrument.monochromator.name

名字

波长

instrument.monochromator.wavelength

双重的

波长

能量

instrument.monochromator.energy

双重的

能量

NXbending_magnet

字段名

元数据名称

资料型态

描述

名称

instrument.bending_magnet.name

名字

bending_radius

instrument.bending_magnet.bending_radius

双重的

折弯半径

光谱

instrument.bending_magnet.spectrum

NXdata

Spectrum

critical_energy

instrument.bending_magnet.critical_energy

双重的

临界能量

NXinsertion_device

字段名

元数据名称

资料型态

描述

名称

instrument.insertion_device.name

名字

类型

instrument.insertion_device.type

“波浪器”或“摇摆器”

缺口

instrument.insertion_device.gap

双重的

差距

锥化

instrument.insertion_device.taper

双重的

锥化

阶段

instrument.insertion_device.phase

双重的

相位

极点

instrument.insertion_device.poles

整数

极数

长度

instrument.insertion_device.length

双重的

设备长度

权力

instrument.insertion_device.power

双重的

设备提供的总功率。

能量

instrument.insertion_device.energy

双重的

峰值能量

带宽

instrument.insertion_device.bandwidth

双重的

峰值能量的带宽

光谱

instrument.insertion_device.spectrum

NXdata

插入器件的频谱。

谐波

instrument.insertion_device.harmonic

整数

峰的谐波。

9.6.3. 将任意元数据写入Nexus文件

在某些情况下,在数据文件中包含任意注释或字段非常有用。要实现这一点,可以指定元数据字段以及应在文件中写入的路径。

例如,要在示例NXsample节点中包含示例名称字段,请在Spring GDA配置中包含类似以下内容的bean:

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="staticMethod" value="gda.data.scan.datawriter.NexusDataWriter.setMetadata"/>
    <property name="arguments">
        <map>
            <entry key="sample_name" value="sample:NXsample/name"/>
        </map>
    </property>
</bean>

这将在采样组中包含一个名称字段,其中包含具有名称的条目的元数据值(在扫描开始时读取 sample_name 。(NB元数据名称不必与结点文件中的条目匹配)

要包含的元数据可以在运行时通过Jython控制台进行更改:

>>> from gda.data.scan.datawriter import NexusDataWriter
>>> NexusDataWriter.updateMetadata({'xyz': 'sample:NXsample/abc'})
>>> # Scans from here will include xyz metadata
>>> NexusDataWriter.removeMetadata(['xyz'])
>>> # xyz will no longer be written to scan files

9.7. GDA帮助器函数

gda.data.nexus.NeXusUtils 类中有许多静电助手函数,它们使得写入NEXUS文件变得简单。下面是最有用(但不是所有)函数的列表。

openNeXusFile()

打开Nexus文件(读写)并返回文件handlen。

openNeXusFileReadOnly()

打开Nexus文件(只读)并返回文件句柄。

writeNexusDouble()

将双精度值写入当前文件位置具有指定名称的字段。

writeNexusDoubleArray()

将双精度数组写入当前文件位置具有指定名称的字段。

writeNexusInteger()

将整数写入当前文件位置具有指定名称的字段。

writeNexusIntegerArray()

将整数数组写入当前文件位置具有指定名称的字段。

writeNexusLong()

将长整型写入当前文件位置具有指定名称的字段。

writeNexusLongArray()

将长整型数组写入当前文件位置具有指定名称的字段。

writeNexusString()

在当前文件位置将字符串写入具有指定名称的字段。

writeNexusBoolean()

在当前文件位置将布尔值写入具有指定名称的字段。