Example #1
0
 def make_locations(self):
     oc = self.out_config
     icd = self.in_config.get_config()
     ocd = self.out_config.__dict__
     
     
     if self.seismosizer:
         rlat, rlon, rtime = self.seismosizer.source_location
         if 'north_shift' in ocd:
             cnorth = oc.north_shift
         elif 'north_shift' in icd:
             cnorth = icd['north_shift']
         else:
             cnorth = 0.
             
         if 'east_shift' in ocd:
             ceast = oc.east_shift
         elif 'east_shift' in icd:
             ceast = icd['east_shift']
         else:
             ceast = 0.
             
         if 'time' in ocd:
             ctime = oc.time
         elif 'time' in icd:
             ctime = icd['time']
         else:
             ctime = 0.
             
         clat, clon = orthodrome.ne_to_latlon( rlat, rlon, cnorth, ceast )
 
         oc.centroid_latitude = clat
         oc.centroid_longitude = clon
         oc.centroid_time = self.ref_time + ctime
         oc.reference_time = self.ref_time
Example #2
0
 def make_alternative_stats(self):
     oc = self.out_config
     c = self.out_config.__dict__
     
     if 'moment_stats' in c:
         oc.magnitude_stats = oc.moment_stats.converted('magnitude', moment_tensor.moment_to_magnitude)
         
     if ('north_shift_stats' in c) and ('east_shift_stats' in c):
         
         rlat, rlon, rtime = self.seismosizer.source_location
         cnorth, ceast =  oc.north_shift_stats.best, oc.east_shift_stats.best
         clat, clon = orthodrome.ne_to_latlon( rlat, rlon, cnorth, ceast )
         
         approx_lat = lambda north: clat + (north-cnorth) * 180. / (config.earthradius*math.pi)
         approx_lon = lambda east: clon + (east-ceast) * 180. / (config.earthradius*math.pi*math.cos(clat*math.pi/180.))
         
         oc.latitude_stats = oc.north_shift_stats.converted( 'latitude', approx_lat )
         oc.longitude_stats = oc.east_shift_stats.converted( 'longitude', approx_lon )
