加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FERA.py 2.58 KB
一键复制 编辑 原始数据 按行查看 历史
yunnai 提交于 2021-12-01 17:00 . Have some bugs in pandas and numpy index
import pandas as pd
from SaftyAssessment import CalEvaculationTime
import TempIO
import os
import shapefile
import numpy as np
'''
Author: Boliang Dong
Date: 2021-11-29 17:03:05
LastEditTime: 2021-12-01 16:56:25
LastEditors: Please set LastEditors
Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
FilePath: \flood-evacuation-risk-assessment\FERA.py
'''
def main():
print("Calculate the Flood Evacuation Risks!!!")
pointName = "Point.txt"
lineName = "Line.shp"
DepthName = "Depth.txt"
VelocityName = "Velocity.txt"
escapeName = "EscapeRoutine.txt"
safeName = "HumanSafty.json"
#制定文件夹路径
currentPath = os.getcwd()
pointName = os.path.join(currentPath, "Input", pointName)
DepthName = os.path.join(currentPath, "Input", DepthName)
lineName = os.path.join(currentPath, "Input", lineName)
VelocityName = os.path.join(currentPath, "Input", VelocityName)
safeName = os.path.join(currentPath, "Input", safeName)
escapeName = os.path.join(currentPath, "Input", escapeName)
#读取计算点水位流速随时间变化情况
pointData = TempIO.read_character_point_hydrodynamic_data(pointName)
depthData = TempIO.read_character_point_hydrodynamic_data(DepthName)
velocityData = TempIO.read_character_point_hydrodynamic_data(VelocityName)
print(depthData)
#读取线条
#lines = shapefile.Reader(lineName)
#lineData = TempIO.convertShpToPandas(lines)
#读取逃生路线
escapeData = []
with open(escapeName) as file:
for line in file:
templist = line.split()
outlist = [int(i) for i in templist]
escapeData.append(outlist)
#计算逃生路线每段的长度与起始点
escapeLenth = []
escapePoint = []
for item in escapeData:
temp1 = []
temp2 = []
for i in range(len(item)-1):
stNode = item[i]
edNode = item[i+1]
temp1.append([stNode, edNode])
temp2.append(np.sqrt((pointData.loc[stNode,"x"]-pointData.loc[edNode,"x"])**2+(pointData.loc[stNode,"y"]-pointData.loc[edNode,"y"])**2))
escapeLenth.append(temp2)
escapePoint.append(temp1)
#计算逃生时间
Results = CalEvaculationTime(depthData, velocityData, escapePoint, escapeLenth, safeName)
Results = pd.DataFrame(Results)
Index = [i*10 for i in range(0, Results.shape[0])]
Results.loc[:,"Time"] = Index
Results.to_csv("EscapeTime.csv")
print("Successfully Finished!!!")
if __name__ == "__main__":
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化