示例#1
0
def scenario_2d(task_id, task_root, single_file, var_name, normalize):
    avg_concentration, times, time_steps, nodes = get_avg_conc_and_times_from_polyline(
        task_id=task_id, task_root=task_root, single_file=single_file)
    times_rfd, concentration_in = extract_rfd(task_root, rfd=1, export=True)

    plt.figure(figsize=(10, 7))
    plt.plot(
        times_rfd / normalize,
        concentration_in,
        linewidth=4,
        label="input concentration",
        color="blue",
    )
    plt.plot(
        times / normalize,
        avg_concentration,
        linewidth=2,
        label="averaged outflow concentration",
        color="orange",
    )
    plt.xlabel("days")
    plt.ylabel("concentration")
    plt.title(os.path.basename(task_root))
    plt.legend()
    plt.savefig(
        task_root + "/" + os.path.basename(single_file) +
        "_avg_concentration.png",
        dpi=300,
    )
    #plt.show()
    np.savetxt(
        task_root + "/" + os.path.basename(single_file) +
        "_avg_concentration.txt",
        avg_concentration,
    )
    return avg_concentration
示例#2
0
 # check if time series for different observation points have already been extracted
 checker = []
 for item in obs_point_list:
     if os.path.exists(str(path_to_project) + "/" + "head_ogs_" + str(item) + "_" + str(which) + ".txt"):
         checker.append(True)
     else:
         checker.append(False)
 if all(checker) == True and checker != []:
     print("All time series have already been extracted. Continuing without checking if content is correct.")
 else:
     # extract the time series from the tec files
     print("Extracting time series...")
     extract_timeseries(path_to_project, which="mean", process="GROUNDWATER_FLOW")
 # extract the rfd curve
 time_time_series, recharge_time_series = extract_rfd(
     path=path_to_project, rfd=1
 )
 # plot the time series vs recharge
 plot_head_timeseries_vs_recharge(path=path_to_project)
 # write OGS input parameters in DataFrame, but don't return kf because it is ditrubuted
 Ss, time_step_size, time_steps = get_ogs_parameters(path_to_project, noKf=True)
 # load from a file with information about the generated field
 field_info = open(path_to_project + "/field_info" + ".dat", "r")
 for line in field_info:
     dim, var, len_scale, mean, seed, geomean, harmean, arimean = line.split()
 field_info.close()
 kf_geo = float(geomean)
 kf_har = float(harmean)
 kf_ari = float(arimean)
 S = Ss * aquifer_thickness
 T_in_geo = kf_geo * aquifer_thickness
示例#3
0
def scenario_2a(task_id, task_root, single_file, var_name, normalize,
                percentage):
    """
    Script to plot the averaged concentration along a polyline vs the input concentration.
    """

    avg_concentration, times, time_steps, nodes = get_avg_conc_and_times_from_polyline(
        task_id=task_id, task_root=task_root, single_file=single_file)
    times_rfd, concentration_in = extract_rfd(task_root, rfd=1, export=True)
    start_time = get_start_time(
        np.asarray([times_rfd, concentration_in]).transpose())

    # 95 % of concentration
    for time, conc_out, conc_in in zip(times, avg_concentration,
                                       concentration_in):
        if conc_out >= percentage * conc_in and time > start_time:
            delta_t = time - start_time
            stop_time = delta_t + start_time
            print("Avegerage concentration at the outlet has reached " +
                  str(percentage) + " % of input concentration after " +
                  str(delta_t / normalize) + " days.")
            break
        if time == np.max(times):
            print(
                "Concentration has not reached " + str(percentage) +
                " % of input concentration within modelling period. Reached {:.3f} %."
                .format(conc_out / conc_in))
            delta_t = " greater than modelling period..."

    plt.figure(figsize=(10, 7))
    plt.plot(
        times / normalize,
        avg_concentration,
        linewidth=4,
        label="averaged outflow concentration",
        color="orange",
    )
    plt.plot(
        times / normalize,
        concentration_in,
        linewidth=2,
        label="input concentration",
        color="blue",
    )
    plt.xlabel("days")
    plt.ylabel("concentration")
    plt.title(os.path.basename(task_root))
    if delta_t == " greater than modelling period...":
        plt.annotate(
            "  " + str(percentage) + " % is" + str(delta_t) +
            " \nReached {:.3f} % in modelling period.".format(
                conc_out / conc_in),
            (np.median(times) / normalize, 0.8 * max(concentration_in)),
        )
    else:
        plt.vlines(
            x=[
                start_time / normalize,
                delta_t / normalize + start_time / normalize
            ],
            ymin=0,
            ymax=max(concentration_in),
            color="g",
        )
        plt.annotate(
            "  $\Delta t$ = " + str(delta_t / normalize) +
            ", Average Outflow concentration has \nreached " +
            str(percentage) + " % of input concentraton.",
            (stop_time / normalize, 0.8 * max(concentration_in)),
        )
    plt.legend()
    plt.savefig(
        task_root + "/" + os.path.basename(single_file) +
        "_avg_concentration.png",
        dpi=300,
    )
    #plt.show()

    np.savetxt(
        task_root + "/" + os.path.basename(single_file) +
        "_avg_concentration.txt",
        avg_concentration,
    )

    return avg_concentration
