def main():
    usage = '%prog [options]'

    parser = OptionParser(usage)
    analysis_options.add_common_options(parser)
    parser.add_option("--h5",
                      type='string',
                      help=".h5 file with data2d_distorted (REQUIRED)")
    parser.add_option("--output-filename", type="string")
    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('--print-status',
                      action='store_true',
                      help="print status messages")
    (options, args) = parser.parse_args()
    if options.kalman_filename is None:
        raise ValueError('--kalman (-K) option must be specified')
    if options.obj_only is not None:
        options.obj_only = core_analysis.parse_seq(options.obj_only)
    plot_ori(
        kalman_filename=options.kalman_filename,
        h5=options.h5,
        start=options.start,
        stop=options.stop,
        obj_only=options.obj_only,
        output_filename=options.output_filename,
        options=options,
    )
示例#2
0
def main():
    usage = '%prog FILE [options]'
    parser = OptionParser(usage)
    parser.add_option("--obj-only", type="string")
    parser.add_option("--ransac", action='store_true', default=False)
    parser.add_option("--show", action='store_true', default=False)
    (options, args) = parser.parse_args()

    h5_filename = args[0]

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

    doit(
        filename=h5_filename,
        obj_only=options.obj_only,
        do_ransac=options.ransac,
        show=options.show,
    )
