def injection_legend(leg_file): args = {'D': 'x0.1/7.5+w4/2/TC', 'C': '0.1i/0.1i', 'F': '+gwhite+p'} with LibGMT() as lib: file_context = dummy_context(leg_file) with file_context as fname: arg_str = ' '.join([fname, build_arg_string(args)]) lib.call_module('pslegend', arg_str) return
def plot_Nga_scale(): scale_args = {'C': 'cool', 'D': '10.25/13.75/3.5/0.5h', 'B': 'px1+l"Date of occurrence"', 'F': '+gwhite+p1.2k'} with LibGMT() as lib: lib.call_module('psscale', ' '.join([build_arg_string(scale_args), '--FONT_ANNOT_PRIMARY=7p', '--FONT_LABEL=9p'])) return
def plot_date_text(dto): pt = '176.21 -38.515' with open('tmp_text.csv', 'w') as f: f.write('{} @:14:Date: {}@::'.format(pt, dto.strftime('%d-%m-%Y'))) with LibGMT() as lib: file_context = dummy_context('tmp_text.csv') with file_context as fname: lib.call_module('pstext', fname) os.remove('tmp_text.csv') return
def plot_NM5_7_4(): pts5_7 = '/home/chet/gmt/data/NZ/wells/NM05_NM07_pts.gmt' args5_7 = {'D': '0.25/0.15', 'F': '+jCB+f8p,red'} pt4 = '/home/chet/gmt/data/NZ/wells/NM04_pt.gmt' args4 = {'D': '0.35/-0.35'} with LibGMT() as lib: for pts, kwargs in zip([pts5_7, pt4], [args5_7, args4]): file_context = dummy_context(pts) with file_context as fname: arg_str = ' '.join([fname, build_arg_string(kwargs)]) lib.call_module('pstext', arg_str) return
def plot_Nga_section_line(start_pt, end_pt, fig): fig.plot(x=np.asarray([start_pt[0], end_pt[0]]), y=np.asarray([start_pt[1], end_pt[1]]), W='1.0,black,-') labels_file = '/home/chet/gmt/data/NZ/misc/section_labels.txt' with LibGMT() as lib: label_args = {'F': '+f16p,black,-'} file_context = dummy_context(labels_file) with file_context as fname: arg_str = ' '.join([fname, build_arg_string(label_args)]) lib.call_module('pstext', arg_str) return
def plot_fm_depth(catalog, center_pt, end_pt, region, scale, Y, B_list, fig, old_cat): if old_cat: color = 'grey' tmp_file = gmt_project(old_cat, center_pt, end_pt, fm_file='/home/chet/gmt/tmp/tmp_old.psmeca') args = {'S': 'a2.0', 'G': color, 'C': '0.5P0.1', 'J': scale, 'R': '{}/{}/{}/{}'.format(region[0], region[1], region[2], region[3]), 'Y': Y} with LibGMT() as lib: file_context = dummy_context(tmp_file) with file_context as fname: arg_str = ' '.join([fname, build_arg_string(args)]) lib.call_module('psmeca', arg_str) color = 'blue' tmp_filen = gmt_project(catalog, center_pt, end_pt, fm_file='/home/chet/gmt/tmp/tmp.psmeca') args = {'S': 'a2.0', 'G': color, 'C': '0.5P0.1'} with LibGMT() as lib: file_context = dummy_context(tmp_filen) with file_context as fname: arg_str = ' '.join([fname, build_arg_string(args)]) lib.call_module('psmeca', arg_str) fig.basemap(B=B_list) else: color = 'blue' tmp_file = gmt_project(catalog, center_pt, end_pt, fm_file='/home/chet/gmt/tmp/tmp.psmeca') args = {'S': 'a2.0', 'G': color, 'C': '0.5P0.1', 'J': scale, 'R': '{}/{}/{}/{}'.format(region[0], region[1], region[2], region[3]), 'Y': Y} with LibGMT() as lib: file_context = dummy_context(tmp_file) with file_context as fname: arg_str = ' '.join([fname, build_arg_string(args)]) lib.call_module('psmeca', arg_str) fig.basemap(B=B_list) return
def plot_fm_map(catalog, fm_file, color, old_cat=False): # Write temporary outfile for psmeca plotting tmp_file = '/home/chet/gmt/tmp/tmp.psmeca' if old_cat: tmp_file = '/home/chet/gmt/tmp/tmp_old.psmeca' format_arnold_to_gmt(fm_file, catalog, outfile=tmp_file, names=False, id_type='detection') args = {'S': 'a2.0', 'G': color, 'C': '0.5P0.1'} with LibGMT() as lib: file_context = dummy_context(tmp_file) with file_context as fname: arg_str = ' '.join([fname, build_arg_string(args)]) lib.call_module('psmeca', arg_str) return
def plot_SURF_4850L(catalog, wells=True, stations=True, FMs=False): """ Plot wells and events for 4850L :return: """ region = [780, 860, -1350, -1270] with LibGMT() as lib: lib.call_module('gmtset', 'FONT_ANNOT_PRIMARY 10p') lib.call_module('gmtset', 'FORMAT_GEO_MAP ddd.xx') lib.call_module('gmtset', 'MAP_FRAME_TYPE plain') lib.call_module('gmtset', 'PS_MEDIA A3') # Set up figure fig = pygmt.Figure() if wells: plot_4850_wells(fig) if FMs: plot_fm_map(catalog, FMs, color='b') else: x, y, z = zip(*[(float(ev.origins[-1].extra.hmc_east.value), float(ev.origins[-1].extra.hmc_north.value), float(ev.origins[-1].extra.hmc_elev.value)) for ev in catalog]) fig.plot(x=np.array(x), y=np.array(y), size=1.0, style='cc') return
def plot_background_datasets(fig, region): fig.plot(region=region, projection='M13', Y='10', data='/home/chet/gmt/data/NZ/resistivity/RT_Boundary_Risk_2000.gmt', color='lightgray') fig.plot( data='/home/chet/gmt/data/NZ/resistivity/NM_Boundary_Bosely2010.gmt', color='lightgray') # Water fig.plot(data='/home/chet/gmt/data/NZ/water/taupo_lakes.gmt', color='cornflowerblue') fig.plot(data='/home/chet/gmt/data/NZ/water/taupo_river_polygons.gmt', color='cornflowerblue') # Faults fig.plot(data='/home/chet/gmt/data/NZ/faults/NZ_active_faults.gmt', W='0.85') # AFZ label with LibGMT() as lib: label_args = {'F': '+f10p+a50'} file_context = dummy_context('/home/chet/gmt/data/NZ/faults/afz_text.txt') with file_context as fname: arg_str = ' '.join([fname, build_arg_string(label_args)]) lib.call_module('pstext', arg_str) fig.basemap(L='x11.5/1/-38/1', frame=['0.02', 'wsEN']) return
def plot_Nga_static(cat, start_pt=None, end_pt=None, secs=[], mags=[], dto=None, flows=False, show=True, outfile=None, old_cat=None, old_mags=None, old_secs=None, fm_file=None, dd_only=True): """ Main code for plotting Ngatamariki seismicity :param catalog: Catalog of events to plot :param center_pt: Center point for the cross section (tup) :param end_pt: End point for the cross_section (tup) :return: """ # Arg check if outfile: show = False if dd_only: catalog = Catalog(events=[ev for ev in cat if ev.preferred_origin().method_id]) else: catalog = cat # Sort catalog catalog.events.sort(key=lambda x: x.origins[-1].time) # Calculate mid-point of cross_section if not start_pt and not end_pt: start_pt = [176.171, -38.517] end_pt = [176.209, -38.575] c_lon = start_pt[0] + ((end_pt[0] - start_pt[0]) / 2.) c_lat = start_pt[1] + ((end_pt[1] - start_pt[1]) / 2.) if len(secs) == 0 and len(mags) == 0 and len(catalog) > 0: secs, mags = catalog_arrays(catalog) # Scale down mags mags = np.array(mags) * 0.5 # Set prefs with LibGMT() as lib: lib.call_module('gmtset', 'FONT_ANNOT_PRIMARY 10p') lib.call_module('gmtset', 'FORMAT_GEO_MAP ddd.xx') lib.call_module('gmtset', 'MAP_FRAME_TYPE plain') lib.call_module('gmtset', 'PS_MEDIA A3') region = [176.15, 176.23, -38.58, -38.51] # Set up figure fig = gmt.Figure() plot_background_datasets(fig, region=region) if not fm_file: plot_earthquakes_map(catalog, mags, secs, fig, old_cat, old_mags) else: if old_cat: # Old guys plot_fm_map(old_cat, fm_file, color='grey', old_cat=True) # New guys plot_fm_map(catalog, fm_file, color='blue') if dto: plot_Nga_well_map(fig, dto=dto) else: plot_Nga_well_map(fig, dto=None) plot_NM5_7_4() plot_stations(fig) if dto: # pstext the date instead of the color scale plot_date_text(dto) else: plot_Nga_scale() plot_Nga_section_line(start_pt=start_pt, end_pt=end_pt, fig=fig) # Cross section scale = 'X13/-6' B_list = ['px1.0+l"Distance from center of x-section (km)"', 'py1.0+l"Depth (km)"', 'WeSn'] Y = '-7.25' # Set new prefs with LibGMT() as lib: lib.call_module('gmtset', 'FONT_ANNOT_PRIMARY 10p') lib.call_module('gmtset', 'FONT_LABEL 12p') # Eq cross section x_region = [-3.635, 3.635, -1.0, 4.5] if not fm_file: plot_earthquakes_depth(catalog, mags, secs, center_pt=(c_lon, c_lat), end_pt=end_pt, region=x_region, scale=scale, B_list=B_list, Y=Y, fig=fig, old_cat=old_cat, old_mags=old_mags, old_secs=old_secs) else: plot_fm_depth(catalog, center_pt=(c_lon, c_lat), end_pt=end_pt, region=x_region, scale=scale, Y=Y, B_list=B_list, fig=fig, old_cat=old_cat) plot_Nga_well_depth(fig) if flows: plot_injection_rates(fig, dto) if show: fig.show(external=True) elif outfile: fig.savefig(outfile) return
def plot_injection_rates(fig, dto=None, field='North', data='Flow'): """ Plot injection rates on separate axis, as well as time of plot as vertical line for video purposes :return: """ well_dir = '/home/chet/data/mrp_data/well_data/flow_rates/July_2017_final' well_fs = glob('{}/*flow_all.csv'.format(well_dir)) well_whps = glob('{}/*WHP_all.csv'.format(well_dir)) well_fs.sort() colors = cycle(['darkturquoise', 'lightblue', 'darkseagreen', 'lawngreen']) region = '2012T/2016T/0/1300' # Time on x, flow rate on y proj = 'X15/9.7' with LibGMT() as lib: lib.call_module('gmtset', 'FONT_ANNOT_PRIMARY 12p') lib.call_module('gmtset', 'FORMAT_DATE_MAP o') lib.call_module('gmtset', 'FORMAT_TIME_PRIMARY_MAP Character') lib.call_module('gmtset', 'FONT_TITLE 16p') if dto: # Set parameters for animation next to map fig.plot(data=well_fs[1], Y=12, X=16, R=region, projection=proj, W='0.7,{}'.format(next(colors))) fig.plot(data=well_fs[2], W='0.7,{}'.format(next(colors))) plot_date_line(dto, fig) # Legend North injection_legend('/home/chet/gmt/data/NZ/misc/ngaN_legend_flow.txt') fig.basemap(B=['pxa1Y', 'pya100+l"Flow rate (t/h)"', 'SEwn+t"Ngatamariki North"']) fig.plot(data=well_fs[0], Y=-12, R=region, projection=proj, W='0.7,{}'.format(next(colors))) fig.plot(data=well_fs[-1], W='0.7,{}'.format(next(colors))) if dto: plot_date_line(dto, fig) # Legend South injection_legend('/home/chet/gmt/data/NZ/misc/ngaS_legend_flow.txt') fig.basemap(B=['pxa1Y', 'pya100+l"Flow rate (t/h)"', 'wSEn+t"Ngatamariki South"']) else: # Standalone plot of flow rates if data == 'Flow': for f in well_fs: well = f.split('/')[-1].split('_')[0] if well in ['NM08', 'NM09'] and field == 'North': fig.plot(data=f, R=region, projection=proj, W='0.7,{}'.format(next(colors))) elif well in ['NM06', 'NM10'] and field == 'South': fig.plot(data=f, R=region, projection=proj, W='0.7,{}'.format(next(colors))) fig.basemap(B=['pxa1Y', 'pya100+l"Flow rate (t/h)"', 'SEwn+t"Ngatamariki {}"'.format(field)]) elif data == 'WHP': for f in well_whps: region = '2012T/2016T/0/35' # Time on x, WHP on y well = f.split('/')[-1].split('_')[0] if well in ['NM08', 'NM09'] and field == 'North': fig.plot(data=f, R=region, projection=proj, W='0.7,{}'.format(next(colors))) elif well in ['NM06', 'NM10'] and field == 'South': fig.plot(data=f, R=region, projection=proj, W='0.7,{}'.format(next(colors))) fig.basemap(B=['pxa1Y', 'pya5+l"WHP (barg)"', 'syf1', 'WSen+t"Ngatamariki {}"'.format(field)], R=region) return