<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
@font-face
{font-family:"Helvetica Neue";
panose-1:2 0 5 3 0 0 0 2 0 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Aptos",sans-serif;
mso-ligatures:standardcontextual;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#467886;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">HI everyone,</p>
<p class="MsoNormal">At yesterday’s Telco, someone asked if I could share the file I showed in NeXpy. If you already have NeXpy installed (‘pip install nexpy’), then you already have the file. Just open NeXpy and click on “Open Example File” in the Help menu.
It was the one called “chopper.nxs”. Since there was some confusion even about the existence of links, I thought some notes might be helpful.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The reason the “target” attribute doesn’t appear in the NXDL files is roughly the same reason that “NX_class” attribute doesn’t appear. It’s part of the standard that is documented elsewhere (<a href="https://manual.nexusformat.org/design.html#design-links">https://manual.nexusformat.org/design.html#design-links</a>).
In fact, at one point, it was considered best practice (or even required) for everything in a NXdata group to be a link to an object elsewhere. If you look at the latest NeXus publication [M. Koennecke, et al, Physica B
<b>385–86</b>, 1343–1345 (2006)], it states that “The NXdata group holds links to all the variables varied or collected during the scan.” It later softens this requirement, but the tree structure of chopper.nxs illustrates this idea:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue"">>>> print(chopper['entry/data'].tree)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue"">data:NXdata<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue""> @axes = ['polar_angle', 'time_of_flight']<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue""> @signal = 'data'<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue""> data = int32(148x750)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue""> polar_angle -> /entry/instrument/detector/polar_angle<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue""> time_of_flight -> /entry/instrument/detector/time_of_flight<o:p></o:p></span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">In the absolutist version of NXdata, the data array should also have been linked to the corresponding NXdetector group.
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In the nexusformat API, I can add a link to a NXdata group (or anywhere) by typing:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue"">chopper[‘entry/data/polar_angle’] = NXlink(‘/entry/instrument/detector/polar_angle’)</span><span style="font-family:"Helvetica Neue""><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This automatically makes this a hard link, although you can add “soft=True” to make it a soft link. It then adds the “target” attribute to chopper[‘(‘/entry/instrument/detector/polar_angle’]. To do the same in h5py, you would have to type:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue"">with h5open(‘chopper.nxs’, ‘r+’) as f:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue""> f[‘/entry/data/polar_angle’] = f[‘/entry/instrument/detector/polar_angle’]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Helvetica Neue""> f[‘/entry/data/polar_angle’].attrs[‘target’] = ‘/entry/instrument/detector/polar_angle’<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This would add the ‘target’ attribute to object in both groups, since it’s the same object.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Personally, I think in the base classes, we should still only refer to fields, not links. In principle, any object, whether group or field, can be a link. In application definitions, if a field is contained within one group but also used
in another, such as a NXdata group, it should be explicitly listed as a link. Whether the documentation needs improving is another debate.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">With best regards,</p>
<p class="MsoNormal">Ray</p>
<div>
<div>
<p class="MsoNormal"><span style="mso-ligatures:none">-- <br>
Ray Osborn, Senior Scientist<br>
Materials Science Division<br>
Argonne National Laboratory<br>
Lemont, IL 60439, USA<br>
Phone: +1 (630) 252-9011<br>
Email: ROsborn@anl.gov<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>