def _prepare(data, datatype): if not data.geoflag: raise RadarPlotError('Geographic information should be contained in data') else: lon, lat = data.lon, data.lat r = data.data if data.dtype is not datatype: raise RadarPlotError('Expected datatype is "{}", received "{}"'.format(datatype, data.dtype)) return lon, lat, r
def highlight_area( area: Union[Array_T, str], linecolor: str = "red", **kwargs ) -> List[Line2D]: r"""Return list of Line2D object for given area name""" fpath = os.path.join(MODULE_DIR, "data", "shapefile", "City") shp = shapefile.Reader(fpath, encoding="gbk") rec = shp.shapeRecords() lines = list() if isinstance(area, str): area = [area] for i in area: if not isinstance(i, str): raise RadarPlotError("Area name should be str") name = np.array([i.record[2] for i in rec]) target = np.array(rec)[(name == i).nonzero()[0]] for j in target: pts = j.shape.points x = [i[0] for i in pts] y = [i[1] for i in pts] lines.append(Line2D(x, y, color=linecolor)) return lines
def highlight_area(area: Union[Array_T, str], linecolor: str = 'red', **kwargs) -> List[Line2D]: r'''Return list of Line2D object for given area name''' fpath = os.path.join(MODULE_DIR, 'shapefile', 'City') shp = shapefile.Reader(fpath) rec = shp.shapeRecords() lines = list() if isinstance(area, str): area = [area] for i in area: if not isinstance(i, str): raise RadarPlotError('Area name should be str') name = np.array([i.record[2].decode('GBK') for i in rec]) target = np.array(rec)[(name == i).nonzero()[0]] for j in target: pts = j.shape.points x = [i[0] for i in pts] y = [i[1] for i in pts] lines.append(Line2D(x, y, color=linecolor)) return lines
def highlight_area(area, facecolor='None', edgecolor='red', **kwargs): r'''Return pathpatch for given area name''' fpath = os.path.join(MODULE_DIR, 'shapefile', 'City') shp = shapefile.Reader(fpath) rec = shp.shapeRecords() vertices = list() codes = list() for i in area: if not isinstance(i, str): raise RadarPlotError('Area name should be str') name = np.array([i.record[2].decode('GBK') for i in rec]) mask = np.ma.array(name, mask=(name == i)) target = np.array(rec)[mask.mask] for j in target: codes += [Path.MOVETO] + [Path.LINETO] * (len(j.shape.points) - 1) vertices += j.shape.points codes += [Path.CLOSEPOLY] vertices += [j.shape.points[0]] path = Path(vertices, codes) patch = PathPatch(path, facecolor=facecolor, edgecolor=edgecolor, **kwargs) return patch