集总式新安江代码(二、三水源)python

这篇具有很好参考价值的文章主要介绍了集总式新安江代码(二、三水源)python。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

首先设置模型参数

import numpy as np
import pandas as pd
import math
df = pd.read_excel(r"C:\Users\Admin\Desktop\pet.xlsx")
df = df.fillna(0)
print(df)
WM,WUM,WLM,WDM,b,K,C,FC,F,T,CG,L,CR = 120,15,85,20,0.3,0.95,0.14,15,2856,24,0.9,5,0.5    # F单位为km^2 T单位为h
Sm,KI,KG,EX,FR1,CI,Q = 20,0.2,0.5,1.5,0.4175,0.9,5.6
WMM = (1+b)*WM
U = F / (3.6 * T)
SMM = Sm * (1+EX)

我的数据是excel数据其中有流域面平均雨量和蒸发资料

集总式新安江代码(二、三水源)python

首先是设置一个for循坏我一共5000多行降雨数据,设置一个for循坏

for i in range(0,5479):
# 计算土湿
    if i == 0:
        df.loc[i, "WU"] = 0
        df.loc[i,"WL"] = 2.2
        df.loc[i, "WD"] = 20
        df.loc[i, "EP"] = K * df.loc[i, "E0"]
        if df.loc[i, "WU"] + df.loc[i, "P"] >= df.loc[i, "EP"]:
            df.loc[i, "EU"] = df.loc[i, "EP"]
            df.loc[i, "EL"] = 0
            df.loc[i, "ED"] = 0
        if df.loc[i, "WU"] + df.loc[i, "P"] < df.loc[i, "EP"] and df.loc[i, "WL"] >= C * WLM:
            df.loc[i, "EU"] = df.loc[i, "WU"] + df.loc[i, "P"]
            df.loc[i, "EL"] = (df.loc[i, "EP"] - df.loc[i, "EU"]) * df.loc[i, "WL"] / WLM
            df.loc[i, "ED"] = 0
        if df.loc[i, "WU"] + df.loc[i, "P"] < df.loc[i, "EP"] and df.loc[i, "WL"] < C * WLM and df.loc[i, "WL"] >= C * (df.loc[i, "EP"] - df.loc[i, "EU"]):
            df.loc[i, "EU"] = df.loc[i, "WU"] + df.loc[i, "P"]
            df.loc[i, "EL"] = C * (df.loc[i, "EP"] - df.loc[i, "EU"])
            df.loc[i, "ED"] = 0
        if df.loc[i, "WU"] + df.loc[i, "P"] < df.loc[i, "EP"] and df.loc[i, "WL"] < C * (
                df.loc[i, "EP"] - df.loc[i, "EU"]):
            df.loc[i, "EU"] = df.loc[i, "WU"] + df.loc[i, "P"]
            df.loc[i, "EL"] = df.loc[i, "WL"]
            df.loc[i, "ED"] = C * (df.loc[i, "EP"] - df.loc[i, "EU"]) - df.loc[i, "EL"]
        df.loc[i, "E"] = df.loc[i, "EU"] + df.loc[i, "EL"] + df.loc[i, "ED"]
        df.loc[i, "PE"] = df.loc[i, "P"] - df.loc[i, "E"]
        df.loc[i, "W"] = df.loc[i, "WU"] + df.loc[i, "WL"] + df.loc[i, "WD"]
    else:
        dw = df.loc[i-1,"PE"] - df.loc[i-1,"R"] #这边需要连接下面R,否则会报错
        df.loc[i,"WU"] = df.loc[i-1,"WU"] + dw
        df.loc[i,"WL"] = df.loc[i-1,"WL"]
        df.loc[i,"WD"] = df.loc[i-1,"WD"]
        if df.loc[i,"WU"] < 0 :
            df.loc[i,"WL"] = df.loc[i-1,"WL"] + dw + df.loc[i-1,"WU"]
            df.loc[i,"WD"] = df.loc[i-1,"WD"]
            df.loc[i,"WU"] = 0
            if df.loc[i,"WL"] < 0:
                df.loc[i,"WD"] = df.loc[i-1,"WD"] + dw + df.loc[i-1,"WU"] + df.loc[i-1,"WL"]
                df.loc[i,"WU"] = 0
                df.loc[i,"WL"] = 0
                if df.loc[i,"WD"] < 0:
                    df.loc[i,"WU"] = 0
                    df.loc[i,"WD"] = 0
                    df.loc[i,"WL"] = 0
        if df.loc[i,"WU"] > WUM:
            df.loc[i,"WU"] = WUM
            df.loc[i,"WL"] = df.loc[i-1,"WL"] + dw - WUM + df.loc[i-1,"WU"]
            df.loc[i,"WD"] = df.loc[i-1,"WD"]
            if df.loc[i,"WL"] > WLM:
                df.loc[i,"WU"] = WUM
                df.loc[i,"WL"] = WLM
                df.loc[i,"WD"] = df.loc[i-1,"WD"] + dw - WLM - WUM + df.loc[i-1,"WU"] + df.loc[i-1,"WL"]
        df.loc[i,"EP"] = K * df.loc[i,"E0"]
        if df.loc[i,"WU"] + df.loc[i,"P"] >= df.loc[i,"EP"]:
            df.loc[i,"EU"] = df.loc[i,"EP"]
            df.loc[i,"EL"] = 0
            df.loc[i,"ED"] = 0
        if df.loc[i,"WU"] + df.loc[i,"P"] < df.loc[i,"EP"] and df.loc[i,"WL"] >= C * WLM:
            df.loc[i,"EU"] = df.loc[i,"WU"] + df.loc[i,"P"]
            df.loc[i,"EL"] = (df.loc[i,"EP"] - df.loc[i,"EU"]) * df.loc[i,"WL"] / WLM
            df.loc[i,"ED"] = 0
        if df.loc[i,"WU"] + df.loc[i,"P"] < df.loc[i,"EP"] and df.loc[i,"WL"] < C * WLM and df.loc[i,"WL"] >= C * (df.loc[i,"EP"]-df.loc[i,"EU"]):
            df.loc[i,"EU"] = df.loc[i,"WU"] + df.loc[i,"P"]
            df.loc[i,"EL"] = C * (df.loc[i,"EP"] - df.loc[i,"EU"])
            df.loc[i,"ED"] = 0
        if df.loc[i,"WU"] + df.loc[i,"P"] < df.loc[i,"EP"] and df.loc[i,"WL"] < C * (df.loc[i,"EP"]-df.loc[i,"EU"]):
            df.loc[i,"EU"] = df.loc[i,"WU"] + df.loc[i,"P"]
            df.loc[i,"EL"] = df.loc[i,"WL"]
            df.loc[i,"ED"] = C * (df.loc[i,"EP"] - df.loc[i,"EU"]) - df.loc[i,"EL"]
        df.loc[i,"E"] = df.loc[i,"EU"] + df.loc[i,"EL"] + df.loc[i,"ED"]
        df.loc[i,"PE"] = df.loc[i,"P"] - df.loc[i,"E"]
        df.loc[i,"W"] = df.loc[i,"WU"] + df.loc[i,"WL"] + df.loc[i,"WD"]

