28
28
from ordered_set import OrderedSet as set
29
29
from tqdm import tqdm
30
30
from seismic .misc import split_list
31
- from seismic .misc import recursive_glob
32
31
from seismic .ASDFdatabase .utils import cleanse_inventory
32
+ from seismic .misc import recursive_glob
33
33
34
34
def make_ASDF_tag (tr , tag ):
35
35
# def make_ASDF_tag(ri, tag):
@@ -45,7 +45,7 @@ def make_ASDF_tag(tr, tag):
45
45
# end func
46
46
47
47
CONTEXT_SETTINGS = dict (help_option_names = ['-h' , '--help' ])
48
- BUFFER_LENGTH = 1000
48
+ BUFFER_LENGTH = 2000
49
49
50
50
@click .command (context_settings = CONTEXT_SETTINGS )
51
51
@click .argument ('input-folder' , required = True ,
@@ -60,7 +60,7 @@ def make_ASDF_tag(tr, tag):
60
60
@click .option ('--min-length-sec' , type = int , default = None , help = "Minimum length in seconds" )
61
61
@click .option ('--merge-threshold' , type = int , default = None , help = "Merge traces if the number of traces fetched for an "
62
62
"interval exceeds this threshold" )
63
- @click .option ('--ntraces-per-file' , type = int , default = 3600 , help = "Maximum number of traces per file; if exceeded, the "
63
+ @click .option ('--ntraces-per-file' , type = int , default = 600 , help = "Maximum number of traces per file; if exceeded, the "
64
64
"file is ignored." )
65
65
@click .option ('--dry-run' , default = False , is_flag = True , show_default = True ,
66
66
help = "Dry run only reports stations that were not found in the stationXML files, for "
@@ -75,6 +75,7 @@ def process(input_folder, inventory_folder, output_file_name, file_pattern,
75
75
OUTPUT_FILE_NAME: Name of output ASDF file \n
76
76
"""
77
77
78
+ inventory_added = defaultdict (bool )
78
79
def _read_inventories (inventory_folder ):
79
80
inv_files = recursive_glob (inventory_folder , '*.xml' )
80
81
@@ -103,8 +104,11 @@ def _write(ds, ostream, inventory_dict, netsta_set):
103
104
# end try
104
105
105
106
for item in netsta_set :
107
+ if (inventory_added [item ]): continue
108
+
106
109
try :
107
110
ds .add_stationxml (inventory_dict [item ])
111
+ inventory_added [item ] = True
108
112
except Exception as e :
109
113
print (e )
110
114
print ('Failed to append inventory:' )
@@ -129,10 +133,7 @@ def _write(ds, ostream, inventory_dict, netsta_set):
129
133
inv = _read_inventories (inventory_folder )
130
134
131
135
# generate a list of files
132
- paths = [i for i in os .listdir (input_folder ) if os .path .isfile (os .path .join (input_folder , i ))]
133
- expr = re .compile (fnmatch .translate (file_pattern ), re .IGNORECASE )
134
- files = [os .path .join (input_folder , j ) for j in paths if re .match (expr , j )]
135
-
136
+ files = recursive_glob (input_folder , file_pattern )
136
137
files = np .array (files )
137
138
random .Random (nproc ).shuffle (files )
138
139
#print(files); exit(0)
@@ -143,21 +144,30 @@ def _write(ds, ostream, inventory_dict, netsta_set):
143
144
stationlist = []
144
145
filtered_files = []
145
146
for file in tqdm (files , desc = 'Reading trace headers: ' ):
146
- #_, _, net, sta, _ = file.split('.')
147
- #tokens = os.path.basename(file).split('.')
148
- #net, sta = tokens[0], tokens[1]
147
+ net = sta = None
149
148
150
- st = []
151
- try :
152
- st = read (file , headonly = True )
153
- except Exception as e :
154
- print (e )
155
- continue
156
- # end try
157
- if (len (st ) == 0 ): continue
149
+ if (True ):
150
+ try :
151
+ fn = os .path .basename (file )
152
+ net , sta = fn .split ('.' )[:2 ]
153
+ except :
154
+ continue
155
+ # end try
156
+ #tokens = os.path.basename(file).split('.')
157
+ #net, sta = tokens[0], tokens[1]
158
+ else :
159
+ st = []
160
+ try :
161
+ st = read (file , headonly = True )
162
+ except Exception as e :
163
+ print (e )
164
+ continue
165
+ # end try
166
+ if (len (st ) == 0 ): continue
158
167
159
- net = st [0 ].meta .network
160
- sta = st [0 ].meta .station
168
+ net = st [0 ].meta .network
169
+ sta = st [0 ].meta .station
170
+ # end if
161
171
162
172
ustations .add ('%s.%s' % (net , sta ))
163
173
networklist .append (net )
0 commit comments