def top_template(): t0 = time() twd = os.path.join(gmt_temp, "top") os.makedirs(twd) t = gmt.GMTPlot("%s/top.ps" % (twd)) gmt.gmt_defaults(wd=twd, ps_media="Custom_%six%si" % (PAGE_WIDTH, PAGE_HEIGHT)) t.spacial( "M", ll_region, sizing=map_width, x_shift=MARGIN_LEFT, y_shift=MARGIN_BOTTOM ) # locations in NZ if ll_region[1] - ll_region[0] > 3: t.sites(gmt.sites_major) else: t.sites(list(gmt.sites.keys())) t.coastlines() # simulation domain t.path(cnr_str, is_file=False, split="-", close=True, width="0.4p", colour="black") # fault path if args.srf is not None: t.fault(args.srf, is_srf=True, plane_width=0.5, top_width=1, hyp_width=0.5) # ticks on top otherwise parts of map border may be drawn over major, minor = gmt.auto_tick(ll_region[0], ll_region[1], map_width) t.ticks(major=major, minor=minor, sides="ws") # render t.finalise() t.png(dpi=args.dpi, clip=False, out_dir=gmt_temp) rmtree(twd) print("top template completed in %.2fs" % (time() - t0))
def test_fill(pf): p = gmt.GMTPlot(pf) gmt.gmt_defaults(wd=os.path.dirname(pf), ps_media='A5') p.background(1.5, 1) p.background(3, 2, x_margin=1.5, colour='blue') p.background(1.5, 1, y_margin=1, colour='red') p.background(3, 2, x_margin=4.5, colour='firebrick') p.finalise() p.png(dpi=100, clip=False)
0, cpt_depth_max, 0.1, invert=True, ) gmt.makecpt( "bilbao", "%s/depth2.cpt" % (gmt_tmp), 0, cpt_depth_max, 0.1, invert=False, bg="white", fg="77/0/1", ) gmt.gmt_defaults(wd=gmt_tmp) # gap on left of maps gap = 1 # width of the region map, if changed, other things also need updating # including tick font size and or tick increment for that map full_width = 4 ### PART A: zoomed in map p = gmt.GMTPlot( "%s/%s_map.ps" % (gmt_tmp, os.path.splitext(os.path.basename(args.srf_file))[0])) # this is how high the region map will end up being full_height = gmt.mapproject( region_corners[0], region_corners[3], region=region_corners,
def render_slice(n): t0 = time() # process working directory swd = "%s/ts%.4d" % (gmt_temp, n) os.makedirs(swd) s = gmt.GMTPlot("%s/ts%.4d.ps" % (swd, n), reset=False) gmt.gmt_defaults(wd=swd, ps_media="Custom_%six%si" % (PAGE_WIDTH, PAGE_HEIGHT)) s.spacial( "M", ll_region, sizing=map_width, x_shift=MARGIN_LEFT, y_shift=MARGIN_BOTTOM ) # timestamp text s.text( ll_region[1], ll_region[3], "t=%.2fs" % (n * xyts.dt), align="RB", size="14p", dy=0.1, ) # overlay if args.xyts2 is None: xyts.tslice_get(n, comp=-1, outfile="%s/ts.bin" % (swd)) else: x1 = xyts.tslice_get(n, comp=-1) x2 = xyts2.tslice_get(n, comp=-1) x2[:, 2] -= x1[:, 2] x2.astype(np.float32).tofile(os.path.join(swd, "ts.bin")) s.clip(cnr_str, is_file=False) if args.land_crop: s.clip(gmt.regional_resource("NZ", resource="coastline"), is_file=True) gmt.table2grd( os.path.join(swd, "ts.bin"), os.path.join(swd, "ts.grd"), dx=grd_dxy, wd=swd, climit=convergence_limit, ) s.overlay( os.path.join(swd, "ts.grd"), cpt_file, dx=grd_dxy, dy=grd_dxy, min_v=lowcut, max_v=highcut, contours=cpt_inc, ) s.clip() # add seismograms if wanted if args.seis is not None: # TODO: if used again, look into storing params inside seismo file s.seismo(os.path.abspath(args.seis), n, fmt="time", colour="red", width="1p") # create PNG s.finalise() s.png(dpi=args.dpi, clip=False, out_dir=png_dir) # cleanup rmtree(swd) print("timeslice %.4d completed in %.2fs" % (n, time() - t0))
def bottom_template(): t0 = time() bwd = os.path.join(gmt_temp, "bottom") os.makedirs(bwd) b = gmt.GMTPlot("%s/bottom.ps" % (bwd)) gmt.gmt_defaults(wd=bwd, ps_media="Custom_%six%si" % (PAGE_WIDTH, PAGE_HEIGHT)) if args.borders: b.background(PAGE_WIDTH, PAGE_HEIGHT, colour="white") else: b.spacial("M", borderless_region, sizing=map_width_a) # topo, water, overlay cpt scale b.basemap(land="lightgray", topo_cpt="grey1", resource_region=region_code) # map margins are semi-transparent b.background( map_width_a, map_height_a, colour="white@25", spacial=True, window=(MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, MARGIN_BOTTOM), ) # leave space for left tickmarks and bottom colour scale b.spacial( "M", ll_region, sizing=map_width, x_shift=MARGIN_LEFT, y_shift=MARGIN_BOTTOM ) if args.borders: # topo, water, overlay cpt scale b.basemap(land="lightgray", topo_cpt="grey1", resource_region=region_code) # title, fault model and velocity model subtitles b.text(sum(ll_region[:2]) / 2.0, ll_region[3], args.title, size=20, dy=0.6) b.text(ll_region[0], ll_region[3], args.subtitle1, size=14, align="LB", dy=0.3) b.text( ll_region[0], ll_region[3], args.subtitle2.replace("<HH>", str(xyts.hh)), size=14, align="LB", dy=0.1, ) # cpt scale b.cpt_scale( "R", "B", cpt_file, cpt_inc, cpt_inc, label=args.legend, length=map_height, horiz=False, pos="rel_out", align="LB", thickness=0.3, dx=0.3, arrow_f=cpt_max > 0, arrow_b=cpt_min < 0, ) # stations - split into real and virtual if args.stations is not None: with open(args.stations, "r") as sf: stations = sf.readlines() stations_real = [] stations_virtual = [] for stat in stations: if len(stat.split()[-1]) == 7: stations_virtual.append(stat) else: stations_real.append(stat) b.points( "".join(stations_real), is_file=False, shape="t", size=0.08, fill=None, line="white", line_thickness=0.8, ) b.points( "".join(stations_virtual), is_file=False, shape="c", size=0.02, fill="black", line=None, ) # render b.finalise() b.png(dpi=args.dpi, clip=False, out_dir=gmt_temp) rmtree(bwd) print("bottom template completed in %.2fs" % (time() - t0))
def template_gs(window_conf, path_conf): """ Create the common background plot. """ gs_file = "%s/template.ps" % (path_conf["gmt_temp"]) p = gmt.GMTPlot(gs_file) gmt.gmt_defaults( wd=path_conf["gmt_temp"], ps_media="Custom_%six%si" % (window_conf["page_width"], window_conf["page_height"]), ) if window_conf["borders"]: p.background( window_conf["page_width"], window_conf["page_height"], colour="white" ) else: # extend map to cover margins map_width_a, map_height_a, borderless_region = gmt.fill_margins( window_conf["ll_region"], window_conf["map_width"], window_conf["dpi"], left=MARGIN_LEFT, right=MARGIN_RIGHT, top=MARGIN_TOP, bottom=MARGIN_BOTTOM, ) p.spacial("M", borderless_region, sizing=map_width_a) # topo, water, overlay cpt scale p.basemap(land="lightgray", topo_cpt="grey1", scale=window_conf["downscale"]) # map margins are semi-transparent p.background( map_width_a, map_height_a, colour="white@25", spacial=True, window=(MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, MARGIN_BOTTOM), ) # leave space for left tickmarks and bottom colour scale p.spacial( "M", window_conf["ll_region"], sizing=window_conf["map_width"], x_shift=MARGIN_LEFT, y_shift=MARGIN_BOTTOM, ) if window_conf["borders"]: # topo, water, overlay cpt scale p.basemap(land="lightgray", topo_cpt="grey1", scale=window_conf["downscale"]) # title, fault model and velocity model subtitles p.text( sum(window_conf["ll_region"][:2]) / 2.0, window_conf["ll_region"][3], "Velocity Model", size=20, dy=0.6, ) p.text( window_conf["ll_region"][0], window_conf["ll_region"][3], f"NZVM v{vm_conf['model_version']} h={vm_conf['hh']}km", size=14, align="LB", dy=0.3, ) p.text( window_conf["ll_region"][0], window_conf["ll_region"][3], os.path.basename(path_conf["vm_file"]), size=14, align="LB", dy=0.1, ) p.leave() return gs_file
### ### STAGE 1: Calculate Region Sizing ### region_nz = gmt.nz_region region_srf = (srf_x_min, srf_x_max, srf_y_min, srf_y_max) map_width, map_height, region_srf = gmt.fill_space(map_width, map_height, region_srf, proj="M", dpi=dpi, wd=gwd) ### ### STAGE 2: Zoom from NZ Region ### gmt.gmt_defaults(wd=gwd, ps_media=f"Custom_{page_width}ix{page_height}i") def zoom_sequence(frame): # working directory for this process pwd = os.path.join(gwd, f"zs{frame:04}") if not os.path.exists(pwd): os.makedirs(pwd) ps_file = os.path.join(pwd, f"seq_{frame:04}.ps") copyfile(os.path.join(gwd, "gmt.conf"), os.path.join(pwd, "gmt.conf")) z = gmt.GMTPlot(ps_file, reset=False) plot_region, plot_width, x_margin, y_margin = gmt.region_transition( "M", region_nz, region_srf, map_width,
else: major_tick *= 2.5 tick_helper = 0 # start plot p = gmt.GMTPlot( os.path.join( gmt_temp, f"{os.path.splitext(os.path.basename(args.srf_file))[0]}_slip_rise_rake.ps", )) # override GMT defaults gmt.gmt_defaults( wd=gmt_temp, font_label=label_size, map_tick_length_primary="0.03i", ps_media="A4", font_annot_primary=base_size, ps_page_orientation="landscape", map_frame_pen=f"{scale_factor * 1.5}p,black", ) p.background(media[0], media[1]) # prepare data and CPTs slips = srf.srf2llv_py(args.srf_file, join_minor=True, value="slip", lonlat=False) tinits = srf.srf2llv_py(args.srf_file, join_minor=True, value="tinit", lonlat=False)