Example #1
0
def createParameterExploration(action_id, xmlString, vistrail):
    if not xmlString:
        return
    # Parse/validate the xml

    try:
        striplen = len("<paramexps>")
        xmlString = xmlString[striplen : -(striplen + 1)].strip()
        xmlDoc = parseString(xmlString).documentElement
    except:
        return None
    # we need the pipeline to look up function/paramater id:s
    pipeline = materializeWorkflow(vistrail, action_id)
    # Populate parameter exploration window with stored functions and aliases
    functions = []
    for f in xmlDoc.getElementsByTagName("function"):
        f_id = long(f.attributes["id"].value)
        # we need to convert function id:s to (module_id, port_name)
        module_id = None
        f_name = None
        for m in pipeline.db_modules:
            for _f in m.db_functions:
                if _f.db_id == f_id:
                    module_id = m.db_id
                    f_name = _f.db_name
                    continue
        if not (module_id and f_name):
            break
        parameters = []
        for p in f.getElementsByTagName("param"):
            # we need to convert function id:s to (module_id, port_name)
            p_id = long(p.attributes["id"].value)
            p_pos = None
            for m in pipeline.db_modules:
                for _f in m.db_functions:
                    for _p in _f.db_parameters:
                        if _p.db_id == p_id:
                            p_pos = _p.db_pos
                        continue
            if p_pos is None:
                break
            p_intType = str(p.attributes["interp"].value)
            if p_intType in ["Linear Interpolation"]:
                p_min = str(p.attributes["min"].value)
                p_max = str(p.attributes["max"].value)
                value = "[%s, %s]" % (p_min, p_max)
            if p_intType in ["RGB Interpolation", "HSV Interpolation"]:
                p_min = str(p.attributes["min"].value)
                p_max = str(p.attributes["max"].value)
                value = '["%s", "%s"]' % (p_min, p_max)
            elif p_intType == "List":
                value = str(p.attributes["values"].value)
            elif p_intType == "User-defined Function":
                # Set function code
                value = str(p.attributes["code"].value)
            param = DBPEParameter(
                id=vistrail.idScope.getNewId(DBPEParameter.vtType),
                pos=p_pos,
                interpolator=p_intType,
                value=value,
                dimension=int(p.attributes["dim"].value),
            )
            parameters.append(param)
        f_is_alias = str(f.attributes["alias"].value) == "True"
        function = DBPEFunction(
            id=vistrail.idScope.getNewId(DBPEFunction.vtType),
            module_id=module_id,
            port_name=f_name,
            is_alias=1 if f_is_alias else 0,
            parameters=parameters,
        )
        functions.append(function)
    pe = DBParameterExploration(
        id=vistrail.idScope.getNewId(DBParameterExploration.vtType),
        action_id=action_id,
        dims=str(xmlDoc.attributes["dims"].value),
        layout=str(xmlDoc.attributes["layout"].value),
        date=str(xmlDoc.attributes["date"].value),
        functions=functions,
    )
    return pe
Example #2
0
def create_prov_from_vistrail(vistrail, version, log):
    workflow = materializeWorkflow(vistrail, version)
    add_group_portSpecs_index(workflow)
    return create_prov(workflow, version, log)
Example #3
0
def create_opm_from_vistrail(vistrail, version, log, registry):
    workflow = materializeWorkflow(vistrail, version)
    add_group_portSpecs_index(workflow)
    add_module_descriptor_index(registry)
    return create_opm(workflow, version, log, registry)
Example #4
0
def createParameterExploration(action_id, xmlString, vistrail):
    if not xmlString:
        return
    # Parse/validate the xml

    try:
        striplen = len("<paramexps>")
        xmlString = xmlString[striplen:-(striplen+1)].strip()
        xmlDoc = parseString(xmlString).documentElement
    except Exception:
        return None
    # we need the pipeline to look up function/paramater id:s
    pipeline = materializeWorkflow(vistrail, action_id)
    # Populate parameter exploration window with stored functions and aliases
    functions = []
    for f in xmlDoc.getElementsByTagName('function'):
        f_id = long(f.attributes['id'].value)
        # we need to convert function id:s to (module_id, port_name)
        module_id = None
        f_name = None
        for m in pipeline.db_modules:
            for _f in m.db_functions:
                if _f.db_id == f_id:
                    module_id = m.db_id
                    f_name = _f.db_name
                    continue
        if not (module_id and f_name):
            break
        parameters = []
        for p in f.getElementsByTagName('param'):
            # we need to convert function id:s to (module_id, port_name)
            p_id = long(p.attributes['id'].value)
            p_pos = None
            for m in pipeline.db_modules:
                for _f in m.db_functions:
                    for _p in _f.db_parameters:
                        if _p.db_id == p_id:
                            p_pos = _p.db_pos
                        continue
            if p_pos is None:
                break
            p_intType = str(p.attributes['interp'].value)
            if p_intType in ['Linear Interpolation']:
                p_min = str(p.attributes['min'].value)
                p_max = str(p.attributes['max'].value)
                value = "[%s, %s]" % (p_min, p_max)
            if p_intType in ['RGB Interpolation', 'HSV Interpolation']:
                p_min = str(p.attributes['min'].value)
                p_max = str(p.attributes['max'].value)
                value = '["%s", "%s"]' % (p_min, p_max)
            elif p_intType == 'List':
                value = str(p.attributes['values'].value)
            elif p_intType == 'User-defined Function':
                # Set function code
                value = str(p.attributes['code'].value)
            param = DBPEParameter(id=vistrail.idScope.getNewId(DBPEParameter.vtType),
                                  pos=p_pos,
                                  interpolator=p_intType,
                                  value=value,
                                  dimension=int(p.attributes['dim'].value))
            parameters.append(param)
        f_is_alias = (str(f.attributes['alias'].value) == 'True')
        function = DBPEFunction(id=vistrail.idScope.getNewId(DBPEFunction.vtType),
                                module_id=module_id,
                                port_name=f_name,
                                is_alias=1 if f_is_alias else 0,
                                parameters=parameters)
        functions.append(function)
    pe = DBParameterExploration(id=vistrail.idScope.getNewId(DBParameterExploration.vtType),
                                action_id=action_id,
                                dims=str(xmlDoc.attributes['dims'].value),
                                layout=str(xmlDoc.attributes['layout'].value),
                                date=str(xmlDoc.attributes['date'].value),
                                functions = functions)
    return pe
Example #5
0
def create_opm_from_vistrail(vistrail, version, log, registry):
    workflow = materializeWorkflow(vistrail, version)
    add_group_portSpecs_index(workflow)
    add_module_descriptor_index(registry)
    return create_opm(workflow, version, log, registry)