Page History
...
Currently LCLS does not offer a an uniform approach to the analysis of accumulated experemental data. Users exploit myana
, pyana
, MatLab
, IDL
, CASS
, and probably something else. The work on long-awaited project of psana
is in progress. The psana
is going to be quite generic and probably not so simple approach. In this page we discuss a simple but absolutly flexible approach to analysis of data stored in HDF5 files. It is based on Python
code with extensive exploitation of standard libraries. A few examples of how to access and process data are presented at the end of this page.
...
Code Block |
---|
print 'arr1ev.shape =', arr1ev.shape print 'arr1ev =\n', arr1ev |
Advanced operations
Get item attributes
Get group name and the list of daughters
Check if the HDF5 item is "File", "Group", or "Data"
Extract time
Time variable is stored in HDF5 as a tuple of two long integer numbers representing the seconds since 01/01/1970 and nanoseconds as a fraction of the second. Time can be stored in the group attributes and in the data record with name "time", which can be extracted as shown below
- from the group attributes
Code Block group = file["/Configure:0000"] time_sec = group.attrs.values()[0] time_nsec = group.attrs.values()[1]
- from the
time
data recordCode Block time_dataset = file['/Configure:0000/Run:0000/CalibCycle:0002/Acqiris::DataDescV1/XppLas.0:Acqiris.0/time'] index = 0 # this is an index in the dataset time = time_dataset[index] # get the time tuple consisting of seconds and nanoseconds time_sec = time[0] time_nsec = time[1]
Code examples
Example 1, basic operations:
Code Block |
---|
#!/usr/bin/env python import h5py import numpy as np eventNumber = 5 file = h5py.File('/reg/d/psdm/XPP/xppcom10/hdf5/xppcom10-r0546.h5', 'r') dataset = file['/Configure:0000/Run:0000/CalibCycle:0000/Camera::FrameV1/XppSb4Pim.1:Tm6740.1/image'] arr1ev = dataset[eventNumber] file.close() print 'arr1ev.shape =', arr1ev.shape print 'arr1ev =\n', arr1ev |
Example 2, advanced operations:
Code Block |
---|
Needs to be added
|
Example, extract and print the time variables:
Code Block |
---|
#!/usr/bin/env python
import h5py
import time
#-----------------------------------------------------
def print_time(t_sec, t_nsec):
"""Converts seconds in human-readable time and prints formatted time"""
tloc = time.localtime(t_sec) # converts sec to the tuple struct_time in local
print 'Input time :',t_sec,'sec,', t_nsec,'nsec, '
print 'Local time :', time.strftime('%Y-%m-%d %H:%M:%S',tloc)
#-----------------------------------------------------
file_name = '/reg/d/psdm/xpp/xpp22510/hdf5/xpp22510-r0100.h5'
file = h5py.File(file_name, 'r') # open read-only
print "EXAMPLE: Get time from the group attributes:"
group = file["/Configure:0000"]
t_sec = group.attrs.values()[0]
t_nsec = group.attrs.values()[1]
print_time(t_sec, t_nsec)
print "EXAMPLE: Get time from the data record 'time':"
dataset = file['/Configure:0000/Run:0000/CalibCycle:0002/Acqiris::DataDescV1/XppLas.0:Acqiris.0/time']
index = 0
time = dataset[ind]
t_sec = time[0]
t_nsec = time[1]
print_time(t_sec, t_nsec)
f.close()
#----------------------------------------------------
|