Skip to content

Commit

Permalink
eqsound + tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
rumachan committed Aug 22, 2023
1 parent 76a74eb commit b8d7081
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 683 deletions.

This file was deleted.

Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions Data_Blog/blog_12_earthquake_sounds/Earthquake_Sound.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "b3918d6c",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import soundfile as sf\n",
"from obspy import UTCDateTime\n",
"from obspy import Stream\n",
"from obspy.clients.fdsn import Client as FDSN_Client\n",
"\n",
"client = FDSN_Client(\"GEONET\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6278778b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 Trace(s) in Stream:\n",
"NZ.ECLS.20.HNZ | 2021-03-04T13:00:00.000000Z - 2021-03-04T15:00:00.000000Z | 200.0 Hz, 1440001 samples\n"
]
}
],
"source": [
"station = 'ECLS'\n",
"location = '20'\n",
"channel = 'HNZ'\n",
"starttime = UTCDateTime(\"2021-03-04T13:00:00.000\")\n",
"endtime = UTCDateTime(\"2021-03-04T15:00:00.000\")\n",
"\n",
"\n",
"st = client.get_waveforms(\"NZ\", station, location, channel , starttime = starttime, endtime = endtime)\n",
"\n",
"print(st)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c9e6f145",
"metadata": {},
"outputs": [],
"source": [
"data = st[0].data\n",
"sampling_rate = 100\n",
"\n",
"# 1) force the signal's mean value to be zero \n",
"data = data - np.mean(data)\n",
"\n",
"#2) limit the signal's amplitude = avoid too large peaks \n",
"data_n = data/np.amax(np.absolute(data))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "49caa296",
"metadata": {},
"outputs": [],
"source": [
"sr_resample = 44100\n",
"file_name = '/Sound_' + str(station) + '.wav'\n",
"dire = ('.') #need to change directory \n",
"sf.write(dire + file_name, data_n, sr_resample)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "general",
"language": "python",
"name": "general"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file not shown.
File renamed without changes.

0 comments on commit b8d7081

Please sign in to comment.