|
|
# Create an `.h5` file
|
|
|
|
|
|
Assume the specfiles from a given experiment are all contained in a `<exp_code>/spec/` directory of contents similar to:
|
|
|
|
|
|
```bash
|
|
|
$ ls -l
|
|
|
-rw-r--r-- 1 opid01 id01 973750 Jul 12 15:48 align_fast_00004.spec
|
|
|
-rw-r--r-- 1 opid01 id01 572904 Jul 12 17:34 align_fast_00005.spec
|
|
|
-rw-r--r-- 1 opid01 id01 142912 Jul 12 18:09 align.spec
|
|
|
-rw-r--r-- 1 opid01 id01 4556562 Jul 13 17:21 E16088_furnace.spec
|
|
|
-rw-r--r-- 1 opid01 id01 902803 Jul 18 05:13 E16095_furnace_2
|
|
|
-rw-r--r-- 1 opid01 id01 7344470 Jul 18 01:18 E16095_furnace_2_fast_00010.spec
|
|
|
-rw-r--r-- 1 opid01 id01 996341 Jul 18 03:29 E16095_furnace_2_fast_00028.spec
|
|
|
-rw-r--r-- 1 opid01 id01 1862854 Jul 19 13:26 E16095_furnace_2_fast_00054.spec
|
|
|
```
|
|
|
|
|
|
Where the sample name or code is contained at least somewhere in the specfile name. Then the following script can be used to create an `.h5` file containing all the data from the experiment organised in Groups having the name of each sample:
|
|
|
|
|
|
```python
|
|
|
from id01lib import id01h5
|
|
|
from silx.io.spech5 import SpecH5
|
|
|
from datetime import datetime
|
|
|
from glob import glob
|
|
|
|
|
|
# Specify spec directory
|
|
|
specpath = '/data/visitor/hc2912/id01/spec/'
|
|
|
# Include sample names
|
|
|
samples = ['E16088', 'E16095', 'E17049', 'm13045ii_a3']
|
|
|
|
|
|
# Loop over all spec files
|
|
|
with id01h5.ID01File('hc2912.h5') as h5f:
|
|
|
for name in samples:
|
|
|
if name in h5f:
|
|
|
sample = h5f[name]zatterin created page: test
|
|
|
else:
|
|
|
sample = h5f.addSample(name)
|
|
|
flist = glob(specpath+'*'+str(name)+'*'+'.spec')
|
|
|
for path in flist:
|
|
|
sample.importSpecFile(path, verbose=True, compr_lvl=6)
|
|
|
hf5.flush()
|
|
|
h5f.close()
|
|
|
```
|
|
|
|
|
|
The output is (in this case) a file `hc2912.h5` contained in the directory where the script is run. If only a specific saample or specfile wants to be added to an `/h5` file, instead:
|
|
|
|
|
|
```python
|
|
|
# create h5 file
|
|
|
h5f = id01h5.ID01File('/users/opid01/edo/inhouse_edo/hc2912.h5')
|
|
|
|
|
|
# specify specfile you're taking data from
|
|
|
specpath = '/data/visitor/hc2912/id01/spec/E17049_fast_00008.spec'
|
|
|
|
|
|
# add the sample
|
|
|
sample = h5f.addSample('e17049')
|
|
|
sample.importSpecFile(specpath, verbose=True)
|
|
|
|
|
|
# close the h5 file
|
|
|
h5f.flush()
|
|
|
h5f.close() |