예제 #1
0
def Graph2Netz(G_Set_Sum):
    """ Creation of a Netz from a networkx network 
    
    \n.. comments:
    Input:
        G_Set_Sum   Network of type networkx
    Return:
        G_Netz      Netz of type K_Netze.NetComp
    """

    G_Netz = K_Netze.NetComp()
    Pipe = []
    Nodes = []

    for node in G_Set_Sum.nodes():
        id = G_Set_Sum.node[node]['id'][0]
        lat = G_Set_Sum.node[node]['pos'][1]
        long = G_Set_Sum.node[node]['pos'][0]
        country_code = getAttrib(G_Set_Sum.node[node], 'country_code')
        param = getAttrib(G_Set_Sum.node[node], 'param', 'param')
        source_id = getAttrib(G_Set_Sum.node[node], 'source_id', id)
        node_id = getAttrib(G_Set_Sum.node[node], 'node_id', id)
        name = getAttrib(G_Set_Sum.node[node], 'name', id)

        Nodes.append(
            K_Component.Nodes(id=id,
                              name=name,
                              source_id=source_id,
                              node_id=node_id,
                              long=long,
                              lat=lat,
                              country_code=country_code,
                              param=param))

    G_Netz.Nodes = Nodes

    for edge in G_Set_Sum.edges():
        for xx in range(len(G_Set_Sum[edge[0]][edge[1]])):
            id = G_Set_Sum[edge[0]][edge[1]][xx]['id'][0]
            latS = G_Set_Sum.node[edge[0]]['pos'][1]
            longS = G_Set_Sum.node[edge[0]]['pos'][0]
            latE = G_Set_Sum.node[edge[1]]['pos'][1]
            longE = G_Set_Sum.node[edge[1]]['pos'][0]

            country_codeS = G_Set_Sum.node[edge[0]]['country_code']
            country_codeE = G_Set_Sum.node[edge[1]]['country_code']
            param = getAttrib(G_Set_Sum[edge[0]][edge[1]][xx], 'param',
                              'param')
            source_id = getAttrib(G_Set_Sum[edge[0]][edge[1]][xx], 'source_id',
                                  id)
            node_id = [str(edge[0]), str(edge[1])]
            name = getAttrib(G_Set_Sum[edge[0]][edge[1]][xx], 'name', id)

            Pipe.append(
                K_Component.PipeSegments(
                    id=id,
                    name=name,
                    source_id=source_id,
                    node_id=node_id,
                    long=[longS, longE],
                    lat=[latS, latE],
                    country_code=[country_codeS, country_codeE]))

    G_Netz.PipeSegments = Pipe

    return G_Netz
예제 #2
0
def read_component(DataType = '', NumDataSets = 1e+100, RelDirName  = None):
    """ Method of reading in LKD components from shape files. **RelDirName** supplies the relative location of the shape files, whereas **DataType** specifies which component is to be reaad in with options 'PipeSegments', 'Nodes', 'Storages', and 'Productions'.

    \n.. comments: 
    Input:
        self:            self
        RelDirName:      string, containing the relative path name of where data will be loaded from
                         Default = 'Eingabe/LKD/'
    Return:
        []
    """
    
    ReturnComponent = []
    inCoord 		= 'epsg:31468'
    outCoord	 	= 'epsg:4326'
    count           = 0
    if DataType in 'PipeSegments':
#        start = time.time()

        FileName_Shape  = str(RelDirName / 'pipelines_utf8.shp')
        # Loading from shape file
        Shapes          = shapefile.Reader(FileName_Shape, encoding = "utf8")
        # Malen der Europa Karte
