Esempio n. 1
0
    def gen_rec(self):
        dt = self.dt
        n = self.n
        slope = self.slope
        length = self.length
        ks = self.ks

        self.Steady_SQ()
        for k in range(0, len(self.ks)):
            ie1 = 10.0
            aa = aw.trans_ana(ie1 * self.ks[k], ie1, length, 201, dt, n, slope)
            aa.run()

            # Normalize outflow and storage curve
            out_s = aa.out_s
            out_q = aa.out_q
            out_s[:, 0] = out_s[:, 0] / aa.max_t
            out_s[:, 1] = (out_s[:, 1] - aa.min_s) / (aa.max_s - aa.min_s)
            out_q[:, 0] = out_q[:, 0] / aa.max_t
            out_q[:, 1] = (out_q[:, 1] - aa.min_q) / (aa.max_q - aa.min_q)

            # Keep outflow-storage curve
            curve = [zip(out_q[:, 1], out_s[:, 1])][0]
            self.header.append(ks[k])
            self.curve.append(curve)

        REC = {'header': self.header, 'curve': self.curve}
        self.REC = REC

        if self.rec_name:
            pickle.dump(
                REC,
                open(self.folder + '/' + self.rec_name + '_CurveRec.flow',
                     'w'))
Esempio n. 2
0
def compareSWRCurve():
    ie0 = 100.0
    ie1 = 5.0
    ie2 = [5.5, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0,
           100.0, 110.0, 130.0, 150.0, 170.0, 200.0]
    L = 100.0
    slope = 0.01
    n = 0.1
    dt = 0.5
    x_space = 201
    a = SWRCurves(L, x_space, dt, n, slope, 2, 4, useFile='ks1_SWRrec.pick')
    a.fitPT()

    # Run curves
    TimeOfChange = 405.0

    SWR_curves = list()
    gen_Curves = list()
    Qratios = list()
    for i in range(0, len(ie2)):
        ca = two_step.two_step_overland(ie0, ie1, ie2[i], L, x_space, dt, n,
                                        slope)
        ca.ie1_duration(TimeOfChange)
        cb = ana_new.trans_ana(ie1, ie2[i], L, x_space, dt, n, slope)
        ca.run()
        cb.run()
        SWR = bcdPoints(ca)
        SWR[:, 0] = (SWR[:, 0] - SWR[0, 0])/(SWR[-1, 0] - SWR[0, 0])
        SWR[:, 1] = SWR[:, 1]/SWR[0, 1]
        SWR[:, 2] = SWR[:, 2]/SWR[0, 2]

        SWR_curves.append(SWR)

        Qratio = SWR[-1, 1]/SWR[0, 1]
        curve, T = a.interpCurve(Qratio)
        gen_Curves.append(curve)
        Qratios.append(Qratio)

    plt.figure(figsize=(10, 8))
    ax = plt.subplot(111)
    for k in range(0, len(ie2)):
        color = randColor()
        ax.plot(SWR_curves[k][:, 1], SWR_curves[k][:, 2], lw=1.0, ls='--',
                label='{:4.3f}'.format(Qratios[k]), color=color)
        ax.plot(gen_Curves[k][:, 0], gen_Curves[k][:, 1], lw=2.0, ls='-',
                label='{:4.3f}'.format(gen_Curves[k][-1, 0]),
                color=color)

    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    ax.legend(loc='upper left', bbox_to_anchor=(1.05, 1.0), ncol=2)
    ax.set_xlabel('q')
    ax.set_ylabel('s')
    plt.title('Secondary Wetting Curve - Original and Generated')
    plt.savefig('SWR_gen_compare.png')
    plt.close()
