Beispiel #1
0
    def test_config_file_points_and_borders_agg(self):
        from pycoast import ContourWriterAGG
        from pyresample.geometry import AreaDefinition

        config_file = os.path.join(os.path.dirname(__file__),
                                   'nh_points_agg.ini')

        grid_img = Image.open(
            os.path.join(os.path.dirname(__file__), 'nh_points_agg.png'))
        grid_data = np.array(grid_img)

        img = Image.new('RGB', (1024, 1024), (255, 255, 255))

        proj4_string = '+proj=laea +lat_0=90 +lon_0=0 +a=6371228.0 +units=m'
        area_extent = (-5326849.0625, -5326849.0625, 5326849.0625,
                       5326849.0625)

        area_def = AreaDefinition('nh', 'nh', 'nh', proj4_string, 1024, 1024,
                                  area_extent)

        cw = ContourWriterAGG(gshhs_root_dir)

        cw.add_overlay_from_config(config_file, area_def, img)

        res = np.array(img)
        self.assertTrue(
            fft_metric(grid_data, res),
            'Add points with agg module from a config file failed')
Beispiel #2
0
    def test_config_file_coasts_and_grid(self):
        from pycoast import ContourWriterAGG
        from pyresample.geometry import AreaDefinition
        overlay_config = os.path.join(os.path.dirname(__file__),
                                      "coasts_and_grid_agg.ini")
        grid_img = Image.open(
            os.path.join(os.path.dirname(__file__), 'grid_nh_cfg_agg.png'))
        grid_data = np.array(grid_img)
        proj_dict = {
            'proj': 'laea',
            'lat_0': 90.0,
            'lon_0': 0.0,
            'a': 6371228.0,
            'units': 'm'
        }
        area_extent = (-5326849.0625, -5326849.0625, 5326849.0625,
                       5326849.0625)
        area_def = AreaDefinition('nh', 'nh', 'nh', proj_dict, 850, 850,
                                  area_extent)

        cw = ContourWriterAGG(gshhs_root_dir)
        overlay = cw.add_overlay_from_config(overlay_config, area_def)
        img = Image.new('RGB', (850, 850), (255, 255, 255))
        img.paste(overlay, mask=overlay)

        res = np.array(img)
        self.assertTrue(fft_metric(grid_data, res),
                        'Writing of nh grid failed')
Beispiel #3
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)
Beispiel #4
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)