再根据自己的要求计算R

# 计算R
    a = WMM * (1- math.pow((1-df.loc[i,"W"]/WM),1/(1+b)))
    if i ==0:
        if df.loc[i,"PE"] > 0:
            if a + df.loc[i,"PE"] <= WMM:
                df.loc[i,"R"] = df.loc[i,"PE"] + df.loc[i,"W"] - WM + WM * math.pow(1-((df.loc[i,"PE"]+a)/WMM),b+1)  # df["R"][i] = df["PE"][i] + df["W"][i] - WM + WM * math.pow(1 - ((df["PE"][i] + a) / WMM), b + 1)
            if a + df.loc[i,"PE"] > WMM:
                df.loc[i,"R"] = df.loc[i,"PE"] - (WM - df.loc[i,"W"])
        if df.loc[i,"R"] < 0:
            df.loc[i,"R"] = 0
    else:
        if df.loc[i,"PE"] > 0:
            if a + df.loc[i, "PE"] <= WMM:
                 df.loc[i, "R"] = df.loc[i, "PE"] + df.loc[i, "W"] - WM + WM * math.pow(1 - ((df.loc[i, "PE"] + a) / WMM),b + 1)  # df["R"][i] = df["PE"][i] + df["W"][i] - WM + WM * math.pow(1 - ((df["PE"][i] + a) / WMM), b + 1)
            if a + df.loc[i, "PE"] > WMM:
                df.loc[i, "R"] = df.loc[i, "PE"] - (WM - df.loc[i, "W"])
        if df.loc[i, "R"] < 0:
            df.loc[i, "R"] = 0

在计算产流面积