Esempio n. 3
0
def run():
    plt.figure

    _file = "/home/room801/anaoverland/Steady_fit/ks1_Rise_CurveRec.flow"
    RiseRec = pickle.load(open(_file, 'r'))
    _file = "/home/room801/anaoverland/Steady_fit/ks1_Fall_CurveRec.flow"
    FallRec = pickle.load(open(_file, 'r'))

    ks = [
        1.01, 1.6, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 20.0, 40.0,
        50.0, 60.0, 70.0, 80.0, 90.0, 100.0
    ]
    for k in ks:
        keystring = 'k=' + str(k)
        out_q = RiseRec['Q'][keystring]
        out_s = RiseRec['S'][keystring]

        #  Normalized curve to [0, 1]
        out_s[:, 1] = (out_s[:, 1] - min(out_s[:, 1])) / (max(out_s[:, 1]) -
                                                          min(out_s[:, 1]))
        out_q[:, 1] = (out_q[:, 1] - min(out_q[:, 1])) / (max(out_q[:, 1]) -
                                                          min(out_q[:, 1]))

        plt.plot(out_q[:, 1],
                 out_s[0:len(out_q), 1],
                 color='dodgerblue',
                 linestyle='-')

    for k in ks:
        keystring = 'k=' + str(k)
        out_q = FallRec['Q'][keystring]
        out_s = FallRec['S'][keystring]

        #  Normalization to [0, 1]
        out_s[:, 1] = (out_s[:, 1] - min(out_s[:, 1])) / (max(out_s[:, 1]) -
                                                          min(out_s[:, 1]))
        out_q[:, 1] = (out_q[:, 1] - min(out_q[:, 1])) / (max(out_q[:, 1]) -
                                                          min(out_q[:, 1]))

        plt.plot(out_q[:, 1],
                 out_s[0:len(out_q), 1],
                 color='tomato',
                 linestyle='-')

    aa = an.trans_ana(10.0, 10.0 * 200, 100.0, 201, 0.5, 0.1, 0.01)
    aa.run()
    out_s = aa.out_s
    out_q = aa.out_q

    out_s[:, 1] = (out_s[:, 1] - min(out_s[:, 1])) / (max(out_s[:, 1]) -
                                                      min(out_s[:, 1]))
    out_q[:, 1] = (out_q[:, 1] - min(out_q[:, 1])) / (max(out_q[:, 1]) -
                                                      min(out_q[:, 1]))
    plt.plot(out_q[:, 1] / max(out_q[:, 1]),
             out_s[0:len(out_q), 1] / max(out_s[:, 1]),
             color='dodgerblue',
             linestyle='-',
             label='Rising Limb')

    ab = an.trans_ana(10.0 * 200, 10.0, 100.0, 201, 0.5, 0.1, 0.01)
    ab.run()
    out_s = ab.out_s
    out_q = ab.out_q

    out_s[:, 1] = (out_s[:, 1] - min(out_s[:, 1])) / (max(out_s[:, 1]) -
                                                      min(out_s[:, 1]))
    out_q[:, 1] = (out_q[:, 1] - min(out_q[:, 1])) / (max(out_q[:, 1]) -
                                                      min(out_q[:, 1]))
    plt.plot(out_q[:, 1] / max(out_q[:, 1]),
             out_s[0:len(out_q), 1] / max(out_s[:, 1]),
             color='tomato',
             linestyle='-',
             label='Falling Limb')

    #  Rising Limb limit
    ac = an.progression(200.0, 100.0, 201, 0.5, 0.1, 0.01)
    ac.run()
    out_q = ac.out_q
    out_s = ac.out_s

    out_s[:, 1] = (out_s[:, 1] - min(out_s[:, 1])) / (max(out_s[:, 1]) -
                                                      min(out_s[:, 1]))
    out_q[:, 1] = (out_q[:, 1] - min(out_q[:, 1])) / (max(out_q[:, 1]) -
                                                      min(out_q[:, 1]))

    plt.plot(out_q[:, 1], out_s[0:len(out_q), 1], 'k-', lw=1.5)

    #  Falling Limb limit
    ad = an.Recession(200.0, 100.0, 201, 0.5, 0.1, 0.01)
    ad.run()
    out_q = ad.out_q
    out_s = ad.out_s

    out_s[:, 1] = (out_s[:, 1] - min(out_s[:, 1])) / (max(out_s[:, 1]) -
                                                      min(out_s[:, 1]))
    out_q[:, 1] = (out_q[:, 1] - min(out_q[:, 1])) / (max(out_q[:, 1]) -
                                                      min(out_q[:, 1]))
    plt.plot(out_q[:, 1],
             out_s[0:len(out_q), 1],
             linestyle='--',
             color='dimgray',
             lw=1.5)

    plt.xlim([0.0, 1.0])
    plt.ylim([0.0, 1.0])
    plt.legend(loc=2)
    plt.xlabel('$q^{{}*{}}$')
    plt.ylabel('$s^{{}*{}}$')
    plt.show()