#        print('there are pipesegments: ' + str(len(Shapes.shapeRecords())))
        for shape in Shapes.shapeRecords():
            # Getting PolyLine
            parts   = sorted(shape.shape.parts)
            # Joining X and Y coordinates from Shape.shape.points
            vec             = shape.shape.points
            polyLine        = K_Component.PolyLine(lat = [], long = [])
            for x,y in vec: 
                polyLine.long.append(x)
                polyLine.lat.append(y)
            
            # Converting to LatLong 
            polyLine = M_Projection.XY2LatLong(polyLine, inCoord, outCoord)            
            
            # Generation of PipeLine
            PipeLine        = M_Shape.PolyLine2PipeLines(polyLine, parts, source = C_Code, country_code = C_Code)

            lat             = PipeLine[0].lat
            long            = PipeLine[0].long
            
            # Getting Meta data
            id          = str(shape.record[0])
            source_id   = [ID_Add + str(id)]
            name        = replaceString(shape.record[1])
            if len(name) == 0:
                name = 'PS_' + str(id)
            # Converting gas_type to boolean
            is_H_gas        = shape.record[2]
            if is_H_gas == 'L':
                is_H_gas = 0
            elif is_H_gas == 'H':
                is_H_gas = 1
            
            length          = float(shape.record[3])/1000
            pipe_class_type = shape.record[6]
            if pipe_class_type == '':
                pipe_class_type = None
            # is_virtualPipe
            is_virtualPipe = False
            if len(shape.record[4]) > 0:
                if shape.record[4] == 1:
                    is_virtualPipe    = True

            # diameter_mm
            if len(shape.record[5]) > 0:
                if 'NULL' == shape.record[5]:
                    diameter_mm    = float('nan')
                else:
                    diameter_mm    = float(shape.record[5])
            else:
                diameter_mm    = float('nan')

            # max_pressure_bar
            if shape.record[7] == None:
                max_pressure_bar    = float('nan')
            elif type(shape.record[7]) == int:
                max_pressure_bar   = float(shape.record[7])
                if max_pressure_bar > 200:
                    max_pressure_bar = float('nan')
            elif len(shape.record[7]) > 0:
                if 'NULL' == shape.record[7]:
                    max_pressure_bar    = float('nan')
                else:
                    max_pressure_bar   = float(shape.record[7])
                    if max_pressure_bar > 200:
                        max_pressure_bar = float('nan')
            else:
                max_pressure_bar  = float('nan')
            
            diam_est            = shape.record[8]
            class_est           = shape.record[9]
            press_est           = shape.record[10]
            if isinstance(diam_est, str):
                if diam_est == 'NULL':
                    diam_est = float('nan')
                    diam_est_method      = 'raw'
                    diam_est_uncertainty = 0
                else:
                    diam_est = diam_est
                    diam_est_method      = 'raw'
                    diam_est_uncertainty = 0
            else:
                if diam_est == 1:
                    diam_est_method      = 'estimated'
                    diam_est_uncertainty = 1
                else:
                    diam_est_method      = 'raw'
                    diam_est_uncertainty = 0
                

            if isinstance(class_est, str):
                if class_est == 'NULL':
                    class_est = float('nan')
                    class_est_method      = 'raw'
                    class_est_uncertainty = 0
                else:
                    class_est = class_est
                    class_est_method      = 'raw'
                    class_est_uncertainty = 0
            else:
                if class_est == 1:
                    class_est_method      = 'estimated'
                    class_est_uncertainty = 1
                else:
                    class_est_method      = 'raw'
                    class_est_uncertainty = 0


            if isinstance(press_est, str):
                if press_est == 'NULL':
                    press_est = float('nan')
                    press_est_method      = 'raw'
                    press_est_uncertainty = 0
                else:
                    press_est_method      = 'raw'
                    press_est_uncertainty = 0
            else:
                if press_est == 1:
                    press_est_method      = 'estimated'
                    press_est_uncertainty = 1
                else:
                    press_est_method      = 'raw'
                    press_est_uncertainty = 0