# 计算流域产流面积
    if i == 0:
        if df.loc[i,"R"] > 0 :
            df.loc[i,"FR"] = df.loc[i,"R"] / df.loc[i,"PE"]
            if df.loc[i,"FR"] >1:
                df.loc[i,"FR"] =1

        else:
            df.loc[i,"FR"] = FR1
    else:
        if df.loc[i, "R"] > 0:
            df.loc[i, "FR"] = df.loc[i, "R"] / df.loc[i, "PE"]
            if df.loc[i, "FR"] > 1:
                df.loc[i, "FR"] = 1
        else:
            df.loc[i, "FR"] = df.loc[i-1,"FR"]

这边是二水源代码

# 划分二水源
#     if i == 0:
#         if df.loc[i, "R"] > 0:
#             df.loc[i, "FR"] = df.loc[i, "R"] / df.loc[i, "PE"]
#             if df.loc[i,"FR"] > 1:
#                 df.loc[i,"FR"] = 1
#             if df.loc[i, "FR"] > 0:
#                 if df.loc[i, "PE"] > FC:
#                     df.loc[i, "RS"] = (df.loc[i, "PE"] - FC) * df.loc[i, "FR"]
#                     df.loc[i, "RG"] = df.loc[i, "R"] - df.loc[i, "RS"]
#                 if df.loc[i, "PE"] <= FC:
#                     df.loc[i, "RS"] = 0
#                     df.loc[i, "RG"] = df.loc[i, "R"]
#             if df.loc[i, "FR"] < 0:
#                 df.loc[i, "FR"] = 0
#                 df.loc[i, "RS"] = 0
#                 df.loc[i, "RG"] = 0
#         if df.loc[i, "R"] == 0:
#             df.loc[i, "RS"] = 0
#             df.loc[i, "RG"] = 0
#     else:
#         if df.loc[i,"R"] > 0 :
#             df.loc[i,"FR"] = df.loc[i,"R"] / df.loc[i,"PE"]
#             if df.loc[i,"FR"] > 0:
#                 if df.loc[i,"PE"] > FC:
#                     df.loc[i,"RS"] = (df.loc[i,"PE"] - FC) * df.loc[i,"FR"]
#                     df.loc[i,"RG"] = df.loc[i,"R"] - df.loc[i,"RS"]
#                 if df.loc[i,"PE"] <= FC:
#                     df.loc[i,"RS"] = 0
#                     df.loc[i,"RG"] = df.loc[i,"R"]
#             if df.loc[i,"FR"] < 0:
#                 df.loc[i,"FR"] = 0
#                 df.loc[i,"RS"] = 0
#                 df.loc[i,"RG"] = 0
#         if df.loc[i,"R"] == 0:
#             df.loc[i,"RS"] = 0
#             df.loc[i,"RG"] = 0

三水源

