Exemplo n.º 1
0
def gmt_north_america(**kwargs):
   '''
   Give rf_data as ([values],[time])
   '''
   from gmtpy import GMT
   #get kwargs
   fname = kwargs.get('fname','USA_map.pdf')
   station_data = kwargs.get('station_data','none')
   quake_locs   = kwargs.get('quake_locs','none')
   rf_data      = kwargs.get('rf_data','none')
   header       = kwargs.get('header','none')

   #topo data
   etopo='/geo/home/romaguir/utils/ETOPO5.grd'
   topo_grad='/geo/home/romaguir/utils/topo_grad.grd'

   #colormap
   colombia='/geo/home/romaguir/utils/colors/colombia'

   region = '-128/-66/24/52'
   scale = 'l-100/35/33/45/1:30000000'

   #initialize gmt
   gmt = GMT(config={'BASEMAP_TYPE':'fancy',
                     'HEADER_FONT_SIZE':'14'})
                     #'COLOR_BACKGROUND':'-',  :setting this to '-' plots z are transparent
                     #'COLOR_FOREGROUND':'-'})

   #make colormap
   cptfile = gmt.tempfilename()
   gmt.makecpt(C=colombia,T='-4000/4950/100',Z=True,out_filename=cptfile,D='i')

   #make gradient
   #topo_grad = gmt.tempfilename()
   #gmt.grdgradient(etopo,V=True,A='100',N='e0.8',M=True,G=topo_grad,K=False)

   #plot topography
   gmt.grdimage( etopo,
                 R = region,
                 J = scale,
                 C = cptfile,
                 E = '200')
                 #I = '0.5')#topo_grad)

   #plot coastlines
   gmt.pscoast( R=region,
                J=scale,
                B='a10',
                D='l',
                A='500',
                W='thinnest,black,-',
                N='all')

   #plot stations
   if station_data != 'none':
      gmt.psxy( R=region,
                J=scale,
                B='a10',
                S='t0.1',
                G='red',
                in_rows = station_data )


   if quake_locs != 'none':
      eq_region = 'g'
      eq_scale  = 'E-100/40/2.25i'
      gmt.pscoast( R = eq_region,
                   J = eq_scale,
                   B = 'p',
                   A = '10000',
                   G = 'lightgrey',
                   W = 'thinnest',
                   Y = '3.5i',
                   X = '-0.5i' ) 
      gmt.psxy( R = eq_region,
                J = eq_scale,
                S = 'a0.05',
                G = 'blue',
                in_rows = quake_locs )

   #plot receiver function stack
   if rf_data != 'none':
      rf_region = '-0.20/0.20/0/100'
      rf_scale  = 'X1i/-5i'
      gmt.psxy( R = rf_region,
                J = rf_scale,
                #G = 'grey', #fill
                B = '0.25::/10:time (s):NE',
                W = 'thin',
                X = '9i',
                Y = '-3.5i',
                in_columns = rf_data )

      #plot shaded area for positive values
      vals = rf_data[0]
      time = rf_data[1]
      poly_vals_pos = []
      poly_time_pos = []
      for i in range(0,len(vals)):
         val_here = max(0,np.float(vals[i]))
         poly_time_pos.append(time[i])
         poly_vals_pos.append(val_here)

      poly_vals_pos.append(0.0)
      poly_time_pos.append(time[::-1][0])
      poly_vals_pos.append(0.0)
      poly_time_pos.append(time[0])
      gmt.psxy( R = rf_region,
                J = rf_scale,
                G = 'red',
                B = '0.25::/10:time (s):NE',
                W = 'thin',
                in_columns = (poly_vals_pos,poly_time_pos) )

      #plot shaded area for negative values
      '''
      vals = rf_data[0]
      time = rf_data[1]
      poly_vals_neg = []
      poly_time_neg = []
      for i in range(0,len(vals)):
         val_here = min(0,np.float(vals[i]))
         poly_time_neg.append(time[i])
         poly_vals_neg.append(val_here)
      poly_vals_neg.append(0.0)
      poly_time_neg.append(time[::-1][0])
      poly_vals_neg.append(0.0)
      poly_time_neg.append(time[0])
      gmt.psxy( R = rf_region,
                J = rf_scale,
                G = 'blue',
                B = '0.25::/10:time (s):NE',
                W = 'thin',
                in_columns = (poly_vals_neg,poly_time_neg) )
      '''

   #header_file = open('header_file','w')
   #header_file.write('<< EOF')
   #header_file.close()

   #write header information
   if header != 'none':
      stations_text = header['N_traces'] + ' traces in stack'
      events_text   = header['N_events'] + ' events'
      freq_text     = header['frequency']
      decon_text    = 'deconvolution method : ' + header['decon']

      gmt.pstext( in_rows = [(-96,60,12,0,1,'MC',stations_text)],
                  R = region,
                  J = scale,
                  N = True,
                  X = '-8.5i' )
      gmt.pstext( in_rows = [(-96,59,12,0,1,'MC',events_text)],
                  R = region,
                  J = scale,
                  N = True )
      gmt.pstext( in_rows = [(-96,58,12,0,1,'MC',freq_text)],
                  R = region,
                  J = scale,
                  N = True )
      gmt.pstext( in_rows = [(-96,57,12,0,1,'MC',decon_text)],
                  R = region,
                  J = scale,
                  N = True )

   #save figure
   gmt.save(fname)
