示例#1
0
    def set_options_from_dict(self, config):
        """
            Reads the configuration from a dictionary.
        
            raises: UserError: Wrong configuration, user's mistake.
                    Exception: all other exceptions
        """
        params = DecentParams()
        self.define_program_options(params)
        
        try:
            self.options = params.get_dpr_from_dict(config)
        except DecentParamsUserError as e:
            raise QuickAppException(str(e))
        except Exception as e:
            msg = 'Could not interpret:\n'
            msg += indent(pformat(config), '| ') 
            msg += 'according to params spec:\n'
            msg += indent(str(params), '| ') + '\n'
            msg += 'Error is:\n'
#             if isinstance(e, DecentParamsUserError):
#                 msg += indent(str(e), '> ')
#             else:
            msg += indent(traceback.format_exc(e), '> ')
            raise QuickAppException(msg)  # XXX class
示例#2
0
    def set_options_from_args(self, args):
        """
            Reads the configuration from command line arguments. 
            
            raises: UserError: Wrong configuration, user's mistake.
                    Exception: all other exceptions
        """
        cls = type(self)
        prog = cls.get_prog_name()
        params = DecentParams()
        self.define_program_options(params)
        
        try:
            usage = cls.get_usage()
            if usage:
                usage = usage.replace('%prog', prog)

            desc = cls.get_program_description()
            epilog = cls.get_epilog()
            self.options = \
                params.get_dpr_from_args(prog=prog, args=args, usage=usage,
                                         description=desc, epilog=epilog)
        except UserError:
            raise
        except Exception as e:
            msg = 'Could not interpret:\n'
            msg += ' args = %s\n' % args
            msg += 'according to params spec:\n'
            msg += indent(str(params), '| ') + '\n'
            msg += 'Error is:\n'
            msg += indent(traceback.format_exc(e), '> ')
            raise Exception(msg)  # XXX class
示例#3
0
    def call_recursive(self, context, child_name, cmd_class, args,
                       extra_dep=[],
                       add_outdir=None,
                       add_job_prefix=None,
                       separate_resource_manager=False,
                       separate_report_manager=False,
                       extra_report_keys=None):     
        instance = cmd_class()
        instance.set_parent(self)
        is_quickapp = isinstance(instance, QuickApp) 

        try:
            # we are already in a context; just define jobs
            child_context = context.child(qapp=instance, name=child_name,
                                          extra_dep=extra_dep,
                                          add_outdir=add_outdir,
                                          extra_report_keys=extra_report_keys,
                                          separate_resource_manager=separate_resource_manager,
                                          separate_report_manager=separate_report_manager,
                                          add_job_prefix=add_job_prefix)  # XXX
        
            if isinstance(args, list):
                instance.set_options_from_args(args)
            elif isinstance(args, dict):
                instance.set_options_from_dict(args)
            else:
                assert False
            
            if not is_quickapp:
                self.child_context = child_context
                res = instance.go()  
            else:
                instance.context = child_context
                res = instance.define_jobs_context(child_context)
                child_context.finalize_jobs()
                
            # Add his jobs to our list of jobs
            context._jobs.update(child_context.all_jobs_dict()) 
            return res
        
        except Exception as e:
            msg = 'While trying to run  %s\n' % cmd_class.__name__
            msg += 'with arguments = %s\n' % args
            if '_options' in instance.__dict__:
                msg += ' parsed options: %s\n' % instance.get_options()
                msg += ' params: %s\n' % instance.get_options().get_params()
            if isinstance(e, QuickAppException):
                msg += indent(str(e), '> ')
            else:
                msg += indent(traceback.format_exc(e), '> ')
            raise QuickAppException(msg)
