示例#1
0
def pull_tune_variables(targetxml, referencexml=None):
    refxml = targetxml
    if referencexml is not None:
        refxml = referencexml
    
    variables = None
    with open(refxml) as rfile:
        refxmlstr = rfile.read()
        variables = idfxml.xml_to_variables(refxmlstr)
    
    if referencexml is not None:
        xmlroot = xml.etree.ElementTree.parse(targetxml)
        for variable in variables:
            if variable.idfobject == variable.idfclass:
                node = xmlroot.find('./{0}/{1}'.format(idfxml.tagconvert(variable.idfclass), 
                                                       idfxml.tagconvert(variable.idffield)))
            else:
                nodes = xmlroot.findall('./{0}'.format(idfxml.tagconvert(variable.idfclass)))
                node = None
                for n in nodes:
                    name = n.find('./Name')
                    if name is not None and name.text.strip() == variable.idfobject:
                        node = n.find('./{0}'.format(idfxml.tagconvert(variable.idffield)))
                        break
            if node is not None:
                variable.value = node.text.strip()
    return variables
示例#2
0
def pull_tune_variables(targetxml, referencexml=None):
    refxml = targetxml
    if referencexml is not None:
        refxml = referencexml

    variables = None
    with open(refxml) as rfile:
        refxmlstr = rfile.read()
        variables = idfxml.xml_to_variables(refxmlstr)

    if referencexml is not None:
        xmlroot = xml.etree.ElementTree.parse(targetxml)
        for variable in variables:
            if variable.idfobject == variable.idfclass:
                node = xmlroot.find('./{0}/{1}'.format(
                    idfxml.tagconvert(variable.idfclass),
                    idfxml.tagconvert(variable.idffield)))
            else:
                nodes = xmlroot.findall('./{0}'.format(
                    idfxml.tagconvert(variable.idfclass)))
                node = None
                for n in nodes:
                    name = n.find('./Name')
                    if name is not None and name.text.strip(
                    ) == variable.idfobject:
                        node = n.find('./{0}'.format(
                            idfxml.tagconvert(variable.idffield)))
                        break
            if node is not None:
                variable.value = node.text.strip()
    return variables
示例#3
0
def random_model(basexml, randomxml):
    basexmlstr = None
    with open(basexml) as basexmlfile:
        basexmlstr = basexmlfile.read()
    varset = idfxml.xml_to_variables(basexmlstr)
    candidate = eplus.EPlusCandidate(varset)
    randcand = candidate.permutation()
    baseidf = idfxml.xml_to_idf(basexmlstr)
    randidf = randcand.values_to_idf(baseidf)
    randomxmlstr = idfxml.idf_to_xml(randidf)
    randomxmlstr = idfxml.variables_to_xml(varset, randomxmlstr)
    with open(randomxml, 'w') as randfile:
        randfile.write(randomxmlstr)
示例#4
0
def random_model(basexml, randomxml):
    basexmlstr = None
    with open(basexml) as basexmlfile:
        basexmlstr = basexmlfile.read()
    varset = idfxml.xml_to_variables(basexmlstr)
    candidate = eplus.EPlusCandidate(varset)
    randcand = candidate.permutation()
    baseidf = idfxml.xml_to_idf(basexmlstr)
    randidf = randcand.values_to_idf(baseidf)
    randomxmlstr = idfxml.idf_to_xml(randidf)
    randomxmlstr = idfxml.variables_to_xml(varset, randomxmlstr)
    with open(randomxml, 'w') as randfile:
        randfile.write(randomxmlstr)