Ejemplo n.º 1
0
def report_dds_fill(id_discdds, **params):
    dds = get_conftools_discdds().instance(id_discdds)

    r = Report('dds_fill-%s' % id_discdds)
    ds = DiffeoSystemBounds(id_discdds, dds, **params)
    ds.display(r)
    return r
Ejemplo n.º 2
0
def make(id_discdds, outdir, **params):
    discdds_library = get_conftools_discdds()
    discdds = discdds_library.instance(id_discdds)
    cases = make_logcases(id_discdds=id_discdds, discdds=discdds, **params)
        
    for tc in cases:
        tc.save(outdir)    
Ejemplo n.º 3
0
def report_dds_fill(id_discdds, **params):
    dds = get_conftools_discdds().instance(id_discdds)

    r = Report('dds_fill-%s' % id_discdds)
    ds = DiffeoSystemBounds(id_discdds, dds, **params)
    ds.display(r)
    return r
Ejemplo n.º 4
0
def make(id_discdds, outdir, **params):
    discdds_library = get_conftools_discdds()
    discdds = discdds_library.instance(id_discdds)
    cases = make_logcases(id_discdds=id_discdds, discdds=discdds, **params)

    for tc in cases:
        tc.save(outdir)
Ejemplo n.º 5
0
 def define_jobs_context(self, context):
     discdds_library = get_conftools_discdds()
     discdds = discdds_library.expand_names(self.options.discdds)
     discdds = natsorted(discdds)
     
     tolerance = self.options.tolerance
     
     for c, id_discdds in iterate_context_names(context, discdds):
         r = c.comp_config(report_dds_geometry, id_discdds, tolerance=tolerance)
         c.add_report(r, 'dds_geometry', tolerance=tolerance, dds=id_discdds)
Ejemplo n.º 6
0
def FromImages(tcname, id_discdds, image1, image2, true_plan=None):
    discdds = get_conftools_discdds().instance(id_discdds)
    shape = discdds.get_shape()

    images = get_conftools_uncertain_images()
    
    y0 = images.instance(image1).resize(shape)
    y1 = images.instance(image2).resize(shape)
    
    tc = TestCase(id_tc=tcname, id_discdds=id_discdds,
                  y0=y0, y1=y1, true_plan=true_plan)

    return tc
Ejemplo n.º 7
0
    def define_jobs_context(self, context):
        discdds_library = get_conftools_discdds()
        discdds = discdds_library.expand_names(self.options.discdds)
        discdds = natsorted(discdds)

        for c, id_discdds in iterate_context_names(context, discdds):
            options = self.options
            params = dict(tolerance=options.tolerance,
                          collapse_threshold=options.collapse_threshold,
                          debug_it=options.debug_it,
                          max_it=options.num_iterations,
                          min_visibility=options.min_visibility)
            r = c.comp_config(report_dds_fill, id_discdds, **params)
            c.add_report(r, 'dds_fill', dds=id_discdds, **params)
Ejemplo n.º 8
0
def report_dds_geometry(id_discdds, tolerance):
    dds = get_conftools_discdds().instance(id_discdds)
    r = Report('dds_geometry-%s-%s' % (id_discdds, tolerance))
    ds = DiffeoStructure(dds, tolerance=tolerance)
    with r.subsection('display') as r:
        ds.display(r)

    with r.subsection('show_reduction_steps') as r:
        ds.show_reduction_steps(r, max_nsteps=5)

    with r.subsection('show_reduction') as r:
        ds.show_reduction(r)

    return r
Ejemplo n.º 9
0
    def define_jobs_context(self, context):
        discdds_library = get_conftools_discdds()
        discdds = discdds_library.expand_names(self.options.discdds)
        discdds = natsorted(discdds)

        for c, id_discdds in iterate_context_names(context, discdds):
            options = self.options
            params = dict(tolerance=options.tolerance,
                     collapse_threshold=options.collapse_threshold,
                     debug_it=options.debug_it,
                     max_it=options.num_iterations,
                     min_visibility=options.min_visibility)
            r = c.comp_config(report_dds_fill, id_discdds, **params)
            c.add_report(r, 'dds_fill', dds=id_discdds, **params)
Ejemplo n.º 10
0
def report_dds_geometry(id_discdds, tolerance):
    dds = get_conftools_discdds().instance(id_discdds)
    r = Report('dds_geometry-%s-%s' % (id_discdds, tolerance))
    ds = DiffeoStructure(dds, tolerance=tolerance)
    with r.subsection('display') as r:
        ds.display(r)
    
    with r.subsection('show_reduction_steps') as r:
        ds.show_reduction_steps(r, max_nsteps=5)
        
    with r.subsection('show_reduction') as r:
        ds.show_reduction(r)
        
    return r
Ejemplo n.º 11
0
 def define_jobs_context(self, context):
     distances_library = get_conftools_uncertain_image_distances()
     distances = distances_library.expand_names(self.options.distances)
     
     streams_library = get_conftools_streams()
     streams = streams_library.expand_names(self.options.streams)
    
     discdds_library = get_conftools_discdds()
     discdds = discdds_library.expand_names(self.options.dds)
    
     for c, id_discdds in iterate_context_names(context, discdds):
         create_predstats_jobs(context=c, distances=distances,
                           id_discdds=id_discdds,
                           streams=streams, maxd=10)
