Пример #1
0
def define_python(ename,
                  args,
                  source=None,
                  file=None,
                  etype='scalar',
                  echo=False):
    """
    Defines a new python expression.
    If expression with given name already exists the new
    definition will replace it.
    """
    etype = etype.lower()
    if not etype in ["scalar", "vector", "curve", "array", "tensor"]:
        raise VisItException("Unsupported expression type: %s" % etype)
    delete(ename)
    if exists(ename):
        raise VisItException("Cannot redefine database expression: %s" % ename)
    kwargs = {"name": ename, "args": args, "type": etype}
    if not source is None:
        kwargs["source"] = source
    if not file is None:
        kwargs["file"] = file
    visit.DefinePythonExpression(**kwargs)
    if echo:
        print "[Created Python Expression: %s ]" % ename
Пример #2
0
def define_flow_vpe(ename, expr, filter_set, platform_id, device_id):
    # get proper vpe path ...
    fvpe = pjoin(vpe_path(), "visit_flow_exec.vpe")
    args = []
    # keep a path for the old way
    if expr.endswith(".py") and os.path.isfile(expr):
        filter_set = "src"
        expr = open(expr).read()
        w = Workspace.load_workspace_script(src=expr)
    else:
        if os.path.isfile(expr):
            expr = open(expr).read()
        w = Workspace()
        w.register_filters(flow.filters.module(filter_set))
        ctx = w.add_context(filter_set, "root")
        w.setup_expression_network(expr, ctx)
    # get root vars & use as expr args
    evars = w.filter_names()
    evars = [evar[1:] for evar in evars if evar[0] == ":" and evar != ":dims"]
    #print "evars: " , evars
    args.extend(evars)
    expr_escaped = escape_src(expr)
    args.extend(['"' + filter_set + '"', '"' + expr_escaped + '"'])
    args.extend(['"%d"' % platform_id, '"%d"' % device_id])
    visit.DefinePythonExpression(ename, file=fvpe, args=args)