Я создал скрипт Python, чтобы попытаться получить информацию из XML, чтобы позже построить несколько графиков.
Цель этого кодекса:
a. Чтобы перебрать XML-файл, чтобы найти , затем , а затем , чтобы достичь 348.000
б. Чтобы сохранить каждый azimutalGap в переменной Gaps=[]
c. Чтобы построить гистограммы азимутального зазора.
До сих пор я пробовал код:
Код: Выделить всё
import xml.etree.ElementTree as ET
def parse_azimuthal_gaps(xml_file):
gaps = []
# Parse the XML file
tree = ET.parse(xml_file)
root = tree.getroot()
# Iterate through each event
for event in root.findall(".//event"):
origin = event.find(".//origin")
if origin is not None:
# Find the azimuthal gap (if present)
azimuthal_gap = origin.find(".//quality/azimuthalGap")
if azimuthal_gap is not None:
gap_value = azimuthal_gap.text
if gap_value is not None:
try:
gaps.append(float(gap_value))
except ValueError:
continue # Skip if not a valid float
return gaps
# Parse azimuthal gaps from the ISC XML file
gaps = parse_azimuthal_gaps("SCB_earthquakes.xml")
print("Azimuthal Gaps:", gaps[:10]) # Print the first 10 gaps for inspection
Входной файл имеет такой формат:
Код: Выделить всё
smi:ISC/origid=601808754
Peru-Bolivia border region
Flinn-Engdahl region
earthquake
known
Event reviewed by the ISC
ISC
ISC
2011-01-23T09:13:37.30Z
0.96
-11.9240
-68.9133
58000.0
operator assigned
8
6
0.4800
353.000
4.260
5.070
SCB
SCB
uncertainty ellipse
20399.9996185303
96000
83.0
smi:ISC/pickid=637614753
Pn
170.165
4.404
3.6
smi:ISC/pickid=637614754
Sn
170.165
4.404
4.6
2011-01-23T09:14:46.10Z
impulsive
positive
Pn
2011-01-23T09:15:37.60Z
emergent
Sn
3.80
0.40
Ml
smi:ISC/origid=601808754
2
SCB
smi:ISC/magid=602398394
Тонино
Подробнее здесь: https://stackoverflow.com/questions/792 ... -in-python
Мобильная версия