示例#4
0
    def get_model(self):
        T = self.get_T()
            
        U = self.U.get_value()
        P = self.y_stats.get_covariance()
        Q = self.u_stats.get_covariance()

        P_inv = self.get_P_inv_cond()
        Q_inv = np.linalg.pinv(Q)

        if False:
            M = get_M_from_P_T_Q(P, T, Q)
        else:
            if hasattr(self, 'use_P_scaling') and self.use_P_scaling:
                M = get_M_from_P_T_Q_alt_scaling(P, T, Q)
            else:
                warnings.warn('untested')
                try:
                    M = get_M_from_Pinv_T_Q(P_inv, T, Q)
                except LinAlgError as e:
                    msg = 'Could not get_M_from_Pinv_T_Q.\n'
                    msg += indent(traceback.format_exc(e), '> ')
                    raise BDSEEstimatorInterface.NotReady(msg)
        
        UQ_inv = np.tensordot(U, Q_inv, axes=(1, 0))
        # This works but badly conditioned
        Myav = np.tensordot(M, self.y_stats.get_mean(), axes=(1, 0))
        N = UQ_inv - Myav

        if self.antisym_M:
            self.info('antisymmetrizing M')
            M = antisym(M)
        
#         # Note: this does not work, don't know why
#         if False:
#             printm('MYav1', Myav)
#             y2 = np.linalg.solve(P, self.y_stats.get_mean())
#             Myav2 = np.tensordot(T, y2, axes=(0, 0))
#             # Myav = np.tensordot(T, y2, axes=(1, 0))
#             printm('MYav2', Myav2)
#         if False:
#             printm('U', U, 'Q_inv', Q_inv)
#             printm('UQ_inv', UQ_inv, 'Myav', Myav, 'N', N)
#             printm('u_mean', self.u_stats.get_mean())
#             printm('u_std', np.sqrt(Q.diagonal()))
#             printm('y_mean', self.y_stats.get_mean())
            
        self.Myav = Myav
        self.UQ_inv = UQ_inv
            
        return BDSEmodel(M, N)
示例#5
0
def fcpx_get_xml_project(videos, project_name, event_name): 
    videos = list(videos)
    assets = fcpx_get_xml_project_resources(videos, event_name)
    clips = fcpx_get_xml_project_clips(videos)

    template = """
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE fcpxml>
<fcpxml version="1.2">
<project name="{name}">
  <resources>
{assets}
  </resources>        
{clips}
</project>
</fcpxml>
    """
    assets = indent(assets, ' ' * 12)
    clips = indent(clips, ' ' * 8)
    s = template.format(name=project_name,
                        assets=assets,
                        clips=clips)
    return s
示例#6
0
 def _get_data_class(self):
     """ Tries to load the data class """
     if self._data_class is None:
         import roslib
         try:
             roslib.load_manifest('landroid_murraylab')  # @IgnorePep8
             from landroid_murraylab.msg import ldr_tracks  # @UnresolvedImport
         except Exception as e:
             msg = 'Could not import "ldr_tracks" datatype: %s' % e
             msg += indent(traceback.format_exc(e), '> ')
             logger.warn(msg)
             ldr_tracks = None
         self._data_class = ldr_tracks
     return self._data_class
示例#7
0
 def get_epilog_commands(cls):
     s = ""
     
     for sub in cls._get_subs():
         cmd_name = sub.cmd
         # XXX: fixme
         cmd_short = sub.get_short_description()
         
         cmd_name = termcolor_colored(cmd_name, attrs=['bold'])
         s += "  %30s  %s\n" % (cmd_name, cmd_short)
         if issubclass(sub, QuickMultiCmdApp):
             s += '\n'
             s += indent(sub.get_epilog_commands(), ' ' * 7)
             s += '\n'
              
     return s
示例#8
0
    def get_epilog_commands(cls):
        s = ""

        for sub in cls._get_subs():
            cmd_name = sub.cmd
            # XXX: fixme
            cmd_short = sub.get_short_description()

            cmd_name = termcolor_colored(cmd_name, attrs=['bold'])
            s += "  %30s  %s\n" % (cmd_name, cmd_short)
            if issubclass(sub, QuickMultiCmdApp):
                s += '\n'
                s += indent(sub.get_epilog_commands(), ' ' * 7)
                s += '\n'

        return s
