def plot_sites(calc_id): """ Plot the sites and the bounding boxes of the sources, enlarged by the maximum distance """ import matplotlib.pyplot as p from matplotlib.patches import Rectangle dstore = datastore.read(calc_id) sitecol = dstore['sitecol'] csm = dstore['composite_source_model'] oq = dstore['oqparam'] rfilter = SourceFilter(sitecol, oq.maximum_distance) fig = p.figure() ax = fig.add_subplot(111) ax.grid(True) for src in csm.get_sources(): llcorner, width, height = rfilter.get_rectangle(src) ax.add_patch(Rectangle(llcorner, width, height, fill=False)) p.scatter(sitecol.lons, sitecol.lats, marker='+') p.show()
def plot_sites(calc_id): """ Plot the sites and the bounding boxes of the sources, enlarged by the maximum distance """ # NB: matplotlib is imported inside since it is a costly import import matplotlib.pyplot as p from matplotlib.patches import Rectangle dstore = datastore.read(calc_id) sitecol = dstore['sitecol'] csm = dstore['composite_source_model'] oq = dstore['oqparam'] rfilter = SourceFilter(sitecol, oq.maximum_distance) fig = p.figure() ax = fig.add_subplot(111) ax.grid(True) for src in csm.get_sources(): llcorner, width, height = rfilter.get_rectangle(src) ax.add_patch(Rectangle(llcorner, width, height, fill=False)) p.scatter(sitecol.lons, sitecol.lats, marker='+') p.show()
def plot_sites(calc_id=-1): """ Plot the sites and the bounding boxes of the sources, enlarged by the maximum distance """ # NB: matplotlib is imported inside since it is a costly import import matplotlib.pyplot as p from matplotlib.patches import Rectangle logging.basicConfig(level=logging.INFO) dstore = datastore.read(calc_id) oq = dstore['oqparam'] sitecol = dstore['sitecol'] lons, lats = sitecol.lons, sitecol.lats srcfilter = SourceFilter(sitecol.complete, oq.maximum_distance) csm = readinput.get_composite_source_model(oq).pfilter( srcfilter, oq.concurrent_tasks) sources = csm.get_sources() if len(sources) > 100: logging.info('Sampling 100 sources of %d', len(sources)) sources = random.Random(42).sample(sources, 100) fig, ax = p.subplots() ax.grid(True) rects = [srcfilter.get_rectangle(src) for src in sources] lonset = set(lons) for ((lon, lat), width, height) in rects: lonset.add(lon) lonset.add(fix_lon(lon + width)) idl = cross_idl(min(lonset), max(lonset)) if idl: lons = lons % 360 for src, ((lon, lat), width, height) in zip(sources, rects): lonlat = (lon % 360 if idl else lon, lat) ax.add_patch(Rectangle(lonlat, width, height, fill=False)) if hasattr(src.__class__, 'polygon'): xs, ys = fix_polygon(src.polygon, idl) p.plot(xs, ys, marker='.') p.scatter(lons, lats, marker='+') p.show()