3 Star 0 Fork 1

mirrors_anthonyfok/seismic-risk-model

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
createSourceLookup.py 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
#!/bin/python
# ======================================
# SPDX-License-Identifier: Open Government Licence - Canada
#
# Copyright (C) 2020-2022 Government of Canada
#
# Main authors: Tiegan Hobbs <[email protected]>
# ======================================
# Python script to generate a list of tectonic source regions in Canada, for CanSRM1 postprocessing. Written by TEH on 20 Oct 2021, updated 27 Oct 2021.
from xml.dom import minidom
import glob
import pandas as pd
### Initialize a dataframe for results
df2 = pd.DataFrame(columns=['code', 'name', 'tectonicRegion'])
### FOR ALL SOURCE FILES:
filepath = "../CanadaSHM6/OpenQuake_model_files/sources/nationalModel/xml/simplifiedModel/"
all_files = glob.glob(filepath + "WCan_*.xml")
for fname in all_files:
### Read in source xml file
file = minidom.parse(fname)
### Extract sources
source = file.getElementsByTagName('areaSource')
for el in source:
code = el.attributes['id'].value
name = el.attributes['name'].value
regi = el.attributes['tectonicRegion'].value
#wrap = pd.DataFrame([[code, name, regi]])
df2 = df2.append({'code': code, 'name': name, 'tectonicRegion': regi}, ignore_index=True)
### Remove duplicates
df2 = df2.drop_duplicates()
### Save it
df2.to_csv('sourceTypes.csv', index=False)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_anthonyfok/seismic-risk-model.git
[email protected]:mirrors_anthonyfok/seismic-risk-model.git
mirrors_anthonyfok
seismic-risk-model
seismic-risk-model
master

搜索帮助