Example #1
0
def get_datafram_aeromap(tixi,aeromap_uid):
    """Return the pandas datafram of an aeromap.

    TODO: * test fuction
          * modify other function to work with pandas

    Args:
        tixi (tixi handle): Tixi handle of the CPACS file.
        aeromapuid (str): UID of the aeromap to retrun

    Returns:
        aeromap (df) : DataFrame of the aeromap
    """

    if not tixi.uIDCheckExists(aeromap_uid):
        raise ValueError('The aeromap {} does not exist!'.format(aeromap_uid))

    apm_xpath = tixi.uIDGetXPath(aeromap_uid) + '/aeroPerformanceMap'

    # state_dict = {'alt': cpsf.get_float_vector(tixi,apm_xpath +'/altitude'),
    #               'mach': cpsf.get_float_vector(tixi,apm_xpath +'/machNumber'),
    #               'aoa': cpsf.get_float_vector(tixi,apm_xpath +'/angleOfAttack'),
    #               'aos': cpsf.get_float_vector(tixi,apm_xpath +'/angleOfSideslip')}

    state_dict = {}

    for state,xstate in zip(STATES,XSTATES):
        state_xpath = apm_xpath +'/' + xstate
        state_dict[state] = cpsf.get_float_vector(tixi,state_xpath)

    aeromap = pd.DataFrame(state_dict)


    for coef in COEF_LIST:
        coef_xpath = apm_xpath + '/' + coef
        try:
            coef_value_list = cpsf.get_float_vector(tixi,coef_xpath)
        except:
            coef_value_list = []

        if coef_value_list:
            aeromap[coef] = coef_value_list
        else:
            aeromap[coef] = float("NaN")

    return aeromap
Example #2
0
def test_get_float_vector():
    """ Test the function 'get_float_vector'"""

    tixi = cpsf.open_tixi(CPACS_IN_PATH)
    xpath = '/cpacs/toolspecific/CEASIOMpy/testVector'

    # Add a new vector
    float_vector = [0.0, 1.1, 5.5]
    cpsf.add_float_vector(tixi, xpath, float_vector)

    # Get a float vector
    float_vector_get = cpsf.get_float_vector(tixi, xpath)

    assert float_vector_get == float_vector

    # Raise an error when the XPath is wrong
    wrong_xpath = '/cpacs/toolspecific/CEASIOMpy/testVectorWrong'
    with pytest.raises(ValueError):
        vector = cpsf.get_float_vector(tixi, wrong_xpath)

    # Raise an error when no value at XPath
    no_value_xpath = '/cpacs/toolspecific/CEASIOMpy'
    with pytest.raises(ValueError):
        vector = cpsf.get_float_vector(tixi, no_value_xpath)
Example #3
0
    def __init__(self, tixi, xpath):
        self.xpath = xpath

        self.xlist = cpsf.get_float_vector(tixi,self.xpath+'/x')
        self.ylist = cpsf.get_float_vector(tixi,self.xpath+'/y')
