-
Notifications
You must be signed in to change notification settings - Fork 1
/
stations-picker.py
68 lines (54 loc) · 1.76 KB
/
stations-picker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import obspy.io.nordic.core as nordic_reader
from obspy.core import read
import obspy
import sys
import getopt
import logging
import random
from obspy.core import utcdatetime
import utils.picks_slicing as picks
import utils.seisan_reader as seisan
import utils.converter as converter
import config.vars as config
# Main function body
if __name__ == "__main__":
# Parse script parameters
argv = sys.argv[1:]
try:
opts, args = getopt.getopt(argv, 'hs:r:w:', ["help", "save=", "rea="])
except getopt.GetoptError:
logging.error(str(getopt.GetoptError))
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
logging.info(config.stations_help_message)
print(config.stations_help_message)
sys.exit()
elif opt in ("-s", "--save"):
config.stations_save_path = arg
elif opt in ("-r", "--rea"):
config.full_readings_path = arg
# Initialize random seed with current time
random.seed()
# Get all nordic files in REA
nordic_dir_data = os.walk(config.full_readings_path)
nordic_file_names = []
for x in nordic_dir_data:
for file in x[2]:
nordic_file_names.append(x[0] + '/' + file)
# Print all nordic file names
if config.output_level >= 5:
logging.info('All nordic files:\n')
for x in nordic_file_names:
logging.info(x)
# Get all stations
stations = picks.get_stations(nordic_file_names, config.output_level)
stations = sorted(stations)
if os.path.isfile(config.stations_save_path):
logging.error('File already exists')
sys.exit(2)
f = open(config.stations_save_path, 'w')
for x in stations:
f.write(x + '\r\n')
f.close()