Example #1
0
def ui_imagearray(header, index=0):
    "Return image array from the header object and event index."
    e = blank_events(header)[index]
    fill_event(e)
    nm = [k for k in e.data if k.endswith('image_lightfield')][0]
    rv = e.data[nm][0]
    return rv
Example #2
0
def export(headers, filename):
    """
    Parameters
    ----------
    headers : a Header or a list of Headers
        objects retruned by the Data Broker
    filename : string
        path to a new or existing HDF5 file
    """
    with h5py.File(filename) as f:
        for header in headers:
            assert isinstance(header, MutableMapping)
            header = copy.deepcopy(header)
            try:
                descriptors = header.pop('event_descriptors')
            except KeyError:
                warnings.warn("Header with uid {header.uid} contains no "
                              "data.".format(header), UserWarning)
                continue
            top_group_name = repr(header).replace(' ', '_')[1:-1]
            group = f.create_group(top_group_name)
            _safe_attrs_assignment(group, header)
            for i, descriptor in enumerate(descriptors):
                desc_group = group.create_group('Event_Stream_{0}'.format(i))
                data_keys = descriptor.pop('data_keys')
                _safe_attrs_assignment(desc_group, descriptor)
                events = list(find_events(descriptor=descriptor))
                event_times = [e['time'] for e in events]
                desc_group.create_dataset('event_times', event_times)
                data_group = desc_group.create_group('data')
                ts_group = desc_group.create_group('timestamps')
                [fill_event(e) for e in events]
                for key, value in data_keys.items():
                    print('data key = %s' % key)
                    timestamps = [e['timestamps'][key] for e in events]
                    ts_group.create_dataset(key, data=timestamps)
                    data = [e['data'][key] for e in events]
                    dataset = data_group.create_dataset(key, data=data)
Example #3
0
def events_generator(header):
    "Return a generator of Events. Large (nonscalar) data is lazy-loaded."
    for e in blank_events(header):
        fill_event(e)
        yield e
Example #4
0
 def fill_all_events(*args, **kwargs):
     events = func(*args, **kwargs)
     for event in events:
         fill_event(event)
     return events