UO-Geophysics / MudPy

Kinematic and static rupture forward modeling and inversion code
Other
116 stars 63 forks source link

Issue in View.py - tsunami_synthetics #79

Open ssantellanes opened 3 years ago

ssantellanes commented 3 years ago

Following code snippet should fix the issue/

   for k in range(len(i)):
        #tsun=read(datapath+sta[i[k]]+'.tsun')
        tsun=read(datapath+sta[i[k]]+'.sac')
  #      tsun=read(datapath+'D43413.sac')
        tsun_synth=read(synthpath+run_name+'.'+run_number+'.'+sta[i[k]]+'.tsun')

        dt=tsun_synth[0].stats.starttime - tsun[0].stats.starttime

        #Make plot
        ax=axarr[k]
        ax.plot(tsun[0].times()/60-dt/60,tsun[0].data/scale,'k',tsun_synth[0].times()/60,tsun_synth[0].data/scale,'r')
        ax.grid(which='both')
        ax.yaxis.set_ticklabels([])
        ax.set_xlim(t_lim)
        ax.yaxis.grid(False)
        ax.yaxis.set_ticks([])
        #Annotations
        trange=t_lim[1]-t_lim[0]
        sign=1.
        if abs(min(tsun[0].data))>max(tsun[0].data):
            sign=-1. 
        tsun_max='%.3f' % (sign*max(abs(tsun[0].data))/scale)
        sign=1.
        if abs(min(tsun_synth[0].data))>max(tsun_synth[0].data):
            sign=-1. 
        tsun_synth_max='%.3f' % (sign*max(abs(tsun_synth[0].data))/scale)
        sign=1.
        tsun_lims=ax.get_ylim()
        tsun_range=tsun_lims[1]-tsun_lims[0]

        ax.annotate(tsun_max,xy=(t_lim[1]-0.2*trange,tsun_lims[0]+0.02*tsun_range),fontsize=12)
        ax.annotate(tsun_synth_max,xy=(t_lim[1]-0.2*trange,tsun_lims[0]+0.7*tsun_range),fontsize=12,color='red')
        #Station name
        ax.set_ylabel(sta[i[k]],rotation=90,fontsize=12)
        #axn.set_title('North (m)')
        if k!=len(i)-1:
            ax.xaxis.set_ticklabels([])
        #    xtick=ax.xaxis.get_majorticklocs()
        #    ix=[1,3,5]
        #    xtick=xtick[ix]
        #    xticklabel=['','50','','150','','250','']
        if k==0: #first plot
            ax.set_title('Tsunami (cm)')
        if k==len(i)-1: #Last plot
            ax.set_xlabel('Minutes after Origin Time')
            #ax.set_title('Tsunami (cm)')
            #ax.xaxis.set_ticklabels(xticklabel)
            #axn.xaxis.set_ticks(xtick)
            #axe.xaxis.set_ticks(xtick)
            #axu.xaxis.set_ticks(xtick)
    plt.subplots_adjust(left=0.2, bottom=0.3, right=0.8, top=0.85, wspace=0, hspace=0)
    plt.show()