1"""
2Reading Ceed Experiment Data
3============================
4
5This script shows how to read the ceed data stored in an h5 file, after it has
6been mrged with the MCS multi-electrode array (MEA) data.
7"""
8from ceed.analysis import CeedDataReader
9from pprint import pprint
10
11ceed_data = '../data/experiment_data_merged.h5'
12
13# create instance that can load the data
14reader = CeedDataReader(ceed_data)
15print('Created reader for file {}'.format(reader.filename))
16# open the data file
17reader.open_h5()
18
19# once loaded, the version and the overall file log and file notes is available
20print('-' * 20)
21print('The ceed version of the file is {}'.format(reader.ceed_version))
22print('The file log is:\n{}\n'.format(reader.app_logs.strip()))
23print('The file notes is:\n{}\n'.format(reader.app_notes.strip()))
24
25# get the number of experiments and images stored in the file. These images
26# are in addition to the camera images stored with each experiment
27print('Experiment names found in the file: {}'.format(
28 reader.experiments_in_file))
29
30print('Number of saved images found in the file (excluding images within the '
31 'experiments): {}'.format(reader.num_images_in_file))
32for i in range(reader.num_images_in_file):
33 img, notes, save_time = reader.get_image_from_file(i)
34 print('Image {}, create at time={}, notes:\n{}\n'.format(
35 img, save_time, notes))
36print('-' * 20)
37
38
39# load the mcs data into memory
40reader.load_mcs_data()
41electrodes = sorted(reader.electrodes_data.keys())
42if electrodes:
43 e0 = electrodes[0]
44 print('Electrodes found in the file: {}'.format(electrodes))
45 print('Electrode "{}" data array shape is {}'.format(
46 e0, reader.electrodes_data[e0].shape))
47
48 s0, s1 = reader.electrodes_data[e0][0], reader.electrodes_data[e0][-1]
49 print('Electrode "{}" first and last raw data samples are {}, {}'.format(
50 e0, s0, s1))
51 offset, scale = reader.get_electrode_offset_scale(e0)
52 unit = reader.electrodes_metadata[e0]['Unit']
53 print('Electrode "{0}" first and last data samples are {1}{3}, {2}{3}'.
54 format(e0, (s0 - offset) * scale, (s1 - offset) * scale, unit))
55
56 print('Electrode "{}" metadata:'.format(e0))
57 pprint(reader.electrodes_metadata[e0])
58else:
59 print('Electrode data not found in the file. Did you forget to merge it '
60 'into the ceed data file?')
61
62if reader.electrode_dig_data is not None:
63 print('Electrodes digital data shape is {}'.format(
64 reader.electrode_dig_data.shape))
65else:
66 print('Electrodes digital data not found in the file')
67print('-' * 20)
68
69
70# load a particular experiment
71reader.load_experiment(1)
72print('Loaded experiment {}'.format(reader.loaded_experiment))
73print('Stage run for this experiment is "{}"'.format(
74 reader.experiment_stage_name))
75
76if reader.electrode_intensity_alignment_gpu_rate is None:
77 print('Ceed-MCS alignment not found in the file. Did you forget to merge '
78 'it into the ceed data file?')
79else:
80 print('Ceed-MCS alignment indices shape is {}'.format(
81 reader.electrode_intensity_alignment_gpu_rate.shape))
82
83# print the experiments notes, if any
84print('The experiment notes is:\n{}\n'.format(reader.experiment_notes.strip()))
85print('Experiment start is at time={}'.format(reader.experiment_start_time))
86print('Experiment camera image={}'.format(reader.experiment_cam_image))
87
88shapes = sorted(reader.shapes_intensity_rendered_gpu_rate.keys())
89print('Found the following shapes in the experiment: {}'.format(shapes))
90print('The intensity array for shape "{}" is size {}'.format(
91 shapes[0], reader.shapes_intensity_rendered_gpu_rate[shapes[0]].shape))
92
93print('The array recording the projector LED state is shape {}'.format(
94 reader.led_state.shape))
95
96print('Closing data file')
97reader.close_h5()