2828from ordered_set import OrderedSet as set
2929from tqdm import tqdm
3030from seismic .misc import split_list
31- from seismic .misc import recursive_glob
3231from seismic .ASDFdatabase .utils import cleanse_inventory
32+ from seismic .misc import recursive_glob
3333
3434def make_ASDF_tag (tr , tag ):
3535 # def make_ASDF_tag(ri, tag):
@@ -45,7 +45,7 @@ def make_ASDF_tag(tr, tag):
4545# end func
4646
4747CONTEXT_SETTINGS = dict (help_option_names = ['-h' , '--help' ])
48- BUFFER_LENGTH = 1000
48+ BUFFER_LENGTH = 2000
4949
5050@click .command (context_settings = CONTEXT_SETTINGS )
5151@click .argument ('input-folder' , required = True ,
@@ -60,7 +60,7 @@ def make_ASDF_tag(tr, tag):
6060@click .option ('--min-length-sec' , type = int , default = None , help = "Minimum length in seconds" )
6161@click .option ('--merge-threshold' , type = int , default = None , help = "Merge traces if the number of traces fetched for an "
6262 "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 "
6464 "file is ignored." )
6565@click .option ('--dry-run' , default = False , is_flag = True , show_default = True ,
6666 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,
7575 OUTPUT_FILE_NAME: Name of output ASDF file \n
7676 """
7777
78+ inventory_added = defaultdict (bool )
7879 def _read_inventories (inventory_folder ):
7980 inv_files = recursive_glob (inventory_folder , '*.xml' )
8081
@@ -103,8 +104,11 @@ def _write(ds, ostream, inventory_dict, netsta_set):
103104 # end try
104105
105106 for item in netsta_set :
107+ if (inventory_added [item ]): continue
108+
106109 try :
107110 ds .add_stationxml (inventory_dict [item ])
111+ inventory_added [item ] = True
108112 except Exception as e :
109113 print (e )
110114 print ('Failed to append inventory:' )
@@ -129,10 +133,7 @@ def _write(ds, ostream, inventory_dict, netsta_set):
129133 inv = _read_inventories (inventory_folder )
130134
131135 # 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 )
136137 files = np .array (files )
137138 random .Random (nproc ).shuffle (files )
138139 #print(files); exit(0)
@@ -143,21 +144,30 @@ def _write(ds, ostream, inventory_dict, netsta_set):
143144 stationlist = []
144145 filtered_files = []
145146 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
149148
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
158167
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
161171
162172 ustations .add ('%s.%s' % (net , sta ))
163173 networklist .append (net )
0 commit comments