def read_setfile(configfile):
    """
    A function for parsing a confuguration file to set basic parameters
    """
    global nu, R, Cf, ngrid, sp_grid_num, lambda_p, dt, x0, g, Ds, cnum, topodx
    parser = scp()
    parser.read(configfile)  # read a configuration file

    nu = parser.getfloat("Physical variables", "nu")  # kinematic viscosity
    # submerged spec. density of sediment
    R = parser.getfloat("Sediments", "R")
    Cf = parser.getfloat("Physical variables", "Cf")  # friction coefficient
    ngrid = parser.getint("Calculation", "ngrid")  # number of grids for a flow
    sp_grid_num = parser.getint("Calculation", "sp_grid_num")  # num of grids
    lambda_p = parser.getfloat("Sediments", "lambda_p")  # sediment porocity
    dt = parser.getfloat("Calculation", "dt")  # time step length
    x0 = parser.getfloat("Calculation", "x0")  # initial location of flow head
    g = parser.getfloat("Physical variables", "g")  # gravity acceleration
    topodx = parser.getfloat("Calculation", "topodx")

    Ds_text = parser.get("Sediments", "Ds")  # grain sizes as strings
    # converting strings of grain diameter to numbers
    Ds_micron = [float(x) for x in Ds_text.split(',') if len(x) != 0]
    Ds = np.array(Ds_micron) * 10**-6  # converting micron to m
    Ds = np.array(np.matrix(Ds).T)  # transpose the matrix
    cnum = len(Ds)  # number of grain-size classes
Esempio n. 2
0
    def __init__(self, appname, appver, cfgfile=None):
        self._conf = {
                 'sounds': {},
                 'active_profile': None,
                 'profiles': {}
                 }
        self._cfgfile = None
        self._configparser = None

        self._appname = appname
        self._appver = appver
        self.setCfgFilename(cfgfile)

        self._configparser = scp()
        self._configparser.optionxform = unicode
Esempio n. 3
0
def read_setfile(configfile):
    """
    read setting file (config.ini) and set parameters to the inverse model
    """
    global observation_x_file, observation_deposit_file, inversion_result_file,\
        inversion_x_file, inversion_deposit_file, inversion_ofunction_file, \
        inversion_startvalues_file, start_params, bound_values

    parser = scp()
    parser.read(configfile)#read a setting file

    #set file names
    observation_x_file = parser.get("Import File Names", "observation_x_file")
    observation_deposit_file = parser.get("Import File Names",\
                                          "observation_deposit_file")
    inversion_result_file = parser.get("Export File Names",\
                                       "inversion_result_file")
    inversion_x_file = parser.get("Export File Names", "inversion_x_file")
    inversion_deposit_file = parser.get("Export File Names",\
                                        "inversion_deposit_file")
    inversion_ofunction_file=parser.get("Export File Names",\
                                        "inversion_ofunction_file")
    inversion_startvalues_file=parser.get("Export File Names",\
                                          "inversion_startvalues_file")

    #Read starting values
    Rw0_text = parser.get("Inversion Options", "Rw0")
    U0_text = parser.get("Inversion Options", "U0")
    H0_text = parser.get("Inversion Options", "h0")
    C0_text = parser.get("Inversion Options", "C0")
    Ds_text = parser.get("Sediments", "Ds")

    #Convert text(CSV) to ndarray
    Rw0 = [float(x) for x in Rw0_text.split(',') if len(x) !=0]
    U0 = [float(x) for x in U0_text.split(',') if len(x) !=0]
    H0 = [float(x) for x in H0_text.split(',') if len(x) !=0]
    C0 = [float(x) for x in C0_text.split(',') if len(x) !=0]
    Ds = [float(x) for x in Ds_text.split(',') if len(x) !=0]
    
    #Make a list of starting values
    for i in range(len(U0)):
        for j in range(len(H0)):
            for k in range(len(C0)):
                init = [Rw0[0],U0[i],H0[j]]
                for l in range(len(Ds)):
                    init.extend([C0[k]])
                start_params.append(init)

    #Import ranges of possible values
    Rwmax = parser.getfloat("Inversion Options", "Rwmax")
    Rwmin = parser.getfloat("Inversion Options", "Rwmin")
    Umax = parser.getfloat("Inversion Options", "Umax")
    Umin = parser.getfloat("Inversion Options", "Umin")
    hmax = parser.getfloat("Inversion Options", "hmax")
    hmin = parser.getfloat("Inversion Options", "hmin")
    Cmax_text = parser.get("Inversion Options", "Cmax")
    Cmax = [float(x) for x in Cmax_text.split(',') if len(x) !=0]
    Cmin_text = parser.get("Inversion Options", "Cmin")
    Cmin = [float(x) for x in Cmin_text.split(',') if len(x) !=0]
    bound_values_list = [(Rwmin, Rwmax), (Umin, Umax), (hmin, hmax)]
    for i in range(0, len(Cmax)):
        bound_values_list.append((Cmin[i],Cmax[i]))
    bound_values = tuple(bound_values_list)
    
    #Set the initial values to the forward model
    fmodel.read_setfile(configfile)
Esempio n. 4
0
from future import standard_library

standard_library.install_aliases()
from configparser import SafeConfigParser as scp

_config = scp()

from .autoworkup import *