Пример #1
0
 def __init__(self, parent=None):
     super(VCSGraphicsMethodModel, self).__init__(parent=parent)
     self.gm_types = sorted(vcs.graphicsmethodlist())
     self.gms = {
         gmtype: [
             el for el in vcs.elements[gmtype].values()
             if el.name[:1] != "__"
         ]
         for gmtype in vcs.graphicsmethodlist()
     }
Пример #2
0
def get_gm():
    for t in vcs.graphicsmethodlist():
        _methods[t] = {}
        for m in vcs.elements[t].keys():
            gm = vcs.elements[t][m]
            _methods[t][m] = vcs.dumpToDict(gm)[0]
            if hasattr(gm, "levels"):
                arr = numpy.array(gm.levels)
                if numpy.allclose(arr, 1e20) and arr.shape[-1] == 2:
                    _methods[t][m]["levels"] = [1e20, 1e20]
    return _methods
Пример #3
0
 def getallgraphicsmethods(self):
     """
     Returns a nested object representing all the available graphics method types as keys.
     Each graphics method type is an object that has the available graphics methods of that type as keys.
     Example:
     {
         boxfill: {
             polar: {...},
             default: {...}
         }
     }
     """
     _methods = {}
     for t in vcs.graphicsmethodlist():
         _methods[t] = {}
         for m in list(vcs.elements[t].keys()):
             gm = vcs.elements[t][m]
             _methods[t][m] = vcs.dumpToDict(gm)[0]
             if hasattr(gm, "levels"):
                 arr = numpy.array(gm.levels)
                 if numpy.allclose(arr, 1e20) and arr.shape[-1] == 2:
                     _methods[t][m]["levels"] = [1e20, 1e20]
     return _methods
Пример #4
0
def export_script(path, variables, plotters, rows=1, columns=1):

    files = {}
    for var in variables:
        new_files = var.get_files()
        for f in new_files:
            if f.uri not in files:
                files[f.uri] = f

    files = files.values()

    v = variables
    tree = VariableTree(variables, files)
    # Have to call tree.serialize before file_loads, in case of any hidden file references
    variable_prep = tree.serialize()
    file_loads = tree.get_file_lines()

    file_script = "\n    ".join(file_loads)
    file_return = ", ".join([tree.file_name(f) for f in files])

    variables = "\n    ".join(variable_prep)
    var_return = ", ".join(
        [tree.var_name(v) for v in tree.used_variables.values()])

    gms = OrderedDict()
    tmpls = OrderedDict()
    default_template = vcs.gettemplate("default")
    for plotter_group in plotters:
        for plotter in plotter_group:
            dp = plotter.dp

            if dp is None or dp.g_type not in vcs.graphicsmethodlist():
                # TODO: Support Secondaries
                continue
            gm = plotter.graphics_method
            key = (dp.g_type, gm.name)

            if key not in gms:
                gms[key] = diff_gm(gm)

            template = plotter.template
            if template.name not in tmpls:
                tmpls[template.name] = diff(template, default_template)

    gm_body = []
    for gm_key, gm_props in gms.iteritems():
        gm_body.append(
            serialize_gm("gm_%d" % len(gm_body), gm_key[0], gm_props))
    gm_body = "\n\n    ".join(gm_body)

    gnames = ["gm_%d" % i for i in range(len(gms))]

    gnames = ", ".join(gnames)

    tmpl_body = []
    for tmpl in tmpls.values():
        tmpl_body.append(serialize_tmpl("tmpl_%d" % len(tmpl_body), tmpl))

    tmpl_names = ["tmpl_%d" % i for i in range(len(tmpl_body))]
    tmpl_names = ", ".join(tmpl_names)
    tmpl_body = "\n\n    ".join(tmpl_body)

    plot_calls = []

    for i, plotter_group in enumerate(plotters):
        for plot in plotter_group:
            plot_calls.append(
                serialize_plot(plot, "canvases[%d]" % i, v, gms.keys(),
                               tmpls.keys()))

    plot_calls = "\n    ".join(plot_calls)
    num_canvases = len(plotters)
    with open(path, "w") as script:
        script.write(get_template().format(shell_script=sys.executable,
                                           files=file_script,
                                           file_ret=file_return,
                                           variables=variables,
                                           variable_ret=var_return,
                                           gms=gm_body,
                                           gm_names=gnames,
                                           tmpls=tmpl_body,
                                           template_ret=tmpl_names,
                                           plot_calls=plot_calls,
                                           num_canvas=num_canvases,
                                           rows=rows,
                                           cols=columns))
        script.write(main)
Пример #5
0
            return 1

        # low level primitives should probably not happen
        if g_type in _primitives:
            return 0

        # 1d takes 2 variables
        if g_type == '1d':
            return 2

        # otherwise assume 1
        return 1


# initialize the list of templates and graphics methods
_ = vcs.init()
_templates = sorted(vcs.elements['template'].keys())
_methods = {}
_2d_methods = (
    'scatter', 'vector', 'xvsy', 'stream', 'glyph', '3d_vector', '3d_dual_scalar'
)
_primitives = (
    'line', 'marker', 'fillarea', 'text'
)
for t in vcs.graphicsmethodlist():
    _methods[t] = {}
    for m in vcs.elements[t].keys():
        _methods[t][m] = {
            'nvars': Visualizer.detect_nvars(t, m, vcs.elements[t][m])
        }