Esempio n. 4
0
def run():
    aa = pickle.load(open('Steady_fit/fit_1_DownToUp.pick', 'r'))
    t, out = aa.out_curve(4.3)

    ab = ana.trans_ana(10.0, 43.0, 100.0, 1001, 1.0, 0.1, 0.01)
    ab.run2()
    out = out*ab.max_q
    t = t*ab.max_t

    plt.figure
    plt.plot(t, out, '-b', label='Interpolation')
    ab.plot_QT(plt_label='Analytical', LT='--r')
    plt.xlabel('time (s)')
    plt.ylabel('flowrate ($m^3/s$)')
    plt.title('10 mm/hr to 43 mm/hr, k=4.3')
    plt.legend(loc=4)
    plt.savefig('10to43.png')
    plt.close()

    ac = pickle.load(open('Steady_fit/fit_1_UpToDown.pick', 'r'))
    t, out = ac.out_curve(0.34)

    ad = ana.trans_ana(100.0, 34.0, 100.0, 1001, 1.0, 0.1, 0.01)
    ad.run2()
    out = out*ad.min_q
    t = t*ad.max_t

    plt.figure
    plt.plot(t, out, '-b', label='Interpolation')
    ad.plot_QT(plt_label='Analytical', LT='--r')
    plt.xlabel('time (s)')
    plt.ylabel('flowrate ($m^3/s$)')
    plt.title('100 mm/hr to 34 mm/hr, k=0.34')
    plt.legend(loc=4)
    plt.savefig('100to34.png')
    plt.close()

    plt.figure
    aa.plot_C(0)
    plt.title('$C_1$')
    plt.legend(loc=3)
    plt.savefig('C1.png')
    plt.close()

    plt.figure
    aa.plot_C(1)
    plt.title('$C_2$')
    plt.legend(loc=4)
    plt.savefig('C2.png')
    plt.close()

    plt.figure
    aa.plot_C(2)
    plt.title('$C_3$')
    plt.legend(loc=1)
    plt.savefig('C3.png')
    plt.close()

    plt.figure
    aa.plot_C(3)
    plt.title('$C_4$')
    plt.legend(loc=1)
    plt.savefig('C4.png')
    plt.close()

    plt.figure
    aa.plot_C(4)
    plt.title('$C_5$')
    plt.legend(loc=1)
    plt.savefig('C5.png')
    plt.close()
