current position:Home>Analysis of earthquake distribution in the past 10 years with Python~
Analysis of earthquake distribution in the past 10 years with Python~
2022-02-01 03:03:51 【Hi_ Python】
Hello everyone , I'm brother CAI .
Some time ago, something happened in the Yellow Sea 5.2 level
The earthquake , At that time, friends in East China were all “ shock ” 了 .
today , Let's take a look at the past 10
Distribution of earthquakes in !
1. Data acquisition
Directly in China earthquake networks
You can download it to In the past 10 year The earthquake data .
China earthquake networks :
You're right here History query Interior selection Time range After the inquiry , Click on Save to local You can get the data .
There are local data previews as follows :
2. Data processing
In data acquisition , We found that the data obtained contains Time 、 Magnitude 、 Longitude and latitude 、 depth as well as Reference position . The longitude and latitude are under Baidu map , Considering that the longitude and latitude of different maps will be different , And our subsequent drawing adopts Gaode map , So here we need to convert the latitude and longitude .
2.1. Latitude and longitude conversion
Gaode open platform has corresponding Latitude and longitude conversion Of API
, We can call ( The free quota is enough ).
import requests
import pandas as pd
# Reading data
df = pd.read_excel(r'eqList.xlsx')
longitude_list = []
latitude_list = []
# Baidu map longitude and latitude is converted to Gaode map longitude and latitude
for i , location in enumerate(df[[' longitude (°)',' latitude (°)']].values):
location = str(location[0])+','+str(location[1])
url = 'https://restapi.amap.com/v3/assistant/coordinate/convert?'
parames = {
'locations':location,
'coordsys':'baidu',
'key':' Yours key',
}
r = eval(requests.get(url, params=parames).json()['locations'])
# longitude
longitude_list.append(r[0])
# latitude
latitude_list.append(r[1])
print(f'\r{i+1}',end='')
df[' longitude (°)'] = longitude_list
df[' latitude (°)'] = latitude_list
Copy code
such , We have successfully converted the longitude and latitude coordinates of Baidu map system into the longitude and latitude coordinates of Gaode map system .
2.2. Data processing at the time of earthquake occurrence
For the moment of earthquake , I want to be accurate to the month and hour , For subsequent statistical analysis .
# Convert to time format
df[' The moment of the earthquake '] = pd.to_datetime(df[' The moment of the earthquake '])
# Get the date
df[' month '] = df[' The moment of the earthquake '].apply(lambda x: str(x)[:7])
# For hours
df[' Hours '] = df[' The moment of the earthquake '].dt.hour
Copy code
Here, I feel that my operation of getting the month and year is a little low
, If you have a better plan, please leave a message , I want to learn .
2.3. Earthquake location ( Provinces )
Because the reference position in the original data can not be easily analyzed to the province and city , I'm going to use the longitude and latitude information through Gaode's API
To get . Refer to previous 《》.
citys = []
provinces = []
for i , location in enumerate(df[[' longitude (°)',' latitude (°)']].values):
location = str(location[0])+','+str(location[1])
url = 'https://restapi.amap.com/v3/geocode/regeo?'
params = {
'location':location,
'key':' Yours key',
'extensions':'base',
'batch':'false',
'roadlevel':0,
}
r = requests.get(url, params=params)
data = r.json()['regeocode']
city = data['addressComponent']['city']
province = data['addressComponent']['province']
if len(city)==0:
city = province
citys.append(city)
provinces.append(province)
print(f'\r{i+1}',end='')
df[' City '] = citys
df[' province '] = provinces
Copy code
After the above treatment , We finally got the following data :
3. Statistics and visualization
In this part, we only make a simple statistical display , Do not make similar predictions or other in-depth analysis , After all, based on the existing raw data, we can't draw much valuable conclusions .
3.1. Number of earthquakes over the years
Number of small and medium earthquakes
according to [2, 4.6]
As the range of medium and small earthquakes , near 10 In all 6188 Time , Average annual 600 Remaining times !
# Small and medium earthquakes ([2,4.6])
df[' year '] = df[' The moment of the earthquake '].dt.year
df_cn = df[df[' province ']!='[]']
df_xiao = df_cn.query('2<=` Magnitude (M)`<=4.6')
df_xiao.groupby(' year ')[' The moment of the earthquake '].count().to_frame(' frequency ').reset_index()
Copy code
Number of destructive earthquakes
according to [4.7, ∞]
As the range of medium and small earthquakes , near 10 In all 505 Time , Average annual 50 Remaining times !
3.2. Number of earthquakes in each province
Considering that some earthquakes occur in the sea , It is unified into Chinese waters , In addition, we don't participate in the events that take place abroad .
in addition , We only see Destructive earthquake Distribution , It can be found that in our country xinjiang 、 Tibet 、 yunnan 、 Taiwan and sichuan It is a zone with high earthquake incidence !
# The provinces Destructive earthquake
df_province = df_cn.query('` Magnitude (M)`>=4.7').groupby(' province ')[' The moment of the earthquake '].count().to_frame(' frequency ').sort_values(by=' frequency ',ascending=False).reset_index()
Copy code
Province | Number of destructive earthquakes |
---|---|
xinjiang | 98 |
Tibet | 63 |
yunnan | 47 |
Taiwan | 47 |
sichuan | 45 |
qinghai | 32 |
gansu | 10 |
Ji Lin | 9 |
Inner Mongolia | 7 |
guangxi | 4 |
hubei | 3 |
guangdong | 2 |
hebei | 2 |
guizhou | 2 |
Chongqing | 2 |
heilongjiang | 2 |
jiangsu | 1 |
fujian | 1 |
liaoning | 1 |
shaanxi | 1 |
3.3. Number of earthquakes in each city
In our country 233
There have been earthquakes in three cities , Most of the cities with the most earthquakes are concentrated in xinjiang 、 sichuan .
notes : The statistics here are all seismic data
Like Xinjiang Kizilsu Kirgiz Autonomous Prefecture
、 Hotan Area
Sichuan Yibin
and Ya'an
etc.
province | City | frequency |
---|---|---|
Xinjiang Uygur Autonomous Region | Kizilsu Kirgiz Autonomous Prefecture | 491 |
Xinjiang Uygur Autonomous Region | Hotan Area | 431 |
Xinjiang Uygur Autonomous Region | Aksu Area | 308 |
Tibet Autonomous Region | Naqu city | 257 |
Sichuan Province | Yibin City | 237 |
Xinjiang Uygur Autonomous Region | Kashgar area | 234 |
Xinjiang Uygur Autonomous Region | Bayingolin Mongol Autonomous Prefecture | 206 |
Sichuan Province | Ya'an City | 188 |
Taiwan Province | Taiwan Province | 167 |
Sichuan Province | Aba Tibetan and Qiang Autonomous Prefecture | 167 |
【 Moving graph 】
3.4. Scatter diagram of earthquake distribution
We only see Destructive earthquake Distribution , Draw according to the longitude and latitude coordinate information
import folium.plugins as plugins
import folium
df = df[df[' Magnitude (M)']>=4.7]
ss1 = [[latitude,longitude] for latitude,longitude in df[[' latitude (°)', ' longitude (°)']].values.tolist()]
m = folium.Map([39.904989, 116.405285],
tiles='https://webrd01.is.autonavi.com/appmaptile?&x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=7',
zoom_start=6,
attr=' Gao de ')
groups = folium.FeatureGroup('')
for l,label in zip(ss1,df[' Reference position '].to_list()):
groups.add_child(
folium.CircleMarker(
location=l,
radius=1,
color='red',
fill=True,
fill_color='red',
fill_opacity=0.4,
popup=folium.Popup(html=label,max_width=100),
)
)
m.add_child(groups)
m.add_child(folium.LatLngPopup())
m.save(' Earthquake distribution .html')
Copy code
3.5. Address distribution diagram
You can see the southwest of Xinjiang , And the eastern waters of Taiwan Province are earthquake prone areas .
data_all = df[[' latitude (°)', ' longitude (°)',' Magnitude (M)']].values.tolist()
m = folium.Map([39.904989, 116.405285],
tiles='https://webrd01.is.autonavi.com/appmaptile?&x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=7',
zoom_start=6,
attr=' Gao de ')
hm = plugins.HeatMap(data_all, radius=10,
gradient={.1: 'green', .6: 'yellow', 1: 'red'},
)
hm.add_to(m)
hm.save(' Seismic thermal map .html')
Copy code
3.6. near 10 Annual monthly earthquake distribution map ( dynamic )
notes : The statistics here are all seismic data
【 Video Number 】
Draw code
data_move = []
date_list = df[' month '].sort_values().unique()
for month in date_list:
data_move.append(df[df[' month '] == month][[' latitude (°)', ' longitude (°)',' Magnitude (M)']].values.tolist())
m = folium.Map([39.904989, 116.405285],
tiles='https://webrd01.is.autonavi.com/appmaptile?&x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=7',
zoom_start=6,
attr=' Gao de ')
time_index = df[' month '].sort_values().unique().tolist()
hm = plugins.HeatMapWithTime(data_move,
index=time_index,
radius=10)
hm.add_to(m)
hm.save(' Seismic dynamic thermodynamic diagram .html')
Copy code
4. Supplementary knowledge
Distribution map of seismic zone
We screen 5 The distribution map of earthquakes above M is as follows :
Basically match ~
That's all of this , If you're interested , Order one Looking at
The private chat Xiaobian can get data Ha ~
copyright notice
author[Hi_ Python],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202010303484698.html
The sidebar is recommended
- Python avatar animation, come and generate your own animation avatar
- leetcode 1884. Egg Drop With 2 Eggs and N Floors(python)
- leetcode 1910. Remove All Occurrences of a Substring(python)
- Python and binary
- First acquaintance with Python class
- [Python data collection] scrapy book acquisition and coding analysis
- Python crawler from introduction to mastery (IV) extracting information from web pages
- Python crawler from entry to mastery (III) implementation of simple crawler
- The apscheduler module in Python implements scheduled tasks
- 1379. Find the same node in the cloned binary tree (Java / C + + / Python)
guess what you like
-
Python connects redis, singleton and thread pool, and resolves problems encountered
-
Python from 0 to 1 (day 11) - Python data application 1
-
Python bisect module
-
Python + OpenGL realizes real-time interactive writing on blocks with B-spline curves
-
Use the properties of Python VTK implicit functions to select and cut data
-
Learn these 10000 passages and become a humorous person in the IT workplace. Python crawler lessons 8-9
-
leetcode 986. Interval List Intersections(python)
-
leetcode 1860. Incremental Memory Leak(python)
-
How to teach yourself Python? How long will it take?
-
Python Matplotlib drawing pie chart
Random recommended
- Django paging (II)
- Concurrent. For Python concurrent programming Futures or multiprocessing?
- Programmers over the age of 25 can't know a few Chinese herbal medicines. Python crawler lessons 9-9
- Python crawler from introduction to pit full series of tutorials (detailed tutorial + various practical combat)
- The second bullet of class in Python
- Python object oriented programming 03: class inheritance and its derived terms
- How IOS developers learn Python Programming 13 - function 4
- Python crawler from introduction to mastery (VI) form and crawler login
- Python crawler from entry to mastery (V) challenges of dynamic web pages
- Deeply understand pandas to read excel, TXT, CSV files and other commands
- Daily python, Chapter 18, class
- "I just want to collect some plain photos in Python for machine learning," he said. "I believe you a ghost!"
- Django view
- Python implements filtering emoticons in text
- When winter comes, python chooses a coat with temperament for mom! Otherwise, there's really no way to start!
- Python crawler - get fund change information
- Highlight actor using Python VTK
- Python crawler actual combat: crawling southern weekend news articles
- leetcode 406. Queue Reconstruction by Height(python)
- leetcode 1043. Partition Array for Maximum Sum (python)
- Python * * packaging and unpacking details
- Python realizes weather query function
- Python from 0 to 1 (day 12) - Python data application 2 (STR function)
- Python from 0 to 1 (day 13) - Python data application 3
- Numpy common operations of Python data analysis series Chapter 8
- How to implement mockserver [Python version]
- Van * Python! Write an article and publish the script on multiple platforms
- Python data analysis - file reading
- Python data De duplication and missing value processing
- Python office automation - play with browser
- Python series tutorial 127 -- Reference vs copy
- Control flow in Python: break and continue
- Teach you how to extract tables in PDF with Python
- leetcode 889. Construct Binary Tree from Preorder and Postorder Traversal(python)
- leetcode 1338. Reduce Array Size to The Half(python)
- Object oriented and exception handling in Python
- How to configure load balancing for Django service
- How to embed Python in go
- Python Matplotlib drawing graphics
- Python object-oriented programming 05: concluding summary of classes and objects