コード例 #1
0
        sta_processed.append(ista)
        if plot_correction:
            obs.plotcorrection(trZ,
                               correct,
                               normalize=normalizecorrectionplot,
                               freq=[0.005, 0.1],
                               size=(12, 3),
                               save=True,
                               form='png')
        """
        Save to ASDF file.
        """
        trZtc, tgtemp = obs.correctdict2stream(trZ, correct, tc_subset)
        print('  saving to: ' + df_tc)
        utils.save2asdf(df_tc,
                        Stream(traces=[tr1, tr2, trZtc[0], trP]),
                        newtags,
                        sta_inv=inv)

    #save auxiliary data to file.
    print('  saving auxiliary data to: ' + df_tc)
    tcpara_temp = tcpara
    tcpara_temp['tilt_stations'] = sta_processed
    utils.save2asdf(df_tc,
                    np.array(tilt),
                    None,
                    group='auxiliary',
                    para={
                        'data_type': 'tcremoval',
                        'data_path': 'tiltdir',
                        'parameters': tcpara_temp
                    })
コード例 #2
0
def download(rawdatadir,
             starttime,
             endtime,
             inc_hours,
             net,
             stalist,
             chanlist=['*'],
             source='IRIS',
             samp_freq=None,
             plot=False,
             rmresp=True,
             rmresp_output='VEL',
             pre_filt=None,
             sacheader=False,
             getstainv=True,
             max_tries=10):

    # if user passes a string instead of a list, make a list of one string
    if isinstance(stalist, str): stalist = [stalist]
    if isinstance(chanlist, str): chanlist = [chanlist]
    if isinstance(net, str): net = [net]

    dtlist = utils.split_datetimestr(starttime, endtime, inc_hours)
    print(dtlist)
    for idt in range(len(dtlist) - 1):
        sdatetime = obspy.UTCDateTime(dtlist[idt])
        edatetime = obspy.UTCDateTime(dtlist[idt + 1])
    fname = os.path.join(rawdatadir,
                         str(sdatetime) + 'T' + str(edatetime) + '.h5')
    """
    Start downloading.
    """
    for inet in net:
        for ista in stalist:

            #print('Downloading ' + inet + "." + ista + " ...")
            """
            3a. Request data.
            """
            for chan in chanlist:
                for nt in range(max_tries):
                    print(ista + '.' + chan + '  downloading ... try ' +
                          str(nt + 1))
                    try:
                        t0 = time.time()

                        output = utils.getdata(inet,
                                               ista,
                                               sdatetime,
                                               edatetime,
                                               chan=chan,
                                               source=source,
                                               samp_freq=samp_freq,
                                               plot=plot,
                                               rmresp=rmresp,
                                               rmresp_output=rmresp_output,
                                               pre_filt=pre_filt,
                                               sacheader=sacheader,
                                               getstainv=getstainv)

                        if getstainv == True or sacheader == True:
                            sta_inv = output[1]
                            tr = output[0]
                        else:
                            tr = output
                            sta_inv = None

                        ta = time.time() - t0
                        print('  downloaded ' + "." + ista + "." + chan +
                              " in " + str(ta) + " seconds.")
                        tag = get_tracetag(tr)
                        chan = tr.stats.channel
                        """
                        Add cleanup
                        """

                        if chan[-1].lower() == 'h':
                            tag_type = "trP"
                            hasPressure = True
                        elif chan[-1].lower() == '1' or chan[-1].lower(
                        ) == 'e':
                            tag_type = "tr1"
                        elif chan[-1].lower() == '2' or chan[-1].lower(
                        ) == 'n':
                            tag_type = "tr2"
                        elif chan[-1].lower() == 'z':
                            tag_type = "trZ"
                        else:
                            print(
                                '  No seismic channels found. Drop the station: '
                                + ista)
                            break

                        #sanity check.
                        badtrace = False
                        hasPressure = False
                        if not isinstance(tr, Trace):
                            print("  " + str(tr) + " is not a Trace object. " +
                                  ista)
                            badtrace = True
                            break
                        elif np.sum(np.isnan(tr.data)) > 0:
                            print('  NaN found in trace: ' + str(tr) + ". " +
                                  ista)
                            badtrace = True
                            break
                        elif np.count_nonzero(tr.data) < 1:
                            print('  All zeros in trace: ' + str(tr) + ". " +
                                  ista)
                            badtrace = True
                            break

                        in_dir = in_directory(fname, ista, inet, tag)
                        if badtrace:
                            if not drop_if_has_badtrace:
                                """
                                3b. Save to ASDF file.
                                """
                                if in_dir == True:
                                    print(inet + '.' + ista + '.' + chan +
                                          '  exists. Continue to next!')
                                    break
                                else:
                                    print(
                                        "  Not enough good traces for TC removal! Save as is without processing!"
                                    )

                                    save2asdf(fname, tr, tag, sta_inv=sta_inv)

                                    break
                            else:
                                print("  Encountered bad trace for " + ista +
                                      ". Skipped!")
                                break
                        else:
                            """
                            3b. Save to ASDF file.
                            """
                            if in_dir == True:
                                print(inet + '.' + ista + "." + chan +
                                      '  exists. Continue to next!')
                                break
                            else:
                                print(" Saving data for",
                                      inet + '.' + ista + '.' + chan)
                                save2asdf(fname, [tr], [tag], sta_inv=sta_inv)
                                break

                    except Exception as e:
                        print(e, 'for', ista)
                        time.sleep(0.05)  # sleep for 50ms before next try.
                        continue
