Esempio n. 1
0
    def read_excel(self,
                   filename,
                   min_sheet='Minerals',
                   min_header=1,
                   mix_sheet='Mineral mixtures',
                   mix_header=1):
        """ 
        Read the mineral mixtures from the project table
        """
        # first read in all minerals
        all_minerals = {}
        min_table = pd.read_excel(filename,
                                  sheet_name=min_sheet,
                                  header=min_header)
        for i, name in enumerate(min_table['Name']):
            if isnan(name):
                continue
            this_min = Mineral(
                min_table['Calculation method'][i] if 'Calculation method'
                in list(min_table.keys()) else 'User specified',
                float(min_table['Bulk moduli [GPa]'][i]),
                float(min_table['Shear moduli [GPa]'][i]),
                float(min_table['Density [g/cm3]'][i]),
                name.lower(),
                cutoffs=min_table['Cutoffs'][i]
                if 'Cutoffs' in list(min_table.keys()) else None,
                status='from excel')
            all_minerals[name.lower()] = this_min

        # Then read in the mineral mixtures
        min_mixes = {}
        mix_table = pd.read_excel(filename,
                                  sheet_name=mix_sheet,
                                  header=mix_header)
        for i, name in enumerate(mix_table['Mineral name']):
            vf = mix_table['Volume fraction'][i]
            if isnan(vf):
                continue  # Avoid minerals where the volume fraction is not set
            this_well = mix_table['Well name'][i].upper()
            this_wi = mix_table['Interval name'][i].upper()
            this_mineral = deepcopy(all_minerals[name.lower()])
            this_mineral.volume_fraction = float(vf) if (
                not isinstance(vf, str)) else vf.lower()
            if this_well in list(min_mixes.keys()):
                if this_wi in list(min_mixes[this_well].keys()):
                    min_mixes[this_well][this_wi][name.lower()] = this_mineral
                else:
                    min_mixes[this_well][this_wi] = {
                        name.lower(): this_mineral
                    }
            else:
                min_mixes[this_well] = {this_wi: {name.lower(): this_mineral}}

        self.minerals = min_mixes
        self.header['orig_file'] = filename
Esempio n. 2
0
def project_wells(filename, working_dir):
    """
    Returns a dictionary containing the requested wells from the project excel table

    :param filename:
        Excel file with well names and las files
    :param working_dir:
    :return:
        dict
        dictionary with las file names as keys
    """
    result = {}
    selected_wells = get_selected_wells(filename)
    sheet_name = 'Well logs'
    table = pd.read_excel(filename, header=1, sheet_name=sheet_name)
    for i, ans in enumerate(table['Given well name']):
        # skip empty rows
        if not isinstance(ans, str):
            continue
        # skip las files we have chosen to ignore
        if table['Use this file'][i].lower() == 'no':
            continue
        if fix_well_name(ans) in selected_wells:
            temp_dict = {}
            log_dict = {}
            for key in list(table.keys()):
                if (key.lower() == 'las file') or (key.lower() == 'use this file'):
                    continue
                elif (key.lower() == 'given well name') or \
                        (key.lower() == 'note') or \
                        (key.lower() == 'translate log names'):
                    if isinstance(table[key][i], str):
                        if key.lower() == 'given well name':
                            value = fix_well_name(table[key][i])
                        else:
                            value = table[key][i]
                        temp_dict[key] = value
                    else:
                        temp_dict[key] = None  # avoid NaN
                else:
                    val = table[key][i]
                    if isnan(val):
                        continue
                    else:
                        this_list = make_clean_list(table[key][i], small_cap=True)
                        for log_name in this_list:
                            log_dict[log_name] = key
                temp_dict['logs'] = log_dict
            # avoid las file names which aren't correctly given as strings
            if not isinstance(table['las file'][i], str):
                temp_file = False
            else:
                temp_file = test_file_path(table['las file'][i], working_dir)
            if temp_file is False:
                warn_txt = 'Warning, las file {} for well {} does not exist'.format(
                    table['las file'][i], ans)
                logger.warning(warn_txt)
                raise Warning(warn_txt)
            result[test_file_path(table['las file'][i], working_dir)] = temp_dict
    return result