Example #4
0
def get_aeromap(tixi, aeromap_uid):
    """ Get aerodynamic parameters and coefficients from an aeroMap

    Function 'get_aeromap' return an object 'AeroCoefficient' fill with the
    values found in the given aeroMap. Parameters are required but if a
    coefficients is not found, an empty list will be return in the corresponding
    node.

    Args:
        tixi (handles): TIXI Handle of the CPACS file
        aeromap_uid (str): UID of the aeroMap to get

    Returns::
        Coef (object): Object containing parameters and aerodynamic coefficients from the aeroMap
    """

    apm_xpath = tixi.uIDGetXPath(aeromap_uid) + '/aeroPerformanceMap'

    Coef = AeroCoefficient()

    Coef.alt = cpsf.get_float_vector(tixi, apm_xpath + '/altitude')
    Coef.mach = cpsf.get_float_vector(tixi, apm_xpath + '/machNumber')
    Coef.aoa = cpsf.get_float_vector(tixi, apm_xpath + '/angleOfAttack')
    Coef.aos = cpsf.get_float_vector(tixi, apm_xpath + '/angleOfSideslip')

    cl_xpath = apm_xpath + '/cl'
    if tixi.checkElement(cl_xpath):
        check_str = tixi.getTextElement(cl_xpath)
        if check_str == '':
            log.warning('No /cl values have been found in the CPACS file')
            log.warning('An empty list will be returned.')
            Coef.cl = []
        else:
            Coef.cl = cpsf.get_float_vector(tixi, cl_xpath)

    cd_xpath = apm_xpath + '/cd'
    if tixi.checkElement(cd_xpath):
        check_str = tixi.getTextElement(cd_xpath)
        if check_str == '':
            log.warning('No /cd values have been found in the CPACS file')
            log.warning('An empty list will be returned.')
            Coef.cd = []
        else:
            Coef.cd = cpsf.get_float_vector(tixi, cd_xpath)

    cs_xpath = apm_xpath + '/cs'
    if tixi.checkElement(cs_xpath):
        check_str = tixi.getTextElement(cs_xpath)
        if check_str == '':
            log.warning('No /cs values have been found in the CPACS file')
            log.warning('An empty list will be returned.')
            Coef.cs = []
        else:
            Coef.cs = cpsf.get_float_vector(tixi, cs_xpath)

    cml_xpath = apm_xpath + '/cml'
    if tixi.checkElement(cml_xpath):
        check_str = tixi.getTextElement(cml_xpath)
        if check_str == '':
            log.warning('No /cml values have been found in the CPACS file')
            log.warning('An empty list will be returned.')
            Coef.cml = []
        else:
            Coef.cml = cpsf.get_float_vector(tixi, cml_xpath)

    cmd_xpath = apm_xpath + '/cmd'
    if tixi.checkElement(cmd_xpath):
        check_str = tixi.getTextElement(cmd_xpath)
        if check_str == '':
            log.warning('No /cmd values have been found in the CPACS file')
            log.warning('An empty list will be returned.')
            Coef.cmd = []
        else:
            Coef.cmd = cpsf.get_float_vector(tixi, cmd_xpath)

    cms_xpath = apm_xpath + '/cms'
    if tixi.checkElement(cms_xpath):
        check_str = tixi.getTextElement(cms_xpath)
        if check_str == '':
            log.warning('No /cms values have been found in the CPACS file')
            log.warning('An empty list will be returned.')
            Coef.cms = []
        else:
            Coef.cms = cpsf.get_float_vector(tixi, cms_xpath)

    #Damping derivatives (TODO: inprove that)

    dcsdrstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcsdrstar'
    if tixi.checkElement(dcsdrstar_xpath):
        check_str = tixi.getTextElement(dcsdrstar_xpath)

        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcsdrstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcsdrstar = []
        else:
            Coef.dcsdrstar = cpsf.get_float_vector(tixi, dcsdrstar_xpath)

    dcsdpstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcsdpstar'
    if tixi.checkElement(dcsdpstar_xpath):
        check_str = tixi.getTextElement(dcsdpstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcsdpstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcsdpstar = []
        else:
            Coef.dcsdpstar = cpsf.get_float_vector(tixi, dcsdpstar_xpath)

    dcldqstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcldqstar'
    if tixi.checkElement(dcldqstar_xpath):
        check_str = tixi.getTextElement(dcldqstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcldqstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcddqstar = []
        else:
            Coef.dcldqstar = cpsf.get_float_vector(tixi, dcldqstar_xpath)

    dcmsdqstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcmsdqstar'
    if tixi.checkElement(dcmsdqstar_xpath):
        check_str = tixi.getTextElement(dcmsdqstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcmsdqstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcmsdqstar = []
        else:
            Coef.dcmsdqstar = cpsf.get_float_vector(tixi, dcmsdqstar_xpath)

    dcddqstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcddqstar'
    if tixi.checkElement(dcddqstar_xpath):
        check_str = tixi.getTextElement(dcddqstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcddqstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcddqstar = []
        else:
            Coef.dcddqstar = cpsf.get_float_vector(tixi, dcddqstar_xpath)

    dcmddpstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcmddpstar'
    if tixi.checkElement(dcmddpstar_xpath):
        check_str = tixi.getTextElement(dcmddpstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcmddpstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcmddpstar = []
        else:
            Coef.dcmddpstar = cpsf.get_float_vector(tixi, dcmddpstar_xpath)

    dcmldqstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcmldqstar'
    if tixi.checkElement(dcmldqstar_xpath):
        check_str = tixi.getTextElement(dcmldqstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcmldqstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcmldqstar = []
        else:
            Coef.dcmldqstar = cpsf.get_float_vector(tixi, dcmldqstar_xpath)

    dcmldpstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcmldpstar'
    if tixi.checkElement(dcmldpstar_xpath):
        check_str = tixi.getTextElement(dcmldpstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcmldpstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcmldpstar = []
        else:
            Coef.dcmldpstar = cpsf.get_float_vector(tixi, dcmldpstar_xpath)

    dcmldrstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcmldrstar'
    if tixi.checkElement(dcmldrstar_xpath):
        check_str = tixi.getTextElement(dcmldrstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcmldrstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcmldrstar = []
        else:
            Coef.dcmldrstar = cpsf.get_float_vector(tixi, dcmldrstar_xpath)

    dcmddrstar_xpath = apm_xpath + '/dampingDerivatives/positiveRates/dcmddrstar'
    if tixi.checkElement(dcmddrstar_xpath):
        check_str = tixi.getTextElement(dcmddrstar_xpath)
        if check_str == '':
            log.warning(
                'No /dampingDerivatives/positiveRates/dcmddrstar,  values have been found in the CPACS file'
            )
            log.warning('An empty list will be returned.')
            Coef.dcmddrstar = []
        else:
            Coef.dcmddrstar = cpsf.get_float_vector(tixi, dcmddrstar_xpath)

    return Coef