##################################### # loop through the windows ##################################### # for n in xrange(len(dataDaysList)): print "\n[INFO] day ",dataDaysList[n] Dfile = {} Hfile = [] thisFile = os.path.join(psdDbDirTag, dataDaysList[n], psdDbFileTag+'*'+xType+'.txt') if VERBOSE: print "[INFO] Looking into:", thisFile thisFileList = sorted(glob.glob(thisFile)) if len(thisFileList)<=0: msgLib.warning('Main','No files found!') if VERBOSE: print "skip" continue elif len(thisFileList)>1: if VERBOSE: print len(thisFileList), "files found!" ##################################### # found the file, open it and read it ##################################### # for thisPsdFile in thisFileList: if VERBOSE >0 : print "[INFO] PSD FILE: " ,thisPsdFile thisFileTimeLabel = fileLib.getFileTimes(param.namingConvention,channel,thisPsdFile)
msg_lib.info(f'PSD DIR TAG: {psd_db_dir_tag}') # Loop through the windows. for n in range(len(data_day_list)): msg_lib.info(f'day {data_day_list[n]}') d_file = dict() h_file = list() this_file = os.path.join(psd_db_dir_tag, data_day_list[n], f'{psd_db_file_tag}*{xtype}.txt') if verbose: msg_lib.info(f'Looking into: {this_file}') this_file_list = sorted(glob.glob(this_file)) if len(this_file_list) <= 0: msg_lib.warning('Main', 'No files found!') if verbose: msg_lib.warning('Main', 'skip') continue elif len(this_file_list) > 1: if verbose: msg_lib.info(f'{len(this_file_list)} files found!') # Found the file, open it and read it. for this_psd_file in this_file_list: if verbose > 0: msg_lib.info(f'PSD FILE: {this_psd_file}') this_file_time_label = file_lib.get_file_times(param.namingConvention, channel, this_psd_file) this_file_time = UTCDateTime(this_file_time_label[0])
def get_channel_waveform_files(network, station, location, channel, start_time, end_time, client, file_tag, resp_dir=None, inventory=None): """ get_channel_waveform_files gets data from files and the response form the FDSN client. for the requested network/station/location/channel and time the output is the corresponding data stream file_tag should be in such a way to guide the function in selecting waveform files like {this Path}/*.SAC channel may have the last one or two letters wildcarded (e.g. channel="EH*") to select all components with a common band/instrument code. All other selection criteria that accept strings (network, station, location) may also contain Unix style wildcards (*, ?, ...). HISTORY: 2015-03-17 Manoch: added the "waterLevel" parameter to provide user with more control on how the ObsPy module shrinks values under water-level of max spec amplitude when removing the instrument response. 2015-02-24 Manoch: introduced two new parameters (performInstrumentCorrection, applyScale) to allow user avoid instrument correction also now user can turn od decon. filter 2014-03-15 Manoch: created """ debug = True sender = 'get_channel_waveform_files' # Stream holds the final stream this_start_time = UTCDateTime(start_time) this_end_time = UTCDateTime(end_time) stream = Stream() try: # Read in the files to a stream. msg_lib.info(f'checking: {file_tag}') msg_lib.info('Apply scaling') stream_in = read(file_tag, start_time=this_start_time, end_time=this_end_time, nearest_sample=True) except Exception as ex: msg_lib.error( f'{network}, {station}, {location}, {channel}, {start_time}, {end_time} {ex}', 2) return None try: # Select the desire streams only. if location == "--": stream_out = stream_in.select(network=network, station=station, location="", channel=channel) else: stream_out = stream_in.select(network=network, station=station, location=location, channel=channel) for i in range(len(stream_out)): # Get the network, station, location and channel information. this_nslc, this_time, junk = str(stream_out[i]).split('|') net, sta, loc, chan = this_nslc.strip().split('.') if len(loc) == 0: loc = "--" # If resp_dir is defined, first look into user's resp_dir for stationXML files, # if not found get it from FDSN start, end = this_time.split(' - ') inv = None if resp_dir is not None: msg_lib.info(f'Getting response from {resp_dir}') this_loc = loc if loc == '--': this_loc = '' inventory, inv = get_response_from_file( inventory, resp_dir, net, sta, this_loc, chan, start_time, debug) if inv is not None: if debug: msg_lib.info(f'Attaching {inv}') stream_out[i].attach_response(inv) stream += stream_out[i] else: this_start_time = UTCDateTime(start.strip()) msg_lib.warning( sender, f'NO RESPONSE FILE: {net}, {sta}, {loc}, {chan}, {this_start_time}' ) if inv is None and client is not None: # The FDSN webservices return StationXML metadata. msg_lib.info('Getting response from IRIS') try: this_start_time = UTCDateTime(start.strip()) this_end_time = UTCDateTime(end.strip()) inv = client.get_stations(network=net, station=sta, location=loc, channel=chan, starttime=this_start_time, endtime=this_end_time, level="response") stream_out[i].attach_response(inv) stream += stream_out[i] if debug: msg_lib.info(f'Response attached: {inv}') except Exception as ex: this_start_time = UTCDateTime(start.strip()) msg_lib.warning( sender, f'NO RESPONSE: {net}, {sta}, {loc}, {chan}, ' f'{this_start_time}, {this_end_time} {ex}') continue except Exception as ex: print(str(e)) msg_lib.error( f'get_channel_waveform_files {network}, {station}, {location}, {channel}, {start_time}, ' f'{end_time}, {ex}', 2) return None, None return inventory, stream
#outputFileName = os.path.join(psdDirTag,'.'.join([psdFileTag,startDateTime.split('.')[0],endDateTime.split('.')[0]+'_'+xType+'.txt'])) with open(outputFileName, 'w') as outputFile: ##################################### # loop through the windows ##################################### # for n in xrange(len(dataDaysList)): thisFile = os.path.join(psdDbDirTag, dataDaysList[n], psdDbFileTag + '*' + xType + '.txt') print "[INFO] Day:", dataDaysList[n] thisFileList = sorted(glob.glob(thisFile)) if len(thisFileList) <= 0: msgLib.warning('Main', 'No files found!') if VERBOSE: print "skip" continue elif len(thisFileList) > 1: if VERBOSE: print len(thisFileList), "files found!" ##################################### # found the file, open it and read it ##################################### # for thisPsdFile in thisFileList: if VERBOSE > 0: print "[INFO] PSD FILE: ", thisPsdFile thisFileTimeLabel = fileLib.getFileTimes(param.namingConvention, channel, thisPsdFile)
production_label = f'{production_label} {script} {version}' production_label = f'{production_label}\n{production_date} UTC' production_label = f'{production_label}\ndoi:{shared.ntk_doi}' # Get data from each Data Center. stream = None for _key in cat: st = None if verbose: msg_lib.info('Sending requests for:') for line in cat[_key]['bulk']: msg_lib.info(line) if not cat[_key]['bulk']: msg_lib.warning(f'Skipping data request from {_key}, no stations to request!\n') continue if request_client == 'FILES': msg_lib.info(f'Reading data from {cat[_key]["bulk"]}') else: msg_lib.info(f'Requesting data from {_key} via {ts_lib.get_service_url(cat, _key)}\n') # Set the client up for this data center. try: client = Client(ts_lib.get_service_url(cat, _key)) st = client.get_waveforms_bulk(cat[_key]['bulk'], attach_response=True) except Exception as ex: msg_lib.warning(script, ex) """Start processing time segments.
requestChannel, segmentStart, segmentEnd, 1, msgLib.param( param, 'performInstrumentCorrection').performInstrumentCorrection, msgLib.param(param, 'applyScale').applyScale, msgLib.param(param, 'deconFilter1').deconFilter1, msgLib.param(param, 'deconFilter2').deconFilter2, msgLib.param(param, 'deconFilter3').deconFilter3, msgLib.param(param, 'deconFilter4').deconFilter4, msgLib.param(param, 'waterLevel').waterLevel, msgLib.param(param, 'unit').unit, client) if stream is None or len(stream) <= 0: msgLib.warning( 'Channel Waveform', 'No data available for ' + '.'.join([ requestNetwork, requestStation, requestLocation, requestChannel ])) continue except Exception, e: print str(e) print "[INFO] waveform request failed\n" continue traceKeyList = [] for streamIndex in xrange(len(stream)): frequency = [] period = [] power = [] stChannel = None
stream = TSL.getChannelWaveformFiles (requestNetwork, requestStation, requestLocation, requestChannel, segmentStart,segmentEnd,1,msgLib.param(param,'performInstrumentCorrection').performInstrumentCorrection,msgLib.param(param,'applyScale').applyScale, msgLib.param(param,'deconFilter1').deconFilter1, msgLib.param(param,'deconFilter2').deconFilter2, msgLib.param(param,'deconFilter3').deconFilter3, msgLib.param(param,'deconFilter4').deconFilter4, msgLib.param(param,'waterLevel').waterLevel, msgLib.param(param,'unit').unit,client,msgLib.param(param,'fileTag').fileTag) # # request via FDSN WS # else: stream = TSL.getChannelWaveform (requestNetwork, requestStation, requestLocation, requestChannel, segmentStart,segmentEnd,1,msgLib.param(param,'performInstrumentCorrection').performInstrumentCorrection,msgLib.param(param,'applyScale').applyScale, msgLib.param(param,'deconFilter1').deconFilter1, msgLib.param(param,'deconFilter2').deconFilter2, msgLib.param(param,'deconFilter3').deconFilter3, msgLib.param(param,'deconFilter4').deconFilter4, msgLib.param(param,'waterLevel').waterLevel, msgLib.param(param,'unit').unit,client) if stream is None or len(stream) <= 0: msgLib.warning('Channel Waveform','No data available for '+ '.'.join([requestNetwork,requestStation,requestLocation,requestChannel])) continue except Exception, e: print str(e) print "[INFO] waveform request failed\n" continue traceKeyList = [] for streamIndex in xrange(len(stream)): frequency = [] period = [] power = [] stChannel = None trChannel = stream[streamIndex] network = trChannel.stats.network