Generating Movie from Ceed Experiment Data

 1"""
 2Generating Movie from Ceed Experiment Data
 3==========================================
 4
 5This script shows how to read the ceed data stored in an h5 file and then
 6generate a movie showing the experiment that was played as well as the MEA
 7data.
 8"""
 9from ceed.analysis import CeedDataReader
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# get the number of experiments and images stored in the file. These images
20# are in addition to the camera images stored with each experiment
21print('Experiment names found in the file: {}'.format(
22      reader.experiments_in_file))
23
24# load the mcs data into memory
25reader.load_mcs_data()
26if not reader.electrodes_data:
27    print('Electrode data not found in the file. Did you forget to merge it '
28          'into the ceed data?')
29if reader.electrode_dig_data is None:
30    print('Electrodes digital data not found in the file')
31
32
33# load a particular experiment
34reader.load_experiment(1)
35print('Loaded experiment {}'.format(reader.loaded_experiment))
36print('Stage run for this experiment is {}'.format(
37    reader.experiment_stage_name))
38if reader.electrode_intensity_alignment_gpu_rate is None:
39    print('Ceed-MCS alignment not found in the file. Did you forget to merge '
40          'it into the ceed data file?')
41
42# experiments normally have a camera image of the slice florescence before the
43# experiment - you can save it to a file. Only bmp is supported (I think)
44print('Saving background camera image at '
45      '../data/experiment_slice_florescence.bmp')
46reader.save_image(
47    '../data/experiment_slice_florescence.bmp', reader.experiment_cam_image)
48
49# this list is a list of functions that is past to the movie generator
50# function, each of the functions are called for every frame and are given the
51# opportunity to show something
52paint_funcs = [
53    # this function displays the experiment's background image in the
54    # background at the appropriate orientation as in the experiment
55    reader.paint_background_image(
56        reader.experiment_cam_image,
57        transform_matrix=reader.view_controller.cam_transform),
58    # this function displays the experiment's MEA electrode center locations
59    # at the appropriate orientation as in the experiment
60    reader.show_mea_outline(reader.view_controller.mea_transform),
61    # this function shows the electrode voltage data
62    reader.paint_electrodes_data_callbacks(
63        reader.get_electrode_names(), draw_pos_hint=(1, 0), volt_axis=50)
64]
65
66print('Generating movie at ../data/experiment_slice_data movie.mp4, please '
67      'be patient')
68reader.generate_movie(
69    '../data/experiment_slice_data movie.mp4',
70    lum=1,
71    # make the video twice as large in the x direction as the projector so we
72    # can show the voltage data to its right
73    canvas_size_hint=(2, 1),
74    # show the data at the normal speed
75    speed=1.,
76    paint_funcs=paint_funcs
77)
78
79print('Done generating movie, closing data file')
80reader.close_h5()