Ejemplo n.º 12
0
    def define_jobs_context(self, context):
        discdds_library = get_conftools_discdds()
        discdds = discdds_library.expand_names(self.options.discdds)
        discdds = natsorted(discdds)

        tolerance = self.options.tolerance

        for c, id_discdds in iterate_context_names(context, discdds):
            r = c.comp_config(report_dds_geometry,
                              id_discdds,
                              tolerance=tolerance)
            c.add_report(r,
                         'dds_geometry',
                         tolerance=tolerance,
                         dds=id_discdds)
Ejemplo n.º 13
0
    def display(self, report, discdds=None):
        report.text('summary',
                    'Testcase: %s\nPlan: %s' % (self.id_tc, self.true_plan))
        report.data('id_tc', self.id_tc)
        report.data('id_discdds', self.id_discdds)
        report.data('true_plan', self.true_plan)

        def zoom(rgb):
            """ Enlarge image so that pixels are distinguishable even though
                the brows makes them smooth. """
            return rgb_zoom(rgb, K=8)

        f = report.figure(cols=4)
        f.data_rgb('y0_rgb', zoom(self.y0.get_rgb()), caption='$y_0$ (rgb)')
        f.data_rgb('y1_rgb', zoom(self.y1.get_rgb()), caption='$y_1$ (rgb)')
        from diffeoplan.library.distances.distance_norm import DistanceNorm
        d = DistanceNorm(2)

        if discdds is None:
            discdds = get_conftools_discdds().instance(self.id_discdds)
        y1p = discdds.predict(self.y0, self.true_plan)

        e_y0_y1_field = d.error_field(self.y1, self.y0)
        e_y1p_y1_field = d.error_field(self.y1, y1p)
        e_max = float(max(e_y0_y1_field.max(), e_y1p_y1_field.max()))

        f.data_rgb('e_y0_y1',
                   zoom(scale(e_y0_y1_field, max_value=e_max)),
                   caption="Discrepancy between $y_0$ and $y_1$.")

        f = report.figure('prediction_model',
                          cols=4,
                          caption="This is the prediction according to the "
                          "learned model."
                          "")

        f.data_rgb('y1p_rgb',
                   zoom(y1p.get_rgb()),
                   caption="$p^\star \cdot y_0$")

        f.data_rgb('y1p_rgb_u',
                   zoom(y1p.get_rgb_uncertain()),
                   caption="Uncertainty")

        f.data_rgb('e_y1p_y1',
                   zoom(scale(e_y1p_y1_field, max_value=e_max)),
                   caption="Discrepancy between $y_1$ and $p^\star "
                   "\cdot y_0$.")
Ejemplo n.º 14
0
def FromImages(tcname, id_discdds, image1, image2, true_plan=None):
    discdds = get_conftools_discdds().instance(id_discdds)
    shape = discdds.get_shape()

    images = get_conftools_uncertain_images()

    y0 = images.instance(image1).resize(shape)
    y1 = images.instance(image2).resize(shape)

    tc = TestCase(id_tc=tcname,
                  id_discdds=id_discdds,
                  y0=y0,
                  y1=y1,
                  true_plan=true_plan)

    return tc
Ejemplo n.º 15
0
    def define_jobs_context(self, context):
        distances_library = get_conftools_uncertain_image_distances()
        distances = distances_library.expand_names(self.options.distances)

        streams_library = get_conftools_streams()
        streams = streams_library.expand_names(self.options.streams)

        discdds_library = get_conftools_discdds()
        discdds = discdds_library.expand_names(self.options.dds)

        for c, id_discdds in iterate_context_names(context, discdds):
            create_predstats_jobs(context=c,
                                  distances=distances,
                                  id_discdds=id_discdds,
                                  streams=streams,
                                  maxd=10)
Ejemplo n.º 16
0
    def display(self, report, discdds=None):
        report.text('summary',
                    'Testcase: %s\nPlan: %s' % (self.id_tc, self.true_plan))
        report.data('id_tc', self.id_tc)
        report.data('id_discdds', self.id_discdds)
        report.data('true_plan', self.true_plan)
        
        def zoom(rgb):
            """ Enlarge image so that pixels are distinguishable even though
                the brows makes them smooth. """
            return rgb_zoom(rgb, K=8)
        
        f = report.figure(cols=4)
        f.data_rgb('y0_rgb', zoom(self.y0.get_rgb()), caption='$y_0$ (rgb)')
        f.data_rgb('y1_rgb', zoom(self.y1.get_rgb()), caption='$y_1$ (rgb)')
        from diffeoplan.library.distances.distance_norm import DistanceNorm
        d = DistanceNorm(2)
        
        if discdds is None:
            discdds = get_conftools_discdds().instance(self.id_discdds)
        y1p = discdds.predict(self.y0, self.true_plan)
        
        e_y0_y1_field = d.error_field(self.y1, self.y0)
        e_y1p_y1_field = d.error_field(self.y1, y1p)
        e_max = float(max(e_y0_y1_field.max(), e_y1p_y1_field.max()))
        
        f.data_rgb('e_y0_y1', zoom(scale(e_y0_y1_field, max_value=e_max)),
                    caption="Discrepancy between $y_0$ and $y_1$.")

        f = report.figure('prediction_model', cols=4,
                          caption="This is the prediction according to the "
                                  "learned model.""")
            
        f.data_rgb('y1p_rgb', zoom(y1p.get_rgb()),
                   caption="$p^\star \cdot y_0$")
        
        f.data_rgb('y1p_rgb_u', zoom(y1p.get_rgb_uncertain()),
                   caption="Uncertainty")

        f.data_rgb('e_y1p_y1', zoom(scale(e_y1p_y1_field, max_value=e_max)),
                   caption="Discrepancy between $y_1$ and $p^\star "
                            "\cdot y_0$.")
