Esempio n. 1
0
 def get_obj_ids_for_timestamp( self, timestamp_string=None ):
     (single_episode, kh5_file, stim_fname
      ) = self._get_episode_for_timestamp(timestamp_string=timestamp_string)
     for include in single_episode.findall('include'):
         raise ValueError('<single_episode> has <include> tag')
     for exclude in single_episode.findall('exclude'):
         raise ValueError('<single_episode> has <exclude> tag')
     include_ids = None
     exclude_ids = None
     for include in kh5_file.findall('include'):
         if include_ids is None:
             include_ids = []
         if include.text is not None:
             obj_ids = parse_seq( include.text )
             include_ids.extend( obj_ids )
         else:
             obj_ids = None
     for exclude in kh5_file.findall('exclude'):
         if exclude_ids is None:
             exclude_ids = []
         if exclude.text is not None:
             obj_ids = parse_seq( exclude.text )
             exclude_ids.extend( obj_ids )
         else:
             obj_ids = None
     return include_ids, exclude_ids
Esempio n. 2
0
def main():
    usage = '%prog [options]'

    parser = OptionParser(usage)

    analysis_options.add_common_options(parser)

    parser.add_option("--interactive", action='store_true', default=False)

    parser.add_option(
        "--fuse",
        action='store_true',
        help=
        "fuse object ids corresponding to a single fly (requires stim-xml fanout)",
        default=False)

    (options, args) = parser.parse_args()

    if options.obj_only is not None:
        options.obj_only = core_analysis.parse_seq(options.obj_only)

    if not options.interactive:
        matplotlib.use('Agg')

    if len(args):
        parser.print_help()
        return

    if options.up_dir is not None:
        options.up_dir = core_analysis.parse_seq(options.up_dir)
    else:
        options.up_dir = None

    doit(options=options, )
Esempio n. 3
0
def doit(options = None,
         ):
    kalman_filename=options.kalman_filename
    import pylab # do after matplotlib.use() call

    fig = pylab.figure(figsize=(5,8))
    figtitle = kalman_filename.split('.')[0]
    pylab.figtext(0,0,figtitle)

    ax = None
    subplot ={}
    subplots = ['xy','xz']
    for i, name in enumerate(subplots):
        ax = fig.add_subplot(len(subplots),1,i+1)#,sharex=ax)
        subplot[name] = ax

    if options.up_dir is not None:
        options.up_dir = core_analysis.parse_seq(options.up_dir)
    else:
        options.up_dir = None

    plot_top_and_side_views(subplot=subplot,
                            options=options,
                            )

    pylab.show()
Esempio n. 4
0
def main():
    usage = '%prog [options]'

    parser = OptionParser(usage)

    analysis_options.add_common_options( parser )
    parser.add_option("--ellipsoids", action='store_true', default=False)
    parser.add_option("--show-obj-id", action='store_true', default=False)
    parser.add_option("--show-observations", action='store_true', default=False)
    parser.add_option("--markersize", type='float',default=0.5)
    (options, args) = parser.parse_args()

    if options.obj_only is not None:
        options.obj_only = core_analysis.parse_seq(options.obj_only)

    if len(args):
        parser.print_help()
        return

    doit( options=options,
         )
def main():
    usage = '%prog [options] FILE1 [FILE2] ...'

    parser = OptionParser(usage)

    parser.add_option('-k',
                      "--kalman-file",
                      dest="kalman_filename",
                      type='string',
                      help=".h5 file with kalman data and 3D reconstructor")

    parser.add_option("--spreadh5",
                      type='string',
                      help=(".spreadh5 file with frame synchronization info "
                            "(make with flydra_analysis_check_sync)"))

    parser.add_option("--start",
                      dest="start",
                      type='int',
                      help="start frame (.h5 frame number reference)")

    parser.add_option("--stop",
                      dest="stop",
                      type='int',
                      help="stop frame (.h5 frame number reference)")

    parser.add_option("--disable-kalman-smoothing",
                      action='store_false',
                      dest='use_kalman_smoothing',
                      default=True,
                      help=("show original, causal Kalman filtered data "
                            "(rather than Kalman smoothed observations)"))

    parser.add_option("--timestamps", action='store_true', default=False)

    parser.add_option("--reproj-error",
                      action='store_true',
                      default=False,
                      help=("calculate and print to console the mean "
                            "reprojection error for each camera"))

    parser.add_option("--hide-source-name",
                      action='store_false',
                      dest='show_source_name',
                      default=True,
                      help="show the source filename?")

    parser.add_option("--fps",
                      dest='fps',
                      type='float',
                      help=("frames per second (used for Kalman "
                            "filtering/smoothing)"))

    parser.add_option("--area-threshold",
                      type='float',
                      default=0.0,
                      help=("area of 2D point required for plotting (NOTE: "
                            "this is not related to the threshold used for "
                            "Kalmanization)"))

    parser.add_option("--likely-only",
                      action='store_true',
                      default=False,
                      help=('plot only points that are deemed likely to '
                            'be true positives'))

    parser.add_option("--save-fig",
                      type='string',
                      default=None,
                      help='path name of figure to save (exits script '
                      'immediately after save)')

    parser.add_option(
        "--dynamic-model",
        type="string",
        dest="dynamic_model",
        default=None,
    )

    parser.add_option("--obj-only", type="string")

    parser.add_option("--up-dir", type="string")

    (options, args) = parser.parse_args()

    if options.obj_only is not None:
        options.obj_only = core_analysis.parse_seq(options.obj_only)

    if options.up_dir is not None:
        up_dir = core_analysis.parse_seq(options.up_dir)
    else:
        up_dir = None

    doit(
        filenames=args,
        kalman_filename=options.kalman_filename,
        start=options.start,
        stop=options.stop,
        fps=options.fps,
        dynamic_model=options.dynamic_model,
        use_kalman_smoothing=options.use_kalman_smoothing,
        up_dir=up_dir,
        options=options,
    )
