def updatePH5(stream): global EXREC, CURRENT_DAS, LAST_SAMPLE_RATE, RESP def process(hdr, header_type): '''''' ll = [{'FileType': 'SEG-2', 'HeaderType': header_type}, hdr] log_array.append(json.dumps(ll, sort_keys=True, indent=4).split('\n')) RESP = Resp(EX.ph5_g_responses) size_guess = len(stream[0].data) * len(stream) for trace in stream: p_das_t = {} p_response_t = {} try: EXREC.ph5close() except BaseException: pass LAST_SAMPLE_RATE = trace.stats.sampling_rate try: CURRENT_DAS = "{0}SV{1:02d}".format( trace.stats.seg2['INSTRUMENT'].split(' ')[-1], int(trace.stats.seg2['CHANNEL_NUMBER'])) except Exception as e: LOGGER.warn( "Can not set DAS serial number: {0}. Set to 0000SV00".format( e.message)) CURRENT_DAS = "0000SV00" size_of_data = len(trace.data) * SIZE_FACTOR if size_guess < size_of_data: size_guess = size_of_data EXREC = get_current_data_only(size_guess) size_guess -= size_of_data # The gain and bit weight try: gain, units = trace.stats.seg2['FIXED_GAIN'].split(' ') except KeyError: gain = 0 units = 'DB' try: bw = (trace.stats.calib / float(trace.stats.seg2['STACK'])) * 1000. except KeyError: bw = trace.stats.calib * 1000. p_response_t['gain/value_i'] = int(gain) p_response_t['gain/units_s'] = units p_response_t['bit_weight/units_s'] = 'volts/count' p_response_t['bit_weight/value_d'] = bw n_i = RESP.match(p_response_t['bit_weight/value_d'], p_response_t['gain/value_i']) if n_i < 0: n_i = RESP.next_i() p_response_t['n_i'] = n_i EX.ph5_g_responses.populateResponse_t(p_response_t) RESP.update() # Check to see if group exists for this das, if not build it EXREC.ph5_g_receivers.newdas(CURRENT_DAS) # Update Maps_g fd = {} td = {} for k in trace.stats.seg2: if k in FILE_BLOCK_KEYS: # ObsPy does not know how to save the NOTE in the File # Descriptor Block! if k != 'NOTE': fd[k] = trace.stats.seg2[k] else: if k != 'NOTE': td[k] = trace.stats.seg2[k] else: tdd = {} for j in trace.stats.seg2[k]: tdd[j] = trace.stats.seg2[k][j] td[k] = tdd log_array, name = getLOG(CURRENT_DAS) process(fd, "File Descriptor Block") process(td, "Trace Descriptor Block") log_array.close() # Fill in das_t p_das_t['raw_file_name_s'] = F p_das_t['response_table_n_i'] = n_i p_das_t['channel_number_i'] = 1 p_das_t['sample_count_i'] = int(trace.stats.npts) p_das_t['sample_rate_i'] = int(trace.stats.sampling_rate) p_das_t['sample_rate_multiplier_i'] = 1 tdoy = timedoy.UTCDateTime2tdoy(trace.stats.starttime) p_das_t['time/epoch_l'] = tdoy.epoch() # XXX need to cross check here XXX p_das_t['time/ascii_s'] = time.asctime( time.gmtime(p_das_t['time/epoch_l'])) p_das_t['time/type_s'] = 'BOTH' # XXX Should this get set???? XXX p_das_t['time/micro_seconds_i'] = tdoy.microsecond() # XXX Need to check if array name exists and generate unique name. p_das_t['array_name_data_a'] = EXREC.ph5_g_receivers.nextarray( 'Data_a_') des = "Epoch: " + str(p_das_t['time/epoch_l']) + \ " Channel: " + trace.stats.channel # XXX This should be changed to handle exceptions XXX EXREC.ph5_g_receivers.populateDas_t(p_das_t) # Write out array data (it would be nice if we had int24) we use int32! EXREC.ph5_g_receivers.newarray(p_das_t['array_name_data_a'], trace.data, dtype='int32', description=des) update_index_t_info( p_das_t['time/epoch_l'] + (float(p_das_t['time/micro_seconds_i']) / 1000000.), p_das_t['sample_count_i'], p_das_t['sample_rate_i'] / p_das_t['sample_rate_multiplier_i']) if DAS_INFO: writeINDEX()
def updatePH5(stream): global EXREC, CURRENT_DAS, LAST_SAMPLE_RATE #XXX CHAN_MAP = { "EL1": 1, "EL2": 2, "ELZ": 3, "EDH": 4, "HH1": 1, "HH2": 2, "HHZ": 3, "HDH": 4, "BHE": 1, "BHN": 2, "BHZ": 3 } size_guess = SIZE_GUESS for trace in stream: #print trace.stats.starttime.timetuple () #print trace.stats.starttime._get_microsecond () p_das_t = {} p_response_t = {} try: EXREC.ph5close() except: pass LAST_SAMPLE_RATE = trace.stats.sampling_rate CURRENT_DAS = trace.stats.station size_of_data = len(trace.data) * SIZE_FACTOR if size_guess < size_of_data: size_guess = size_of_data EXREC = get_current_data_only(size_guess) size_guess -= size_of_data # The gain and bit weight p_response_t['gain/value_i'] = 1 p_response_t['bit_weight/units_s'] = 'volts/count' p_response_t['bit_weight/value_d'] = 1 n_i = RESP.match(p_response_t['bit_weight/value_d'], p_response_t['gain/value_i']) if n_i < 0: n_i = RESP.next_i() p_response_t['n_i'] = n_i EX.ph5_g_responses.populateResponse_t(p_response_t) RESP.update() # Check to see if group exists for this das, if not build it junk_t = EXREC.ph5_g_receivers.newdas(CURRENT_DAS) # Fill in das_t p_das_t['raw_file_name_s'] = F p_das_t['response_table_n_i'] = n_i p_das_t['channel_number_i'] = CHAN_MAP[trace.stats.channel] p_das_t['sample_count_i'] = trace.stats.npts p_das_t['sample_rate_i'] = trace.stats.sampling_rate p_das_t['sample_rate_multiplier_i'] = 1 # tdoy = timedoy.UTCDateTime2tdoy(trace.stats.starttime) p_das_t['time/epoch_l'] = tdoy.epoch() # XXX need to cross check here XXX p_das_t['time/ascii_s'] = time.asctime( time.gmtime(p_das_t['time/epoch_l'])) p_das_t['time/type_s'] = 'BOTH' # XXX Should this get set???? XXX p_das_t['time/micro_seconds_i'] = tdoy.microsecond() # XXX Need to check if array name exists and generate unique name. XXX p_das_t['array_name_data_a'] = EXREC.ph5_g_receivers.nextarray( 'Data_a_') des = "Epoch: " + str( p_das_t['time/epoch_l']) + " Channel: " + trace.stats.channel # XXX This should be changed to handle exceptions XXX EXREC.ph5_g_receivers.populateDas_t(p_das_t) # Write out array data (it would be nice if we had int24) we use int32! EXREC.ph5_g_receivers.newarray(p_das_t['array_name_data_a'], trace.data, dtype='int32', description=des) update_index_t_info( p_das_t['time/epoch_l'] + (float(p_das_t['time/micro_seconds_i']) / 1000000.), p_das_t['sample_count_i'], p_das_t['sample_rate_i'] / p_das_t['sample_rate_multiplier_i']) if DAS_INFO: writeINDEX()