Example #3
0
def draw_rupture(gmt, widget, source_infos, axes, view='rupture-plane', source_loc=None, outer_scaler=None, with_centroids=True):
    
    conf = dict(**config.rupture_vis_config)
    
    symbol_nucleation_point = conf.pop('symbol_nucleation_point')
    rupture_cpt = conf.pop('rupture_cpt')

    if 'outline' not in source_infos: raise NoOutlineFound()
     
    sec_outline = source_infos['outline']
    
    if (num.all(sec_outline[1][:,0] == sec_outline[1][0,0]) and
        num.all(sec_outline[1][:,1] == sec_outline[1][0,1]) and
        num.all(sec_outline[1][:,2] == sec_outline[1][0,2])):
        raise NoOutlineFound()
    
    if view == 'rupture-plane':
        outline = sec_outline[1][:,3], sec_outline[1][:,4]
    elif view == 'from-top':
        lats, lons = orthodrome.ne_to_latlon(source_loc[0],source_loc[1], sec_outline[1][:,0], sec_outline[1][:,1])
        outline = (lons,lats)
        
    eigrid = source_infos['eikonal-grid'][1].transpose()
    eigrid_valid = num.compress(eigrid[5,:] >= 0., eigrid, axis=1)
    if view == 'rupture-plane':
        ruptime = eigrid_valid[3:6,:]
    elif view == 'from-top':
        lats, lons = orthodrome.ne_to_latlon(source_loc[0],source_loc[1], eigrid_valid[0], eigrid_valid[1])
        ruptime = (lons, lats, eigrid_valid[5])

    eigrid_valid_d = num.compress(eigrid[2,:] > 0., eigrid, axis=1)
    depth = eigrid_valid_d[2,:]
    depth1 = (-(depth-num.min(depth))/(num.max(depth)-num.min(depth))*2.+1.)*0.8
    if view == 'rupture-plane':
        rupdepth = (eigrid_valid_d[3,:],eigrid_valid_d[4,:],depth1)
    elif view == 'from-top':
        lats, lons = orthodrome.ne_to_latlon(source_loc[0],source_loc[1], eigrid_valid_d[0],eigrid_valid_d[1])
        rupdepth = (lons,lats,depth1)
    
    nucleation_point = None
    if 'nucleation-point' in source_infos:
        nucl = source_infos['nucleation-point'][1][0]
        if view == 'rupture-plane':
            nucleation_point = (nucl[3],nucl[4])
        elif view == 'from-top':
            lat, lon = orthodrome.ne_to_latlon(source_loc[0],source_loc[1], nucl[0],nucl[1])
            nucleation_point = (lon,lat)
        
    zax = gmtpy.Ax(snap=True, label='Time', unit='s')

    scaler = gmtpy.ScaleGuru( [ outline, ruptime ], axes=(axes[0],axes[1],zax), aspect=widget.height()/widget.width() )
    grdfile = gmt.tempfilename()
    grdfile_extra = gmt.tempfilename()
    igrdfile = gmt.tempfilename()
    cptfile = gmt.tempfilename()
    
    if outer_scaler is not None:
        R = outer_scaler.R()
    else:
        R = scaler.R()
    
    if outer_scaler is None: outer_scaler = scaler
    par = outer_scaler.get_params()
    inc_interpol = ((par['xmax']-par['xmin'])/(widget.width()/gmtpy.inch*150.),
                    (par['ymax']-par['ymin'])/(widget.height()/gmtpy.inch*150.))
    inc_interpol_extra = ((par['xmax']-par['xmin'])/(widget.width()/gmtpy.inch*20.),
                          (par['ymax']-par['ymin'])/(widget.height()/gmtpy.inch*20.))
    
    rxyj = R + widget.XYJ()
        
    dark_color = '%g/%g/%g' % gmtpy.tango_colors['aluminium6']
    gmt.makecpt( I=True, C=rupture_cpt, Z=True, out_filename=cptfile, *scaler.T())
    if len(ruptime[0]) > 4:
        gmt.triangulate(in_columns=ruptime, G=grdfile, I=inc_interpol, out_discard=True, *R )
        gmt.surface(in_columns=ruptime, G=grdfile_extra, I=inc_interpol_extra, T=0.3, out_discard=True, *R )
        #gmt.triangulate(in_columns=ruptime, G=grdfile_extra, I=inc_interpol_extra, out_discard=True, *R )
        gmt.surface(in_columns=rupdepth, G=igrdfile, I=inc_interpol_extra, T=0.3, out_discard=True, *R )
        gmt.psclip( in_columns=outline, *rxyj )
        gmt.grdimage( grdfile_extra, I=igrdfile, C=cptfile, *rxyj)
        if with_centroids:
            gmt.psxy( in_columns=(ruptime[0],ruptime[1]), S='c3p', G=dark_color, *rxyj)
        gmt.grdcontour( grdfile, W='1p,%s' % dark_color, G='d5c', A='%g+g%s+kwhite+us+o' % (scaler.get_params()['zinc'], dark_color), *rxyj )
        gmt.psclip( C=True, *widget.XY() )
        gmt.psxy( in_columns=outline,  L=True, W='1p,%s' % dark_color, *rxyj )
        
    if nucleation_point:
        gmt.psxy( in_rows=[nucleation_point], *(symbol_nucleation_point+rxyj))
    return scaler, cptfile