Exemplo n.º 2
0
def plot_vtk_slice(vtk_slice,theta_range=[0,360],depth_range=[0,2885],**kwargs): 
#--------------------------------------------------------------------------------

   '''
   This will plot a cross section of a .vtk file.  Open the .vtk file in paraview,
   choose a slice, and select 'File -> export data'.  This will save the data as
   a .csv file, which can be plotted with this function.

   args--------------------------------------------------------------------------
   vtk_slice: the .csv file
   theta_range: the range in degrees you wish to plot. 
                dtype=tuple
                default=[0,360] (whole earth)
   depth_range: the range in depth you wish to plot.
                dtype=tuple
                default=[0,2885] (whole mantle)

   kwargs------------------------------------------------------------------------
   cmap = colormap to use
          dtype=string
          default='BlueWhiiteOrangeRed'

   data_range = max and min values to use in colorbar.
                dtype=tuple
                default=[-1.0,1.0]

   csteps = number of divisions in colorbar
            dtype=int
            default=100

   cmap_direction = forward or reverse colormap
                    dtype=string
                    default='i'

   fname = filename
           dtype=string
           default='slice.pdf'

   rotation = number of degrees to rotate figure
            dtype=float
            default=90.0 (i.e., rotate from lat coor to colat based coor)

   contour = True or False
   '''

   #get kwargs-------------------------------------------------------------------
   cmap_dir = '/geo/home/romaguir/utils/colors/'
   cmap = kwargs.get('cmap','BlueWhiteOrangeRed')
   cmap = cmap_dir+cmap
   data_range = kwargs.get('data_range',[-0.25,0.25])
   csteps = kwargs.get('csteps',100)
   cmap_direction=kwargs.get('cmap_direction','i')
   fname = kwargs.get('fname','slice.pdf')
   rotation=kwargs.get('rotation',90.0)
   contour=kwargs.get('contour',True)

   #read csv slice (output of paraview)------------------------------------------
   f = pandas.read_csv(vtk_slice)
   p1 = f['Points:0']
   p2 = f['Points:1']
   p3 = f['Points:2']
   dvp = f['dVp()']

   #transform to polar, earth coordinates----------------------------------------
   r,t = cart2polar(p1,p3)
   r *= 6371.0
   t=np.degrees(t)
   

   print min(dvp),max(dvp)

   #setup GMT plot---------------------------------------------------------------
   gmt = GMT(config={'BASEMAP_TYPE':'fancy',
                      'HEADER_FONT_SIZE':'14'})
   region = '{}/{}/{}/{}'.format(theta_range[0],theta_range[1],6371.0-depth_range[1],6371.0-depth_range[0])
   surf_region = '{}/{}/{}/{}'.format(theta_range[0]-2,theta_range[1]+2,6371.0-depth_range[1],6500.0-depth_range[0])
   scale = 'P6i' #Polar, 8 inch radius
   cptfile = gmt.tempfilename()
   grdfile = gmt.tempfilename()

   #gmt.makecpt(C=cmap,T='{}/{}/{}'.format(data_range[0],data_range[1],csteps),Z=False,out_filename=cptfile,D=cmap_direction)
   gmt.makecpt(C=cmap,T='-0.25/0.25/0.025',A=100,out_filename=cptfile,D=True)

   gmt.surface(in_columns=[t+rotation,r,dvp],G=grdfile,I='0.5/25',T=0.0,R=surf_region,out_discard=True)

   '''
   #plot the data----------------------------------------------------------------
   gmt.psxy( R=region,
             J=scale,
             #B='a15f15:"":/200f200:""::."":WSne',
             B='a300f300',
             S='s0.20',
             #G='blue',
             C=cptfile,
             in_columns=[t+rotation,r,dvp] )
   '''
   #plot the data----------------------------------------------------------------
   gmt.grdimage( grdfile, 
                 R=region,
                 J=scale,
                 B='a300f300',
                 C=cptfile,
                 E='i5' )
   
   #contour the data-------------------------------------------------------------
   if contour == True:
      gmt.grdcontour( grdfile,
                      R=region,
                      J=scale,
                      C=cptfile,
                      W='1' )

   #plot 660---------------------------------------------------------------------
   d660 = np.loadtxt('/geo/home/romaguir/utils/660_polar.dat')
   print d660
   gmt.psxy( R=region,
             J=scale,
             W='1',
             in_rows=[d660] )
            
   gmt.save(fname)