コード例 #3
0
         badtrace = True
         break
     elif np.count_nonzero(tr.data) < 1:
         print('  All zeros in trace: ' + str(tr) + ". " + ista)
         badtrace = True
         break
 if badtrace:
     if not drop_if_has_badtrace:
         print(
             "  Not enough good traces for TC removal! Save as is without processing!"
         )
         outtrace = []
         for tg in all_tags:
             outtrace.append(ds.waveforms[ista][tg][0])
         utils.save2asdf(df_tc,
                         Stream(traces=outtrace),
                         all_tags,
                         sta_inv=inv)
     else:
         print("  Encountered bad trace for " + ista + ". Skipped!")
     continue
 elif requirePressure and not hasPressure:  #if station doesn't have pressure channel, it might be an obs or a land station
     newtags_tmp = []
     if isinstance(tr1, Trace) and isinstance(
             tr2, Trace
     ) and correct_obs_orient and ista in obs_orient_data.keys():
         #correct horizontal orientations if in the obs_orient_data list.
         print("  Correctting horizontal orientations for: " + ista)
         trE, trN = obs.correct_orientations(tr1, tr2, obs_orient_data)
         newtags_tmp.append(utils.get_tracetag(trE))
         newtags_tmp.append(utils.get_tracetag(trN))
         print(newtags_tmp)
コード例 #4
0
                                         samp_freq=samp_freq,
                                         plot=False,
                                         rmresp=rmresp,
                                         pre_filt=pre_filt)
        sta_inv = client.get_stations(network=net,
                                      station=ista,
                                      starttime=sdatetime,
                                      endtime=edatetime,
                                      location='*',
                                      level='response')
        ta = time.time() - t0
        print('  downloaded ' + net + "." + ista + " in " + str(ta) +
              " seconds.")
        """
        3b. Save to ASDF file.
        """
        tags = []
        for itr, tr in enumerate([tr1, tr2, trZ, trP], 1):
            if len(tr.stats.location) == 0:
                tlocation = '00'
            else:
                tlocation = tr.stats.location

            tags.append(tr.stats.channel.lower() + '_' + tlocation.lower())

        print('  saving to ' + fname)
        utils.save2asdf(fname,
                        Stream(traces=[tr1, tr2, trZ, trP]),
                        tags,
                        sta_inv=sta_inv)
コード例 #5
0
         badtrace = True
         break
     elif np.count_nonzero(tr.data) < 1:
         print('  All zeros in trace: ' + str(tr) + ". " + ista)
         badtrace = True
         break
 if badtrace:
     if not drop_if_has_badtrace:
         print(
             "  Not enough good traces for TC removal! Save as is without processing!"
         )
         outtrace = []
         for tg in all_tags:
             outtrace.append(ds.waveforms[ista][tg][0])
         utils.save2asdf(df_out,
                         Stream(traces=outtrace),
                         all_tags,
                         sta_inv=inv)
     else:
         print("  Encountered bad trace for " + ista + ". Skipped!")
     continue
 else:
     newtags_tmp = []
     if isinstance(tr1, Trace) and isinstance(
             tr2, Trace
     ) and correct_obs_orient and ista in obs_orient_data.keys():
         #correct horizontal orientations if in the obs_orient_data list.
         print("  Correctting horizontal orientations for: " + ista)
         trE, trN = obs.correct_orientations(tr1, tr2, obs_orient_data)
         newtags_tmp.append(utils.get_tracetag(trE))
         newtags_tmp.append(utils.get_tracetag(trN))
         if isinstance(trP, Trace):