示例#9
0
    def get_resource_job(self, context, rtype: str, **params):
        # print('RM %s %s get_resource %s %s' % (id(self), self._context, rtype, params))
        key = dict(rtype=rtype, **params)
        already_done = key in self.allresources
        if already_done:
            return self.allresources[key]

        check_is_in('resource type', rtype, self.providers)

        prefix = self._make_prefix(rtype, **params)
        #         print('adding job prefix %r' % prefix)
        c = context.child(name=rtype, add_job_prefix=prefix, add_outdir=rtype)
        c._job_prefix = prefix
        # Add this point we should check if we already created the job
        ok = []
        errors = []
        for provider in self.providers[rtype]:
            try:
                res_i = provider(c, **params)
                ok.append((provider, res_i))
            except ResourceManager.CannotProvide as e:
                errors.append(e)
            except Exception as e:
                msg = 'Error while trying to get resource.\n'
                msg += ' type: %r params: %s\n' % (rtype, params)
                msg += 'While calling provider %r:\n' % provider
                msg += indent(traceback.format_exc(), '> ')
                raise Exception(msg)

        if not ok:
            msg = 'No provider could create this resource:\n'
            msg += "\n".join('- %s' % str(e) for e in errors)
            raise Exception(msg)

        if len(ok) >= 2:
            msg = 'The same resource could be created by two providers.'
            msg += '\n%s %s' % (rtype, params)
            for prov, _ in ok:
                msg += '\n - %s' % prov
            raise Exception(msg)

        assert len(ok) == 1
        res = ok[0][1]
        self.set_resource(res, rtype, **params)
        return res
示例#10
0
    def get_resource_job(self, context, rtype, **params):
        # print('RM %s %s get_resource %s %s' % (id(self), self._context, rtype, params))
        key = dict(rtype=rtype, **params)
        already_done = key in self.allresources
        if already_done:
            return self.allresources[key]

        check_is_in('resource type', rtype, self.providers)

        prefix = self._make_prefix(rtype, **params)
        #         print('adding job prefix %r' % prefix)
        c = context.child(name=rtype, add_job_prefix=prefix, add_outdir=rtype)
        c._job_prefix = prefix
        # Add this point we should check if we already created the job
        ok = []
        errors = []
        for provider in self.providers[rtype]:
            try:
                res_i = provider(c, **params)
                ok.append((provider, res_i))
            except ResourceManager.CannotProvide as e:
                errors.append(e)
            except Exception as e:
                msg = 'Error while trying to get resource.\n'
                msg += ' type: %r params: %s\n' % (rtype, params)
                msg += 'While calling provider %r:\n' % provider
                msg += indent(traceback.format_exc(), '> ')
                raise Exception(msg)

        if not ok:
            msg = 'No provider could create this resource:\n'
            msg += "\n".join('- %s' % str(e) for e in errors)
            raise Exception(msg)

        if len(ok) >= 2:
            msg = 'The same resource could be created by two providers.'
            msg += '\n%s %s' % (rtype, params)
            for prov, _ in ok:
                msg += '\n - %s' % prov
            raise Exception(msg)

        assert len(ok) == 1
        res = ok[0][1]
        self.set_resource(res, rtype, **params)
        return res
示例#11
0
def summarize(rawlog):
    s = ""
    s += 'Resources:\n'
    for x in rawlog.get_resources():
        s += ' - %s\n' % friendly_path(x)

    s += 'Signals:\n'
    signals = rawlog.get_signals()
    names = sorted(signals.keys())
    
    for x in names:
        v = signals[x]
        t0, t1 = v.get_time_bounds()
        length = t1 - t0
        reftime = v.get_time_reference()
        s += '%-55s  %10s %4.2f %10.4f %10.4f %s\n' % (x, reftime, length, t0, t1, v)
        
    s += 'Tags: %s\n' % rawlog.get_tags()

    
    s += 'Annotations:\n'
    s += indent(pformat(rawlog.get_annotations()), ' | ')

    return s