class SandboxSceneConfig(Object): frame = FrameConfig.T(default=FrameConfig(), help='Frame/reference configuration') extent_north = Int.T(default=800, help='Model size towards north in [px]') extent_east = Int.T(default=800, help='Model size towards east in [px]') sources = List.T(help='List of sources') reference_scene = String.T(optional=True, help='Reference kite.Scene container')
def create_kite_scene_asc(store_id, dip, depth, patches, llLat=0., llLon=0.): km = 1e3 d2r = num.pi/180. engine = gf.LocalEngine(store_superdirs=['.']) # Define the scene's frame frame = FrameConfig( # Lower left geographical reference [deg] llLat=llLat, llLon=llLon, # Pixel spacing [m] or [degrees] spacing='degrees', dE=550, dN=550) # Resolution of the scene npx_east = 1400 npx_north = 1400 # 2D arrays for displacement and look vector displacement = num.empty((npx_east, npx_north)) # Look vectors # Theta is elevation angle from horizon theta = num.full_like(displacement, 56.*d2r) # Phi is azimuth towards the satellite, counter-clockwise from East phi = num.full_like(displacement, -166.*d2r) scene = Scene( displacement=displacement, phi=phi, theta=theta, frame=frame) satellite_target = gf.KiteSceneTarget( scene, store_id=store_id) sources = CombiSource(subsources=patches) result = engine.process( sources, satellite_target, # Use all available cores nthreads=0) kite_scenes = result.kite_scenes() return kite_scenes
def post_process(self, *args, **kwargs): resp = gf.SatelliteTarget.post_process(self, *args, **kwargs) from kite import Scene from kite.scene import SceneConfig, FrameConfig, Meta patch = self.scene_patch grid, _ = patch.get_grid() displacement = num.empty_like(grid) displacement.fill(num.nan) displacement[patch.get_mask()] = resp.result['displacement.los'] theta, phi = patch.get_incident_angles() llLat, llLon = patch.get_ll_anchor() urLat, urLon = patch.get_ur_anchor() dLon = num.abs(llLon - urLon) / patch.resolution[0] dLat = num.abs(llLat - urLat) / patch.resolution[1] scene_config = SceneConfig(meta=Meta( scene_title='Pyrocko Scenario Generator - {orbit} ({time})'. format(orbit=self.scene_patch.orbital_node, time=datetime.now()), orbital_node=patch.orbital_node, scene_id='pyrocko_scenario_%s' % self.scene_patch.orbital_node, satellite_name='Sentinel-1 (Scenario)'), frame=FrameConfig(llLat=float(llLat), llLon=float(llLon), dN=float(dLat), dE=float(dLon), spacing='degree')) scene = Scene(displacement=displacement, theta=theta, phi=phi, config=scene_config) resp.scene = scene return resp
def main(): if len(sys.argv) < 2: print( "input: asc_path dsc_path minlat minlon maxlat maxlon --workdir=name m" ) try: x0 = float(sys.argv[3]) y0 = float(sys.argv[4]) x1 = float(sys.argv[5]) y1 = float(sys.argv[6]) except: x0 = "eins" y0 = "eins" x1 = "eins" y1 = "eins" sharp = False loading = False plot = True topo = False synthetic = False calc_statistics = False subsample = False dump_grid = False for argv in sys.argv: if argv == "--sharp": sharp = True if argv == "--basic": sharp = "basic" if argv == "--ss": sharp = "ss" if argv == "--loading=True": loading = True if argv == "--loading=true": loading = True if argv == "--plot=False": plot = False if argv[0:10] == "--workdir=": name = argv[10:] if argv == "--topography": topo = True if argv == "--synthetic": synthetic = True if argv == "--statistics": calc_statistics = True if argv == "--subsample": subsample = True if argv == "--grond_export": dump_grid = True strikes = [] lengths = [] widths = [] if loading is False: img_asc, coh_asc, scene_asc, dates_asc = load(sys.argv[1], kite_scene=True) try: os.mkdir('work-%s' % name) except: pass files = glob.glob('work-%s/*' % name) for f in files: os.remove(f) fname = 'work-%s/asc.mod.tif' % name writeout(img_asc, fname, sc=scene_asc) longs_asc, lats_asc = to_latlon(fname) try: global_cmt_catalog = catalog.GlobalCMT() events = global_cmt_catalog.get_events( time_range=(num.min(dates_asc), num.max(dates_asc)), magmin=2., latmin=num.min(lats_asc), latmax=num.max(lats_asc), lonmin=num.min(longs_asc), lonmax=num.max(longs_asc)) areas = [] for ev in events: areas.append(num.cbrt(ev.moment_tensor.moment) / 1000) area = num.max(areas) except: area = 400 fname = 'work-%s/asc-' % name img_asc = process(img_asc, coh_asc, longs_asc, lats_asc, scene_asc, x0, y0, x1, y1, fname, plot=plot, mode=sharp, loading=loading, topo=topo, synthetic=synthetic, calc_statistics=calc_statistics, subsample=subsample) fname = 'work-%s/asc.mod.tif' % name writeout(img_asc, fname, sc=scene_asc) db = 1 dates = [] img_asc, coh_asc, scene_asc, dates_asc = load(sys.argv[1], kite_scene=True) dates.append(dates_asc) snr_asc = aoi_snr(img_asc, area) img_dsc, coh_dsc, scene_dsc, dates_dsc = load(sys.argv[2], kite_scene=True) dates.append(dates_dsc) fname = 'work-%s/dsc.mod.tif' % name writeout(img_dsc, fname, sc=scene_dsc) longs_dsc, lats_dsc = to_latlon(fname) fname = 'work-%s/dsc-' % name img_dsc = process(img_dsc, coh_dsc, longs_dsc, lats_dsc, scene_dsc, x0, y0, x1, y1, fname, plot=plot, mode=sharp, loading=loading, topo=topo, synthetic=synthetic, calc_statistics=calc_statistics, subsample=subsample) fname = 'work-%s/dsc.mod.tif' % name writeout(img_dsc, fname, sc=scene_dsc) db = 1 img_dsc, coh_dsc, scene_dsc, dates = load(sys.argv[2], kite_scene=True) snr_dsc = aoi_snr(img_dsc, area) minda = num.min(scene_asc.displacement) mindd = num.min(scene_dsc.displacement) mind = num.min([minda, mindd]) maxa = num.max(scene_asc.displacement) maxdd = num.max(scene_dsc.displacement) maxd = num.max([maxa, maxdd]) max_cum = num.max([abs(maxd), abs(mind)]) minda = -max_cum mindd = -max_cum mind = -max_cum maxa = max_cum maxdd = max_cum maxd = max_cum if plot is True: fname = 'work-%s/asc' % name plot_on_map(db, scene_asc, longs_asc, lats_asc, x0, y0, x1, y1, minda, maxa, fname, synthetic=synthetic, topo=topo, kite_scene=True) fname = 'work-%s/dsc' % name plot_on_map(db, scene_dsc, longs_dsc, lats_dsc, x0, y0, x1, y1, mindd, maxdd, fname, synthetic=synthetic, topo=topo, kite_scene=True) fname = 'work-%s/asc.mod.tif' % name comb = rasterio.open(fname) longs_comb, lats_comb = to_latlon(fname) comb_img = comb.read(1) centers_bounding, coords_out, coords_box, strike, ellipses, max_bound = bounding_box( comb_img, 400, sharp) for st in strike: strikes.append(st) print("Strike(s) of moment weighted centerline(s) are :%s" % strike) if plot is True: fname = 'work-%s/asc-comb-' % name plot_on_kite_box(coords_box, coords_out, scene_asc, longs_asc, lats_asc, longs_comb, lats_comb, x0, y0, x1, y1, name, ellipses, minda, maxa, fname, synthetic=synthetic, topo=topo) fname = 'work-%s/dsc.mod.tif' % name comb = rasterio.open(fname) longs_comb, lats_comb = to_latlon(fname) comb_img = comb.read(1) centers_bounding, coords_out, coords_box, strike, ellipses, max_bound = bounding_box( comb_img, 400, sharp) for st in strike: strikes.append(st) print("Strike(s) of moment weighted centerline(s) are :%s" % strike) if plot is True: fname = 'work-%s/dsc-comb-' % name plot_on_kite_box(coords_box, coords_out, scene_dsc, longs_dsc, lats_dsc, longs_comb, lats_comb, x0, y0, x1, y1, name, ellipses, mindd, maxdd, fname, synthetic=synthetic, topo=topo) comb_img = combine('work-%s/asc.mod.tif' % name, 'work-%s/dsc.mod.tif' % name, name, weight_asc=snr_asc, weight_dsc=snr_dsc, plot=False) longs_comb, lats_comb = to_latlon("work-%s/merged.tiff" % name) else: fname = 'work-%s/merged.tiff' % name comb = rasterio.open(fname) longs, lats = to_latlon(fname) comb_img = comb.read(1) easts, norths = get_coords_from_geotiff(fname, comb_img) dE = easts[1] - easts[0] dN = norths[1] - norths[0] ll_long = num.min(longs) ll_lat = num.min(lats) dates = [] img_asc, coh_asc, scene_asc, dates_asc = load(sys.argv[1], kite_scene=True) img_dsc, coh_dsc, scene_dsc, dates_dsc = load(sys.argv[2], kite_scene=True) minda = num.min(scene_asc.displacement) mindd = num.min(scene_dsc.displacement) mind = num.min([minda, mindd]) maxa = num.max(scene_asc.displacement) maxdd = num.max(scene_dsc.displacement) maxd = num.max([maxa, maxdd]) if plot is True: plt.figure(figsize=(sz1, sz2)) plt.title('Loaded combined image') xr = plt.imshow(comb_img) plt.close() if subsample is True: # Define the scene's frame frame = FrameConfig( # Lower left geographical reference [deg] llLat=ll_lat, llLon=ll_long, # Pixel spacing [m] or [degrees] spacing='meter', dE=dE, dN=dN) displacement = comb_img # Look vectors # Theta is elevation angle from horizon theta = num.full_like(displacement, 48. * d2r) # Phi is azimuth towards the satellite, counter-clockwise from East phi = num.full_like(displacement, 23. * d2r) kite_comb_scene = Scene(displacement=displacement, phi=phi, theta=theta, frame=frame) kite_comb_scene.spool() # For convenience we set an abbreviation to the quadtree qt = kite_comb_scene.quadtree # Parametrisation of the quadtree qt.epsilon = 0.024 # Variance threshold qt.nan_allowed = 0.9 # Percentage of NaN values allowed per tile/leave qt.tile_size_max = 12000 # Maximum leave edge length in [m] or [deg] qt.tile_size_min = 250 # Minimum leave edge length in [m] or [deg] # We save the scene in kite's format # sc.save('kite_scene') # Or export the quadtree to CSV file # qt.export('/tmp/tree.csv') # statistical output # img_asc, coh_asc, scene_asc = load('muji_kite/asc', kite_scene=True) # comb_img = process(img_asc, coh_asc, plot=True) # use quadtree subsampling on gradient img_asc, coh_asc, scene_asc, dates = load(sys.argv[1], kite_scene=True) fname = 'work-%s/asc.mod.tif' % name longs_asc, lats_asc = to_latlon(fname) db = 1 longs_comb, lats_comb = to_latlon("work-%s/merged.tiff" % name) mindc = num.min(comb_img) maxdc = num.max(comb_img) try: global_cmt_catalog = catalog.GlobalCMT() events = global_cmt_catalog.get_events(time_range=(num.min(dates), num.max(dates)), magmin=2., latmin=num.min(lats_comb), latmax=num.max(lats_comb), lonmin=num.min(longs_comb), lonmax=num.max(longs_comb)) areas = [] for ev in events: areas.append(num.cbrt(ev.moment_tensor.moment) / 1000) area = num.max(areas) except: area = 400 if dump_grid is True: from scipy import signal es = longs_comb.flatten() es_resamp = signal.decimate(es, 20) ns = lats_comb.flatten() ns_resamp = signal.decimate(ns, 20) comb_img_grid = comb_img.flatten() comb_img_grid_resamp = signal.decimate(comb_img_grid, 20) fobj_cum = open(os.path.join('work-%s/grad_grid.ASC' % name), 'w') for x, y, sembcums in zip(es, ns, comb_img_grid.flatten()): fobj_cum.write('%.2f %.2f %.20f\n' % (x, y, sembcums)) fobj_cum.close() fobj_cum = open(os.path.join('work-%s/grad_grid_resam.ASC' % name), 'w') for x, y, sembcums in zip(es_resamp, ns_resamp, comb_img_grid_resamp): fobj_cum.write('%.2f %.2f %.20f\n' % (x, y, sembcums)) fobj_cum.close() if plot is True: fname = 'work-%s/comb-' % name plot_on_map(db, comb_img.copy(), longs_comb, lats_comb, x0, y0, x1, y1, mindc, maxdc, fname, synthetic=synthetic, topo=topo, comb=True) centers_bounding, coords_out, coords_box, strike, ellipses, max_bound = bounding_box( comb_img, area, sharp) for st in strike: strikes.append(st) print("Strike(s) of moment weighted centerline(s) are :%s" % strike) if plot is True: fname = 'work-%s/comb-' % name lengths, widths = plot_on_kite_box(coords_box, coords_out, scene_asc, longs_asc, lats_asc, longs_comb, lats_comb, x0, y0, x1, y1, name, ellipses, mind, maxd, fname, synthetic=synthetic, topo=topo) fobj_cum = open(os.path.join('work-%s/priors.ASC' % name), 'w') for lens, wid in zip(lengths, widths): fobj_cum.write('%.2f %.2f\n' % (lens, wid)) fobj_cum.close() fobj_cum = open(os.path.join('work-%s/priors_strike.ASC' % name), 'w') for st in zip(strikes): fobj_cum.write('%.2f\n' % (st)) fobj_cum.close() plot_on_kite_line(coords_out, scene_asc, longs_asc, lats_asc, longs_comb, lats_comb, x0, y0, x1, y1, mind, maxd, fname, synthetic=synthetic, topo=topo) simp_fault, comp_fault = simplify(centers_bounding) db = dump_geojson(simp_fault, longs_comb, lats_comb, name) if plot is True: plot_on_kite_scatter( db, scene_asc, longs_asc, lats_asc, x0, y0, x1, y1, mind, maxd, fname, synthetic=synthetic, topo=topo, ) img_dsc, coh_dsc, scene_dsc, dates = load(sys.argv[2], kite_scene=True) fname = 'work-%s/dsc.mod.tif' % name longs_dsc, lats_dsc = to_latlon(fname) fname = 'work-%s/comb-' % name if plot is True: plot_on_kite_scatter( db, scene_dsc, longs_dsc, lats_dsc, x0, y0, x1, y1, mind, maxd, fname, synthetic=synthetic, topo=topo, ) centers = skelotonize(comb_img) simp_fault, comp_fault = simplify(centers) if calc_statistics is True: res_faults = rup_prop(db) y = l1tf_prep(res_faults) run_l1tf(y)
depth=6.5 * km, # Dimensions of the fault [m] width=5 * km, length=8 * km, strike=104., dip=90., rake=0., # Slip in [m] slip=1., anchor='top') # Define the scene's frame frame = FrameConfig( # Lower left geographical reference [deg] llLat=0., llLon=0., # Pixel spacing [m] or [degrees] spacing='meter', dE=250, dN=250) # Resolution of the scene npx_east = 800 npx_north = 800 # 2D arrays for displacement and look vector displacement = num.empty((npx_east, npx_north)) # Look vectors # Theta is elevation angle from horizon theta = num.full_like(displacement, 48. * d2r) # Phi is azimuth towards the satellite, counter-clockwise from East