示例#3
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('filename', nargs='+',
                        help='name of flydra .hdf5 file',
                        )

    parser.add_argument("--stim-xml",
                        type=str,
                        default=None,
                        help="name of XML file with stimulus info",
                        required=True,
                        )

    parser.add_argument("--align-json",
                        type=str,
                        default=None,
                        help="previously exported json file containing s,R,T",
                        )

    parser.add_argument("--radius", type=float,
                      help="radius of line (in meters)",
                      default=0.002,
                      metavar="RADIUS")

    parser.add_argument("--obj-only", type=str)

    parser.add_argument("--obj-filelist", type=str,
                      help="use object ids from list in text file",
                      )

    parser.add_argument(
        "-r", "--reconstructor", dest="reconstructor_path",
        type=str,
        help=("calibration/reconstructor path (if not specified, "
              "defaults to FILE)"))

    args = parser.parse_args()
    options = args # optparse OptionParser backwards compatibility

    reconstructor_path = args.reconstructor_path
    fps = None

    ca = core_analysis.get_global_CachingAnalyzer()
    by_file = {}

    for h5_filename in args.filename:
        assert(tables.is_hdf5_file(h5_filename))
        obj_ids, use_obj_ids, is_mat_file, data_file, extra = ca.initial_file_load(
            h5_filename)
        this_fps = result_utils.get_fps( data_file, fail_on_error=False )
        if fps is None:
            if this_fps is not None:
                fps = this_fps
        if reconstructor_path is None:
            reconstructor_path = data_file
        by_file[h5_filename] = (use_obj_ids, data_file)
    del h5_filename
    del obj_ids, use_obj_ids, is_mat_file, data_file, extra

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

    if reconstructor_path is None:
        raise RuntimeError('must specify reconstructor from CLI if not using .h5 files')

    R = reconstruct.Reconstructor(reconstructor_path)

    if fps is None:
        fps = 100.0
        warnings.warn('Setting fps to default value of %f'%fps)
    else:
        fps = 1.0

    if options.stim_xml is None:
        raise ValueError(
            'stim_xml must be specified (how else will you align the data?')

    if 1:
        stim_xml = xml_stimulus.xml_stimulus_from_filename(
            options.stim_xml,
            )
        try:
            fanout = xml_stimulus.xml_fanout_from_filename( options.stim_xml )
        except xml_stimulus.WrongXMLTypeError:
            pass
        else:
            include_obj_ids, exclude_obj_ids = fanout.get_obj_ids_for_timestamp(
                timestamp_string=file_timestamp )
            if include_obj_ids is not None:
                use_obj_ids = include_obj_ids
            if exclude_obj_ids is not None:
                use_obj_ids = list( set(use_obj_ids).difference(
                    exclude_obj_ids ) )
            print('using object ids specified in fanout .xml file')
        if stim_xml.has_reconstructor():
            stim_xml.verify_reconstructor(R)

    x = []
    y = []
    z = []
    speed = []

    if options.obj_filelist is not None:
        obj_filelist=options.obj_filelist
    else:
        obj_filelist=None

    if obj_filelist is not None:
        obj_only = 1

    if obj_only is not None:
        if len(by_file) != 1:
            raise RuntimeError("specifying obj_only can only be done for a single file")
        if obj_filelist is not None:
            data = np.loadtxt(obj_filelist,delimiter=',')
            obj_only = np.array(data[:,0], dtype='int')
            print(obj_only)

        use_obj_ids = numpy.array(obj_only)
        h5_filename = by_file.keys()[0]
        (prev_use_ob_ids, data_file) = by_file[h5_filename]
        by_file[h5_filename] = (use_obj_ids, data_file)

    for h5_filename in by_file:
        (use_obj_ids, data_file) = by_file[h5_filename]
        for obj_id_enum,obj_id in enumerate(use_obj_ids):
            rows = ca.load_data( obj_id, data_file,
                                 use_kalman_smoothing=False,
                                 #dynamic_model_name = dynamic_model_name,
                                 #frames_per_second=fps,
                                 #up_dir=up_dir,
                                )
            verts = numpy.array( [rows['x'], rows['y'], rows['z']] ).T
            if len(verts)>=3:
                verts_central_diff = verts[2:,:] - verts[:-2,:]
                dt = 1.0/fps
                vels = verts_central_diff/(2*dt)
                speeds = numpy.sqrt(numpy.sum(vels**2,axis=1))
                # pad end points
                speeds = numpy.array([speeds[0]] + list(speeds) + [speeds[-1]])
            else:
                speeds = numpy.zeros( (verts.shape[0],) )

            if verts.shape[0] != len(speeds):
                raise ValueError('mismatch length of x data and speeds')
            x.append( verts[:,0] )
            y.append( verts[:,1] )
            z.append( verts[:,2] )
            speed.append(speeds)
        data_file.close()
    del h5_filename, use_obj_ids, data_file

    if 0:
        # debug
        if stim_xml is not None:
            v = None
            for child in stim_xml.root:
                if child.tag == 'cubic_arena':
                    info = stim_xml._get_info_for_cubic_arena(child)
                    v=info['verts4x4']
            if v is not None:
                for vi in v:
                    print('adding',vi)
                    x.append( [vi[0]] )
                    y.append( [vi[1]] )
                    z.append( [vi[2]] )
                    speed.append( [100.0] )

    x = np.concatenate(x)
    y = np.concatenate(y)
    z = np.concatenate(z)
    w = np.ones_like(x)
    speed = np.concatenate(speed)

    # homogeneous coords
    verts = np.array([x,y,z,w])

    #######################################################

    # Create the MayaVi engine and start it.
    e = Engine()
    # start does nothing much but useful if someone is listening to
    # your engine.
    e.start()

    # Create a new scene.
    from tvtk.tools import ivtk
    #viewer = ivtk.IVTK(size=(600,600))
    viewer = IVTKWithCalGUI(size=(800,600))
    viewer.open()
    e.new_scene(viewer)

    viewer.cal_align.set_data(verts,speed,R,args.align_json)

    if 0:
        # Do this if you need to see the MayaVi tree view UI.
        ev = EngineView(engine=e)
        ui = ev.edit_traits()

    # view aligned data
    e.add_source(viewer.cal_align.source)

    v = Vectors()
    v.glyph.scale_mode = 'data_scaling_off'
    v.glyph.color_mode = 'color_by_scalar'
    v.glyph.glyph_source.glyph_position='center'
    v.glyph.glyph_source.glyph_source = tvtk.SphereSource(
        radius=options.radius,
        )
    e.add_module(v)

    if stim_xml is not None:
        if 0:
            stim_xml.draw_in_mayavi_scene(e)
        else:
            actors = stim_xml.get_tvtk_actors()
            viewer.scene.add_actors(actors)

    gui = GUI()
    gui.start_event_loop()
