Page History
...
Code Block |
---|
dataset = fieldA: [3x1 uint16] fieldB: [3x1 float32] |
new users that will work with Matlab should contact their experiment POC's to see if they have any recommended code or tools. For instance XPP has developed numerous functions to help Matlab users work with LCLS data efficiently, including Evr vlen data which we discuss below.
vlen data
Although much of the LCLS data fits into the simpler static model of arrays, or structs whose fields are arrays, some of the LCLS data can be quite complex. In particular data written as HDF5 variable length data (vlen data) will show up in cell arrays in Matlab. One example that users may want to work with is the Evr Data. the The evr data includes a list of the event codes that fired during an event. Below we'll take a look at As suggested above, contact your experiment POC about any Matlab code that is recommend for this kind of task. Below we provide a simple example for working with the evr data in Matlab. We'll unpack the cell array based data into a flat array. From the flat array, we'll make a logical index array of the events with a certain event code. Then we'll use this to average over cspad for those events.
Code Block |
---|
% we'll read evr data from the first calib cycle of a tutorial file: using Matlab's high level read function evrData = h5read('/reg/d/psdm/xpp/xpptut13/hdf5/xpptut13-r0179.h5','/Configure:0000/Run:0000/CalibCycle:0000/EvrData::DataV3/NoDetector.0:Evr.0/data'); % evrData is a struct with one element - fifoEvents. fifoEvents is a cell array with one entry per event in the CalibCycle fifoEvents = evrData.fifoEvents; numberOfEvents = length(fifoEvents); % numberOfEvents is 483 % let's identify the smallest and largest event code codes in this calib cycle minEventCode=99999; maxEventCode=0; for eventIdx = 1:numberOfEvents; maxEventCode = max(maxEventCode, max(fifoEvents{eventIdx}.eventCode)); end; for eventIdx = 1:numberOfEvents; minEventCode = min(minEventCode, min(fifoEvents{eventIdx}.eventCode)); end; assert(minEventCode>0, 'unexpected - minimum event code should be greater than 0. matlab uses 1-up array indexing, 0 will not work with below code'); % lets fill out a flat Array, each row is an event, and column k is 1 only if eventCode k occurred in that event eventCodesFlat = int8(zeros(numberOfEvents, maxEventCode)); for evtIdx=1:numberOfEvents; eventCode = fifoEvents{evtIdx}.eventCode; for ec=eventCode; eventCodesFlat(evtIdx,ec)=1; end; end; % here is an example of how you might work with the flat array numberOfEventsWithEventCode42 = sum(eventCodesFlat(:,42)); % there are 121 events with event code 42 % lets say we want to average over the cspad data for just those 121 events. % The below code is easy to write, although it uses quite a bit of memory: cspad = h5read('/reg/d/psdm/xpp/xpptut13/hdf5/xpptut13-r0179.h5','/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGon.0:Cspad.0/data'); % That reads in 2GB - 483 events * 2 bytes per element * 32 * 185 * 388. % cspad's size is 388 185 32 483 eventsWith42 = eventCodesFlat(:,42)==1; assert(length(eventsWith42)==length(cspad), 'number of events with cspad != number of events with evr data, even if equal, should do more and check that all entries in time datasets are the same'); Â cspadEventCode42 = cspad(:,:,:,eventsWith42); % size(cspadEventCode42) returns 388 185 32 121 cspadAverageEventCode42 = mean(cspadEventCode42,4); |
...