示例#4
0
def scenario_2b(task_id, task_root, single_file, var_name, normalize):
    """
    Dirac impulse of concentration for 1 day at a single point.
    """

    avg_concentration, times, time_steps, nodes = get_avg_conc_and_times_from_polyline(
        task_id=task_id, task_root=task_root, single_file=single_file)

    times_rfd, concentration_in = extract_rfd(task_root, rfd=1, export=True)

    start_time = get_start_time(
        np.asarray([times_rfd, concentration_in]).transpose())

    # index of maximum concentration - 2 (because of initial time step beeing 0)
    delta_t = times[np.argmax(avg_concentration)] - start_time
    stop_time = start_time + delta_t

    fig, ax1 = plt.subplots(figsize=(10, 7))
    ax1.set_title(os.path.basename(task_root))
    ax1.set_xlabel("days")
    ax1.set_ylabel("concentration in", color="b")
    ax1.tick_params("y", colors="b")
    ax1.plot(
        times / normalize,
        concentration_in,
        linewidth=4,
        label="input concentration",
        color="b",
    )
    ax1.legend(loc=2)
    plt.vlines(
        x=[start_time / normalize, stop_time / normalize],
        ymin=0,
        ymax=np.max(concentration_in),
        color="g",
    )
    plt.annotate(
        "  $\Delta t$ = " + str(delta_t / normalize),
        (stop_time / normalize, 0.3 * np.max(concentration_in)),
    )
    ax2 = ax1.twinx()
    ax2.plot(
        times / normalize,
        avg_concentration,
        linewidth=2,
        label="averaged outflow concentration",
        color="orange",
    )
    ax2.set_ylabel("concentration out", color="orange")
    ax2.tick_params("y", colors="orange")

    # if delta_t == " greater than modelling period...":
    #    plt.annotate(str(percentage) + " % is" + delta_t + " \nReached {:.3f} % in modelling period.".format(conc_out / conc_in), (np.median(times) + 1 ,0.8*max(concentration_in)))
    # else:
    #    plt.vlines(x=[start_time,delta_t+start_time], ymin=0, ymax=max(concentration_in))
    #    plt.annotate("$\Delta t$ = " + str(delta_t) + ", Average Outflow concentration has \nreached " + str(percentage) + " % of input concentraton.", (stop_time + 1 ,0.8*max(concentration_in)))

    ax2.legend(loc=0)
    plt.savefig(
        task_root + "/" + os.path.basename(single_file) +
        "_avg_concentration.png",
        dpi=300,
    )
    np.savetxt(
        task_root + "/" + os.path.basename(single_file) +
        "_avg_concentration.txt",
        avg_concentration,
    )