Exemplo n.º 3
0
def gmt_north_america(**kwargs):
   '''
   Give rf_data as ([values],[time])
   '''
   from gmtpy import GMT
   #get kwargs
   fname = kwargs.get('fname','USA_map.pdf')
   station_data = kwargs.get('station_data','none')
   quake_locs   = kwargs.get('quake_locs','none')
   rf_data      = kwargs.get('rf_data','none')
   header       = kwargs.get('header','none')

   #topo data
   etopo='/geo/home/romaguir/utils/ETOPO5.grd'
   topo_grad='/geo/home/romaguir/utils/topo_grad.grd'

   #colormap
   colombia='/geo/home/romaguir/utils/colors/colombia'

   region = '-128/-66/24/52'
   scale = 'l-100/35/33/45/1:30000000'

   #initialize gmt
   gmt = GMT(config={'BASEMAP_TYPE':'fancy',
                     'HEADER_FONT_SIZE':'14'})
                     #'COLOR_BACKGROUND':'-',  :setting this to '-' plots z are transparent
                     #'COLOR_FOREGROUND':'-'})

   #make colormap
   cptfile = gmt.tempfilename()
   gmt.makecpt(C=colombia,T='-4000/4950/100',Z=True,out_filename=cptfile,D='i')

   #make gradient
   #topo_grad = gmt.tempfilename()
   #gmt.grdgradient(etopo,V=True,A='100',N='e0.8',M=True,G=topo_grad,K=False)

   #plot topography
   gmt.grdimage( etopo,
                 R = region,
                 J = scale,
                 C = cptfile,
                 E = '200')
                 #I = '0.5')#topo_grad)

   #plot coastlines
   gmt.pscoast( R=region,
                J=scale,
                B='a10',
                D='l',
                A='500',
                W='thinnest,black,-',
                N='all')

   #plot stations
   if station_data != 'none':
      gmt.psxy( R=region,
                J=scale,
                B='a10',
                S='t0.1',
                G='red',
                in_rows = station_data )


   if quake_locs != 'none':
      eq_region = 'g'
      eq_scale  = 'E-100/40/2.25i'
      gmt.pscoast( R = eq_region,
                   J = eq_scale,
                   B = 'p',
                   A = '10000',
                   G = 'lightgrey',
                   W = 'thinnest',
                   Y = '3.5i',
                   X = '-0.5i' ) 
      gmt.psxy( R = eq_region,
                J = eq_scale,
                S = 'a0.05',
                G = 'blue',
                in_rows = quake_locs )

   #plot receiver function stack
   if rf_data != 'none':
      rf_region = '-0.20/0.20/0/100'
      rf_scale  = 'X1i/-5i'
      gmt.psxy( R = rf_region,
                J = rf_scale,
                #G = 'grey', #fill
                B = '0.25::/10:time (s):NE',
                W = 'thin',
                X = '9i',
                Y = '-3.5i',
                in_columns = rf_data )

      #plot shaded area for positive values
      vals = rf_data[0]
      time = rf_data[1]
      poly_vals_pos = []
      poly_time_pos = []
      for i in range(0,len(vals)):
         val_here = max(0,np.float(vals[i]))
         poly_time_pos.append(time[i])
         poly_vals_pos.append(val_here)

      poly_vals_pos.append(0.0)
      poly_time_pos.append(time[::-1][0])
      poly_vals_pos.append(0.0)
      poly_time_pos.append(time[0])
      gmt.psxy( R = rf_region,
                J = rf_scale,
                G = 'red',
                B = '0.25::/10:time (s):NE',
                W = 'thin',
                in_columns = (poly_vals_pos,poly_time_pos) )

      #plot shaded area for negative values
      '''
      vals = rf_data[0]
      time = rf_data[1]
      poly_vals_neg = []
      poly_time_neg = []
      for i in range(0,len(vals)):
         val_here = min(0,np.float(vals[i]))
         poly_time_neg.append(time[i])
         poly_vals_neg.append(val_here)

      poly_vals_neg.append(0.0)
      poly_time_neg.append(time[::-1][0])
      poly_vals_neg.append(0.0)
      poly_time_neg.append(time[0])
      gmt.psxy( R = rf_region,
                J = rf_scale,
                G = 'blue',
                B = '0.25::/10:time (s):NE',
                W = 'thin',
                in_columns = (poly_vals_neg,poly_time_neg) )
      '''

   #header_file = open('header_file','w')
   #header_file.write('<< EOF')
   #header_file.close()

   #write header information
   if header != 'none':
      stations_text = header['N_traces'] + ' traces in stack'
      events_text   = header['N_events'] + ' events'
      freq_text     = header['frequency']
      decon_text    = 'deconvolution method : ' + header['decon']

      gmt.pstext( in_rows = [(-96,60,12,0,1,'MC',stations_text)],
                  R = region,
                  J = scale,
                  N = True,
                  X = '-8.5i' )
      gmt.pstext( in_rows = [(-96,59,12,0,1,'MC',events_text)],
                  R = region,
                  J = scale,
                  N = True )
      gmt.pstext( in_rows = [(-96,58,12,0,1,'MC',freq_text)],
                  R = region,
                  J = scale,
                  N = True )
      gmt.pstext( in_rows = [(-96,57,12,0,1,'MC',decon_text)],
                  R = region,
                  J = scale,
                  N = True )

   #save figure
   gmt.save(fname)
