Ejemplo n.º 1
0
def nt(model_name, dat, let):
    """
    Read the number of time steps (used in observation file)
    """

    # Define path and file
    output_path = rm.make_output_dirs(model_name, dat, let)[0]
    input_file = rm.make_file_dir_names(model_name)[2]

    # Read records (number lines in time step input)
    num_time_records = rm.read_records_input(output_path + '/' + input_file,
                                             '# time periods')

    # Read hashtag input
    lines = rm.read_hashtag_input(output_path + '/' + input_file,
                                  '# time periods', num_time_records)

    # Split hashtag input by white space
    split_lines = str.split(lines)

    # Read entry 3/4 in each line
    right_entries = split_lines[2::4]

    # Sum of the entries
    # -> Adding one accounts for the first time step at time = 0
    nt = sum([int(right_entries[i]) for i in range(len(right_entries))]) + 1

    return nt
Ejemplo n.º 2
0
def units(model_name, dat, let, uindex, pindex):
    """
    Read parameters pindex from unit uindex
    pindex:
    1 - Porosity
    4 - Permeability
    8 - Thermal conductivity
    10 - Volumetric heat capacity
    """

    # Define path and file
    output_path = rm.make_output_dirs(model_name, dat, let)[0]
    input_file = rm.make_file_dir_names(model_name)[2]

    # Read hashtag input
    lines = rm.read_hashtag_input(output_path + '/' + input_file, '# units',
                                  uindex)

    # Split hashtag input by white space
    split_lines = str.split(lines)

    # Find the number of parameters per line
    num_ps = len(split_lines) / uindex
    # Calculate the index of the right parameter
    right_index = (uindex - 1) * num_ps + pindex

    right_entry = split_lines[right_index]

    return right_entry
Ejemplo n.º 3
0
def delz(model_name, dat, let):
    """
    Read model name, output date and letter and
    return the corresponding array of cell lengths
    in z-direction.
    """
    output_dir = rm.make_output_dirs(model_name, dat, let)[0]
    input_file = rm.make_file_dir_names(model_name)[2]

    arr_filename = pm.py_output_filename('specs', 'delz',
                                         specl(model_name, dat, let), 'npy')

    if rm.check_hashtag(output_dir, input_file, "# delz"):
        line = rm.read_hashtag_input(output_dir + '/' + input_file, '# delz',
                                     1)
    else:
        input_file = rm.make_file_dir_names(model_name)[4]
        if rm.check_hashtag(output_dir, input_file, "# delz"):
            line = rm.read_hashtag_input(output_dir + '/' + input_file,
                                         '# delz', 1)
        else:
            if os.path.isfile(arr_filename):
                return np.load(arr_filename)
            else:
                raise IOError('Input files, hashtags or' +
                              ' npy file not found:\n\n' + output_dir +
                              '\n\n' + input_file + '\n\n' + arr_filename)

    num_entries = len(str.split(line))
    nums = [
        int(str.split(entry, "*")[0]) if len(str.split(entry, "*")) > 1 else 1
        for entry in str.split(line)
    ]
    lens = [
        float(str.split(entry, "*")[1])
        if len(str.split(entry, "*")) > 1 else float(str.split(entry, "*")[0])
        for entry in str.split(line)
    ]

    vec = [[lens[i] for j in range(nums[i])] for i in range(num_entries)]

    arr = np.array([num for elem in vec for num in elem])

    np.save(arr_filename, arr)

    return arr
Ejemplo n.º 4
0
def nrobs_int(model_name, dat, let):
    """
    Number of observation intervals for model_name.
    """
    output_path = rm.make_output_dirs(model_name, dat, let)[0]
    enkf_input_file = rm.make_file_dir_names(model_name)[3]

    line = rm.read_hashtag_input(output_path + '/' + enkf_input_file,
                                 '# nrobs_int', 1)
    first_entry = str.split(line)[0]
    nrobs_int = int(first_entry)
    return nrobs_int
Ejemplo n.º 5
0
def nrens(model_name, dat, let):
    """
    Number of ensemble members for model_name
    """
    output_path = rm.make_output_dirs(model_name, dat, let)[0]
    input_file = rm.make_file_dir_names(model_name)[2]

    line = rm.read_hashtag_input(output_path + '/' + input_file, '# simulate',
                                 1)
    first_entry = str.split(line)[0]
    nrens = int(first_entry)

    return nrens
Ejemplo n.º 6
0
def monitor_locs(model_name, dat, let):
    """
    Monitor point locations of model_name.
    """
    output_path = rm.make_output_dirs(model_name, dat, let)[0]
    true_input_file = rm.make_file_dir_names(model_name)[4]
    n_mons = num_mons(model_name, dat, let)

    lines = rm.read_hashtag_input(output_path + '/' + true_input_file,
                                  '# monitor', n_mons)
    locs = [[int(str.split(lines)[j]) for j in range(i, i + 3)]
            for i in range(0, 4 * n_mons, 4)]

    return locs
Ejemplo n.º 7
0
def single_cell_locs(model_name, dat, let):
    """
    Single cell locations of model_name, dat and lets
    """
    output_path = rm.make_output_dirs(model_name, dat, let)[0]
    enkf_input_file = rm.make_file_dir_names(model_name)[3]
    n_sc = num_single_cell(model_name, dat, let)

    lines = rm.read_hashtag_input(output_path + '/' + enkf_input_file,
                                  '# single cell output, ', n_sc)

    locs = [[int(str.split(lines)[j]) for j in range(i, i + 3)]
            for i in range(0, 5 * n_sc, 5)]

    return locs
Ejemplo n.º 8
0
def single_cell_variables(model_name, dat, let):
    """
    Single cell variable of model_name.

     1: head,  2:temp,  3:conc,  4:kz,  5:lz,  6:por  (inside mem)
    11: head, 12:temp, 13:conc, 14:kz, 15:lz, 16:por  (not inside mem)
    """
    output_path = rm.make_output_dirs(model_name, dat, let)[0]
    enkf_input_file = rm.make_file_dir_names(model_name)[3]
    n_sc = num_single_cell(model_name, dat, let)

    lines = rm.read_hashtag_input(output_path + '/' + enkf_input_file,
                                  '# single cell output, ', n_sc)
    variables = [int(str.split(lines)[i]) for i in range(3, 5 * n_sc, 5)]

    return variables