示例#5
0
def scenario_2c(
    task_id,
    task_root,
    single_file,
    var_name,
    normalize,
    percentage,
    ref_conc=None,
):
    """
    Script to plot the averaged concentration along a polyline vs the input concentration.

    Parameters
    ----------

    ref_conc : float, default: None
        If None, its extrated from second block in .ic from ogs model run.

    """

    if ref_conc == None:
        from ogs5py import OGS
        import glob

        ogs = OGS(
            task_root=task_root,
            task_id=os.path.basename(str(glob.glob(task_root + "/*.bc")))[:-5],
            output_dir=task_root,
        )
        ogs.ic.read_file(path=task_root + "/" + task_id + ".ic")
        ref_conc = ogs.ic.get_block(1)["DIS_TYPE"][0][1]

    avg_concentration, times, time_steps, nodes = get_avg_conc_and_times_from_polyline(
        task_id=task_id, task_root=task_root, single_file=single_file)
    times_rfd, concentration_in = extract_rfd(task_root, rfd=1, export=True)
    start_time = get_start_time(
        np.asarray([times_rfd, concentration_in]).transpose())

    # 95 % of concentration
    for time, conc_out in zip(times, avg_concentration):
        if percentage * conc_out <= ref_conc and time > start_time:
            delta_t = time - start_time
            stop_time = delta_t + start_time
            print("Avegerage concentration at the outlet has reached " +
                  str(percentage) + " % of reference concentration " +
                  str(ref_conc) + " after " + str(delta_t / normalize) +
                  " days.")
            break
        if time == np.max(times):
            print("Concentration has not reached " + str(percentage) +
                  " % of reference concentration " + str(ref_conc) +
                  " within modelling period. Reached {:.3f} %.".format(
                      ref_conc / conc_out))
            delta_t = " greater than modelling period..."

    fig, ax1 = plt.subplots(figsize=(10, 7))
    ax1.set_title(os.path.basename(task_root))
    ax1.set_xlabel("days")
    ax1.set_ylabel("concentration in", color="b")
    ax1.tick_params("y", colors="b")
    ax1.plot(
        times / normalize,
        concentration_in,
        linewidth=4,
        label="input concentration",
        color="b",
    )
    ax1.legend(loc=2)
    if delta_t != " greater than modelling period...":
        plt.vlines(
            x=[start_time / normalize, stop_time / normalize],
            ymin=0,
            ymax=np.max(concentration_in),
            color="g",
        )
        plt.annotate(
            "  $\Delta t$ = " + str(delta_t / normalize) + " to reach " +
            str(percentage) + " % of reference concentration.",
            (stop_time / normalize, 0.3 * np.max(concentration_in)),
        )
    ax2 = ax1.twinx()
    ax2.plot(
        times / normalize,
        avg_concentration,
        linewidth=2,
        label="averaged outflow concentration",
        color="orange",
    )
    ax2.set_ylabel("concentration out", color="orange")
    ax2.tick_params("y", colors="orange")

    # if delta_t == " greater than modelling period...":
    #    plt.annotate(str(percentage) + " % is" + delta_t + " \nReached {:.3f} % in modelling period.".format(conc_out / conc_in), (np.median(times) + 1 ,0.8*max(concentration_in)))
    # else:
    #    plt.vlines(x=[start_time,delta_t+start_time], ymin=0, ymax=max(concentration_in))
    #    plt.annotate("$\Delta t$ = " + str(delta_t) + ", Average Outflow concentration has \nreached " + str(percentage) + " % of input concentraton.", (stop_time + 1 ,0.8*max(concentration_in)))

    ax2.legend(loc=0)
    plt.savefig(
        task_root + "/" + os.path.basename(single_file) +
        "_avg_concentration.png",
        dpi=300,
    )
    np.savetxt(
        task_root + "/" + os.path.basename(single_file) +
        "_avg_concentration.txt",
        avg_concentration,
    )
    #plt.show()

    return avg_concentration