示例#4
0
def main():
    # keep default config file in sync with get_config_defaults() above
    usage = """%prog DATAFILE3D.h5 [options]"""
    parser = OptionParser(usage)
    parser.add_option("--dest-dir",
                      type='string',
                      help="destination directory to save resulting files")
    parser.add_option(
        '--movie-fname',
        type='string',
        default=None,
        help="name of .ufmf of .fmf movie file (don't autodiscover from .h5)")
    parser.add_option("-r",
                      "--reconstructor",
                      type='string',
                      help="calibration/reconstructor path")
    parser.add_option(
        '--cam-id',
        type='string',
        default=None,
        help="cam_id of movie file (don't autodiscover from .h5)")
    parser.add_option('--start',
                      type='int',
                      default=None,
                      help="first frame of the movie (not .h5) file to export")
    parser.add_option('--stop',
                      type='int',
                      default=None,
                      help="last frame of the movie (not .h5) file to export")
    parser.add_option('--h5start',
                      type='int',
                      default=None,
                      help="first frame of the .h5 file to export")
    parser.add_option('--h5stop',
                      type='int',
                      default=None,
                      help="last frame of the .h5 file to export")
    parser.add_option('--transform',
                      type='string',
                      default=None,
                      help="how to orient the movie file")
    parser.add_option('--show-obj-ids',
                      action='store_true',
                      default=False,
                      help="show object ids")
    parser.add_option("--obj-only", type="string")
    parser.add_option("--image-format", type="string", default='png')
    parser.add_option("--subtract-frame", type="string")
    parser.add_option('--save-framelist', type='string')
    (options, args) = parser.parse_args()

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

    h5_fname = args[0]

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

    doit(
        movie_fname=options.movie_fname,
        reconstructor_fname=options.reconstructor,
        h5_fname=h5_fname,
        cam_id=options.cam_id,
        dest_dir=options.dest_dir,
        transform=options.transform,
        start=options.start,
        stop=options.stop,
        h5start=options.h5start,
        h5stop=options.h5stop,
        show_obj_ids=options.show_obj_ids,
        obj_only=options.obj_only,
        image_format=options.image_format,
        save_framelist_fname=options.save_framelist,
        subtract_frame=options.subtract_frame,
    )
示例#5
0
def main(hdf5_only=False):
    # hdf5_only is to maintain backwards compatibility...
    parser = argparse.ArgumentParser()
    if hdf5_only:
        dest_help = "filename of output .h5 file"
    else:
        dest_help = "filename of output .mat file"
    parser.add_argument("file", type=str, default=None, help='input file')
    parser.add_argument("--progress",
                        dest='show_progress',
                        action='store_true',
                        default=False,
                        help='show progress bar on console')
    parser.add_argument("--progress-json",
                        dest='show_progress_json',
                        action='store_true',
                        default=False,
                        help='show JSON progress messages')
    parser.add_argument("--dest-file", type=str, default=None, help=dest_help)
    parser.add_argument(
        "--time-data",
        dest="file2d",
        type=str,
        help=
        "hdf5 file with 2d data FILE2D used to calculate timestamp information and take UUID",
        metavar="FILE2D")
    parser.add_argument("--no-timestamps",
                        action='store_true',
                        dest='no_timestamps',
                        default=False)
    if not hdf5_only:
        parser.add_argument("--hdf5",
                            action='store_true',
                            default=False,
                            help='save output as .hdf5 file (not .mat)')
    parser.add_argument("--start-obj-id",
                        default=None,
                        type=int,
                        help='last obj_id to save')
    parser.add_argument("--stop-obj-id",
                        default=None,
                        type=int,
                        help='last obj_id to save')
    parser.add_argument("--obj-only", type=str)
    parser.add_argument("--stop",
                        default=None,
                        type=int,
                        help='last obj_id to save (DEPRECATED)')
    parser.add_argument("--profile",
                        action='store_true',
                        dest='profile',
                        default=False)
    parser.add_argument(
        "--dynamic-model",
        type=str,
        dest="dynamic_model",
        default=None,
    )
    core_analysis.add_arguments_to_parser(parser)
    options = parser.parse_args()

    if options.stop_obj_id is not None and options.stop is not None:
        raise ValueError('--stop and --stop-obj-id cannot both be set')

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

        if options.start_obj_id is not None or options.stop_obj_id is not None:
            raise ValueError(
                "cannot specify start and stop with --obj-only option")

    if options.stop is not None:
        warnings.warn(
            'DeprecationWarning: --stop will be phased out in favor of --stop-obj-id'
        )
        options.stop_obj_id = options.stop

    if hdf5_only:
        do_hdf5 = True
    else:
        do_hdf5 = options.hdf5

    infilename = options.file
    if options.dest_file is None:
        if do_hdf5:
            # import h5py early so if we don't have it we know sooner rather than later.
            import h5py
            outfilename = os.path.splitext(infilename)[0] + '_smoothed.h5'
        else:
            outfilename = os.path.splitext(infilename)[0] + '_smoothed.mat'
    else:
        outfilename = options.dest_file

    kwargs = core_analysis.get_options_kwargs(options)
    if options.profile:
        import cProfile

        out_stats_filename = outfilename + '.profile'
        print 'profiling, stats will be saved to %r' % out_stats_filename
        cProfile.runctx(
            '''convert(infilename,outfilename,
                file_time_data=options.file2d,
                save_timestamps = not options.no_timestamps,
                start_obj_id=options.start_obj_id,
                stop_obj_id=options.stop_obj_id,
                obj_only=options.obj_only,
                dynamic_model_name=options.dynamic_model,
                return_smoothed_directions = True,
                hdf5 = do_hdf5,
                show_progress = options.show_progress,
                show_progress_json=options.show_progress_json,
                **kwargs)''', globals(), locals(), out_stats_filename)

    else:
        convert(infilename,
                outfilename,
                file_time_data=options.file2d,
                save_timestamps=not options.no_timestamps,
                start_obj_id=options.start_obj_id,
                stop_obj_id=options.stop_obj_id,
                obj_only=options.obj_only,
                dynamic_model_name=options.dynamic_model,
                return_smoothed_directions=True,
                hdf5=do_hdf5,
                show_progress=options.show_progress,
                show_progress_json=options.show_progress_json,
                **kwargs)
