The NxsReader Class

NxsReader servers these purposes:

Let's look at an example:

In [16]: import HasyUtils

In [17]: o = HasyUtils.nxsReader( 'nexusTest_00385.nxs')

In [18]: dir(o)
Out[18]: 
[...
 'collectStatus',
 'createFile',
 'display',
 'fileName',
 'fillTestData',
 'pathDct',
 'purge',
 'search',
 ...]

Explanations:

Let's look at a specific NeXus field holding the Pilatus data:

In [1]: import HasyUtils

In [2]: o = HasyUtils.nxsReader( 'nexusTest_00385.nxs')

In [3]:  lst = o.search(ndim=3)

In [4]: len(lst)
Out[4]: 1

In [5]: pilatus = lst[0]

In [6]: pilatus.path
Out[6]: '/scan:NXentry/instrument:NXinstrument/pilatus:NXdetector/data'

In [7]: pilatus.shape
Out[7]: (27, 195, 487)

In [8]: pilatus.dtype
Out[8]: 'int32'

In [9]: type( pilatus.value)
Out[9]: numpy.ndarray

In [10]: pilatus.value
Out[10]: 
array([[[33, 34, 32, ..., 19, 22, 19],
        [25, 19, 17, ..., 20, 12, 31],
        [33, 21, 28, ..., 14, 16, 18],
        ..., 
        [27, 16, 26, ..., 12, 19, 26],
        [33, 20, 25, ..., 17, 10, 24],
        [30, 31, 27, ..., 21, 14, 14]]], dtype=int32)

In [11]: pilatus.parent.path
Out[11]: '/scan:NXentry/instrument:NXinstrument/pilatus:NXdetector'

In [12]: pilatus.parent.parent.path
Out[12]: '/scan:NXentry/instrument:NXinstrument'

In [13]: pilatus.parent.parent.parent.path
Out[13]: '/scan:NXentry'

In [14]: pilatus.parent.parent.parent.parent.path
Out[14]: '/'

Explanation:

The next example shows how a field is inserted:

In [29]: import HasyUtils

In [30]: import numpy as np

In [31]: o = HasyUtils.nxsReader( 'nexusTest_00414.nxs')

In [32]: targetGroup = o.pathDct['/']

In [33]: lst = [1, 3, 5, 7, 11, 13, 17, 19]

In [34]: newField = HasyUtils.NxsField( targetGroup, "Primes", "/Primes", 'int64', (len(lst),), np.array(lst))

In [35]: targetGroup.fields.append( newField)

In [36]: p, = o.search( field='Primes')

In [37]: p.name
Out[37]: 'Primes'

In [38]: p.path
Out[38]: '/Primes'

In [39]: p.shape
Out[39]: (8,)

In [40]: p.value
Out[40]: array([ 1,  3,  5,  7, 11, 13, 17, 19])

In [41]: newField = HasyUtils.NxsField( targetGroup, "TestString", "/TestString", 'string', (1,), "a test string")

In [42]: targetGroup.fields.append( newField)

In [43]: o.createFile( 'newFileName.nxs')

Explanation:

2019-11-13