Beispiel #1
0
    def test_add_polygon_agg(self):
        from pycoast import ContourWriterAGG
        grid_img = Image.open(os.path.join(os.path.dirname(__file__),
                                           'nh_polygons_agg.png'))
        grid_data = np.array(grid_img)

        img = Image.new('RGB', (425, 425))
        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 = (proj4_string, area_extent)

        cw = ContourWriterAGG(gshhs_root_dir)

        polygons = {
            'REYKJAVIK_ATC_A': ((-20.0, 73.0), (0.0, 73.0), (0.0, 61.0), (-30.0, 61.0), (-39.0, 63.5), (-20, 70)),
            'REYKJAVIK_ATC_B': (
            (-39, 63.5), (-55 + 4 / 6.0, 63.5), (-57 + 45 / 60.0, 65), (-76, 76), (-75, 78), (-60, 82), (0, 90),
            (30, 82), (0, 82), (0, 73), (-20, 73), (-20,
                                                    70)),
            'REYKJAVIK_ATC':   (
            (0.0, 73.0), (0.0, 61.0), (-30.0, 61.0), (-39, 63.5), (-55 + 4 / 6.0, 63.5), (-57 + 45 / 60.0, 65),
            (-76, 76), (-75, 78), (-60, 82), (0, 90), (30, 82), (0, 82)),
            'ICELAND_BOX':     ((-25, 62.5), (-25, 67), (-13, 67), (-13, 62.5))
        }

        cw.add_polygon(img, area_def, polygons['REYKJAVIK_ATC'], outline='red', width=2)
        cw.add_polygon(img, area_def, polygons['ICELAND_BOX'], outline='green', fill='gray', width=2)
        cw.add_coastlines(img, area_def, resolution='l', level=4)

        res = np.array(img)
        self.failUnless(fft_metric(grid_data, res), 'Writing of nh polygons failed')
    def show_swath_pycoast(self, start, period=None):
        """
        A helper method that displays the orbital swath
        starting at datetime start, for a period number of minutes.
        If, start is iterable, then the method assumes it is an iterable
        of datetimes, plotting a number of swaths at those times.
        """
        # test if start is iterable, EAFP style:
        try:
            for e in start:
                pass
        except TypeError:
            start = [start]
        start.sort()

        from PIL import Image
        from pycoast import ContourWriterAGG
        from pydecorate import DecoratorAGG
        img = Image.new('RGB', (650, 650))
        proj4_string = ""
        for x in self.working_projection:
            proj4_string += "+%s=%s "%(x,self.working_projection[x])
        area_extent = (-6700000.0, -6700000.0, 6700000.0, 6700000.0)
        area_def = (proj4_string, area_extent)
        cw = ContourWriterAGG()

        cw.add_grid(img, area_def, (10.0,10.0),(2.0,2.0), fill='blue',
                    outline='gray', outline_opacity=130, minor_outline=None, write_text=False)

        
        # Plot granules
        for t in start:
            # fetch the coordinates
            xys_segs = self.swath_working_projection(t, period)
            for xys in xys_segs:
                lls = self.proj(xys[0],xys[1],inverse=True)
                cw.add_polygon(img, area_def, zip(lls[0], lls[1]), outline="blue", fill="blue", fill_opacity=70, width=1)
        cw.add_coastlines(img, area_def, resolution='l')
        aoi_coords = zip(*self.aoi)
        ## TODO: Handle single point case properly
        if len(aoi_coords) == 1:
            x, y = aoi_coords[0]
            d =  0.5
            line_coords = [(x-d,y),(x+d,y)]
            cw.add_line(img, area_def, line_coords, 
                        outline="red", fill="red", fill_opacity=100, width=2)
        elif len(aoi_coords) == 2:
            cw.add_line(img, area_def, aoi_coords, outline="red", fill="red", fill_opacity=100, width=10)
        else:
            cw.add_polygon(img, area_def, aoi_coords, outline="red", fill="red", fill_opacity=100, width=2)
        # Decorate
        dc = DecoratorAGG(img)
        text = "Granules from time: %s + %.2f min."%(start[0].strftime('%Y.%m.%d %H:%M:%S'), 
                                            (start[-1]-start[0]).total_seconds()/60.0)
        dc.align_bottom()
        dc.add_text(text,height=0)

        img.show()                
