Ejemplo n.º 1
0
def hr_overview(self):
    """Make a High Resolution Overview RGB image composite from Seviri
    channels.
    """
    self.check_channels('VIS006', 'VIS008', 'IR_108', "HRV")

    ch1 = self['VIS006'].check_range()
    ch2 = self['VIS008'].check_range()
    ch3 = -self['IR_108'].data

    img = GeoImage((ch1, ch2, ch3),
                   self.area,
                   self.time_slot,
                   fill_value=(0, 0, 0),
                   mode="RGB")

    img.enhance(stretch="crude")
    img.enhance(gamma=[1.6, 1.6, 1.1])

    luminance = GeoImage((self["HRV"].data),
                         self.area,
                         self.time_slot,
                         crange=(0, 100),
                         mode="L")

    luminance.enhance(gamma=2.0)

    img.replace_luminance(luminance.channels[0])

    return img
Ejemplo n.º 2
0
def hr_natural(self, stretch=None, gamma=1.8):
    """Make a Natural Colors RGB image composite.

    +--------------------+--------------------+--------------------+
    | Channels           | Range (reflectance)| Gamma (default)    |
    +====================+====================+====================+
    | IR1.6              | 0 - 90             | gamma 1.8          |
    +--------------------+--------------------+--------------------+
    | VIS0.8             | 0 - 90             | gamma 1.8          |
    +--------------------+--------------------+--------------------+
    | VIS0.6             | 0 - 90             | gamma 1.8          |
    +--------------------+--------------------+--------------------+
    """
    self.check_channels('VIS006', 'VIS008', 'IR_016')

    ch1 = self['IR_016'].check_range()
    ch2 = self['VIS008'].check_range()
    ch3 = self['VIS006'].check_range()

    img = GeoImage((ch1, ch2, ch3),
                   self.area,
                   self.time_slot,
                   fill_value=(0, 0, 0),
                   mode="RGB",
                   crange=((0, 90), (0, 90), (0, 90)))

    if stretch:
        img.enhance(stretch=stretch)
    if gamma:
        img.enhance(gamma=gamma)

    luminance = GeoImage((self["HRV"].data),
                         self.area,
                         self.time_slot,
                         crange=(0, 100),
                         mode="L")

    luminance.enhance(gamma=2.0)

    img.replace_luminance(luminance.channels[0])

    return img
Ejemplo n.º 3
0
def hr_airmass(self):
    """Make an airmass RGB image composite.

    +--------------------+--------------------+--------------------+
    | Channels           | Temp               | Gamma              |
    +====================+====================+====================+
    | WV6.2 - WV7.3      |     -25 to 0 K     | gamma 1            |
    +--------------------+--------------------+--------------------+
    | IR9.7 - IR10.8     |     -40 to 5 K     | gamma 1            |
    +--------------------+--------------------+--------------------+
    | WV6.2              |   243 to 208 K     | gamma 1            |
    +--------------------+--------------------+--------------------+
    """
    self.check_channels('WV_062', 'WV_073', 'IR_097', 'IR_108')

    ch1 = self['WV_062'].data - self['WV_073'].data
    ch2 = self['IR_097'].data - self['IR_108'].data
    ch3 = self['WV_062'].data

    img = GeoImage((ch1, ch2, ch3),
                   self.area,
                   self.time_slot,
                   fill_value=(0, 0, 0),
                   mode="RGB",
                   crange=((-25, 0), (-40, 5), (243, 208)))

    luminance = GeoImage((self["HRV"].data),
                         self.area,
                         self.time_slot,
                         crange=(0, 100),
                         mode="L")

    luminance.enhance(gamma=2.0)

    img.replace_luminance(luminance.channels[0])

    return img