示例#6
0
def main():
    usage = "%prog FILE [options]"

    parser = OptionParser(usage)

    parser.add_option(
        "-f",
        "--file",
        dest="filename",
        type="string",
        help="hdf5 file with data to display FILE",
        metavar="FILE",
    )

    parser.add_option(
        "-k",
        "--kalman-file",
        dest="kalman_filename",
        type="string",
        help="hdf5 file with kalman data to display KALMANFILE",
        metavar="KALMANFILE",
    )

    parser.add_option(
        "-r",
        "--reconstructor",
        dest="reconstructor_path",
        type="string",
        help=
        "calibration/reconstructor path (if not specified, defaults to KALMANFILE)",
        metavar="RECONSTRUCTOR",
    )

    parser.add_option("--start",
                      type="int",
                      help="first frame to plot",
                      metavar="START")

    parser.add_option("--stop",
                      type="int",
                      help="last frame to plot",
                      metavar="STOP")

    parser.add_option(
        "--show-nth-frame",
        type="int",
        dest="show_nth_frame",
        help="show Nth frame number (0=none)",
    )

    parser.add_option(
        "--stim-xml",
        type="string",
        default=None,
        help="name of XML file with stimulus info",
    )

    parser.add_option(
        "--save-fig",
        type="string",
        help="save output to filename (disables gui)",
    )

    parser.add_option("--show-orientation", action="store_true", default=False)

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

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

    (options, args) = parser.parse_args()

    if options.filename is not None:
        args.append(options.filename)

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

    if len(args) > 1:
        print("arguments interpreted as FILE supplied more than once",
              file=sys.stderr)
        parser.print_help()
        return

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

    h5_filename = args[0]

    fig = pylab.figure()
    fig.text(
        0.5,
        1.0,
        "Press '?' over this window to print help to console",
        verticalalignment="top",
        horizontalalignment="center",
    )
    showit = ShowIt()
    showit.show_it(
        fig,
        h5_filename,
        kalman_filename=options.kalman_filename,
        frame_start=options.start,
        frame_stop=options.stop,
        show_nth_frame=options.show_nth_frame,
        obj_only=options.obj_only,
        reconstructor_filename=options.reconstructor_path,
        options=options,
    )
    if options.save_fig is not None:
        print("saving to %s" % options.save_fig)
        pylab.savefig(options.save_fig)
    else:
        pylab.show()
示例#7
0
def main():
    usage = '%prog [options]'

    parser = OptionParser(usage)

    parser.add_option("--h5",
                      type='string',
                      help=".h5 file with data2d_distorted (REQUIRED)")

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

    parser.add_option(
        "--output-h5",
        type='string',
        help="filename for output .h5 file with data2d_distorted")

    parser.add_option(
        '--gate-angle-threshold-degrees',
        type='float',
        default=40.0,
        help='maximum angle (in degrees) to include 2D orientation')

    parser.add_option(
        '--area-threshold-for-orientation',
        type='float',
        default=0.0,
        help='minimum area required to use 2D feature for 3D orientation')

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

    parser.add_option("--start",
                      type='int',
                      default=None,
                      help="frame number to begin analysis on")

    parser.add_option("--stop",
                      type='int',
                      default=None,
                      help="frame number to end analysis on")

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

    (options, args) = parser.parse_args()

    if options.h5 is None:
        raise ValueError('--h5 option must be specified')

    if options.output_h5 is None:
        raise ValueError('--output-h5 option must be specified')

    if options.kalman_filename is None:
        raise ValueError('--kalman-file option must be specified')

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

    doit(kalman_filename=options.kalman_filename,
         data2d_filename=options.h5,
         area_threshold_for_orientation=options.area_threshold_for_orientation,
         gate_angle_threshold_degrees=options.gate_angle_threshold_degrees,
         start=options.start,
         stop=options.stop,
         output_h5_filename=options.output_h5,
         obj_only=options.obj_only,
         options=options)