<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_image(self, size, latitude_interval, longitude_interval, max_elevation, min_elevation=0, unknown_color = (255, 255, 255, 255), zero_color = (0, 0, 255, 255), min_color = (0, 0, 0, 255), max_color = (0, 255, 0, 255), mode='image'):
 """ Returns a numpy array or PIL image. """


        if not size or len(size) != 2:
            raise Exception('Invalid size %s' % size)
        if not latitude_interval or len(latitude_interval) != 2:
            raise Exception('Invalid latitude interval %s' % latitude_interval)
        if not longitude_interval or len(longitude_interval) != 2:
            raise Exception('Invalid longitude interval %s' % longitude_interval)

        width, height = size
        width, height = int(width), int(height)

        latitude_from,  latitude_to  = latitude_interval
        longitude_from, longitude_to = longitude_interval


        if mode == 'array':
            import numpy as np
            array = np.empty((height,width))
            for row in range(height):
                for column in range(width):
                    latitude  = latitude_from  + float(row) / height * (latitude_to  - latitude_from)
                    longitude = longitude_from + float(column) / width * (longitude_to - longitude_from)
                    elevation = self.get_elevation(latitude, longitude)
                    array[row,column] = elevation

            return array

        elif mode == 'image':
            try:    import Image as mod_image
            except: from PIL import Image as mod_image
            try:    import ImageDraw as mod_imagedraw
            except: from PIL import ImageDraw as mod_imagedraw

            image = mod_image.new('RGBA', (width, height),
                              (255, 255, 255, 255))
            draw = mod_imagedraw.Draw(image)

            max_elevation -= min_elevation

            for row in range(height):
                for column in range(width):
                    latitude  = latitude_from  + float(row) / height * (latitude_to  - latitude_from)
                    longitude = longitude_from + float(column) / width * (longitude_to - longitude_from)
                    elevation = self.get_elevation(latitude, longitude)
                    if elevation == None:
                        color = unknown_color
                    else:
                        elevation_coef = (elevation - min_elevation) / float(max_elevation)
                        if elevation_coef < 0: elevation_coef = 0
                        if elevation_coef > 1: elevation_coef = 1
                        color = mod_utils.get_color_between(min_color, max_color, elevation_coef)
                        if elevation <= 0:
                            color = zero_color
                    draw.point((column, height - row), color)

            return image
        else:
            raise Exception('Invalid mode ' + mode)