def _metadata_fixed(self):
        """
        Define the most important tab parametersfor a fixed-type tab file
        """
        # Number of fluids and index of all the phisical properties
        fluids = {}
        props_idx = {}
        with open(self.abspath) as fobj:
            contents = fobj.readlines()
            for idx, line in enumerate(contents):
                if re.findall(r"\'[\w \-\,]*\'", line):
                    if line.split('\'')[-1] not in ('', '\n'):
                        fluid = line.split('\'')[-1].replace("\n", "")
                    else:
                        fluid = 'unknown'
                    fluids[fluid] = [idx, contents[idx+1], contents[idx+2]]
                if idx not in (0, 1) and re.findall(r"[\w\-\/\,]*[()]+", line):
                    prop, unit = line.replace("\n", "").split("(")[0:2]
                    prop = prop[1:-1]
                    props_idx[idx] = (fluid, prop, unit.replace(")", ""))
        self.metadata['nfluids'] = len(fluids)
        # Delete the fluid idx from multiple fluids tab
        for fluid in fluids:
            if self.metadata['nfluids'] != 1:
                fluids[fluid] = [el for idx, el in
                                 enumerate(fluids[fluid]) if idx != 1]
        # Define T and P arrays and all the other patrameters for a fixed tab
        for fluid_idx, fluid in enumerate(fluids):
            p_points, t_points = re.findall(r'[\w+\-\.]+',
                                            fluids[fluid][1])[0:2]
            self.metadata['t_points'].append(int(t_points))
            self.metadata['p_points'].append(int(p_points))
            self.metadata['fluids'].append(fluid)
            # t and p arrays definition
            with open(self.abspath) as fobj:
                contents = fobj.readlines()
                if len(re.findall(r'[\w+\-\.]+', contents[2])) == 2 and\
                   len(re.findall(r'[\w+\-\.]+', contents[3])) == 2:
                    # for tab file like 'Pearl-2-rich-sep2008.tab':
                    # 'WATER-OPTION ENTROPY 'P-2-rich EOS = PR
                    #    42   35    .205826E-01
                    #   .487805E+06    .882353E+01
                    #   .100000E+06   -.500000E+02
                    p_0, t_0 = re.findall(r'[\w+\-\.]+', contents[3])
                    p_step, t_step = re.findall(r'[\w+\-\.]+', contents[2])
                    t_points = self.metadata["t_points"]
                    p_points = self.metadata["p_points"]
                    t_f = float(t_step)*t_points[fluid_idx] + float(t_0)
                    p_f = float(p_step)*p_points[fluid_idx] + float(p_0)
                    self.metadata['t_array'].append(np.arange(float(t_0),
                                                              t_f,
                                                              float(t_step)))
                    self.metadata['p_array'].append(np.arange(float(p_0),
                                                              p_f,
                                                              float(p_step)))
                else:
                    # for tab file like 'Malampaya_export_gas_2011.tab':
                    if self.metadata['nfluids'] != 1:
                        t_p = self._partial_extraction_fixed(fluids[fluid][0],
                                                             3)
                    else:
                        t_p = self._partial_extraction_fixed(fluids[fluid][0],
                                                             2)
                    len_t_array = self.metadata['t_points'][fluid_idx]
                    len_p_array = self.metadata['p_points'][fluid_idx]

        self.metadata['p_array'].append(t_p[:len_p_array])
        self.metadata['t_array'].append(t_p[len_p_array:
                                            len_t_array+len_p_array])
        self.data = pd.DataFrame(props_idx,
                                 index=("Fluid", "Property",
                                        "Unit")).transpose()
def _metadata_fixed ( self ) : fluids = { } props_idx = { } with open ( self . abspath ) as fobj : contents = fobj . readlines ( ) for idx , line in enumerate ( contents ) : if re . findall ( r"\'[\w \-\,]*\'" , line ) : if line . split ( '\'' ) [ - 1 ] not in ( '' , '\n' ) : fluid = line . split ( '\'' ) [ - 1 ] . replace ( "\n" , "" ) else : fluid = 'unknown' fluids [ fluid ] = [ idx , contents [ idx + 1 ] , contents [ idx + 2 ] ] if idx not in ( 0 , 1 ) and re . findall ( r"[\w\-\/\,]*[()]+" , line ) : prop , unit = line . replace ( "\n" , "" ) . split ( "(" ) [ 0 : 2 ] prop = prop [ 1 : - 1 ] props_idx [ idx ] = ( fluid , prop , unit . replace ( ")" , "" ) ) self . metadata [ 'nfluids' ] = len ( fluids ) for fluid in fluids : if self . metadata [ 'nfluids' ] != 1 : fluids [ fluid ] = [ el for idx , el in enumerate ( fluids [ fluid ] ) if idx != 1 ] for fluid_idx , fluid in enumerate ( fluids ) : p_points , t_points = re . findall ( r'[\w+\-\.]+' , fluids [ fluid ] [ 1 ] ) [ 0 : 2 ] self . metadata [ 't_points' ] . append ( int ( t_points ) ) self . metadata [ 'p_points' ] . append ( int ( p_points ) ) self . metadata [ 'fluids' ] . append ( fluid ) with open ( self . abspath ) as fobj : contents = fobj . readlines ( ) if len ( re . findall ( r'[\w+\-\.]+' , contents [ 2 ] ) ) == 2 and len ( re . findall ( r'[\w+\-\.]+' , contents [ 3 ] ) ) == 2 : p_0 , t_0 = re . findall ( r'[\w+\-\.]+' , contents [ 3 ] ) p_step , t_step = re . findall ( r'[\w+\-\.]+' , contents [ 2 ] ) t_points = self . metadata [ "t_points" ] p_points = self . metadata [ "p_points" ] t_f = float ( t_step ) * t_points [ fluid_idx ] + float ( t_0 ) p_f = float ( p_step ) * p_points [ fluid_idx ] + float ( p_0 ) self . metadata [ 't_array' ] . append ( np . arange ( float ( t_0 ) , t_f , float ( t_step ) ) ) self . metadata [ 'p_array' ] . append ( np . arange ( float ( p_0 ) , p_f , float ( p_step ) ) ) else : if self . metadata [ 'nfluids' ] != 1 : t_p = self . _partial_extraction_fixed ( fluids [ fluid ] [ 0 ] , 3 ) else : t_p = self . _partial_extraction_fixed ( fluids [ fluid ] [ 0 ] , 2 ) len_t_array = self . metadata [ 't_points' ] [ fluid_idx ] len_p_array = self . metadata [ 'p_points' ] [ fluid_idx ] self . metadata [ 'p_array' ] . append ( t_p [ : len_p_array ] ) self . metadata [ 't_array' ] . append ( t_p [ len_p_array : len_t_array + len_p_array ] ) self . data = pd . DataFrame ( props_idx , index = ( "Fluid" , "Property" , "Unit" ) ) . transpose ( )
Define the most important tab parametersfor a fixed-type tab file