Esempio n. 3
0
def project_wellpath_info(filename):
    result = {}
    table = None
    try:
        table = pd.read_excel(filename, header=1, sheet_name='Well paths')
    except ValueError:
        raise
    except Exception as e:
        print(e)
    for i, ans in enumerate(table['Use this file']):
        # skip empty rows
        if not isinstance(ans, str):
            continue
        if ans.lower() == 'yes':
            temp_dict = {}
            for key in list(table.keys()):
                if (key.lower() == 'use this file') or (key.lower() == 'given well name'):
                    continue
                if isnan(table[key][i]):
                    temp_dict[key.lower()] = None  # avoid NaN
                else:
                    value = table[key][i]
                    temp_dict[key.lower()] = value
            result[table['Given well name'][i]] = temp_dict
    return result
Esempio n. 4
0
def project_templates(filename):
    table = pd.read_excel(filename, header=1, sheet_name='Templates')
    result = {}
    for i, ans in enumerate(table['Log type']):
        if not isinstance(ans, str):
            continue
        result[ans] = {}
        for key in ['bounds', 'center', 'colormap', 'description', 'max', 'min',
                    'scale', 'type', 'unit', 'line color', 'line style', 'line width']:
            result[ans][key] = None if isnan(table[key][i]) else table[key][i]
        result[ans]['full_name'] = ans

    # Also add the well settings
    table = pd.read_excel(filename, header=1, sheet_name='Well settings')
    for i, ans in enumerate(table['Given well name']):
        if not isinstance(ans, str):
            continue
        result[ans.upper().strip()] = {}
        for key in ['Color', 'Symbol', 'Content', 'KB', 'UWI', 'UTM', 'X', 'Y', 'Water depth', 'Note']:
            result[ans.upper().strip()][key.lower()] = None if isnan(table[key][i]) else table[key][i]

    return result
Esempio n. 5
0
    def __init__(
            self,
            calculation_method=None,  # 'Interval average' or 'User specified'
            k=None,  # Bulk moduli [GPa] given by a MineralData object
            mu=None,  # Shear moduli [GPa] given by a MineralData object
            rho=None,  # Density [g/cm3] given by a MineralData object
            name='Quartz',  # str
            volume_fraction=None,  # str 'complement', volume log name, or float
            cutoffs=None,  # cutoffs used when calculating the average mineral properties within an interval
            status=None,
            header=None):

        if header is None:
            header = {}
        if name is not None:
            header['name'] = name

        self.header = Header(header)

        # Case input data is given as a float or integer, create a MineralData
        # object with default units and description
        for this_name, param, unit_str, desc_str, def_val in zip(
            ['k', 'mu', 'rho', 'calculation_method', 'cutoffs', 'status'],
            [k, mu, rho, calculation_method, cutoffs, status],
            ['GPa', 'GPa', 'g/cm3', 'str', 'str', 'str'],
            ['Bulk moduli', 'Shear moduli', 'Density', '', '', 'Status'],
            [36.6, 45., 2.65, 'User specified', None, None]):
            if (param is None) or (isnan(param)):
                param = def_val
            if isinstance(param, int):
                param = float(param)
            if isinstance(param, float):
                param = MineralData(this_name, param, unit_str, desc_str)

            super(Mineral, self).__setattr__(this_name, param)

        super(Mineral, self).__setattr__('name', name)
        super(Mineral, self).__setattr__('volume_fraction', volume_fraction)
Esempio n. 6
0
    def calc_k(self, bd):
        """
        Calculates the fluid bulk modulus at given burial depth
        :param bd:
        :return:
        """
        if self.calculation_method.value == 'Batzle and Wang':
            #print('calc_k: {}, Burial depth: {}'.format(self.name, bd))
            if (bd is None) or isnan(bd):
                warn_txt = 'No Burial depth value given for the fluid calculation. ' \
                           'Batzle and Wang not possible to calculate'
                print('WARNING: {}'.format(warn_txt))
                logger.warning(warn_txt)

            _s = self.salinity
            _p = self.pressure_ref.value + self.pressure_gradient.value * bd
            _t = self.temp_ref.value + self.temp_gradient.value * bd
            if self.fluid_type == 'brine':
                rho_b = rp.rho_b(_s, _p, _t).value
                v_p_b = rp.v_p_b(_s, _p, _t).value
                this_k = Param(name='k_b',
                               value=v_p_b**2 * rho_b * 1.E-6,
                               unit='GPa',
                               desc='Brine bulk modulus')
            elif self.fluid_type == 'oil':
                this_k, rho_o = rp.k_and_rho_o(self.oil_api, self.gas_gravity,
                                               self.gor, _p, _t)
            elif self.fluid_type == 'gas':
                this_k, rho_g = rp.k_and_rho_g(self.gas_gravity, _p, _t)
            else:
                raise NotImplementedError(
                    'Bulk modulus not possible to calculate for {}'.format(
                        self.fluid_type))
            self.k = this_k
        else:
            # No calculation done
            pass