Пример #6
0
 def getgraphicsmethodtypes(self):
     """Returns a list of available graphics methods"""
     return vcs.graphicsmethodlist()
Пример #7
0
 def getgraphicsmethodtypes(self):
     """Returns a list of available graphics methods"""
     return vcs.graphicsmethodlist()
Пример #8
0
        # meshfill takes one or two, but there are extra requirements that we will
        # have to pass through the api once they are understood
        if g_type == 'meshfill':
            return 1

        # low level primitives should probably not happen
        if g_type in _primitives:
            return 0

        # 1d takes 2 variables
        if g_type == '1d':
            return 2

        # otherwise assume 1
        return 1


# initialize the list of templates and graphics methods
_ = vcs.init()
_templates = sorted(vcs.elements['template'].keys())
_methods = {}
_2d_methods = ('scatter', 'vector', 'xvsy', 'stream', 'glyph', '3d_vector',
               '3d_dual_scalar')
_primitives = ('line', 'marker', 'fillarea', 'text')
for t in vcs.graphicsmethodlist():
    _methods[t] = {}
    for m in vcs.elements[t].keys():
        _methods[t][m] = {
            'nvars': Visualizer.detect_nvars(t, m, vcs.elements[t][m])
        }
Пример #9
0
 def __init__(self, parent=None):
     super(VCSGraphicsMethodModel, self).__init__(parent=parent)
     self.gm_types = sorted(vcs.graphicsmethodlist())
     self.gms = {gmtype: [el for el in vcs.elements[gmtype].values() if el.name[:1] != "__"]
                 for gmtype in vcs.graphicsmethodlist()}
Пример #10
0
def get_default_gms():
    _defaults = {}
    for t in vcs.graphicsmethodlist():
        _defaults[t] = vcs.elements[t].keys()
    return _defaults
Пример #11
0
def get_gm():
    for t in vcs.graphicsmethodlist():
        _methods[t] = {}
        for m in vcs.elements[t].keys():
            _methods[t][m] = {'nvars': detect_nvars(t, m, vcs.elements[t][m])}
    return json.dumps(_methods)
Пример #12
0
def export_script(path, variables, plotters, rows=1, columns=1):

    files = {}
    for var in variables:
        new_files = var.get_files()
        for f in new_files:
            if f.uri not in files:
                files[f.uri] = f

    files = files.values()

    v = variables
    tree = VariableTree(variables, files)
    # Have to call tree.serialize before file_loads, in case of any hidden file references
    variable_prep = tree.serialize()
    file_loads = tree.get_file_lines()

    file_script = "\n    ".join(file_loads)
    file_return = ", ".join([tree.file_name(f) for f in files])

    variables = "\n    ".join(variable_prep)
    var_return = ", ".join([tree.var_name(v) for v in tree.used_variables.values()])

    gms = OrderedDict()
    tmpls = OrderedDict()
    default_template = vcs.gettemplate("default")
    for plotter_group in plotters:
        for plotter in plotter_group:
            dp = plotter.dp

            if dp is None or dp.g_type not in vcs.graphicsmethodlist():
                # TODO: Support Secondaries
                continue
            gm = plotter.graphics_method
            key = (dp.g_type, gm.name)

            if key not in gms:
                gms[key] = diff_gm(gm)

            template = plotter.template
            if template.name not in tmpls:
                tmpls[template.name] = diff(template, default_template)

    gm_body = []
    for gm_key, gm_props in gms.iteritems():
        gm_body.append(serialize_gm("gm_%d" % len(gm_body), gm_key[0], gm_props))
    gm_body = "\n\n    ".join(gm_body)

    gnames = ["gm_%d" % i for i in range(len(gms))]

    gnames = ", ".join(gnames)

    tmpl_body = []
    for tmpl in tmpls.values():
        tmpl_body.append(serialize_tmpl("tmpl_%d" % len(tmpl_body), tmpl))

    tmpl_names = ["tmpl_%d" % i for i in range(len(tmpl_body))]
    tmpl_names = ", ".join(tmpl_names)
    tmpl_body = "\n\n    ".join(tmpl_body)

    plot_calls = []

    for i, plotter_group in enumerate(plotters):
        for plot in plotter_group:
            plot_calls.append(serialize_plot(plot, "canvases[%d]" % i, v, gms.keys(), tmpls.keys()))

    plot_calls = "\n    ".join(plot_calls)
    num_canvases = len(plotters)
    with open(path, "w") as script:
        script.write(get_template().format(shell_script=sys.executable,
                                           files=file_script,
                                           file_ret=file_return,
                                           variables=variables,
                                           variable_ret=var_return,
                                           gms=gm_body,
                                           gm_names=gnames,
                                           tmpls=tmpl_body,
                                           template_ret=tmpl_names,
                                           plot_calls=plot_calls,
                                           num_canvas=num_canvases,
                                           rows=rows,
                                           cols=columns))
        script.write(main)