#            if isinstance(class_est, str):
#                if class_est == 'NULL':
#                    class_est = float('nan')
#            if isinstance(press_est, str):
#                if press_est == 'NULL':
#                    press_est = float('nan')
            
            
            max_cap_GWh_per_d   = shape.record[11]
            operator_name       = str(shape.record[12])
            node_id             = ['N_' + str(shape.record[13]), 'N_' + str(shape.record[14])]
            if 'N_809066' in node_id and 'N_809063' in node_id:
                if node_id[0] == 'N_809066':
                    node_id[0] = 'N_809076'
                else:
                    node_id[1] = 'N_809076'
            if 'N_809066' in node_id and 'N_1000001' in node_id:
                if node_id[0] == 'N_809066':
                    node_id[0] = 'N_809076'
                else:
                    node_id[1] = 'N_809076'
                    
            if 'N_809065' in node_id and 'N_809025' in node_id:
                if node_id[0] == 'N_809065':
                    node_id[0] = 'N_809075'
                else:
                    node_id[1] = 'N_809075'
            if 'N_809065' in node_id and 'N_1000001' in node_id:
                if node_id[0] == 'N_809065':
                    node_id[0] = 'N_809075'
                else:
                    node_id[1] = 'N_809075'
                    
            if 'N_809064' in node_id and 'N_809026' in node_id:
                if node_id[0] == 'N_809064':
                    node_id[0] = 'N_809074'
                else:
                    node_id[1] = 'N_809074'
            if 'N_809064' in node_id and 'N_1000001' in node_id:
                if node_id[0] == 'N_809064':
                    node_id[0] = 'N_809074'
                else:
                    node_id[1] = 'N_809074'
                
            country_code        = ['DE', 'DE']
            
            if is_virtualPipe == False:
                ReturnComponent.append(K_Component.PipeSegments(id = id, 
                        name        = name, 
                        lat         = lat, 
                        long        = long, 
                        country_code = country_code, 
                        node_id     = node_id, 
                        source_id   = source_id, 
                        param = {'max_pressure_bar': max_pressure_bar, 
                        'is_H_gas'      : is_H_gas, 
                        'length'        : length, 
                        'diameter_mm'   : diameter_mm, 
                        'pipe_class_type': pipe_class_type, 
                        'max_cap_GWh_per_d': max_cap_GWh_per_d, 
                        'operator_name' : operator_name},
                        method = {'diameter_mm'     : diam_est_method, 
                        'pipe_class_type'           : class_est_method, 
                        'max_pressure_bar'          : press_est_method},
                        uncertainty = {'diameter_mm': diam_est_uncertainty, 
                        'pipe_class_type'           : class_est_uncertainty, 
                        'max_pressure_bar'          : press_est_uncertainty},
                        )) 
                count           = count + 1
            if count > NumDataSets:
                return ReturnComponent
    
    elif DataType in 'Nodes':
        inCoord 		= 'epsg:31468'
        outCoord	 	= 'epsg:4326'
        FileName_Shape = str(RelDirName / 'nodes_utf8.shp')
        # Loading from shape file
        Shapes  = shapefile.Reader(FileName_Shape, encoding = "utf8")
        # Malen der Europa Karte
        for shape in Shapes.shapeRecords():
            id              = 'N_' + shape.record[0]
            source_id       = [ID_Add + str(shape.record[0])]
            name            = replaceString(shape.record[1])
            operator_name   = str(shape.record[2])
            is_import           = shape.record[3]
            is_export            = shape.record[4]
            H_L_conver      = int(shape.record[5])
            operator_Z      = shape.record[6]
            compressor      = shape.record[7]
            compUnit        = shape.record[8]
            if 'NULL' in compUnit:
                compUnit = 0
            elif len(compUnit) == 0:
                compUnit = 0
            else:
                compUnit = float(compUnit)
                
            country_code= shape.record[12]
            X_coor      = shape.record[13]
            Y_coor      = shape.record[14]
            entsog_nam  = str(shape.record[15])
            if len(entsog_nam) > 0:
                name            = entsog_nam
            if name == '':
                name = 'Ort_' + str(id)
            entsog_key  = shape.record[16]
            if entsog_key == '':
                entsog_key = None
            is_crossBorder = shape.record[17]
            ugs         = shape.record[19]
            production  = shape.record[20]
            exact       = 1
            license     = 'open data'
            Line        = K_Component.PolyLine(lat = Y_coor, long = X_coor)
            Line        = M_Projection.XY2LatLong(Line, inCoord, outCoord)
            lat         = Line.lat
            long        = Line.long
            if id == 'N_809066' and country_code == 'AT':
                id = 'N_809076'
            elif id == 'N_809065' and country_code == 'AT':
                id = 'N_809075'
            elif id == 'N_809064' and country_code == 'AT':
                id = 'N_809074'
            
            ReturnComponent.append(K_Component.Nodes(id = id, 
                    node_id     = [id], 
                    name        = name, 
                    source_id   = source_id, 
                    long        = long, 
                    lat         = lat, 
                    country_code= country_code,
                    param       = {'exact': exact, 
                    'H_L_conver': H_L_conver, 
                    'operator_Z': operator_Z, 
                    'compressor': compressor, 
                    'comp_units': compUnit,
                    'entsog_key': entsog_key, 
                    'is_crossBorder': is_crossBorder, 
                    'ugs'       : ugs, 
                    'production': production, 
                    'operator_name': operator_name, 
                    'is_import' : is_import, 
                    'is_export' : is_export, 
                    'license'   : license}))
            count           = count + 1
            if count > NumDataSets:
                return ReturnComponent
    
    
    elif DataType in 'Storages':
        FileName_Shape = str(RelDirName / 'storages_utf8.shp')
        # Loading from shape file
        Shapes  = shapefile.Reader(FileName_Shape, encoding = "utf8")
        # Malen der Europa Karte
        for shape in Shapes.shapeRecords():
            id              = 'N_' + shape.record[0]
            source_id       = [ID_Add + str(shape.record[0])]
            name            = replaceString(shape.record[1])
            operator_name   = str(shape.record[2])
            entsog_nam      = str(shape.record[9])
            if len(entsog_nam) > 0:
                name            = entsog_nam
                
            entsog_key      = shape.record[10]
            if entsog_key == '':
                entsog_key = None
            max_cap_pipe2store_GWh_per_d   = shape.record[11]
            max_cap_store2pipe_GWh_per_d   = shape.record[12]
            node_id         = ['N_' + shape.record[0]]
            country_code    = shape.record[6]
            ReturnComponent.append(K_Component.Storages(id = id, 
                    name        = name, 
                    source_id   = source_id, 
                    country_code = country_code, 
                    node_id     = node_id, 
                    param       = {'operator_name': operator_name, 
                    'entsog_key'                  : entsog_key, 
                    'max_cap_pipe2store_GWh_per_d': max_cap_pipe2store_GWh_per_d, 
                    'max_cap_store2pipe_GWh_per_d': max_cap_store2pipe_GWh_per_d}))
                    
            count           = count + 1
            if count > NumDataSets:
                return ReturnComponent
        

    elif DataType in 'Productions':
        FileName_Shape = str(RelDirName / 'productions_utf8.shp')
        # Loading from shape file
        Shapes  = shapefile.Reader(FileName_Shape, encoding = "utf8")
        # Malen der Europa Karte
        for shape in Shapes.shapeRecords():
            id              = 'N_' + shape.record[0]
            source_id       = [ID_Add + str(shape.record[0])]
            name            = replaceString(shape.record[1])
            operator_name   = str(shape.record[2])
            entsog_nam      = str(shape.record[9])
            if len(entsog_nam) > 0:
                name            = entsog_nam
            entsog_key      = shape.record[10]
            if entsog_key == '':
                entsog_key = None
            max_production  = shape.record[11]
            node_id         = ['N_' + shape.record[0]]
            country_code    = shape.record[6]
            ReturnComponent.append(K_Component.Productions(id =  id, 
                    name        = name, 
                    source_id   = source_id, 
                    node_id     = node_id, 
                    country_code = country_code, 
                    param       = {'entsog_key': entsog_key, 
                    'operator_name': operator_name, 
                    'is_H_gas'     : 1, 
                    'max_production_GWh_per_d': max_production}))
            count           = count + 1
            if count > NumDataSets:
                return ReturnComponent
    
    return ReturnComponent