# 划分三水源
    if i == 0:     # 第一时段计算
        df.loc[i, "S1"] = 3.4525
        if df.loc[i,"PE"] > 0:
            AU = SMM * (1 - math.pow((1-(((df.loc[i,"S1"]*FR1)/df.loc[i,"FR"])/Sm)),1/(1+EX)))
            if df.loc[i,"PE"] + AU < SMM:
                df.loc[i,"RS"] = df.loc[i,"FR"] * (df.loc[i,"PE"] +(df.loc[i,"S1"] * FR1)/df.loc[i,"FR"] - Sm +
                                                 Sm *math.pow((1-(df.loc[i,"PE"] +AU)/SMM),1+EX))
            if df.loc[i,"PE"] + AU >= SMM:
                df.loc[i,"RS"] = df.loc[i,"FR"] * (df.loc[i,"PE"] + (df.loc[i,"S1"] * FR1)/df.loc[i,"FR"] - Sm)
            S = (df.loc[i,"S1"] * FR1)/df.loc[i,"FR"] + (df.loc[i,"R"] - df.loc[i,"RS"])/df.loc[i,"FR"]
            df.loc[i,"RI"] = KI * S *df.loc[i,"FR"]
            df.loc[i,"RG"] = KG * S *df.loc[i,"FR"]
            df.loc[i+1,"S1"] = S*(1-KI-KG)
        else:
            S = (df.loc[i, "S1"] * FR1) / df.loc[i, "FR"]
            df.loc[i + 1, "S1"] = S * (1 - KG - KI)
            df.loc[i, "RS"] = 0
            df.loc[i, "RG"] = KI*S * df.loc[i,"FR"]
            df.loc[i, "RI"] = KG * S *df.loc[i,"FR"]
    else: #其余时段计算
        if df.loc[i, "PE"] > 0:
            AU = SMM * (1 - math.pow((1-(((df.loc[i,"S1"]*df.loc[i-1,"FR"])/df.loc[i,"FR"])/Sm)),1/(1+EX)))
            if df.loc[i,"PE"] + AU < SMM:
                df.loc[i,"RS"] = df.loc[i,"FR"] * (df.loc[i,"PE"] +(df.loc[i,"S1"] * df.loc[i-1,"FR"])/df.loc[i,"FR"] - Sm +
                                                 Sm *math.pow((1-(df.loc[i,"PE"] +AU)/SMM),1+EX))
            if df.loc[i,"PE"] + AU >= SMM:
                df.loc[i,"RS"] = df.loc[i,"FR"] * (df.loc[i,"PE"] + (df.loc[i,"S1"] * df.loc[i-1,"FR"])/df.loc[i,"FR"] - Sm)
            S = (df.loc[i,"S1"] * df.loc[i-1,"FR"])/df.loc[i,"FR"] + (df.loc[i,"R"] - df.loc[i,"RS"])/df.loc[i,"FR"]
            df.loc[i,"RI"] = KI * S *df.loc[i,"FR"]
            df.loc[i,"RG"] = KG * S *df.loc[i,"FR"]
            df.loc[i+1,"S1"] = S*(1-KI-KG)
        else:
            S = (df.loc[i, "S1"] * df.loc[i-1,"FR"]) / df.loc[i, "FR"]
            df.loc[i + 1, "S1"] =S * (1 - KG - KI)
            df.loc[i, "RS"] = 0
            df.loc[i, "RG"] = KG *S *df.loc[i,"FR"]
            df.loc[i, "RI"] = KI * S *df.loc[i,"FR"]

二水源汇流

# # 计算二水源汇流
#     if i == 0:
#         df.loc[i, "Qs"] = df.loc[i, "RS"] * U
#         df.loc[i,"Qg"] = 5.6
#         df.loc[i, "QT"] = df.loc[i, "Qs"] + df.loc[i, "Qg"]
#         df.loc[i,"Qt"] = 5.6
#     else:
#         df.loc[i,"Qs"] = df.loc[i,"RS"] * U
#         df.loc[i,"Qg"] = CG * df.loc[i-1, "Qg"] + (1-CG) * df.loc[i,"RG"] * U
#         df.loc[i,"QT"] = df.loc[i,"Qs"] + df.loc[i,"Qg"]
#         df.loc[i,"Qt"] = CR * df.loc[i-1,"Qt"] + (1 - CR) * df.loc[i-L,"QT"]

三水源汇流

# 计算三水源汇流
    if i == 0:
        df.loc[i,"QS"] = df.loc[i,"RS"] * U
        df.loc[i,"QI"] = 1/3 * Q
        df.loc[i,"QG"] = 1/3 * Q
        df.loc[i, "QT"] = df.loc[i, "QS"] + df.loc[i, "QI"] + df.loc[i, "QG"]
    if i >0:
        df.loc[i, "QS"] = df.loc[i, "RS"] * U
        df.loc[i,"QI"] = CI * df.loc[i-1,"QI"] + (1-CI)*df.loc[i,"RI"]*U
        df.loc[i,"QG"] = CG* df.loc[i-1,"QG"]+(1-CG)*df.loc[i,"RG"] *U
        df.loc[i,"QT"] = df.loc[i,"QS"]+df.loc[i,"QI"]+df.loc[i,"QG"]
    if i >=0 and i <= L:
        df.loc[i,"Qt"] = Q
    if i >= L+1:
        df.loc[i,"Qt"] = df.loc[i-1,"Qt"]*CR+(1-CR) * df.loc[i-L,"QT"]

最后写入excel表,保留4位小数

ds = pd.DataFrame(df)
ds.to_excel(r"C:\Users\Admin\Desktop\新安江1.xlsx",float_format='%.4f')

最后三水源结果

集总式新安江代码(二、三水源)python

写到这感觉自己写的太麻烦了,希望以后能够改进吧

这边蒸散发还是借鉴了一个哥们的代码,链接在这边:(26条消息) Python数据分析实例,利用Pandas建立流域三层蒸发和蓄满产流模型_三层蒸发模型代码_Joyonlyonly的博客-CSDN博客文章来源地址https://www.toymoban.com/news/detail-506916.html