Exemplo n.º 4
0
     elat = eval(conf.get('we-profiles','elat'))
     elon = eval(conf.get('we-profiles','elon'))
     anot = eval(conf.get('we-profiles','anot'))
 else:
     print "'direction' has to be either 'ns' or 'we'"
     sys.exit(1)
     
 #maxdist = find_scale(slat,slon,elat,elon)
 gmt = GMT(config={'ANOT_FONT_SIZE':14,'LABEL_FONT_SIZE':14,
                   'ANNOT_OFFSET_SECONDARY':'0.1c',
                   'ANNOT_OFFSET_PRIMARY':'0.1c',
                   'LABEL_OFFSET':'0.1c',
                   'FRAME_PEN':'.5p'})
 #scly = (28.-3.-3.*len(slat))/len(slat)
 cptws = gmt.tempfilename('ws.cpt')
 gmt.makecpt(C='seis',D=True,T='3.0/4.5/0.05',out_filename=cptws)
 gmt.psscale(C=cptws,D='8c/.5c/10c/.2ch',B='a%ff.1:Vs:'%(.5))
 cnt = 1
 for _slat,_slon,_elat,_elon in zip(slat,slon,elat,elon):
     print "plotting profile %d"%cnt
     ndist, nd, values = plot_2d(field,_slat,_slon,_elat,_elon,pdepth,new=True)
     lbl1,lbl2 = anot[cnt-1]
     fstr = cStringIO.StringIO()
     for dist,depth,vs in zip(ndist,nd,values):
         fstr.write("%f %f %f\n"%(dist,depth,vs))
     sclx = 18.*ndist.max()/xscale
     scly = yscale
     scl = 'X%fc/%fc'%(sclx,scly)
     print scl
     rng = '%f/%f/%f/%f'%(ndist.min(),ndist.max(),nd.min(),nd.max())
     grdws = gmt.tempfilename('ws.grd')
