Exemple #1
0
def extract_rfd(path, rfd=1, export=True):
    """
    Function to extract the x and y values of a given rfd or to load it from previosly exportet .txt-files.

    Parameters
    ----------

    path : string
        path to ogs directory
    rfd : int
        Extract the #rfd curve from the rfd file and save it as txt. rfd = 0 : no extraction
    export : bool (Default: True)
        If True .txt-files will be saved to the path.

    Yields
    ------

    A txt file for x and y values of given rfd and returns x_values and y_values as tuple of lists.

    """

    import numpy as np
    import os.path
    from tools import get_ogs_task_id

    # get the task if from ogs model run
    task_id = get_ogs_task_id(path)

    # extract the series given in the rfd file
    if rfd != 0:
        if os.path.exists(str(path) + "/" + "rfd_curve#" + str(rfd) + "_x_values.txt") and os.path.exists(str(path) + "/" + "rfd_curve#" + str(rfd) + "_y_values.txt"):
            print("Txt.file of corresponding rfd curve already exists. Continuing without checking if content is correct.")
            # load this files to return from function
            x_values = np.loadtxt(path + "/" + "rfd_curve#" + str(rfd) + "_x_values.txt")
            y_values = np.loadtxt(path + "/" + "rfd_curve#" + str(rfd) + "_y_values.txt")
        else:
            from ogs5py import OGS
            ogs = OGS(task_root=path + "/", task_id=task_id)
            ogs.rfd.read_file(path=path + "/" + task_id + ".rfd")
            #print(ogs.rfd.get_block(rfd-1)[''])
            y_values = np.asarray([y_values[1] for y_values in ogs.rfd.get_block(rfd - 1)[""]])
            x_values = np.asarray([x_values[0] for x_values in ogs.rfd.get_block(rfd - 1)[""]])
            if export == True:
                np.savetxt(str(path) + "/" + "rfd_curve#" + str(rfd) + "_x_values.txt", x_values)
                np.savetxt(str(path) + "/" + "rfd_curve#" + str(rfd) + "_y_values.txt", y_values)
            else:
                pass
    return x_values, y_values
Exemple #2
0
 print(
     "###################################################################"
 )
 print("Project folder: " + project_folder)
 print("Observation point: " + obs_point)
 print("Observation point location: " + str(obs_loc))
 if obs_loc == aquifer_length:
     print(
         "Spectral analysis for the baseflow (not every functionality is considered (e.g. cut_index, norm))"
     )
     # If the current observation point is equal to the aquifer
     # length, it is assumed that this polyline-file contains the
     # velocities to calculate the baseflow. First, the baseflow
     # is calculated and afterwards, the diffusivity is derived
     # with the spectral analysis.
     task_id = get_ogs_task_id(path_to_project)
     baseflow = get_baseflow_from_polyline(
         task_id, path_to_project,
         path_to_project + "/" + task_id + "_ply_obs_01000_t" +
         str(len(obs_point_list)) + "_GROUNDWATER_FLOW.tec")
     # multiply the recharge time series with the aquifer length to get the total inflow
     recharge = recharge_time_series * aquifer_length
     try:
         D, D_cov, frequency, Sqq = discharge_ftf_fit(
             recharge, baseflow, time_step_size, aquifer_length)
     except RuntimeError:
         print("Optimal parameters not found...")
         D[0], D_cov[0] = [np.nan, np.nan], [[np.nan, np.nan],
                                             [np.nan, np.nan]]
         print("popt and pcov have been set to np.nan")
     except ValueError:
Exemple #3
0
def extract_timeseries(path, which="mean", process="GROUNDWATER_FLOW"):
    """
    Function to extract time series for each observation point and store them as .txt.

    Parameters
    ----------

    path : string
        path to ogs directory
    which : string, 'mean', 'max', 'min'
        Which value should be taken from the vertical polyline of obs point.
    process : string
        Which modelling process.

    Yields
    ------

    .txt from every observation point with head values

    """

    import numpy as np
    from ogs5py.reader import readtec_polyline
    import glob
    import vtk

    from tools import get_ogs_task_id

    # pipe vtk output errors to file
    errOut = vtk.vtkFileOutputWindow()
    errOut.SetFileName(path + "/VTK_Error_Out.txt")
    vtkStdErrOut = vtk.vtkOutputWindow()
    vtkStdErrOut.SetInstance(errOut)

    task_id = get_ogs_task_id(path)

    # read all tec files
    print("Reading tec-files from " + path)
    # This will throw an ERROR which is redirected to VTK_Error_Out.txt
    tecs = readtec_polyline(task_id=task_id, task_root=path)

    # extract the time series and save them as .txt
    for obs in tecs["GROUNDWATER_FLOW"].keys():
        time_steps = len(tecs["GROUNDWATER_FLOW"][obs]["TIME"])
        number_of_columns = tecs[process][obs]["HEAD"].shape[1]
        if which == "max":
            # select the maximum value (i.e. the uppermost) of polyline as long as polylines are defined from bottom to top
            head_ogs_timeseries_each_obs = tecs[process][obs]["HEAD"][
                :, number_of_columns - 1
            ]
        elif which == "min":
            # select the minimum value (i.e. the lowermost) of polyline as long as polylines are defined from bottom to top
            head_ogs_timeseries_each_obs = tecs[process][obs]["HEAD"][:, 0]
        elif which == "mean":
            head_ogs_timeseries_each_obs = []
            for step in range(time_steps):
                # calculates the mean of each time step
                head_ogs_timeseries_each_obs.append(
                    np.mean(tecs[process][obs]["HEAD"][step, :])
                )
            head_ogs_timeseries_each_obs = np.asarray(head_ogs_timeseries_each_obs)
        np.savetxt(
            str(path) + "/" + "head_ogs_" + str(obs) + "_" + str(which) + ".txt",
            head_ogs_timeseries_each_obs,
        )