到了这里,关于集总式新安江代码(二、三水源)python的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 解析MPC多方计算钱包:私钥分片与备份的新安全前沿

    前言 什么是MPC钱包 1.1 定义和基本原理 当前用户的困境 MPC钱包简介 3.1 工作原理 3.2 解决问题的关键点 MPC钱包优势与劣势 4.1 优势 4.2 缺点 MPC主流算法实现 5.1 概述不同算法 市场竞品 6.1 竞品列表 个人观点 7.1 安全性评价 7.2 中心化问题 7.3 技术黑盒挑战 7.4 移植性局限 7.5 期望

    2024年01月16日
    浏览(42)
  • Unraid的NginxProxyManager新安装以后出现初始账号登录失败502问题 gateway

    新安装以后出现初始账号登录失败502问题 gateway,怎么可能登录都没得登录呢 这个问题情况大概如下 si突然没找到图,大概演示一下吧 反正就是一种502错误 查了日志和各种东西都没什么用 重装也重装了好几次 (这个图里的错误代码是我自己画的,反正大概那个意思,就是莫

    2024年02月06日
    浏览(32)
  • UEFI|电脑Windows系统如何迁移到新安装的硬盘?系统迁移详细教程!

    前面讲了很多很多关于安装系统、重装系统的教程。但唯独没有讲到电脑换了新的硬盘之后,怎么把旧系统迁移到新的硬盘上。 今天小白就来跟各位小伙伴详细唠唠: 开始之前需要把系统迁移的条件准备好,意思就是在WinPE系统下,可以正常且同时访问新硬盘和旧系统盘。点

    2024年04月15日
    浏览(53)
  • 新安webpack插件后编译报错compiler.plugin is not a function

            安装使用generate-asset-webpack-plugin时报错 TypeError:compiler.plugin is not a function ,网上搜索了一下大概就是webpack5与这些插件不匹配。推荐的方法几乎都是换一个适配的插件版本,但我所需要的这个插件在npm上最近更新时间是7年前💔。等不着作者适配于是决定自己改。

    2023年04月24日
    浏览(40)
  • 解析MPC多方计算钱包:私钥分片与备份的新安全前沿_详解析mpc钱包

    先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7 深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前! 因此收集整理了一份《2024年最新网络安全全套学习资料》

    2024年04月26日
    浏览(42)
  • python程序编程代码大全,python编程代码详解

    大家好,本文将围绕python程序编程代码大全展开说明,python编程游戏代码是一个很多人都想弄明白的事情,想搞清楚python代码大全简单需要先了解以下几个事情。 download python编程代码​​​​​​​ python编程经典例子: 1、画爱心表白、图形都是由一系列的点(X,Y)构成的曲

    2024年02月03日
    浏览(57)
  • python100行代码案例,python1000行代码

    本篇文章给大家谈谈python100行代码案例,以及python1000行代码,希望对各位有所帮助,不要忘了收藏本站喔。 python 250行代码开发一个贪吃蛇 1. 前提工作准备 2. 全局变量的定义与包的导入 3. 游戏开始界面初始化 4. 游戏界面的设置 4.1 游戏界面,使用一个Point类进行划分 4.2 预处

    2024年02月03日
    浏览(31)
  • python代码编写规范有哪些,Python如何编写代码运行

    大家好,小编来为大家解答以下问题,编写高质量python代码的59个有效方法,python代码编写规范有哪些,今天让我们一起来看看吧! 大家好,本文将围绕python程序编程代码大全展开说明,python编程游戏代码是一个很多人都想弄明白的事情,想搞清楚python代码大全简单需要先了

    2024年01月19日
    浏览(50)
  • 简单好玩的python编程代码,python有趣简单的代码

    这篇文章主要介绍了一个简单又好玩的python代码手机版,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获,下面让小编带着大家一起了解一下。 本篇文章给大家谈谈python200行有趣小程序,以及python简单小游戏代码,希望对各位有所帮助,不要

    2024年02月03日
    浏览(81)
  • python游戏编程代码大全,python代码自动生成器

    大家好,给大家分享一下python游戏编程入门游戏代码,很多人还不知道这一点。下面详细解释一下。现在让我们来看看! 大家好,小编来为大家解答以下问题,python游戏代码大全可复制100行,python游戏代码大全可复制免费,今天让我们一起来看看吧! python有趣的编程代码

    2024年02月21日
    浏览(47)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包