Пример #1
0
savedir = "web/PyGema_Web/PyGema_Web/static/figs_html"

deadtime = 5
while True:
    utc_now = UTCDateTime().now()
    starttime = utc_now - 60 * 30
    endtime = utc_now

    for network, station in zip(networks, stations):
        try:
            if network == "GM":
                # read and process data
                st, gaps = get_streams_gema([network], [station],
                                            starttime,
                                            endtime,
                                            only_vertical_channel=True,
                                            local_dir_name=None)

                if len(st) > 0:
                    # compute rsam
                    twin, freqmin, freqmax = load_rsam_parameters()
                    rsam_utcs, rsam_values = compute_rsam(st,
                                                          twin,
                                                          freqmin,
                                                          freqmax,
                                                          overlap=0.6)
                    # compute ssam
                    twin, freqmin, freqmax, nfreqs = load_ssam_parameters()
                    ssam_utcs, ssam_values, ssam_freqs = compute_ssam(
                        st, twin, freqmin, freqmax, nfreqs, overlap=0.6)
Пример #2
0
            if len(events_list) > 0:
                for event in events_list:
                    evtime = event[0]
                    evlon = event[1]
                    evlat = event[2]
                    evdep = event[3]
                    evnstats = event[4]
                    evgap = event[5]
                    evrms = event[6]

                    # calculate local magnitude
                    t1 = evtime - 60
                    t2 = evtime + 300
                    st, gaps = get_streams_gema(networks,
                                                stations,
                                                t1,
                                                t2,
                                                only_vertical_channel=True,
                                                local_dir_name=None)
                    evmag = get_local_magnitude(st,
                                                stations,
                                                stlons,
                                                stlats,
                                                evtime,
                                                evlon,
                                                evlat,
                                                evdep,
                                                freqmin=1,
                                                freqmax=10,
                                                max_epicenter_dist=100)

                    # insert event to pygema db
Пример #3
0
def build_event_directory_for_nonlinloc(event_time,
                                        networks,
                                        stations,
                                        freqmin=None,
                                        freqmax=None,
                                        deconvolve=False,
                                        only_vertical_channel=False,
                                        time_before=60,
                                        time_after=300):

    starttime = event_time - time_before
    endtime = event_time + time_after
    print("+ Reading seismic data from server ...")
    st, gaps = get_streams_gema(networks,
                                stations,
                                starttime,
                                endtime,
                                only_vertical_channel=only_vertical_channel,
                                local_dir_name=None)

    print("+ Pre-processing seismic data ...")
    if len(st) > 0:
        for tr in st:
            try:
                if deconvolve:
                    tr = remove_instrument_response(tr,
                                                    pre_filt=(0.01, 0.02, 50,
                                                              100),
                                                    detrend=True,
                                                    taper=True,
                                                    dataless_file=None)
                else:
                    tr.detrend('demean')
                    tr.detrend('linear')
                    tr.taper(max_percentage=0.005, type='hann')

                if freqmin is not None and freqmax is not None:
                    tr.filter("bandpass",
                              freqmin=freqmin,
                              freqmax=freqmax,
                              corners=3)

            except:
                st.remove(tr)
                continue

        outdir = "%s" % (event_time.strftime("%Y-%m-%d-%H%M%S"))
        if len(st) > 0:
            print("+ Exporting waveforms ...")
            if not os.path.isdir(outdir):
                os.makedirs(outdir)

            for tr in st:
                outfile = "%s/%s.%s.%s.%s.%s-%s.sac" % (
                    outdir, tr.stats.network, tr.stats.station,
                    tr.stats.location, tr.stats.channel,
                    tr.stats.starttime.strftime("%Y%m%d%H%M%S"),
                    tr.stats.endtime.strftime("%Y%m%d%H%M%S"))
                #print(outfile)
                tr.write(outfile, "SAC")

        else:
            print("+ No data found ...")

    return outdir
