def plot(): cur.execute("SELECT z,v FROM zvaq;") # cur.execute("SELECT z,a FROM zvaq") # cur.execute("SELECT z,q FROM zo") data = np.array(cur.fetchall()) y = data[:, 0] x = data[:, 1] yx = np.polyfit(x, y, 2) p1 = np.poly1d(yx) plt.plot(x, y, 'o', label='original points') xnew = np.linspace(x.min(), x.max(), 1000) ynew = Interpolate.inter1d(x, p1(x), xnew) plt.plot(xnew, ynew, '--', label='fit') plt.text(1000, 94, "$y={}x^2+{}x+{}$" .format(round(float(yx[0]), 8), round(float(yx[1]), 4), round(float(yx[2]), 4))) # plt.text(100, 150, # "$y=4.9\\times 10^{-5}x^2+0.1113x+101.4907$") # plt.xlabel("$V(10^8m^3)$") # plt.xlabel("$A(km^2)$") plt.xlabel("$Q(m^3/s)$") plt.ylabel("$Z(m)$") plt.grid() plt.legend() plt.show()
def __init__(self, data, error, z_s, z_d, zo, k, zv, odh, mon_d=30.4): # 接受参数 data-> 数据 # data = { # 'gsq':{mon1:Q1, mon2:Q2, mon3:Q3}, # 'xsq':{mon1:Q1, mon2:Q2, mon3:Q3}, # 'bxbg':{mon1:Q1, mon2:Q2, mon3:Q3}, # } # error->误差, Z_s->高水位,Z_d->死水位 # 常参定义 self.zo_x = zo[:, 1] self.zo_y = zo[:, 0] self.K_H = k[:, 0] self.K_K = k[:, 1] self.zv_x = zv[:, 0] self.zv_y = zv[:, 1] self.odh_q = odh[:, 0] self.odh_dh = odh[:, 1] self.error = error # self.des_q = des_q self.mon_d = mon_d self.Z_s = z_s # 正常蓄水位 self.Z_d = z_d # 死水位 self.data = data # 枯水年径流过程 xnew = np.linspace(self.zv_x.min(), self.zv_x.max(), len(self.zv_x) * 100) self.V_s = Interpolate.inter1d(list(self.zv_x), list(self.zv_y), xnew, self.Z_s)[1] # V蓄 self.V_d = Interpolate.inter1d(list(self.zv_x), list(self.zv_y), xnew, self.Z_d)[1] # V死 self.V_x = np.array(self.V_s) - np.array(self.V_d) # V兴 self.dh = 1 # 水头损失 self.matrix = None # 结果矩阵 # 月份映射关系 self.map = { 5: 1, 6: 2, 7: 3, 8: 4, 9: 5, 10: 6, 11: 7, 12: 8, 1: 9, 2: 10, 3: 11, 4: 12 } # 变参数定义 self.N = 600*10000 self.N_eq = self.N self.N_chk = np.zeros((13, 1)) # 检验出力 self.Q_na = np.zeros((13, 1)) # 来水 self.Q_y = np.zeros((13, 1)) # 引用流量 self.qy() # 初始化Q引 self.Q_xg = np.zeros((13, 1)) # 蓄水供水流量 self.V_xg = np.zeros((13, 1)) # 蓄水供水水量 self.V_begin = np.zeros((13, 1)) # 时段初水量 self.V_begin[0] = self.V_d self.Z_u = np.zeros((13, 1)) # 上游均水头 self.Z_d = np.zeros((13, 1)) # 下游均水头 self.Z_ave = np.zeros((13, 1)) # 平均水头 self.V_ave = np.zeros((13, 1)) # 时段平均水量 self.K = np.zeros((13, 1)) # 出力系数 self.dh = np.zeros((13, 1)) # 损失水头 mons = [0] mons.extend(list(self.map.keys())) self.mon = np.array(mons, dtype=float).reshape((13, 1))
def _dh(self, q): xnew = np.linspace(self.odh_q.min(), self.odh_q.max(), len(self.odh_q)*100) dh = Interpolate.inter1d(self.odh_q, self.odh_dh, xnew, q) return dh
def _k(self, h): xnew = np.linspace(self.K_H.min(), self.K_H.max(), len(self.K_H)*100) k = Interpolate.inter1d(self.K_H, self.K_K, xnew, h) return k
def h_u(self, v): xnew = np.linspace(self.zv_y.min(), self.zv_y.max(), len(self.zv_y)*100) h = Interpolate.inter1d(list(self.zv_y), list(self.zv_x), xnew, v) return h
def h_d(self, q): xnew = np.linspace(self.zo_x.min(), self.zo_x.max(), len(self.zo_x)*100) h = Interpolate.inter1d(list(self.zo_x), list(self.zo_y), xnew, q) return h
# print(round(d, 0)) # # print('\n') # # for d in q_des02: # print(round(d, 0)) # # print('\n') # # for d in q_des01: # print(round(d, 0)) # 插值,使曲线光滑 t = np.array([i for i in range(len(q15))]) xnew = np.linspace(t.min(), t.max(), 360) ynew15 = Interpolate.inter1d(t, q15, xnew) ynew5 = Interpolate.inter1d(t, q_des5, xnew) ynew02 = Interpolate.inter1d(t, q_des02, xnew) ynew01 = Interpolate.inter1d(t, q_des01, xnew) # 绘图 plt.plot(xnew, ynew15, '-', label='$typical \quad year$') # 典型年 plt.plot(xnew, ynew5, '--', label='$5\%$') # 设计防洪标准5% plt.plot(xnew, ynew02, '-.', label='$0.2\%$') # 设计洪水0.2% plt.plot(xnew, ynew01, ':', label='$0.1\%$') # 校核洪水0.1% plt.grid() # plt.xticks(t, t) plt.xlabel('$day$') plt.ylabel('$Q(m^3/s)$') plt.legend() plt.show()