Esempio n. 5
0
def calc_testk(rain_rec, length):
    dt = 5.0
    Fall = sh.FallingLimb()
    Rise = sh.RisingLimb()
    std = pickle.load(open('Steady_fit/SQ_Steady.pick', 'r'))

    rain_rec = np.array(rain_rec)
    max_t = max(rain_rec[:, 0])

    q_curve = list()
    s_curve = list()

    q2_curve = list()
    s2_curve = list()

    S0 = std.ie_to_storage(rainParse2(rain_rec, 0.0))
    Q0 = std.ie_to_outflow(rainParse2(rain_rec, 0.0))
    max_S = S0
    max_Q = Q0

    q_curve.append([0.0, Q0])
    s_curve.append([0.0, S0])
    q2_curve.append([0.0, Q0])
    s2_curve.append([0.0, S0])

    t = 0.0
    S = S0
    Q = Q0
    S2 = S0
    Q2 = Q0
    k_rec = list()

    k = rainParse(rain_rec, dt)/rainParse(rain_rec, 0.0)  # Initial k setting
    fixed_k = k
    while t < max_t:
        t = t + dt

        c_ie = rainParse2(rain_rec, t)
        pre_ie = rainParse2(rain_rec, t-dt)
        if c_ie != pre_ie:
            print(c_ie)
            max_S = std.ie_to_storage(c_ie)
            max_Q = std.ie_to_outflow(c_ie)

        print(t, Q)

        if t % 60.0 == 0 or c_ie != pre_ie:
            if S < std.ie_to_storage(c_ie):
                k, t_star = Rise.SQtok(
                    S/max_S, Q/max_Q, (std.ie_to_storage(c_ie)/max_S)**(5.0/3))
                #  k, t_star = Rise.SQtok(S/max_S, Q/max_Q, 5.0)
            elif S > std.ie_to_storage(c_ie):
                k, t_star = Fall.SQtok(S/max_S, Q/max_Q,
                                       (std.ie_to_storage(c_ie)/max_S)**(5.0/3)
                                       - 0.01)
            print(k)
            k_rec.append(k)

        dS1 = h1(length, c_ie, k, S/max_S, dt, std, Fall, Rise)
        dS2 = h2(length, c_ie, k, S/max_S, dS1, dt, std, Fall, Rise)
        dS3 = h3(length, c_ie, k, S/max_S, dS2, dt, std, Fall, Rise)

        dS = 0.25*dS1 + 0.75*dS3

        dS1_2 = h1(length, c_ie, fixed_k, S2/max_S, dt, std, Fall, Rise)
        dS2_2 = h2(length, c_ie, fixed_k, S2/max_S, dS1_2, dt, std, Fall, Rise)
        dS3_2 = h3(length, c_ie, fixed_k, S2/max_S, dS2_2, dt, std, Fall, Rise)

        dS_2 = 0.25*dS1_2 + 0.75*dS3_2

        if k > 1.0:
            Q = Rise.s_to_q(k, (S + dS)/max_S)*max_Q
        elif k < 1.0:
            Q = Fall.s_to_q(k, (S + dS)/max_S)*max_Q

        if fixed_k > 1.0:
            Q2 = Rise.s_to_q(fixed_k, (S2 + dS_2)/max_S)*max_Q
        elif fixed_k < 1.0:
            Q2 = Fall.s_to_q(fixed_k, (S2 + dS_2)/max_S)*max_Q

        #  print k, (S + dS)/max_S
        S = S + length*c_ie*dt - Q*dt
        S2 = S2 + length*c_ie*dt - Q2*dt
        s_curve.append([t, S])
        q_curve.append([t, Q])
        s2_curve.append([t, S2])
        q2_curve.append([t, Q2])

    q_curve = np.array(q_curve)
    s_curve = np.array(s_curve)
    q2_curve = np.array(q2_curve)
    s2_curve = np.array(s2_curve)

    q_curve[:, 0] = q_curve[:, 0] - 60.0
    s_curve[:, 0] = s_curve[:, 0] - 60.0
    q2_curve[:, 0] = q2_curve[:, 0] - 60.0
    s2_curve[:, 0] = s2_curve[:, 0] - 60.0

    ab = an.trans_ana(54.3, 3.11, 100.0, 201, 1.0, 0.1, 0.01)
    ab.run()

    standard_k = np.ones(len(k_rec))
    standard_k = standard_k*18.31

    ie_list = np.arange(0.1, 160.1, 1.0)
    std_s = std.ie_to_storage(ie_list/3600*10**-3)
    std_o = std.ie_to_outflow(ie_list/3600*10**-3)

    plt.figure
    plt.plot(q_curve[:, 0], q_curve[:, 1], '-b', label='k-AutoSearch')
    plt.plot(q2_curve[:, 0], q2_curve[:, 1], '-k', label='k-fixed')
    ab.plot_QT(LT='--r', plt_label='Analytic')
    plt.title('Outflow - Test k 54.3 mm/hr to 3.11 mm/hr')
    plt.legend(loc=4)
    plt.xlabel('time (s)')
    plt.ylabel('Outflow ($m^3/s$)')
    plt.xlim([0, t])
    plt.savefig('modified-BKW_testk3.png')
    plt.close()

    plt.figure
    plt.plot(s_curve[:, 0], s_curve[:, 1], '-b', label='k-AutoSearch')
    plt.plot(s2_curve[:, 0], s2_curve[:, 1], '-k', label='k-fixed')
    ab.plot_ST(LT='--r', plt_label='Analytic')
    plt.legend(loc=4)
    plt.title('Storage - Test k 54.3 mm/hr to 3.11 mm/hr')
    plt.xlabel('time (s)')
    plt.ylabel('Storage ($m^3$)')
    plt.xlim([0, t])
    plt.savefig('modified-BKW_storage_testk3.png')
    plt.close()

    plt.figure
    plt.plot(std_o, std_s, '-r', linewidth=2.0)
    plt.plot(q_curve[:, 1], s_curve[:, 1], '-b', label='k-AutoSearch')
    plt.plot(q2_curve[:, 1], s2_curve[:, 1], '-m', label='k-fixed')
    plt.legend(loc=2)
    plt.title('S-Q - Test Case k 54.3 mm/hr to 3.11 m/hr')
    plt.xlabel('Outflow ($m^3/s$)')
    plt.ylabel('Storage ($m^3$)')
    plt.savefig('storage-outflow_testk3.png')
    plt.close()
