def add_overlay_config(self, config_file): """Add overlay to image parsing a configuration file. """ import ConfigParser conf = ConfigParser.ConfigParser() conf.read(os.path.join(CONFIG_PATH, "satpy.cfg")) coast_dir = conf.get('shapes', 'dir') logger.debug("Getting area for overlay: " + str(self.area.area_id)) try: import aggdraw from pycoast import ContourWriterAGG cw_ = ContourWriterAGG(coast_dir) except ImportError: logger.warning( "AGGdraw lib not installed...width and opacity properties are not available for overlays." ) from pycoast import ContourWriter cw_ = ContourWriter(coast_dir) logger.debug("Getting area for overlay: " + str(self.area)) if self.area is None: raise ValueError("Area of image is None, can't add overlay.") if self.mode != "RGB": self.convert("RGB") img = self.pil_image() from satpy.projector import get_area_def if isinstance(self.area, str): self.area = get_area_def(self.area) logger.info("Add overlays to image.") logger.debug("Area = " + str(self.area.area_id)) foreground = cw_.add_overlay_from_config(config_file, self.area) img.paste(foreground, mask=foreground.split()[-1]) arr = np.array(img) if len(self.channels) == 1: self.channels[0] = np.ma.array(arr[:, :] / 255.0) else: for idx in range(len(self.channels)): self.channels[idx] = np.ma.array(arr[:, :, idx] / 255.0)
def add_overlay_config(self, config_file): """Add overlay to image parsing a configuration file. """ import ConfigParser conf = ConfigParser.ConfigParser() conf.read(os.path.join(CONFIG_PATH, "satpy.cfg")) coast_dir = conf.get('shapes', 'dir') logger.debug("Getting area for overlay: " + str(self.area.area_id)) try: import aggdraw from pycoast import ContourWriterAGG cw_ = ContourWriterAGG(coast_dir) except ImportError: logger.warning("AGGdraw lib not installed...width and opacity properties are not available for overlays.") from pycoast import ContourWriter cw_ = ContourWriter(coast_dir) logger.debug("Getting area for overlay: " + str(self.area)) if self.area is None: raise ValueError("Area of image is None, can't add overlay.") if self.mode != "RGB": self.convert("RGB") img = self.pil_image() from satpy.projector import get_area_def if isinstance(self.area, str): self.area = get_area_def(self.area) logger.info("Add overlays to image.") logger.debug("Area = " + str(self.area.area_id)) foreground = cw_.add_overlay_from_config(config_file, self.area) img.paste(foreground, mask=foreground.split()[-1]) arr = np.array(img) if len(self.channels) == 1: self.channels[0] = np.ma.array(arr[:, :] / 255.0) else: for idx in range(len(self.channels)): self.channels[idx] = np.ma.array(arr[:, :, idx] / 255.0)
def add_overlay(self, color=(0, 0, 0), width=0.5, resolution=None): """Add coastline and political borders to image, using *color* (tuple of integers between 0 and 255). Warning: Loses the masks ! *resolution* is chosen automatically if None (default), otherwise it should be one of: +-----+-------------------------+---------+ | 'f' | Full resolution | 0.04 km | | 'h' | High resolution | 0.2 km | | 'i' | Intermediate resolution | 1.0 km | | 'l' | Low resolution | 5.0 km | | 'c' | Crude resolution | 25 km | +-----+-------------------------+---------+ """ img = self.pil_image() import ConfigParser conf = ConfigParser.ConfigParser() conf.read(os.path.join(CONFIG_PATH, "satpy.cfg")) coast_dir = conf.get('shapes', 'dir') logger.debug("Getting area for overlay: " + str(self.area)) if self.area is None: raise ValueError("Area of image is None, can't add overlay.") from satpy.projector import get_area_def if isinstance(self.area, str): self.area = get_area_def(self.area) logger.info("Add coastlines and political borders to image.") logger.debug("Area = " + str(self.area)) if resolution is None: x_resolution = ( (self.area.area_extent[2] - self.area.area_extent[0]) / self.area.x_size) y_resolution = ( (self.area.area_extent[3] - self.area.area_extent[1]) / self.area.y_size) res = min(x_resolution, y_resolution) if res > 25000: resolution = "c" elif res > 5000: resolution = "l" elif res > 1000: resolution = "i" elif res > 200: resolution = "h" else: resolution = "f" logger.debug("Automagically choose resolution " + resolution) from pycoast import ContourWriterAGG cw_ = ContourWriterAGG(coast_dir) cw_.add_coastlines(img, self.area, outline=color, resolution=resolution, width=width) cw_.add_borders(img, self.area, outline=color, resolution=resolution, width=width) arr = np.array(img) if len(self.channels) == 1: self.channels[0] = np.ma.array(arr[:, :] / 255.0) else: for idx in range(len(self.channels)): self.channels[idx] = np.ma.array(arr[:, :, idx] / 255.0)
def add_overlay(self, color=(0, 0, 0), width=0.5, resolution=None): """Add coastline and political borders to image, using *color* (tuple of integers between 0 and 255). Warning: Loses the masks ! *resolution* is chosen automatically if None (default), otherwise it should be one of: +-----+-------------------------+---------+ | 'f' | Full resolution | 0.04 km | | 'h' | High resolution | 0.2 km | | 'i' | Intermediate resolution | 1.0 km | | 'l' | Low resolution | 5.0 km | | 'c' | Crude resolution | 25 km | +-----+-------------------------+---------+ """ img = self.pil_image() import ConfigParser conf = ConfigParser.ConfigParser() conf.read(os.path.join(CONFIG_PATH, "satpy.cfg")) coast_dir = conf.get('shapes', 'dir') logger.debug("Getting area for overlay: " + str(self.area)) if self.area is None: raise ValueError("Area of image is None, can't add overlay.") from satpy.projector import get_area_def if isinstance(self.area, str): self.area = get_area_def(self.area) logger.info("Add coastlines and political borders to image.") logger.debug("Area = " + str(self.area)) if resolution is None: x_resolution = ((self.area.area_extent[2] - self.area.area_extent[0]) / self.area.x_size) y_resolution = ((self.area.area_extent[3] - self.area.area_extent[1]) / self.area.y_size) res = min(x_resolution, y_resolution) if res > 25000: resolution = "c" elif res > 5000: resolution = "l" elif res > 1000: resolution = "i" elif res > 200: resolution = "h" else: resolution = "f" logger.debug("Automagically choose resolution " + resolution) from pycoast import ContourWriterAGG cw_ = ContourWriterAGG(coast_dir) cw_.add_coastlines(img, self.area, outline=color, resolution=resolution, width=width) cw_.add_borders(img, self.area, outline=color, resolution=resolution, width=width) arr = np.array(img) if len(self.channels) == 1: self.channels[0] = np.ma.array(arr[:, :] / 255.0) else: for idx in range(len(self.channels)): self.channels[idx] = np.ma.array(arr[:, :, idx] / 255.0)