forked from Vindaar/TimepixAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDL_toNewVarNames.nim
More file actions
73 lines (60 loc) · 2.57 KB
/
CDL_toNewVarNames.nim
File metadata and controls
73 lines (60 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
## a simple program which extracts the names of the properties
## in the calibration-cdl.h5 file, in order to relate them to
## the new variable names.
import nimhdf5
import os, strutils
import strtabs
import tables
const pathCDL = "/mnt/Daten/CAST/CDL-reference/calibration-cdl.h5"
const pathRun = "/home/basti/CastData/ExternCode/TimepixAnalysis/Analysis/ingrid/run_file.h5"
# take a random group as the path in order to extract the names
const groupCdlPath = "/calibration-cdl-apr2014-Ag-Ag-6kV"
const groupRunPath = "/reconstruction/run_114/chip_3"
var h5cdl = H5open(pathCDL, "r")
var h5run = H5open(pathRun, "r")
var groupCDl = h5cdl[groupCdlPath.grp_str]
var groupRun = h5run[groupRunPath.grp_str]
for d in groupCDL:
echo d.name.extractFilename
echo ""
for d in groupRun:
echo d.name.extractFilename
# the resulting tab is the following
let tab = {"NumberOfPixels" : "hits",
"Width" : "width",
"SkewnessTransverse" : "skewnessTransverse",
"KurtosisLongitudinal" : "kurtosisLongitudinal",
"Length" : "length",
"FractionWithinRmsTransverse" : "fractionInTransverseRms",
"PositionX" : "centerX",
"RmsLongitudinal" : "rmsLongitudinal",
"KurtosisTransverse" : "kurtosisTransverse",
"EnergyFromCharge" : "energyFromCharge",
"RotationAngle" : "rotationAngle",
"SkewnessLongitudinal" : "skewnessLongitudinal",
"EventNumber" : "eventNumber",
"RmsTransverse" : "rmsTransverse",
"PositionY" : "centerY",
"Excentricity" : "eccentricity",
"TotalCharge" : "totalCharge" }.toTable()
# using this we will store all information from the CDL file in a
# new version of it
var h5f = H5open("calibration-newTos.h5", "rw")
var recoGroup = h5f.create_group("/reconstrution")
var dataTab = initTable[string, seq[float32]]()
for k in keys(tab):
dataTab[k] = @[]
for g in h5cdl:
# iterating over all groups and read data in `tab`, then add to dataTab
echo "in g ", g
for key in keys(tab):
echo "accessing ", g.name / key
let data = h5cdl[g.name / key, float32]
# given data add to tab
dataTab[key].add data
for k, v in dataTab:
# get key for output
let outKey = tab[k]
var dset = h5f.create_dataset(recoGroup.name / outKey, dtype = float32, shape_raw = @[v.len, 1])
dset[dset.all] = v
discard h5f.close()