示例#1
0
def test_projection(output_dir):
    """
    draw the "same sized" rectangle at three latitudes to see how the look
    """
    mc = MapCanvas((400, 400), preset_colors='web')

    mc.viewport = ((-20, 25), (20, 65))
    mc.draw_polygon(((-15, 60), (15, 60), (15, 30), (-15, 30)),
                    fill_color='maroon',
                    line_color='black')

    mc.save_foreground(os.path.join(output_dir, "image_projection_north.png"))

    mc.viewport = ((-20, -20), (20, 20))
    mc.draw_polygon(((-15, 15), (15, 15), (15, -15), (-15, -15)),
                    fill_color='maroon',
                    line_color='black')

    mc.save_foreground(os.path.join(output_dir,
                                    "image_projection_equator.png"))

    mc.viewport = ((-20, -45), (20, -90))
    mc.draw_polygon(((-15, -80), (15, -80), (15, -50), (-15, -50)),
                    fill_color='maroon',
                    line_color='black')

    mc.save_foreground(os.path.join(output_dir, "image_projection_south.png"))
示例#2
0
def test_set_colors():

    mc = MapCanvas((400, 300))

    colors = [('blue', (0, 0, 255)), ('red', (255, 0, 0))]

    mc.add_colors(colors)

    assert mc.fore_image.get_color_names() == mc.back_image.get_color_names()

    colors = mc.get_color_names()

    assert colors == ['transparent', 'black', 'white', 'blue', 'red']
示例#3
0
    def __init__(self,
                 ice_movers=None,
                 image_size=(800, 600),
                 projection=None,
                 viewport=None,
                 **kwargs):
        '''
            :param ice_movers: ice_movers associated with this outputter.
            :type ice_movers: An ice_mover object or sequence of ice_mover
                              objects.

            Use super to pass optional \*\*kwargs to base class __init__ method
        '''
        # this is a place where we store our gradient color infomration
        self.gradient_lu = {}

        self.map_canvas = MapCanvas(image_size,
                                    projection=projection,
                                    viewport=viewport,
                                    preset_colors='transparent')
        self.map_canvas.add_colors([('black', (0, 0, 0))])

        self.set_gradient_colors(
            'thickness',
            color_range=(
                (0, 0, 0x7f, 0x7f),  # dark blue
                (0, 0, 0x7f, 0x3f),  # dark blue
                (0, 0, 0x7f, 0x00),  # dark blue
                (0xff, 0, 0, 0x00)),  # red
            scale=(0.0, 6.0),
            num_colors=64)

        self.set_gradient_colors(
            'concentration',
            color_range=(
                (0x80, 0xc0, 0xd0, 0x7f),  # sky blue
                (0, 0x40, 0x60, 0x00)),  # dark blue
            scale=(0.0, 1.0),
            num_colors=64)

        super(IceImageOutput, self).__init__(**kwargs)

        if (isinstance(ice_movers, collections.Iterable)
                and not isinstance(ice_movers, str)):
            self.ice_movers = ice_movers
        elif ice_movers is not None:
            self.ice_movers = (ice_movers, )
        else:
            self.ice_movers = tuple()
示例#4
0
def test_foreground_polyline(output_dir):
    """
    test drawing polygons to the background
    """
    mc = MapCanvas((400, 300), preset_colors='web')

    mc.background_color = 'transparent'
    mc.clear_background()

    mc.draw_polyline(((-30, 30), (30, 30), (30, -20), (-30, -20)),
                     line_color='red',
                     line_width=5,
                     background=False)

    mc.save_foreground(os.path.join(output_dir, "foreground_polyline.png"))
示例#5
0
def test_foreground_poly(output_dir):
    """
    test drawing polygons to the foreground
    """
    mc = MapCanvas((400, 300), preset_colors='web')

    mc.background_color = 'transparent'
    mc.clear_background()

    mc.draw_polygon(((-30, 30), (30, 30), (30, -20), (-30, -20)),
                    fill_color='white',
                    line_color='black',
                    background=False)

    mc.save_foreground(os.path.join(output_dir, "foreground.png"))
示例#6
0
def test_copy_back_to_fore(output_dir):

    mc = MapCanvas((400, 300), preset_colors='web')

    mc.background_color = 'white'
    mc.clear_background()
    mc.clear_foreground()

    mc.draw_polyline(((-30, 30), (30, 30), (30, -20), (-30, -20)),
                     line_color='red',
                     line_width=5,
                     background=True)

    mc.copy_back_to_fore()
    mc.draw_polyline(((-20, 20), (20, 20), (20, -10), (-20, -10)),
                     line_color='blue',
                     line_width=5,
                     background=False)

    mc.save_foreground(os.path.join(output_dir, "copy_back_to_fore.png"))
示例#7
0
def test_init():
    """
    can we even initialize one
    """
    mc = MapCanvas((400, 300))