Пример #4
0
def plot_triggers_stalta(networks, stations, starttime, endtime, freqmin=1, freqmax=10, include_trig_off=False, dark_background=False, show_plot=False, save_plot=True, savedir=None, format='jpg', dpi=150):

  if dark_background:
    plt.style.use(['dark_background'])
  else:
    plt.style.use(['default'])

  fig = plt.figure(dpi=dpi)
  adjustFigAspect(fig,aspect=1.75)
  gs = mpl.gridspec.GridSpec(len(stations), 1, hspace=0.) 
  date_format = DateFormatter('%H:%M:%S')

  for i in range(len(stations)):
    network = networks[i]
    station = stations[i]

    if i == 0:
      ax1 = fig.add_subplot(gs[i])
      ax1.set_title("last update: %s UTC" % (UTCDateTime().now().strftime("%Y/%m/%d %H:%M:%S")), fontsize=4.5, loc='right')
    else:
      ax1 = fig.add_subplot(gs[i], sharex=ax1)

    ax1.minorticks_on()
    ax1.tick_params(axis='both', which='major', labelsize=8, bottom='off', top='off', left='off', right='off', direction='in')
    ax1.tick_params(axis='both', which='minor', labelsize=8, bottom='off', top='off', left='off', right='off', direction='in')
    ax1.tick_params(axis='x', which='major', labelsize=6, bottom='off', top='off', left='off', right='off', direction='in', rotation=0)
    ax1.tick_params(axis='x', which='minor', labelsize=6, bottom='off', top='off', left='off', right='off', direction='in', rotation=0)
    ax1.spines['right'].set_visible(False)
    ax1.spines['top'].set_visible(False)
    ax1.spines['left'].set_visible(False)
    ax1.spines['bottom'].set_visible(False)
    ax1.set_ylabel(network+"."+station, fontsize=5, rotation=0, labelpad=10)
    ax1.xaxis.set_major_formatter(date_format)
    ax1.set_xlim([ date2num(starttime.datetime), date2num(endtime.datetime) ])
    plt.setp( ax1.get_yticklabels(), visible=False)
    plt.setp(ax1.spines.values(), linewidth=.5)
    ax1.grid(axis='x', lw=0.7, ls=':', color='0.75')

    if i == len(stations)-1:
      plt.setp( ax1.get_xticklabels(), visible=True)
    else:
      plt.setp( ax1.get_xticklabels(), visible=False)

    try:
      st, gaps = get_streams_gema([network], [station], starttime, endtime, only_vertical_channel=True, local_dir_name=None)
      tr = st.select(station=station)
      if len(tr)>0:
        tr = tr[0]
        if not isinstance(tr.data, np.ma.masked_array):
          tr.detrend('demean')
          tr.detrend('linear')
          tr.taper(max_percentage=0.005,type='hann')
          tr.filter("bandpass", freqmin=freqmin, freqmax=freqmax, corners=2)

        if dark_background:
          ax1.plot(tr.times("matplotlib"), tr.data, lw=0.09, color="0.85")
        else:
          ax1.plot(tr.times("matplotlib"), tr.data, lw=0.09, color="k")

      triggers_list = select_triggers_stalta(station, starttime, endtime)
      for trigger in triggers_list:
        on = date2num(trigger[0].datetime)
        off = date2num(trigger[1].datetime)
        y1 = ax1.get_ylim()[0]; y2 = ax1.get_ylim()[1]
        ax1.axvline(on, y1, y2, lw=0.5, color='r', zorder=100, clip_on=True, alpha=0.9)
        #ax1.annotate( "P", (on, y2), color='r', zorder=100, fontsize=6)
        if include_trig_off:
          ax1.axvline(off, y1, y2, lw=0.7, color='g', zorder=100)
          if dark_background:
            ax1.add_patch( Rectangle((on, y1), off-on, y2-y1, fill=True, edgecolor=None, facecolor='w', alpha=0.8, linewidth=0, zorder=10) )
          else:
            ax1.add_patch( Rectangle((on, y1), off-on, y2-y1, fill=True, edgecolor=None, facecolor='w', alpha=0.8, linewidth=0, zorder=10) )

    except:
      continue



  if save_plot:
    if savedir is None:
      outdir = "figs" 
    else:
      outdir = "%s" % (savedir)

    if not os.path.isdir(outdir):
      os.makedirs(outdir)

    figname = "%s/triggers_stalta.%s" % (outdir, format)
    plt.savefig(figname, dpi=dpi, bbox_inches='tight', transparent=False)
    if not show_plot:
      plt.close('all')

  if show_plot:
    plt.show()
    plt.close('all')