def plot_assets(calc_id=-1): """ Plot the sites and the assets """ # NB: matplotlib is imported inside since it is a costly import import matplotlib.pyplot as p from openquake.hmtk.plotting.patch import PolygonPatch dstore = datastore.read(calc_id) try: region = dstore['oqparam'].region except KeyError: region = None sitecol = dstore['sitecol'] try: assetcol = dstore['assetcol'].value except AttributeError: assetcol = dstore['assetcol'].array fig = p.figure() ax = fig.add_subplot(111) if region: pp = PolygonPatch(shapely.wkt.loads(region), alpha=0.1) ax.add_patch(pp) ax.grid(True) p.scatter(sitecol.complete.lons, sitecol.complete.lats, marker='.', color='gray') p.scatter(assetcol['lon'], assetcol['lat'], marker='.', color='green') p.scatter(sitecol.lons, sitecol.lats, marker='+', color='black') if 'discarded' in dstore: disc = dstore['discarded'] p.scatter(disc['lon'], disc['lat'], marker='x', color='red') p.show()
def plot_assets(calc_id=-1): """ Plot the sites and the assets """ # NB: matplotlib is imported inside since it is a costly import import matplotlib.pyplot as p from openquake.hmtk.plotting.patch import PolygonPatch dstore = datastore.read(calc_id) oq = dstore['oqparam'] sitecol = dstore['sitecol'] assetcol = dstore['assetcol'].array fig = p.figure() ax = fig.add_subplot(111) if oq.region: pp = PolygonPatch(shapely.wkt.loads(oq.region), alpha=0.01) ax.add_patch(pp) else: ax.grid(True) p.scatter(sitecol.complete.lons, sitecol.complete.lats, marker='.', color='gray') p.scatter(assetcol['lon'], assetcol['lat'], marker='.', color='green') p.scatter(sitecol.lons, sitecol.lats, marker='o', color='black') p.show()
def add(self, poly, **kw): from openquake.hmtk.plotting.patch import PolygonPatch minx, miny, maxx, maxy = poly.bounds self.minxs.append(minx) self.maxxs.append(maxx) self.minys.append(miny) self.maxys.append(maxy) self.ax.add_patch(PolygonPatch(poly, **kw))
def add(self, poly, **kw): from openquake.hmtk.plotting.patch import PolygonPatch minx, miny, maxx, maxy = poly.bounds self.minxs.append(minx) self.maxxs.append(maxx) self.minys.append(miny) self.maxys.append(maxy) try: self.ax.add_patch(PolygonPatch(poly, **kw)) except ValueError: # LINESTRING, not POLYGON pass
def main(calc_id: int = -1, site_model=False): """ Plot the sites and the assets """ # NB: matplotlib is imported inside since it is a costly import import matplotlib.pyplot as p from openquake.hmtk.plotting.patch import PolygonPatch dstore = util.read(calc_id) try: region = dstore['oqparam'].region except KeyError: region = None sitecol = dstore['sitecol'] try: assetcol = dstore['assetcol'][()] except AttributeError: assetcol = dstore['assetcol'].array fig = p.figure() ax = fig.add_subplot(111) if region: pp = PolygonPatch(shapely.wkt.loads(region), alpha=0.1) ax.add_patch(pp) ax.grid(True) if site_model and 'site_model' in dstore: sm = dstore['site_model'] sm_lons, sm_lats = sm['lon'], sm['lat'] if len(sm_lons) > 1 and cross_idl(*sm_lons): sm_lons %= 360 p.scatter(sm_lons, sm_lats, marker='.', color='orange', label='site model') # p.scatter(sitecol.complete.lons, sitecol.complete.lats, marker='.', # color='gray', label='grid') p.scatter(assetcol['lon'], assetcol['lat'], marker='.', color='green', label='assets') p.scatter(sitecol.lons, sitecol.lats, marker='+', color='black', label='sites') if 'discarded' in dstore: disc = numpy.unique(dstore['discarded']['lon', 'lat']) p.scatter(disc['lon'], disc['lat'], marker='x', color='red', label='discarded') ax.legend() p.show()
def make_figure_sources(extractors, what): """ Plot the sources (except point sources) """ # NB: matplotlib is imported inside since it is a costly import import matplotlib.pyplot as plt from openquake.hmtk.plotting.patch import PolygonPatch [ex] = extractors info = ex.get(what) fig, ax = plt.subplots() ax.grid(True) # sitecol = ex.get('sitecol') # bmap = basemap('cyl', sitecol) # bmap.plot(sitecol['lon'], sitecol['lat'], 'x') minxs = [] maxxs = [] minys = [] maxys = [] n = 0 tot = 0 for rec in info: if not rec['wkt'].startswith('POINT'): poly = shapely.wkt.loads(rec['wkt']) minx, miny, maxx, maxy = poly.bounds minxs.append(minx) maxxs.append(maxx) minys.append(miny) maxys.append(maxy) if rec['eff_ruptures']: # not filtered out alpha = .3 n += 1 else: alpha = .1 pp = PolygonPatch(poly, alpha=alpha) ax.add_patch(pp) tot += 1 ax.set_xlim(min(minxs), max(maxxs)) ax.set_ylim(min(minys), max(maxys)) ax.set_title('%d/%d sources for source model #%d' % (n, tot, info.sm_id)) return plt