def test_srf2llv_py(test_srf, sample_out_array): sample_array = np.fromfile(sample_out_array, dtype="3<f4") out_array_list = srf.srf2llv_py(test_srf) print("Adsfafsaf", out_array_list) out_array = out_array_list[0] # out_array[0] += 1 # Use this, if you want to test for a fail case, by changing a value in the out_array for array in out_array_list[1:]: out_array = np.concatenate([out_array, array]) print("first out array", out_array) utils.compare_np_array(sample_array, out_array)
def srf2bin(srf_file, out_file, py_method=False): """srffile: path to input srf file islist: srffile function return a numpy array or a list(of numpy array(s)) islist is true for srf2llv_py; false for srfllv. default false """ # load data if py_method: out_array_list = srf.srf2llv_py(srf_file) out_array = out_array_list[0] for array in out_array_list[1:]: out_array = np.concatenate([out_array, array]) else: out_array = srf.srf2llv(srf_file) # save data try: out_array.astype(np.float32).tofile(out_file) except Exception as e: sys.exit(e)
plot_dy = "%sk" % (dy * 0.6) # output for plane data os.makedirs(os.path.join(gmt_tmp, "PLANES")) else: text_dx = "N/A" text_dy = "N/A" ### ### OUTPUT 1: binary file for GMT grid plotting ### if finite_fault: # get all corners bounds = srf.get_bounds(args.srf_file) # get all tinit values, set a sane countour interval # contour interval should probably also depend on area tinit = srf.srf2llv_py(args.srf_file, value="tinit") tinit_max = max([np.max(tinit[p][:, 2]) for p in range(len(bounds))]) contour_int = 2 if tinit_max < 10: contour_int = 1 if tinit_max < 2: contour_int = 0.3 # gridding is computationally expensive # each segment should include minimal region seg_regions = [] # for percentile to automatically calculate colour palette range values = np.array([], dtype=np.float32) # find total extremes np_bounds = np.array(bounds) x_min, y_min = np.min(np.min(np_bounds, axis=0), axis=0) x_max, y_max = np.max(np.max(np_bounds, axis=0), axis=0)
output=os.path.join(gwd, f"plane_{i}.bounds"), ) # create mask from path x_min, y_min = np.min(plane, axis=0) x_max, y_max = np.max(plane, axis=0) plane_regions.append((x_min, x_max, y_min, y_max)) gmt.grd_mask( os.path.join(gwd, f"plane_{i}.bounds"), os.path.join(gwd, f"plane_{i}.mask"), dx=plot_dx, dy=plot_dy, region=plane_regions[i], ) # total length of rupture slip_end = srf.srf2llv_py(srf_file, value="ttotal") rup_time = max([max(slip_end[p][:, 2]) for p in range(len(slip_end))]) srf_dt = srf.srf_dt(srf_file) ftime = srf_ddt * srf_dt srf_frames = int(ceil(rup_time / ftime)) ### ### 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,
)) # 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) trises = srf.srf2llv_py(args.srf_file, join_minor=True, value="trise", lonlat=False) rakes = srf.srf2llv_py(args.srf_file, join_minor=True, value="rake", flip_rake=True, lonlat=False) slips = [slips[i] for i in args.plane_order]