Ejemplo n.º 4
0
def create_PIL_image(rgb, data, in_msg):

    if in_msg.verbose:
        print("*** make image for: ", rgb)

    # get the data array that you want to plot
    if rgb in products.MSG:
        prop = data[rgb].data
        plot_type = 'channel_image'
    elif rgb in products.MSG_color:
        prop = data[rgb.replace("c", "")].data
        plot_type = 'trollimage'
    elif rgb in products.CTTH:
        prop = data[rgb].data
        prop.mask = (prop == 0)
        if rgb == 'CTH':
            prop /= 1000.  # 1000. == m -> km
        plot_type = 'trollimage'
    elif rgb in products.CT:
        prop = data[rgb].data
        plot_type = 'palette'
        if rgb == 'CT_QUALITY':
            plot_type = 'trollimage'
    elif rgb in products.CMa or rgb in products.SPhR:
        prop = data[rgb].data
        if hasattr(data[rgb], 'palette') and in_msg.nwcsaf_calibrate == False:
            plot_type = 'palette'
        else:
            plot_type = 'trollimage'
    elif rgb in products.HSAF:
        prop = data[rgb].data
        plot_type = 'trollimage'
    else:
        # includes products.RGBs_buildin
        prop = ma.asarray([-999., -999.])
        plot_type = 'user_defined'

    #from numpy import log10
    #prop=log10(prop)

    # search minimum and maximum
    # (default)
    min_data = prop.min()
    max_data = prop.max()
    # replace default with fixed min/max if specified

    if in_msg.fixed_minmax:
        if rgb in list(in_msg.rad_min.keys()):
            min_data = in_msg.rad_min[rgb]
        else:
            if rgb not in products.RGBs_buildin:
                print(
                    "*** Warning, no specified minimum for plotting in get_input_msg.py or input file"
                )
        if rgb in list(in_msg.rad_max.keys()):
            max_data = in_msg.rad_max[rgb]
        else:
            if rgb not in products.RGBs_buildin:
                print(
                    "*** Warning, no specified maximum for plotting in get_input_msg.py or input file"
                )
    if in_msg.verbose and rgb not in products.RGBs_buildin:
        print('... set value range from min_data (', min_data,
              ') to max_data (', max_data, ')')

    # specifies if a colorbar does make sense at all
    in_msg.colormap = {}

    # make the image
    if plot_type == 'channel_image':
        if in_msg.verbose:
            print(
                "    use data.image.channel_image for black and white pictures"
            )
        img = data.image.channel_image(rgb)
        in_msg.colormap[rgb] = None
    elif plot_type == 'trollimage':
        if in_msg.verbose:
            print(
                "    use trollimage.image.image for colorized pictures (min=" +
                str(min_data) + ", max=" + str(max_data) + ")")
        img = trollimage(prop, mode="L", fill_value=in_msg.fill_value)
        rainbow.set_range(min_data, max_data)
        img.colorize(rainbow)
        rainbow_r.set_range(
            min_data, max_data
        )  # attention set_range does modify the colormap, but does not have a return values !
        in_msg.colormap[rgb] = rainbow.reverse()
        # print "in_msg.colormap[rgb]", rgb, in_msg.colormap[rgb]
    elif plot_type == 'palette':
        min_data = 0.
        max_data = float(len(data[rgb].palette) - 1)
        if in_msg.verbose:
            print("    use GeoImage and colorize with a palette (min=" +
                  str(min_data) + ", max=" + str(max_data) + ")")
        img = GeoImage(prop,
                       data.area,
                       data.time_slot,
                       mode="P",
                       palette=data[rgb].palette,
                       fill_value=in_msg.fill_value)
        colormap = convert_palette2colormap(data[rgb].palette)
        colormap.set_range(min_data, max_data)  # no return value!
        in_msg.colormap[rgb] = colormap
    elif plot_type == 'user_defined':
        obj_image = get_image(data, rgb)
        if in_msg.verbose:
            print("    use image function defined by my_msg_module.py")
        img = obj_image()
        in_msg.colormap[rgb] = None
        #if rgb == 'ndvi':
        #   in_msg.colormap[rgb] = rdylgn_r
    else:
        print("*** Error in create_PIL_image (" +
              inspect.getfile(inspect.currentframe()) + ")")
        print("    unknown plot_type ", plot_type)
        quit()

    if in_msg.HRV_enhancement:
        if in_msg.verbose:
            print("enhance the image with the HRV channel")
        luminance = GeoImage((data["HRV"].data),
                             data.area,
                             data.time_slot,
                             crange=(0, 100),
                             mode="L")
        luminance.enhance(gamma=2.0)
        img.replace_luminance(luminance.channels[0])
        rgb = 'HR' + rgb

    ## alternative: for geoimages is possible to add coasts and borders, but not for trollimage
    #if hasattr(img, 'add_overlay'):
    #   if in_msg.verbose:
    #      print "    add coastlines to image by add_averlay"
    #   img.add_overlay(color=(0, 0, 0), width=0.5, resolution=None)

    # convert image to PIL image
    if hasattr(img, 'pil_image'):
        if in_msg.verbose:
            print("    convert to PIL_image by pil_image function")
        PIL_image = img.pil_image()
    else:
        if in_msg.verbose:
            print("    convert to PIL_image by saving and reading")
        tmp_file = outputDir + satS + '_' + dateS + '_' + timeS + '__' + area + '_' + rgb.replace(
            "_", "-") + '_tmp.png'  # in_msg.
        img.save(tmp_file)
        PIL_image = Image.open(tmp_file)
        subprocess.call("rm " + tmp_file, shell=True)

    return PIL_image