Esempio n. 7
0
    def __init__(
            self,
            calculation_method=None,  # or Batzle and Wang',  # or 'User specified'
            k=None,  # Bulk modulus in GPa
            mu=None,  # Shear modulus in GPa
            rho=None,  # Density in g/cm3
            temp_gradient=None,
            temp_ref=None,
            pressure_gradient=None,
            pressure_ref=None,
            salinity=None,
            gor=None,
            oil_api=None,
            gas_gravity=None,
            gas_mixing=None,
            brie_exponent=None,
            fluid_type=None,
            name='Default',
            volume_fraction=None,
            status=None,
            header=None):

        if header is None:
            header = {}
        if name is not None:
            header['name'] = name

        self.header = Header(header)
        # initiating class variables to None to avoid warnings
        self.calculation_method = None
        self.k = None
        self.mu = None
        self.rho = None
        self.temp_gradient = None
        self.temp_ref = None
        self.pressure_gradient = None
        self.pressure_ref = None
        self.salinity = None
        self.gor = None
        self.oil_api = None
        self.gas_gravity = None
        self.gas_mixing = None
        self.brie_exponent = None
        self.fluid_type = None
        self.name = None
        self.volume_fraction = None

        # Case input data is given as a float or integer, create a Param
        # object with default units and description
        for this_name, param, unit_str, desc_str, def_val in zip(
            [
                'k',
                'mu',
                'rho',
                'calculation_method',
                'temp_gradient',
                'temp_ref',
                #['calculation_method', 'temp_gradient', 'temp_ref',
                'pressure_gradient',
                'pressure_ref',
                'salinity',
                'gor',
                'oil_api',
                'gas_gravity',
                'gas_mixing',
                'brie_exponent',
                'status'
            ],
            [
                k,
                mu,
                rho,
                calculation_method,
                temp_gradient,
                temp_ref,
                #[calculation_method, temp_gradient, temp_ref,
                pressure_gradient,
                pressure_ref,
                salinity,
                gor,
                oil_api,
                gas_gravity,
                gas_mixing,
                brie_exponent,
                status
            ],
            [
                'GPa',
                'GPa',
                'g/cm3',
                '',
                'C/m',
                'C',
                #['', 'C/m', 'C',
                'MPa/m',
                'MPa',
                'ppm',
                '',
                'API',
                '',
                '',
                '',
                'str'
            ],
            [
                'Bulk moduli',
                'Shear moduli',
                'Density',
                '',
                '',
                '',
                #['', '', '',
                '',
                'Pressure at mudline',
                '',
                'Gas/Oil ratio',
                '',
                '',
                'Wood or Brie',
                '',
                'Status'
            ],
            [
                np.nan,
                np.nan,
                np.nan,
                'User specified',
                0.03,
                10.,
                #['User specified', 0.03, 10.,
                0.0107,
                0.,
                70000.,
                1.,
                30.,
                0.6,
                'Wood',
                2.,
                None
            ]):
            if (param is None) or isnan(param):
                param = def_val
                #print('param {} is None'.format(this_name))
            if isinstance(param, int):
                param = float(param)
                #print('param {} is integer'.format(this_name))
            if isinstance(param, float) or isinstance(param, str):
                #print('param {} is float or string'.format(this_name))
                param = Param(this_name, param, unit_str, desc_str)
            # TODO
            # catch the cases where input data is neither None, int,  float or str
            # TODO
            # The handling of parameters that are strings are different for fluids (Param) and minerals (strings)

            super(Fluid, self).__setattr__(this_name, param)

        super(Fluid, self).__setattr__('name', name)
        super(Fluid, self).__setattr__('fluid_type', fluid_type)
        super(Fluid, self).__setattr__('volume_fraction', volume_fraction)