def plot_recharge_vs_baseflow(
    task_root,
    flow_timeseries,
    aquifer_length=None,
    calculate_tc_tr=False,
    percent=0.95,
    normalizer=86400,
):
    """
    Plot the discharge from the model with the recharge extracted from the rfd file.

    Parameters
    ----------
    task_root : string
        Directory of ogs model run.
    flow_timeseries : 1D array
        Output of get_baseflow_from_polyline()
    aquifer_length : float, default=None
        If a value is provided the script calculates the sum of inflow and
        outflow in the modelling period and prints it to the stdout.
    calculate_tc_tr : bool, default=False
        If True, tc and tr are calculated based on the first time step when
        recharge has reached the maximum.
    percet : float between 0 and 1, default: 0.95
        The percentage of discharge from recharge which should be considered
        for tc.
    normalizer : float, dafault=86400
        Time will be devided by this value.

    """

    import matplotlib.pyplot as plt
    from transect_plot import extract_rfd
    import numpy as np
    import os

    print("Starting with task root: " + task_root)

    rfd = extract_rfd(path=task_root, export=False)

    if aquifer_length != None:
        q_total = np.sum(flow_timeseries)
        print(
            "Total discharge rate in modelling period: {:.5f} [m^2/s]".format(
                q_total))
        r_total = np.sum(rfd[1][1:] * aquifer_length)
        print("Total recharge rate in modelling period: {:.5f} [m^2/s]".format(
            r_total))
        print("{:.5f} % of recharge has reached the outflow of the model.".
              format(q_total / r_total))

        if calculate_tc_tr == True:
            for i, item in enumerate(rfd[1]):
                if item == np.max(rfd[1]):
                    start_time = rfd[0][i] / normalizer
                    print("Time of max recharge: " + str(start_time))
                    break

            # switch(recharge_case):
            # case 1:
            # calculation of tc based on 95 % of recharge volume has reached the outflow
            sum_recharge = 0
            sum_discharge = 0
            for i, (item, jtem) in enumerate(
                    zip(rfd[1] * aquifer_length, flow_timeseries)):
                if (rfd[0][i] / normalizer > start_time
                        and jtem >= percent * item):
                    stop_time = rfd[0][i] / normalizer
                    delta_t = stop_time - start_time
                    print("Discharge has reached " + str(percent) +
                          " % of recharge at time: " + str(stop_time) +
                          ". Delta t = " + str(delta_t))
                    break
                if i == len(flow_timeseries) - 1:
                    print("Discharge has not reached " + str(percent) +
                          " % of recharge.")

    elif aquifer_length == None and calculate_tc_tr == True:
        print("You need to specify the aquifer length to calculate tc and tr.")

    time = rfd[0][:] / normalizer
    fig, ax1 = plt.subplots()
    ax1.set_title(os.path.basename(task_root))
    ax1.plot(time[:len(flow_timeseries)],
             flow_timeseries,
             color="#1f77b4",
             linewidth=4)
    ax1.set_xlabel("time [d]")
    # Make the y-axis label, ticks and tick labels match the line color.
    ax1.set_ylabel("discharge $[m^2/s]$", color="#1f77b4")
    ax1.tick_params("y", colors="#1f77b4")
    y_lims = (0, 0.0002)
    # ax1.set_ylim((0, 0.0002))
    ax2 = ax1.twinx()

    if aquifer_length == None:
        ax2.plot(time, rfd[1][:], color="#ff7f0e")
        ax2.set_ylabel("recharge $[m/s]$", color="#ff7f0e")
    elif aquifer_length != None:
        ax2.plot(time, rfd[1][:] * aquifer_length, "#ff7f0e", linewidth=0.5)
        ax2.set_ylabel("recharge $[m^2/s]$", color="#ff7f0e")
        # ax2.set_ylim((0, y_lims[1]))
        if "stop_time" in locals():
            plt.vlines(x=[start_time, stop_time],
                       ymin=0,
                       ymax=y_lims[1],
                       color="g")
            plt.annotate(
                "$\Delta t$ = " + str(delta_t),
                (stop_time + 1, 0.8 * y_lims[1]),
            )
    ax2.tick_params("y", colors="#ff7f0e")
    fig.tight_layout()
    plt.savefig(task_root + "/baseflow_vs_recharge.png", dpi=300)
示例#7
0
        listdir_1101_1200.append(dir)

# stor = 0.0001, white noise
listdir_1201_1300 = []
for dir in clean_listdir:
    if int(dir[:4]) > 1200 and int(dir[:4]) <= 1300:
        listdir_1201_1300.append(dir)

# stor = 0.0001, mHM
listdir_1301_1400 = []
for dir in clean_listdir:
    if int(dir[:4]) > 1300 and int(dir[:4]) <= 1400:
        listdir_1301_1400.append(dir)

# get the recharge and multiply it by the amount of model: White Noise
rfd = extract_rfd(path_to_multiple_projects + "/" + listdir_1001_1100[0],
                  export=False)
# multiplied with the number of models and multiplied with the aquifer length to get the flow
recharge_1001_1100 = rfd[1] * len(listdir_1001_1100) * aquifer_length

# get the recharge and multiply it by the amount of model: mHM
rfd = extract_rfd(path_to_multiple_projects + "/" + listdir_1101_1200[0],
                  export=False)
# multiplied with the number of models and multiplied with the aquifer length to get the flow
recharge_1101_1200 = rfd[1] * len(listdir_1101_1200) * aquifer_length

# get the recharge and multiply it by the amount of model: White Noise
rfd = extract_rfd(path_to_multiple_projects + "/" + listdir_1201_1300[0],
                  export=False)
# multiplied with the number of models and multiplied with the aquifer length to get the flow
recharge_1201_1300 = rfd[1] * len(listdir_1201_1300) * aquifer_length