Example #4
0
def location_map( filename, lat, lon, lat_delta, conf_overrides, source=None, 
                source_model_infos=None, receivers=None, 
                with_palette=False, shakemap_data=None, shakemap_range=None, shakemap_cpt=None, show_topo=True):

    conf = dict(**config.location_map_config)
    conf.update( conf_overrides )
    
    w = conf.pop('width')
    h = conf.pop('height')
    margins = conf.pop('margins')
        
    d2r = math.pi/180.0
    if source:
        slat, slon = lat, lon
        lat, lon = orthodrome.ne_to_latlon(lat,lon, source['north-shift'], source['east-shift'])
    
    south = lat - 0.5*lat_delta
    north = lat + 0.5*lat_delta
    if lat_delta > 20. or south < -80. or north > 80.:
        resolution = 5
        coastline_resolution = 'i'
        rivers=[]
    else:
        resolution = 1
        coastline_resolution = 'f'
        rivers = ['-Ir',]
        
    lon_delta = lat_delta/math.cos(lat*d2r)
    
    delta = lat_delta/360.*config.earthradius*2.*math.pi
    scale_km = gmtpy.nice_value(delta/10.)/1000.
    
    west = lon - 0.5*lon_delta
    east = lon + 0.5*lon_delta
    
    x,y,z = (west, east), (south,north), (-6000.,4500.)
    xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
    yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
    zax = gmtpy.Ax(mode='min-max', inc=1000., label='Height', scaled_unit='km', scaled_unit_factor=0.001)
    scaler = gmtpy.ScaleGuru( data_tuples=[(x,y,z)], axes=(xax,yax,zax))
    
    curcfg = {'TICK_PEN': '1.25p',
                                'TICK_LENGTH': '0.2c',
                                'ANNOT_FONT_PRIMARY': '1',
                                'ANNOT_FONT_SIZE_PRIMARY': '14p',
                                'LABEL_FONT': '1',
                                'LABEL_FONT_SIZE': '14p',
                                'CHAR_ENCODING': 'ISOLatin1+',
                                'D_FORMAT': '%.1f',
                                'PLOT_DEGREE_FORMAT':'DF',
                                'PAPER_MEDIA':'Custom_%ix%i' % (w,h),
                                'GRID_PEN_PRIMARY': 'thinnest/0/0/0' }
    
    #degree_format = 'dddF'
    #if scaler.get_params()['xinc'] < 1. or scaler.get_params()['yinc'] < 1.:
    #    degree_format = 'ddd:mmF'
        
    gmt = gmtpy.GMT( config=curcfg )
    
    if with_palette:
        layout = gmt.default_layout(with_palette=True)
        layout.set_fixed_margins(*margins)
        widget = layout.get_widget().get_widget(0,0)
        palette_layout = gmtpy.FrameLayout()
        palette_layout.set_policy( *layout.get_widget().get_widget(2,0).get_policy() )
        layout.get_widget().set_widget(2,0,palette_layout)
        inset = h-margins[2]-margins[3]
        palette_layout.set_fixed_margins(0.,0.,inset/6., inset/6.)
        palette_widget = palette_layout.get_widget()
    else:
        layout = gmt.default_layout()
        layout.set_fixed_margins(*margins)
        widget = layout.get_widget()
        
    widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
    aspect = gmtpy.aspect_for_projection( *(widget.J() + scaler.R()) )
    widget.set_aspect(aspect)
    
    if show_topo:
        cptfile = draw_topo(gmt, widget.JXY(), (west,east,south,north), resolution, coastline_resolution, rivers, conf)
    
    zscaler = scaler
    if shakemap_data is not None:
        cptfile, zscaler = draw_shakemap( gmt, widget, scaler, (xax,yax,zax), 
                shakemap_range, shakemap_cpt, *shakemap_data)
        draw_coastlines(gmt, widget.JXY(), (west,east,south,north),  coastline_resolution, rivers)
    
    if source_model_infos and source:
        try:
            draw_rupture(gmt, widget, source_model_infos, axes=(xax,yax,zax), view='from-top', source_loc=(slat,slon), outer_scaler=scaler, with_centroids=False)
        except NoOutlineFound:
            gmt.psxy( in_rows=[[lon,lat]], S='c20p', W='2p,0/0/0',  *(widget.JXY()+scaler.R()))
    
    else:
        if source and 'strike' in source.keys() and 'dip' in source.keys() and 'slip-rake' in source.keys():
            gmt.psmeca( in_rows=[[lon, lat, 1., source['strike'], source['dip'], source['slip-rake'], 6., 0.,0., '' ]],
                     S='a0.3', *(widget.JXY()+scaler.R()) )
        else:
            gmt.psxy( in_rows=[[lon,lat]], S='c20p', W='2p,0/0/0',  *(widget.JXY()+scaler.R()))
    
    if receivers:
        rlats, rlons, rnames = receivers
        gmt.psxy( in_columns=(rlons, rlats), S='t12p', W='1p,black', G='red', *(widget.JXY()+scaler.R()))
        
        nr = len(rnames)
        size = [7]*nr
        angle = [0]*nr
        fontno = [1]*nr
        justify = ['MC']*nr
        gmt.pstext( in_columns=(rlons,rlats,size,angle,fontno,justify,rnames), D=(0.,-0.1), *(widget.JXY()+scaler.R()))
        
    if lat > 0:
        axes_layout = 'WSen'
    else:
        axes_layout = 'WseN'
        
    gmt.psbasemap( B=('%(xinc)gg%(xinc)g:%(xlabel)s:/%(yinc)gg%(yinc)g:%(ylabel)s:' % scaler.get_params())+axes_layout,
                   L=('x%gp/%gp/%g/%g/%gk' % (widget.width()/2., widget.height()/7.,lon,lat,scale_km) ),
                   *(widget.JXY()+scaler.R()) )
                   
    if with_palette and (show_topo or shakemap_data is not None):
        gmtpy.nice_palette(gmt, palette_widget, zscaler, cptfile, innerticks=False, zlabeloffset=1.5*gmtpy.cm)
    gmt.save(filename)