Esempio n. 8
0
    def read_excel(self,
                   filename,
                   fluid_sheet='Fluids',
                   fluid_header=1,
                   mix_sheet='Fluid mixtures',
                   mix_header=1):

        # First read in all fluids defined in the project table
        all_fluids = {}
        fluids_table = pd.read_excel(filename,
                                     sheet_name=fluid_sheet,
                                     header=fluid_header)

        for i, name in enumerate(fluids_table['Name']):
            if isnan(name):
                continue  # Avoid empty lines
            #if fluids_table['Calculation method'][i] == 'Batzle and Wang':
            #    warn_txt = 'Calculation of fluid properties is still not implemented, please use constant values'
            #    print('WARNING {}'.format(warn_txt))
            #    logger.warning(warn_txt)
            this_fluid = Fluid(
                    'User specified' if isnan(fluids_table['Calculation method'][i]) else \
                        fluids_table['Calculation method'][i],
                    float(fluids_table['Bulk moduli [GPa]'][i]),
                    float(fluids_table['Shear moduli [GPa]'][i]),
                    float(fluids_table['Density [g/cm3]'][i]),
                    float(fluids_table['T gradient [deg C/m]'][i]),
                    float(fluids_table['T ref [C]'][i]),
                    float(fluids_table['P gradient [MPa/m]'][i]),
                    float(fluids_table['P ref [MPa]'][i]),
                    float(fluids_table['Salinity [ppm]'][i]),
                    float(fluids_table['GOR'][i]),
                    float(fluids_table['Oil API'][i]),
                    float(fluids_table['Gas gravity'][i]),
                    fluids_table['Gas mixing'][i],
                    float(fluids_table['Brie exponent'][i]),
                    # Fluid type is now defined in the fluid mixture sheet
                    #fluid_type=None if isnan(fluids_table['Fluid type'][i]) else fluids_table['Fluid type'][i].lower(),
                    name=name.lower(),
                    status='from excel'
            )
            all_fluids[name.lower()] = this_fluid

        # Then read in the fluid mixes
        fluids_mixes = {'initial': {}, 'final': {}}
        mix_table = pd.read_excel(filename,
                                  sheet_name=mix_sheet,
                                  header=mix_header)
        for i, name in enumerate(mix_table['Fluid name']):
            if mix_table['Use'][i] != 'Yes':
                continue
            vf = mix_table['Volume fraction'][i]
            ftype = mix_table['Fluid type'][i]
            # Need to pair fluid name with fluid type to get unique fluid names in fluid mixture
            this_name = '{}_{}'.format(name.lower(),
                                       '' if isnan(ftype) else ftype.lower())
            #this_name = name.lower()
            if isnan(vf):
                continue  # Avoid fluids where the volume fraction is not set
            this_subst = mix_table['Substitution order'][i].lower()
            this_well = mix_table['Well name'][i].upper()
            this_wi = mix_table['Interval name'][i].upper()
            this_fluid = deepcopy(all_fluids[name.lower()])
            this_fluid.volume_fraction = \
                float(vf) if (not isinstance(vf, str)) else vf.lower()
            this_fluid.fluid_type = None if isnan(ftype) else ftype.lower()
            this_fluid.name = this_name
            this_fluid.header.name = this_name

            # iterate down in this complex dictionary
            # {this_subst:                          # 1'st level: initial or final
            #       {this_well:                     # 2'nd level: well
            #           {this_wi:                   # 3'd level: working interval
            #               {fluid_name: Fluid()    # 4'th level: fluid
            #       }}}}
            # 2'nd level
            if this_well in list(fluids_mixes[this_subst].keys()):
                # 3'rd level
                if this_wi in list(fluids_mixes[this_subst][this_well].keys()):
                    # 4'th level
                    fluids_mixes[this_subst][this_well][this_wi][
                        this_name] = this_fluid
                else:
                    fluids_mixes[this_subst][this_well][this_wi] = {
                        this_name: this_fluid
                    }
            else:
                fluids_mixes[this_subst][this_well] = {
                    this_wi: {
                        this_name: this_fluid
                    }
                }

        self.fluids = fluids_mixes
        self.header['orig_file'] = filename