def plot_hor_mag(gplt): text = gen_codisp_hor_mag_file() gmt = pGMT.GMT() gmt.nearneighbor(text.name, G='~ver.grd', I='1k', N='8', R='', S='60k') gmt = pGMT.GMT() gmt.makecpt(C='seminf-haxby.cpt', T='-3/.6/0.1', Q='', M='') gmt.save_stdout('~hor_mag.cpt') gplt.grdimage('~ver.grd', J='', R='', C='~hor_mag.cpt', O='', K='') text.close() # fill water with white color gplt.pscoast(R='', J='', S='white', O='', K='')
def plot_slip_contour( self, contours=[5, 10, 20, 40, 60], W='thickest', ): _txt = '' for ii in contours: _txt += '%f A\n' % ii with tempfile.NamedTemporaryFile('w+t') as fid: fid.write(_txt) fid.seek(0, 0) gmt = pGMT.GMT() self.gplt.grdcontour( self.slip_file_grd_cutted, C=fid.name, A='1+f9+um', G='n1/.5c', J='', R='', O='', K='', W=W, )
def plot(self): self._get_info_from_fault_file_and_result_file() self.gmt = gmt = pGMT.GMT() self.gplt = gplt = gmt.gplt gmt.gmtset('ANNOT_FONT_SIZE_PRIMARY','6', 'LABEL_FONT_SIZE','6', 'FONT_ANNOT_PRIMARY','4', 'MAP_FRAME_TYPE','plain', 'MAP_FRAME_PEN','thinner,black', 'PS_MEDIA','letter', 'MAP_TICK_LENGTH_PRIMARY','.05', 'MAP_ANNOT_OFFSET_PRIMARY','.05') self._plot_coseismic_slip() # plot afterslip: self._num_of_subplots_in_a_row = 1 for nth, si in enumerate(self.slip[1:,:,:],1): offset_X, offset_Y = self._next_offset() _plt = self._plot_afterslip_at_nth_epoch( nth = nth, offset_X = offset_X, offset_Y = offset_Y ) if nth ==1: _plt.add_psscale( gridline_interval = self.color_label_interval_aslip)
def plot_vertical_coseismic_disp(gplt): text = gen_coseismic_vertical_file() gmt = pGMT.GMT() gmt.nearneighbor(text.name, G='~ver.grd', I='1k', N='8', R='', S='60k') gplt.grdimage('~ver.grd', J='', R='', C='vertical_disp.cpt', O='', K='') text.close() # fill water with white color gplt.pscoast(R='', J='', S='white', O='', K='')
def _trench_cut_slip_grd(self, grd_in, grd_out): gmt = pGMT.GMT() file_mask = join(self._workdir, 'trench_cut_mask.grd') gmt.grdmask(file_kur_top, G=file_mask, A='', N='1/1/NaN', I=self.I, R='') gmt.grdmath(grd_in, file_mask, 'OR', '= ', grd_out)
def plot_etopo1(gplt, A='-70/20', file_topo_cpt=topo_cpts['afrikakarte']): gmt = pGMT.GMT() file_topo_cut = tempfile.NamedTemporaryFile() gmt.grdcut(file_etopo1, G=file_topo_cut.name, R='') gmt = pGMT.GMT() file_topo_grad = tempfile.NamedTemporaryFile() gmt.grdgradient(file_topo_cut.name, G=file_topo_grad.name, A=A, R='') gplt.grdimage(file_topo_cut.name, J='', C=file_topo_cpt, I=file_topo_grad.name, O='', K='') # close temporary files: file_topo_cut.close() file_topo_grad.close()
def init(self): self.gmt = pGMT.GMT() self.gplt = self.gmt.gplt self.gmt.gmtset('ANNOT_FONT_SIZE_PRIMARY', '10', 'LABEL_FONT_SIZE', '6', 'FONT_ANNOT_PRIMARY', '10', 'MAP_FRAME_TYPE', 'plain', 'MAP_FRAME_PEN', 'thinner,black', 'PS_MEDIA', 'letter', 'MAP_TICK_LENGTH_PRIMARY', '.05', 'MAP_ANNOT_OFFSET_PRIMARY', '.05') self._make_cpt_file()
def _interpolate_slip_file(self, out_grd): make_basename_dir(out_grd) gmt = pGMT.GMT() gmt.nearneighbor(self.slip_file_txt, G='"%s"' % out_grd, I=self.I, N='8', R='', S='40k') gmt.grdfilter(out_grd, G=out_grd, D='4', F='c25')
def test(self): gmt = pGMT.GMT() gmt.gplt.psbasemap( R='5/15/52/58', # region J='B10/55/55/60/10c', # projection B='4g4', K='') gmt.gplt.pscoast(R='', J='', D='f', W='thinnest', O='') gmt.save(join(self.outs_dir, 'out.pdf')) gmt.save_shell_script(join(self.outs_dir, 'shell.sh'), output_file='>out.ps')
def _prepare_intensity_file(self): self.intensity_file = join(self._workdir, 'intensity.grd') self._cutted_topo = join(self._workdir, 'cutted_topo.grd') _intensity_file_before_resample = join( self._workdir, '~intensity_before_resample.grd') gmt = pGMT.GMT() gmt.grdcut(self.topo_file, G=self._cutted_topo, R='') gmt.grdgradient(self._cutted_topo, G=_intensity_file_before_resample, A=self.A, R='') gmt.grdsample(_intensity_file_before_resample, G=self.intensity_file, I=self.I)
def plot( infile, outfile, if_log_color_scale, cpt_scale, contours, scale_interval, ): gmt = pGMT.GMT() gmt.gmtset('ANNOT_FONT_SIZE_PRIMARY', '9', 'LABEL_FONT_SIZE', '9', 'COLOR_NAN', 'white', 'COLOR_BACKGROUND', 'white', 'COLOR_FOREGROUND', 'white') gmt.gplt.psbasemap( R='128/148/30/46', # region J='B138/38/30/46/16c', # projection B='4', U='20/0/25/Yang', P='', K='') plt_ver = vj.gmt.GMTXYZ( gmt, infile, cpt_scale=cpt_scale, if_log_color_scale=if_log_color_scale, ) plt_ver.plot_xyz() plt_ver.plot_scale(scale_interval='1') plt_ver.plot_contour(contours=contours, W='thick') vj.gmt.plot_plate_boundary(gmt.gplt, color='150') gmt.gplt.pscoast(R='', J='', D='h', N='a/faint,50,--', W='faint,100', L='f145/31/38/200+lkm+jt', O='', K='') vj.gmt.plot_Tohoku_focal_mechanism(gmt.gplt, K=None) gmt.save(outfile) gmt.gplt.save_shell_script('shell.sh', output_file=' > out.ps')
def _prepare_cpt_file(self, original_cpt_file='no_green', if_cpt_reverse=False): self.cpt_file = join(self._workdir, 'slip.cpt') gmt = pGMT.GMT() if if_cpt_reverse: I = '' else: I = None gmt.grd2cpt( self.slip_file_grd, #C='temperature.cpt', C=original_cpt_file, Z='', I=I, ) gmt.save_stdout(self.cpt_file)
def plot_stations_map(self): gmt = pGMT.GMT() gmt.gmtset('ANNOT_FONT_SIZE_PRIMARY', '9', 'LABEL_FONT_SIZE', '9', 'FONT_ANNOT_PRIMARY', '6', 'MAP_FRAME_TYPE', 'plain') gplt = gmt.gplt gplt.psbasemap( R='125/146/30/46', # region JB='135.5/38.5/35/41.5/16c', # projection B='5', U='18/25/0', P='', K='', ) gplt.pscoast(R='', J='', D='h', N='a/faint,150,-.', W='faint,dimgray', A='500', L='144/32/38/200+lkm+jt', O='', K='') plot_stations( gplt, self.sites, S='s.2', color='red', fill_color='red', fontcolor='blue', fontsize='8', text_offset_X=0, text_offset_Y=0, ) plot_focal_mechanism_JMA(gplt, scale=.2, fontsize=0) gplt.finish() gmt.save(self.file_sites_map)
from os.path import join import numpy as np import tempfile import pGMT import viscojapan as vj gmt = pGMT.GMT() gmt.gmtset( 'ANNOT_FONT_SIZE_PRIMARY', '9', 'LABEL_FONT_SIZE', '9', 'BASEMAP_TYPE', 'PLAIN', ) gplt = gmt.gplt lon1 = 131.5 lon2 = 135.7 lat1 = 33 lat2 = 35.8 gplt.psbasemap( R='{lon1}/{lon2}/{lat1}/{lat2}'.format(lon1=lon1, lon2=lon2, lat1=lat1, lat2=lat2), # region J='B{lon0}/{lat0}/{lat1}/{lat2}/18c'.format(lon0=(lon1 + lon2) / 2.,
def __init__(self): self.gmt = pGMT.GMT() self.gplt = self.gmt.gplt
def plot( disp_file1, disp_file2, outf, leg1='', leg2='', color1='black', color2='red', ): gmt = pGMT.GMT() gmt.gmtset( 'ANNOT_FONT_SIZE_PRIMARY', '9', 'LABEL_FONT_SIZE', '9', 'BASEMAP_TYPE', 'PLAIN', ) gplt = gmt.gplt lon1 = 133.5 lon2 = 135.1 lat1 = 34.5 lat2 = 35.5 gplt.psbasemap( R='{lon1}/{lon2}/{lat1}/{lat2}'.format(lon1=lon1, lon2=lon2, lat1=lat1, lat2=lat2), # region J='B{lon0}/{lat0}/{lat1}/{lat2}/18c'.format(lon0=(lon1 + lon2) / 2., lat0=(lat1 + lat2) / 2., lat1=lat1, lat2=lat2), # projection B='.5', U='20/0/22/Yang', K='') gplt.pscoast(R='', J='', D='h', N='a/faint,50,--', A='500', G='lightblue2', O='', K='') scale = 27 # plot disp file1 plt_vec = vj.gmt.VecFieldPlotter(gmt, disp_file1, scale, color1) plt_vec.plot_vectors(arrow_width='.2', head_length='.1', head_width='.1', pen_width='1.2') plt_vec.plot_vec_legend( lon=135, lat=33.4, leg_len=0.05, leg_txt=leg1, text_offset_lon=0, text_offset_lat=-0.06, ) # plot disp file2 plt_vec = vj.gmt.VecFieldPlotter(gmt, disp_file2, scale, color2) plt_vec.plot_vectors(arrow_width='.2', head_length='.1', head_width='.1', pen_width='1.2') plt_vec.plot_vec_legend( lon=135, lat=33.2, leg_len=0.05, leg_txt=leg2, text_offset_lon=0, text_offset_lat=-0.06, ) gplt.pscoast(R='', J='', D='h', N='a/faint,50,--', A='500', W='faint,100', L='f144/35.4/38/100+lkm+jt', O='', K='') #plot_horizontal_coseismic_vector(gplt) vj.gmt.plot_focal_mechanism_JMA(gplt) gplt.finish() gmt.save(outf)
def _land_cut_slip_grd(self, grd_in, grd_out): gmt = pGMT.GMT() file_mask = join(self._workdir, 'land_mask.grd') gmt.grdlandmask(R='', Dh='', I=self.I, N='1/NaN', G=file_mask) gmt.grdmath(grd_in, file_mask, 'OR', '= ', grd_out)
def plot( self, lons, lats, mags, output_file, contours=[0.001, 0.0026, 0.005, 0.01, 0.1, 0.2], if_topo=True, unit_label='m', title='', ): gmt = pGMT.GMT() gmt.gmtset('ANNOT_FONT_SIZE_PRIMARY', '9', 'LABEL_FONT_SIZE', '9', 'FONT_ANNOT_PRIMARY', '6', 'MAP_FRAME_TYPE', 'plain') gplt = gmt.gplt north = 60 south = 12 east = 190 west = 100 gplt.psbasemap( R = '{west}/{east}/{south}/{north}'.format( west = west, east = east, south = south, north = north), # region JD = '{lon0}/{lat0}/{lat1}/{lat2}/{wid}'\ .format(lon0 = vj.TOHOKU_EPICENTER[0], lat0 = vj.TOHOKU_EPICENTER[1], lat1 = south, lat2 = north, wid = '9i', ), # projection B = '20:."%s":'%title, U='18/25/0', K = '') # topo if if_topo: vj.gmt.plot_etopo1(gplt) with tempfile.NamedTemporaryFile('w+t') as fid: self._write_to_temp_file(fid, lons, lats, mags) pltxyz = vj.gmt.GMTXYZ( gmt, file_xyz=fid.name, if_log_color_scale=True, cpt_scale='-3.1/0.6/0.001', interp_inc='40k', interp_searching_radius='10', ) #pltxyz.maskout_water(A='1000k',D='h') #pltxyz.plot_xyz() pltxyz.plot_contour( contours=contours, W='thick,red', label_line= 'L142.37/38.30/80/60,142.37/38.30/90/20,142.37/38.30/-160/40,158/38.30/180/5', label_font_size=8, smooth_factor=100, unit_label=unit_label, ) #pltxyz.plot_scale(x=15, y=8) # plot coast gplt.pscoast(R='', J='', D='h', N='a/faint,100,-.', W='faint,50', A='5000', Lf='180/15/35/500+lkm+jt', K='', O='') # plot plate boundary vj.gmt.plot_plate_boundary(gplt, color='100') vj.gmt.plot_focal_mechanism_JMA(gplt, scale=0.2, fontsize=0) gplt.finish() gmt.save(output_file)
def _low_cut_slip_grd(self, grd_in, grd_out): gmt = pGMT.GMT() gmt.grdclip(grd_in, G=grd_out, Sb='%f/NaN' % self.low_cut_value)