Ejemplo n.º 17
0
def ManualMotion(tcname, id_discdds, id_image, planstring):
    discdds = get_conftools_discdds().instance(id_discdds)
    shape = discdds.get_shape()
    
    images = get_conftools_uncertain_images()
    y0 = images.instance(id_image).resize(shape)
    
    
    chars = "abcdefghilmnopqrst"
    char2int = dict([(c, i) for i, c in enumerate(chars)])
    plan = tuple(map(char2int.__getitem__, planstring))
    
    
    # predict the result
    y1 = discdds.predict(y0, plan)
    
    tc = TestCase(id_tc=tcname, id_discdds=id_discdds,
                  y0=y0, y1=y1, true_plan=plan)

    return tc
Ejemplo n.º 18
0
def ManualMotion(tcname, id_discdds, id_image, planstring):
    discdds = get_conftools_discdds().instance(id_discdds)
    shape = discdds.get_shape()

    images = get_conftools_uncertain_images()
    y0 = images.instance(id_image).resize(shape)

    chars = "abcdefghilmnopqrst"
    char2int = dict([(c, i) for i, c in enumerate(chars)])
    plan = tuple(map(char2int.__getitem__, planstring))

    # predict the result
    y1 = discdds.predict(y0, plan)

    tc = TestCase(id_tc=tcname,
                  id_discdds=id_discdds,
                  y0=y0,
                  y1=y1,
                  true_plan=plan)

    return tc
Ejemplo n.º 19
0
def compute_predstats(id_discdds, id_stream, delta, id_distances):
    dds = get_conftools_discdds().instance(id_discdds)
    stream = get_conftools_streams().instance(id_stream)
    distances_library = get_conftools_uncertain_image_distances()
    distances = dict(map(lambda x: (x, distances_library.instance(x)), id_distances))
    dtype = [(x, 'float32') for x in id_distances]
    
    results = []
    for logitem in iterate_testcases(stream.read_all(), delta):
        assert_allclose(len(logitem.u), delta)
        y0 = UncertainImage(logitem.y0)
        y1 = UncertainImage(logitem.y1)
        py0 = dds.predict(y0, dds.commands_to_indices(logitem.u))
        ds = []
        for name in id_distances:
            d = distances[name].distance(y1, py0)
            #  d0 = distances[name].distance(y1, y0)
            ds.append(d)
        
        a = np.array(tuple(ds), dtype=dtype)
        results.append(a)
        
    return results
Ejemplo n.º 20
0
def compute_predstats(id_discdds, id_stream, delta, id_distances):
    dds = get_conftools_discdds().instance(id_discdds)
    stream = get_conftools_streams().instance(id_stream)
    distances_library = get_conftools_uncertain_image_distances()
    distances = dict(
        map(lambda x: (x, distances_library.instance(x)), id_distances))
    dtype = [(x, 'float32') for x in id_distances]

    results = []
    for logitem in iterate_testcases(stream.read_all(), delta):
        assert_allclose(len(logitem.u), delta)
        y0 = UncertainImage(logitem.y0)
        y1 = UncertainImage(logitem.y1)
        py0 = dds.predict(y0, dds.commands_to_indices(logitem.u))
        ds = []
        for name in id_distances:
            d = distances[name].distance(y1, py0)
            #  d0 = distances[name].distance(y1, y0)
            ds.append(d)

        a = np.array(tuple(ds), dtype=dtype)
        results.append(a)

    return results
Ejemplo n.º 21
0
 def from_yaml(discdds, servo):
     _, i = get_conftools_discdds().instance_smarter(discdds)
     return DiffeoPlanAgent(i, servo)
Ejemplo n.º 22
0
 def from_yaml(discdds, servo):
     _, i = get_conftools_discdds().instance_smarter(discdds)
     return DiffeoPlanAgent(i, servo)
Ejemplo n.º 23
0
def instantiate_discdds(id_discdds):
    warnings.warn('make sure it it called with comp_config')
    return get_conftools_discdds().instance(id_discdds)
Ejemplo n.º 24
0
def instantiate_discdds(id_discdds):
    warnings.warn('make sure it it called with comp_config')
    return get_conftools_discdds().instance(id_discdds)