Exemplo n.º 5
0
def plot_vtk_slice(vtk_slice,
                   theta_range=[0, 360],
                   depth_range=[0, 2885],
                   **kwargs):
    #--------------------------------------------------------------------------------
    '''
   This will plot a cross section of a .vtk file.  Open the .vtk file in paraview,
   choose a slice, and select 'File -> export data'.  This will save the data as
   a .csv file, which can be plotted with this function.

   args--------------------------------------------------------------------------
   vtk_slice: the .csv file
   theta_range: the range in degrees you wish to plot. 
                dtype=tuple
                default=[0,360] (whole earth)
   depth_range: the range in depth you wish to plot.
                dtype=tuple
                default=[0,2885] (whole mantle)

   kwargs------------------------------------------------------------------------
   cmap = colormap to use
          dtype=string
          default='BlueWhiiteOrangeRed'

   data_range = max and min values to use in colorbar.
                dtype=tuple
                default=[-1.0,1.0]

   csteps = number of divisions in colorbar
            dtype=int
            default=100

   cmap_direction = forward or reverse colormap
                    dtype=string
                    default='i'

   fname = filename
           dtype=string
           default='slice.pdf'

   rotation = number of degrees to rotate figure
            dtype=float
            default=90.0 (i.e., rotate from lat coor to colat based coor)

   contour = True or False
   '''

    #get kwargs-------------------------------------------------------------------
    cmap_dir = '/geo/home/romaguir/utils/colors/'
    cmap = kwargs.get('cmap', 'BlueWhiteOrangeRed')
    cmap = cmap_dir + cmap
    data_range = kwargs.get('data_range', [-0.25, 0.25])
    csteps = kwargs.get('csteps', 100)
    cmap_direction = kwargs.get('cmap_direction', 'i')
    fname = kwargs.get('fname', 'slice.pdf')
    rotation = kwargs.get('rotation', 90.0)
    contour = kwargs.get('contour', True)

    #read csv slice (output of paraview)------------------------------------------
    f = pandas.read_csv(vtk_slice)
    p1 = f['Points:0']
    p2 = f['Points:1']
    p3 = f['Points:2']
    dvp = f['dVp()']

    #transform to polar, earth coordinates----------------------------------------
    r, t = cart2polar(p1, p3)
    r *= 6371.0
    t = np.degrees(t)

    print min(dvp), max(dvp)

    #setup GMT plot---------------------------------------------------------------
    gmt = GMT(config={'BASEMAP_TYPE': 'fancy', 'HEADER_FONT_SIZE': '14'})
    region = '{}/{}/{}/{}'.format(theta_range[0], theta_range[1],
                                  6371.0 - depth_range[1],
                                  6371.0 - depth_range[0])
    surf_region = '{}/{}/{}/{}'.format(theta_range[0] - 2, theta_range[1] + 2,
                                       6371.0 - depth_range[1],
                                       6500.0 - depth_range[0])
    scale = 'P6i'  #Polar, 8 inch radius
    cptfile = gmt.tempfilename()
    grdfile = gmt.tempfilename()

    #gmt.makecpt(C=cmap,T='{}/{}/{}'.format(data_range[0],data_range[1],csteps),Z=False,out_filename=cptfile,D=cmap_direction)
    gmt.makecpt(C=cmap,
                T='-0.25/0.25/0.025',
                A=100,
                out_filename=cptfile,
                D=True)

    gmt.surface(in_columns=[t + rotation, r, dvp],
                G=grdfile,
                I='0.5/25',
                T=0.0,
                R=surf_region,
                out_discard=True)
    '''
   #plot the data----------------------------------------------------------------
   gmt.psxy( R=region,
             J=scale,
             #B='a15f15:"":/200f200:""::."":WSne',
             B='a300f300',
             S='s0.20',
             #G='blue',
             C=cptfile,
             in_columns=[t+rotation,r,dvp] )
   '''
    #plot the data----------------------------------------------------------------
    gmt.grdimage(grdfile, R=region, J=scale, B='a300f300', C=cptfile, E='i5')

    #contour the data-------------------------------------------------------------
    if contour == True:
        gmt.grdcontour(grdfile, R=region, J=scale, C=cptfile, W='1')

    #plot 660---------------------------------------------------------------------
    d660 = np.loadtxt('/geo/home/romaguir/utils/660_polar.dat')
    print d660
    gmt.psxy(R=region, J=scale, W='1', in_rows=[d660])

    gmt.save(fname)