Esempio n. 6
0
def run(k):

    if k > 1.0:
        aa = an.trans_ana(10.0, 10.0*k, 100.0, 201, 0.5, 0.1, 0.01)
        aa.run()
        ab = an.trans_ana(30.0, 30.0*k, 100.0, 201, 0.5, 0.1, 0.01)
        ab.run()
        ac = an.trans_ana(60.0, 60.0*k, 100.0, 201, 0.5, 0.1, 0.01)
        ac.run()
    elif k < 1.0:
        aa = an.trans_ana(50.0, 50.0*k, 100.0, 201, 0.5, 0.1, 0.01)
        aa.run()
        ab = an.trans_ana(100.0, 100.0*k, 100.0, 201, 0.5, 0.1, 0.01)
        ab.run()
        ac = an.trans_ana(200.0, 200.0*k, 100.0, 201, 0.5, 0.1, 0.01)
        ac.run()

    fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(14, 6))
    axes[0].plot(ac.out_q[:, 0]/max(ac.out_q[:, 0]),
                 ac.out_q[:, 1]/max(ac.out_q[:, 1]), linestyle='-',
                 color='orange', lw=8.0,
                 label=str(ac.ie0*3600*1000)+' to '+str(ac.ie1*3600*1000))
    axes[0].plot(ab.out_q[:, 0]/max(ab.out_q[:, 0]),
                 ab.out_q[:, 1]/max(ab.out_q[:, 1]), linestyle='-',
                 color='beige', lw=3.5,
                 label=str(ab.ie0*3600*1000)+' to '+str(ab.ie1*3600*1000))
    axes[0].plot(aa.out_q[:, 0]/max(aa.out_q[:, 0]),
                 aa.out_q[:, 1]/max(aa.out_q[:, 1]), linestyle='--',
                 color='steelblue',
                 label=str(aa.ie0*3600*1000)+' to '+str(aa.ie1*3600*1000),
                 lw=2.0)
    if k > 1:
        axes[0].legend(loc=2)
    elif k < 1:
        axes[0].legend(loc=1)
    axes[0].set_xlabel('$t_{{}*{}}$')
    axes[0].set_ylabel('$q_{{}*{}}$')
    axes[0].set_title('Outflow rate - Time')

    axes[1].plot(ac.out_s[:, 0]/max(ac.out_s[:, 0]),
                 ac.out_s[:, 1]/max(ac.out_s[:, 1]), linestyle='-',
                 color='orange', lw=8.0,
                 label=str(ac.ie0*3600*1000)+' to '+str(ac.ie1*3600*1000))
    axes[1].plot(ab.out_s[:, 0]/max(ab.out_s[:, 0]),
                 ab.out_s[:, 1]/max(ab.out_s[:, 1]), linestyle='-',
                 color='beige', lw=3.5,
                 label=str(ab.ie0*3600*1000)+' to '+str(ab.ie1*3600*1000))
    axes[1].plot(aa.out_s[:, 0]/max(aa.out_s[:, 0]),
                 aa.out_s[:, 1]/max(aa.out_s[:, 1]), linestyle='--',
                 color='steelblue',
                 label=str(aa.ie0*3600*1000)+' to '+str(aa.ie1*3600*1000),
                 lw=2.0)
    if k > 1:
        axes[1].legend(loc=2)
    elif k < 1:
        axes[1].legend(loc=1)
    axes[1].set_xlabel('$t_{{}*{}}$')
    axes[1].set_ylabel('$S_{{}*{}}$')
    axes[1].set_title('Storage - Time')
    fig.suptitle('k = '+str(k))
    plt.savefig('graph/eq_k_'+str(k)+'.png')
    plt.close()
Esempio n. 7
0
def run_farPoint(L, dt, n, S, x_grds, ie0, ie1):
    aa = ana_new.trans_ana(ie0, ie1, L, x_grds, dt, n, S)
    aa.run()
    farPoint(aa.out_s, aa.out_q)