Esempio n. 6
0
def main():
    usage = '%prog [options]'

    parser = OptionParser(usage)

    analysis_options.add_common_options(parser)

    parser.add_option(
        "--frames",
        action='store_true',
        help="plot horizontal axis in frame number (not seconds)",
        default=False)

    parser.add_option(
        "--fuse",
        action='store_true',
        help=
        "fuse object ids corresponding to a single fly (requires stim-xml fanout)",
        default=False)

    parser.add_option("--P55",
                      action='store_true',
                      help="plot P[5,5] component of covariance matrix",
                      default=False)

    parser.add_option(
        "--timestamp-file",
        type='string',
        help="file with data2d_distorted table to get timestamps")

    parser.add_option("--save-fig",
                      type='string',
                      default=None,
                      help='path name of figure to save (exits script '
                      'immediately after save)')

    parser.add_option("--ori-qual",
                      type='float',
                      default=None,
                      help=('minimum orientation quality to use'))

    parser.add_option("--smooth-orientations",
                      action='store_true',
                      help="if displaying orientations, use smoothed data",
                      default=False)

    parser.add_option("--show-3d-orientations",
                      action='store_true',
                      help="show orientation data?",
                      default=False)

    (options, args) = parser.parse_args()

    if options.obj_only is not None:
        options.obj_only = core_analysis.parse_seq(options.obj_only)

    if len(args):
        parser.print_help()
        return

    doit(options=options, )
Esempio n. 7
0
def doit(options=None, ):
    import pylab  # do after matplotlib.use() call

    if options.up_dir is not None:
        options.up_dir = core_analysis.parse_seq(options.up_dir)
    else:
        options.up_dir = None

    fig = pylab.figure()  #figsize=(6,4))
    figtitle = options.kalman_filename
    pylab.figtext(0, 0, figtitle)

    ax = None
    subplot = {}
    if options.show_3d_orientations:
        subplots = ['x', 'y', 'z', 'dx', 'dy', 'dz']
    else:
        subplots = ['x', 'y', 'z', 'xy_vel', 'vel', 'accel', 'frame']

    if options.P55:
        subplots.append('P55')

    #subplots = ['x','y','z','vel','accel']
    for i, name in enumerate(subplots):
        ax = fig.add_subplot(len(subplots), 1, i + 1, sharex=ax)
        ax.grid(True)
        subplot[name] = ax

    fig.subplots_adjust(bottom=0.15)

    if 0:
        fig = pylab.figure()
        figtitle = options.kalman_filename
        pylab.figtext(0, 0, figtitle)

        ax = fig.add_subplot(1, 1, 1)
        subplot['vel_hist'] = ax
        ax.grid(True)

    line2obj_id = plot_timeseries(
        subplot=subplot,
        options=options,
    )

    class MyPickObj(object):
        def __init__(self, line2obj_id):
            self.line2obj_id = line2obj_id
            self.obj_ids = []

        def onpick(self, event):
            if isinstance(event.artist, matplotlib.lines.Line2D):
                thisline = event.artist
                obj_id = self.line2obj_id[thisline]
                if obj_id not in self.obj_ids:
                    self.obj_ids.append(obj_id)
                    self.obj_ids.sort()
                    print 'picked', obj_id
                    print 'all:'
                    print self.obj_ids
                ## else:
                ##     print '(already had obj_id %d)'%obj_id
        def on_key_press(self, event):
            #print 'received key',repr(event.key)
            if event.key == 'c':
                del self.obj_ids[:]
                print self.obj_ids
            if event.key == 'l':
                del self.obj_ids[-1]
                print self.obj_ids
            #print 'all:'
            #print self.obj_ids

    if options.save_fig is not None:
        pylab.savefig(options.save_fig)
    else:
        pick_receiver = MyPickObj(line2obj_id)
        fig.canvas.mpl_connect('pick_event', pick_receiver.onpick)
        fig.canvas.mpl_connect('key_press_event', pick_receiver.on_key_press)
        pylab.show()