コード例 #1
0
            def onpress(event):
                if key_x != key_y:
                    path = c.slim_particles[c.old_index][1]
                    filename = c.slim_particles[c.old_index][2][c.old_j]
                    if not os.path.exists(path + filename):
                        # try going to next segment
                        prefix, dot, suffix = path.partition(
                            '/trigger'
                        )  # .../video7_000, /trigger, _thr0.005_cl9_op3/cc_filtered_2den0.81_gausrad2.0/
                        next_segment_ID = int(prefix[-3:]) + 1
                        path = prefix[:-3] + ('%03d' %
                                              next_segment_ID) + dot + suffix
                    #os.system('killall eog')

                    if event.key == 'n':  # next trace of this particle
                        c.old_j = (c.old_j + 1) % len(
                            c.slim_particles[c.old_index][2])
                        ax = plt.suptitle(
                            'particle %d: frame %d/%d' %
                            (c.slim_particles[c.old_index][0], c.old_j + 1,
                             len(c.slim_particles[c.old_index][2])))

                    elif event.key == 'r':  # recall last particle when changing view
                        ax = plt.suptitle(
                            'particle %d: frame %d/%d' %
                            (c.slim_particles[c.old_index][0], c.old_j + 1,
                             len(c.slim_particles[c.old_index][2])))
                        ax = plt.scatter(c.values[c.old_index,
                                                  Particle.what_index(key_x)],
                                         c.values[c.old_index,
                                                  Particle.what_index(key_y)],
                                         marker='o',
                                         color='orange')
                        #os.system('eog '+path+filename+' &')
                    elif event.key == 'f':  # show frame
                        os.system('eog ' + path + filename + ' &')
                    elif event.key == 't':  # show trace analysis
                        t = Trace(path, filename)
                        t.compute_estimators()
                        t.scatter_trace('temp.png')
                        os.system('eog temp.png &')
                    elif event.key == 'a':
                        ax = plt.scatter(c.values[:,
                                                  Particle.what_index(key_x)],
                                         c.values[:,
                                                  Particle.what_index(key_y)],
                                         marker='o',
                                         color=color(labels))
                        prefix1, dot, suffix1 = filename.partition(
                            '_'
                        )  # mean, _, 280519-video7_000-009_opened_cc10.png
                        prefix2, dot, suffix2 = suffix1.partition(
                            '_')  # 280519-video7, _, 000-009_opened_cc10.png
                        prefix3, dot, suffix3 = suffix2.partition(
                            '_')  # 000-009, _, opened_cc10.png
                        beginnung = prefix1 + dot + prefix2 + dot + prefix3 + dot  # mean_280519-video7_000-009_
                        for i, p in enumerate(c.slim_particles):
                            for name in p[2]:
                                if name.startswith(beginnung):
                                    c.same_frame.append(i)
                        for i in c.same_frame:
                            ax = plt.scatter(
                                c.values[i, Particle.what_index(key_x)],
                                c.values[i, Particle.what_index(key_y)],
                                marker='o',
                                color='red')
                    elif event.key == 'e':
                        raw_path = '/media/alessandro/DATA/tesi/Nebbia/raw_data/'
                        prefix, dot, suffix = path.partition(
                            '/trigger'
                        )  # .../video7_000, /trigger, _thr0.005_cl9_op3/cc_filtered_2den0.81_gausrad2.0/
                        pattume, dot, suffix2 = prefix.partition(
                            'pre-processed_data/'
                        )  # .../, pre-processed_data/, 280519/video7_000
                        add_path = suffix2[:-4] + '/frames/'  # 280519/video7/frames/
                        prefix1, dot, suffix3 = filename.partition(
                            '-'
                        )  # mean_280519, -, video7_000-009_opened_cc10.png
                        prefix2, dot, data = prefix1.partition(
                            '_')  # mean, _, 280519
                        segment, dot, suffix4 = suffix3.partition(
                            '-')  # video7_000, -, 009_opened_cc10.png
                        frame, dot, suffix5 = suffix4.partition(
                            '_')  # 009, _, opened_cc10.png
                        frame_name = 'outvid-' + data + '-' + segment + '-' + frame + '.png'
                        os.system('eog ' + raw_path + add_path + frame_name +
                                  ' &')
                    elif event.key == 'w':
                        ax = plt.suptitle('')
                        os.system('killall eog')
                        ax = plt.scatter(c.values[:,
                                                  Particle.what_index(key_x)],
                                         c.values[:,
                                                  Particle.what_index(key_y)],
                                         marker='o',
                                         color=color(labels))
                        c.same_frame = []
                    elif event.key == 'b':
                        c.labels[c.old_index] = (c.labels[c.old_index] +
                                                 1) % len(color_list)
                        ax = plt.scatter(c.values[:,
                                                  Particle.what_index(key_x)],
                                         c.values[:,
                                                  Particle.what_index(key_y)],
                                         marker='o',
                                         color=color(labels))
                    elif event.key == 's':
                        c.save()