예제 #3
0
def read_component(DataType = '', NumDataSets = 100000, RelDirName  = None, sourceName = None, Nodes = []):
    """ Reading in GasLib data sets from XML file, **NumDataSets** maximum number of records to read, 
	and **requeYear** for which year to get data. Relative path name of CSV file location is **RelDirName**.

    \n.. comments: 
    Input:
        DataType:        	string, containing the data type to read, e.g 'Nodes'.
        NumDataSets:     	number of data sets to be read in 
                            (Default = 100000). 
        RelDirName:      	string, containing directory name where GasLib data can be found
                            (Default = 'Eingabe/GSE/'). 
		sourceName:     	string containing an abbreviation for the source of the data.
                            (Default = None)
		Nodes: 				list of nodes. Obsolete!!!!
    Return:
	    []
    """
        
    ReturnComponent = []
    
    if 'GasLib-135' in sourceName:
        ID_Add = 'GL135_'
    elif 'GasLib-4197' in sourceName:
        ID_Add = 'GL4197_'
    elif 'GasLib-582-v2' in sourceName:
        XML_fileName    = os.path.join(RelDirName, sourceName)
        XML_fileName    = Path(XML_fileName)
        ID_Add = 'GL582_'
    elif 'GasLib-134-v2' in sourceName:
        XML_fileName    = os.path.join(RelDirName, sourceName)
        XML_fileName    = Path(XML_fileName)
        ID_Add = 'GL134_'
    else:
        print('ERROR: M_GasLib.read_component: sourceName not known. Program Terminates')
        return []
    schrott         = '{http://gaslib.zib.de/Gas}'
    XML_fileName    = os.path.join(RelDirName, sourceName)
    XML_fileName    = Path(XML_fileName)
    if 'Nodes'  in DataType:
        # Accessing the xml file
        tree = ET.parse(XML_fileName)
        root = tree.getroot()
        
        # going through each entry
        for child in root[1]:
            id              = child.attrib['id']
            node_id         = [id ]
            if 'alias' in child.attrib.keys():
                name            = child.attrib['alias']
            else: 
                name = []
            if len(name) == 0:
                name    = id
            lat             = float(child.attrib['geoWGS84Lat'])
            long            = float(child.attrib['geoWGS84Long'])
            source_id       = [ID_Add + id] 
            country_code    = 'DE'
            
            elevation_m        = None
            min_pressure_bar= None
            max_pressure_bar= None

            for kind in child:
                if 'height' == kind.tag.replace(schrott, ''):
                    elevation_m         = float(kind.attrib['value'])
                elif 'pressureMin' == kind.tag.replace(schrott, ''):
                    min_pressure_bar    = float(kind.attrib['value'])
                elif 'pressureMax' == kind.tag.replace(schrott, ''):
                    max_pressure_bar    = float(kind.attrib['value'])

            ReturnComponent.append(K_Component.Nodes(id = id, 
                                node_id             = node_id, 
                                name                = name, 
                                lat                 = lat, 
                                long                = long, 
                                source_id           = source_id, 
                                country_code        = country_code,
                                param               = {'elevation_m': elevation_m, 
                                'min_pressure_bar'  : min_pressure_bar, 
                                'max_pressure_bar'  : max_pressure_bar}))


    elif 'EntryPoints' in DataType:
        # Accessing the XML file
        tree = ET.parse(XML_fileName)
        root = tree.getroot()
        
        # going through each entry
        for child in root[1]:
            id              = child.attrib['id']
            if 'source' in id:
                node_id                     = [id ]
                name                        = child.attrib['alias']
                if len(name) == 0:
                    name    = id
                lat                         = float(child.attrib['geoWGS84Lat'])
                long                        = float(child.attrib['geoWGS84Long']) 
                source_id                   = [ID_Add + id] 
                country_code                = 'DE'
                
                elevation_m                 = None
                min_pressure_bar            = None
                max_pressure_bar            = None
                min_cap_M_m3_per_d          = None
                max_cap_M_m3_per_d          = None
                gasTemperature_C            = None
                calorificValue_MJ_per_m3    = None
                normDensity_kg_per_m3       = None
                coefficient_A_heatCapacity  = None
                coefficient_B_heatCapacity  = None
                coefficient_C_heatCapacity  = None
                molarMass_kg_per_kmol       = None
                pseudocriticalPressure      = None
                pseudocriticalTemperature   = None
                for kind in child:
                    if 'height' == kind.tag.replace(schrott, ''):
                        elevation_m                = float(kind.attrib['value'])
                    elif 'pressureMin' == kind.tag.replace(schrott, ''):
                        min_pressure_bar        = float(kind.attrib['value'])
                    elif 'pressureMax' == kind.tag.replace(schrott, ''):
                        max_pressure_bar        = float(kind.attrib['value'])
                    elif 'flowMin' == kind.tag.replace(schrott, ''):
                        min_cap_M_m3_per_d      = float(kind.attrib['value'])/1000*24
                    elif 'flowMax' == kind.tag.replace(schrott, ''):
                        max_cap_M_m3_per_d      = float(kind.attrib['value'])/1000*24
                    elif 'gasTemperature' == kind.tag.replace(schrott, ''):
                        gasTemperature_C        = float(kind.attrib['value'])
                    elif 'calorificValue' == kind.tag.replace(schrott, ''):
                        calorificValue_MJ_per_m3= float(kind.attrib['value'])
                    elif 'normDensity' == kind.tag.replace(schrott, ''):
                        normDensity_kg_per_m3   = float(kind.attrib['value'])
                    elif 'coefficient_A_heatCapacity' == kind.tag.replace(schrott, ''):
                        coefficient_A_heatCapacity  = float(kind.attrib['value'])
                    elif 'coefficient_B_heatCapacity' == kind.tag.replace(schrott, ''):
                        coefficient_B_heatCapacity  = float(kind.attrib['value'])
                    elif 'coefficient_C_heatCapacity' == kind.tag.replace(schrott, ''):
                        coefficient_C_heatCapacity  = float(kind.attrib['value'])
                    elif 'molarMass' == kind.tag.replace(schrott, ''):
                        molarMass_kg_per_kmol         = float(kind.attrib['value'])
                    elif 'pseudocriticalPressure' == kind.tag.replace(schrott, ''):
                        pseudocriticalPressure  = float(kind.attrib['value'])
                    elif 'pseudocriticalTemperature' == kind.tag.replace(schrott, ''):
                        pseudocriticalTemperature  = float(kind.attrib['value'])
                
            
                ReturnComponent.append(K_Component.EntryPoints(id = id, 
                                    node_id                     = node_id, 
                                    name                        = name, 
                                    lat                         = lat, 
                                    long                        = long, 
                                    source_id                   = source_id, 
                                    country_code                = country_code,
                                    param                       = {'elevation_m': elevation_m, 
                                    'min_pressure_bar'          : min_pressure_bar, 
                                    'max_pressure_bar'          : max_pressure_bar,
                                    'min_cap_M_m3_per_d'        : min_cap_M_m3_per_d, 
                                    'max_cap_M_m3_per_d'        : max_cap_M_m3_per_d, 
                                    'gasTemperature_C'          : gasTemperature_C,
                                    'calorificValue_MJ_per_m3'  : calorificValue_MJ_per_m3, 
                                    'normDensity_kg_per_m3'     : normDensity_kg_per_m3,
                                    'coefficient_A_heatCapacity': coefficient_A_heatCapacity, 
                                    'coefficient_B_heatCapacity': coefficient_B_heatCapacity, 
                                    'coefficient_C_heatCapacity': coefficient_C_heatCapacity, 
                                    'molarMass_kg_per_kmol'     : molarMass_kg_per_kmol, 
                                    'pseudocriticalPressure'    : pseudocriticalPressure,
                                    'pseudocriticalTemperature' : pseudocriticalTemperature}))


        
    elif 'PipeSegments' in DataType:
        # Initialization
        tree    = ET.parse(XML_fileName)
        root    = tree.getroot()
        schrott = '{http://gaslib.zib.de/Gas}'
        # disecting entries from XML file        
        for child in root[2]:
            id                      = child.attrib['id']
            node_id                = [child.attrib['from'], child.attrib['to']]
            name                    = child.attrib['alias']
            if len(name) == 0:
                name    = id
            source_id               = [ID_Add + id]
            country_code            = 'DE'
            max_pressure_bar        = None
            min_cap_M_m3_per_d      = None
            max_cap_M_m3_per_d      = None
            length                  = None
            diameter_mm             = None
            roughness_mm            = None
            heatTransferCoefficient_W_per_m2_per_K = None
            for kind in child:
                if 'flowMin' == kind.tag.replace(schrott, ''):
                    min_cap_M_m3_per_d  = float(kind.attrib['value'])/1000*24
                elif 'flowMax' == kind.tag.replace(schrott, ''):
                    max_cap_M_m3_per_d  = float(kind.attrib['value'])/1000*24
                elif 'length' == kind.tag.replace(schrott, ''):
                    length           = float(kind.attrib['value'])
                elif 'diameter' == kind.tag.replace(schrott, ''):
                    diameter_mm         = float(kind.attrib['value'])
                elif 'roughness' == kind.tag.replace(schrott, ''):
                    roughness_mm        = float(kind.attrib['value'])
                elif 'pressure' == kind.tag.replace(schrott, ''):
                    max_pressure_bar    = float(kind.attrib['value'])
                elif 'heatTransferCoefficient' == kind.tag.replace(schrott, ''):
                    heatTransferCoefficient_W_per_m2_per_K = float(kind.attrib['value'])



            
            ReturnComponent.append(K_Component.PipeSegments( id = id, name = name, 
                            source_id           = source_id, 
                            node_id             = node_id, 
                            country_code        = country_code, 
                            param               = {'max_pressure_bar': max_pressure_bar, 
                            'min_cap_M_m3_per_d': min_cap_M_m3_per_d, 
                            'max_cap_M_m3_per_d': max_cap_M_m3_per_d, 
                            'length'            : length, 
                            'diameter_mm'       : diameter_mm, 
                            'roughness_mm'      : roughness_mm, 
                            'heatTransferCoefficient_W_per_m2_per_K' : heatTransferCoefficient_W_per_m2_per_K}))


    elif 'Compressors' in DataType:
        # Initialization
        tree    = ET.parse(XML_fileName)
        root    = tree.getroot()
        # disecting entries from XML file        
        # going through each entry
        for child in root[2]:
            id              = child.attrib['id']
            if 'compressorStation' in id:
                node_id                     = [child.attrib['from'] ]
                source_id                   = [ID_Add + id]
                country_code                = 'DE'
                name                        = child.attrib['alias']
                if len(name) == 0:
                    name    = id
                from_node                   = child.attrib['from'] 
                to_node                     = child.attrib['to'] 
                energy_node                 = child.attrib['fuelGasVertex'] 
                
                loss_pressure_pipe2comp_bar = None
                loss_pressure_comp2pipe_bar = None
                min_pressure_pipe2comp_bar  = None
                max_pressure_comp2pipe_bar  = None
                diameter_pipe2comp_mm       = None
                diameter_comp2pipe_mm       = None
                dragFactor_pipe2comp        = None
                dragFactor_comp2pipe        = None
                min_cap_M_m3_per_d          = None
                max_cap_M_m3_per_d          = None
                # has_gasCooler
                has_gasCooler               = float(child.attrib['gasCoolerExisting'])
                # internalBypassRequired
                internalBypassRequired      = float(child.attrib['internalBypassRequired'])
                
                for kind in child:
                    if 'flowMin' == kind.tag.replace(schrott, ''):
                        min_cap_M_m3_per_d  = float(kind.attrib['value'])/1000*24
                    elif 'flowMax' == kind.tag.replace(schrott, ''):
                        max_cap_M_m3_per_d  = float(kind.attrib['value'])/1000*24
                        
                    elif 'pressureLossIn' == kind.tag.replace(schrott, ''):
                        loss_pressure_pipe2comp_bar     = float(kind.attrib['value'])
                    elif 'pressureLossOut' == kind.tag.replace(schrott, ''):
                        loss_pressure_comp2pipe_bar     = float(kind.attrib['value'])
                    elif 'pressureInMin' == kind.tag.replace(schrott, ''):
                        min_pressure_pipe2comp_bar      = float(kind.attrib['value'])
                    elif 'pressureOutMax' == kind.tag.replace(schrott, ''):
                        max_pressure_comp2pipe_bar      = float(kind.attrib['value']) 
                    elif 'diameterIn' == kind.tag.replace(schrott, ''):
                        diameter_pipe2comp_mm      = float(kind.attrib['value'])   
                    elif 'diameterOut' == kind.tag.replace(schrott, ''):
                        diameter_comp2pipe_mm      = float(kind.attrib['value'])
                    elif 'dragFactorIn' == kind.tag.replace(schrott, ''):
                        dragFactor_pipe2comp      = float(kind.attrib['value'])
                    elif 'dragFactorOut' == kind.tag.replace(schrott, ''):
                        dragFactor_comp2pipe      = float(kind.attrib['value'])

            
                ReturnComponent.append(K_Component.Compressors( id = id, 
                                name                        = name, 
                                source_id                   = source_id,  
                                node_id                     = node_id, 
                                country_code                = country_code,
                                param                       = {'from_node': from_node, 
                                'to_node'                   : to_node, 
                                'has_gasCooler'             : has_gasCooler, 
                                'energy_node'               : energy_node, 
                                'loss_pressure_pipe2comp_bar': loss_pressure_pipe2comp_bar, 
                                'loss_pressure_comp2pipe_bar': loss_pressure_comp2pipe_bar, 
                                'min_pressure_pipe2comp_bar': min_pressure_pipe2comp_bar, 
                                'max_pressure_comp2pipe_bar': max_pressure_comp2pipe_bar, 
                                'diameter_pipe2comp_mm'     : diameter_pipe2comp_mm,
                                'diameter_comp2pipe_mm'     : diameter_comp2pipe_mm,
                                'dragFactor_pipe2comp'      : dragFactor_pipe2comp,
                                'dragFactor_comp2pipe'      : dragFactor_comp2pipe,
                                'internalBypassRequired'    : internalBypassRequired}))

    return ReturnComponent