Beispiel #3
0
    def test_add_polygon_agg(self):
        from pycoast import ContourWriterAGG
        grid_img = Image.open(
            os.path.join(os.path.dirname(__file__), 'nh_polygons_agg.png'))
        grid_data = np.array(grid_img)

        img = Image.new('RGB', (425, 425))
        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 = (proj4_string, area_extent)

        cw = ContourWriterAGG(gshhs_root_dir)

        polygons = {
            'REYKJAVIK_ATC_A': ((-20.0, 73.0), (0.0, 73.0), (0.0, 61.0),
                                (-30.0, 61.0), (-39.0, 63.5), (-20, 70)),
            'REYKJAVIK_ATC_B':
            ((-39, 63.5), (-55 + 4 / 6.0, 63.5), (-57 + 45 / 60.0, 65),
             (-76, 76), (-75, 78), (-60, 82), (0, 90), (30, 82), (0, 82),
             (0, 73), (-20, 73), (-20, 70)),
            'REYKJAVIK_ATC':
            ((0.0, 73.0), (0.0, 61.0), (-30.0, 61.0), (-39, 63.5),
             (-55 + 4 / 6.0, 63.5), (-57 + 45 / 60.0, 65), (-76, 76),
             (-75, 78), (-60, 82), (0, 90), (30, 82), (0, 82)),
            'ICELAND_BOX': ((-25, 62.5), (-25, 67), (-13, 67), (-13, 62.5))
        }

        cw.add_polygon(img,
                       area_def,
                       polygons['REYKJAVIK_ATC'],
                       outline='red',
                       width=2)
        cw.add_polygon(img,
                       area_def,
                       polygons['ICELAND_BOX'],
                       outline='green',
                       fill='gray',
                       width=2)
        cw.add_coastlines(img, area_def, resolution='l', level=4)

        res = np.array(img)
        self.assertTrue(fft_metric(grid_data, res),
                        'Writing of nh polygons failed')
Beispiel #4
0
    def show_swath_pycoast(self, start, period=None):
        """
        A helper method that displays the orbital swath
        starting at datetime start, for a period number of minutes.
        If, start is iterable, then the method assumes it is an iterable
        of datetimes, plotting a number of swaths at those times.
        """
        # test if start is iterable, EAFP style:
        try:
            for e in start:
                pass
        except TypeError:
            start = [start]
        start.sort()

        from PIL import Image
        from pycoast import ContourWriterAGG
        from pydecorate import DecoratorAGG
        img = Image.new('RGB', (650, 650))
        proj4_string = ""
        for x in self.working_projection:
            proj4_string += "+%s=%s " % (x, self.working_projection[x])
        area_extent = (-6700000.0, -6700000.0, 6700000.0, 6700000.0)
        area_def = (proj4_string, area_extent)
        cw = ContourWriterAGG()

        cw.add_grid(img,
                    area_def, (10.0, 10.0), (2.0, 2.0),
                    fill='blue',
                    outline='gray',
                    outline_opacity=130,
                    minor_outline=None,
                    write_text=False)

        # Plot granules
        for t in start:
            # fetch the coordinates
            xys_segs = self.swath_working_projection(t, period)
            for xys in xys_segs:
                lls = self.proj(xys[0], xys[1], inverse=True)
                cw.add_polygon(img,
                               area_def,
                               zip(lls[0], lls[1]),
                               outline="blue",
                               fill="blue",
                               fill_opacity=70,
                               width=1)
        cw.add_coastlines(img, area_def, resolution='l')
        aoi_coords = zip(*self.aoi)
        ## TODO: Handle single point case properly
        if len(aoi_coords) == 1:
            x, y = aoi_coords[0]
            d = 0.5
            line_coords = [(x - d, y), (x + d, y)]
            cw.add_line(img,
                        area_def,
                        line_coords,
                        outline="red",
                        fill="red",
                        fill_opacity=100,
                        width=2)
        elif len(aoi_coords) == 2:
            cw.add_line(img,
                        area_def,
                        aoi_coords,
                        outline="red",
                        fill="red",
                        fill_opacity=100,
                        width=10)
        else:
            cw.add_polygon(img,
                           area_def,
                           aoi_coords,
                           outline="red",
                           fill="red",
                           fill_opacity=100,
                           width=2)
        # Decorate
        dc = DecoratorAGG(img)
        text = "Granules from time: %s + %.2f min." % (
            start[0].strftime('%Y.%m.%d %H:%M:%S'),
            (start[-1] - start[0]).total_seconds() / 60.0)
        dc.align_bottom()
        dc.add_text(text, height=0)

        img.show()