Esempio n. 1
0
    bgimg.convert("RGB")
    fls_img = Image(fls_img.channels[0], mode='L')
    fls_img.colorize(fogcol)
    fls_img.merge(bgimg)

    ele_img = Image(ele_img.channels[0], mode='L')
    #cwp_img = Image(cwp_img.channels[0], mode='L')
    #cwp_masked = np.ma.array(cwp_ger.image_data, mask=fogmask)
    #print(np.histogram(cwp_masked.compressed()))
    #ele_img.show()
    #cwp_img.show()
    #overview.show()
    #fls_img.show()
    #snow_rgb.show()
    #daymicro_rgb.show()
    ele_img.save("/tmp/fog_example_msg_ger_elevation_{}.png".format(
        time.strftime("%Y%m%d%H%M")))
    cot_img.save("/tmp/fog_example_msg_ger_cot_{}.png".format(
        time.strftime("%Y%m%d%H%M")))
    reff_img.save("/tmp/fog_example_msg_ger_reff_{}.png".format(
        time.strftime("%Y%m%d%H%M")))
    cwp_img.save("/tmp/fog_example_msg_ger_cwp_{}.png".format(
        time.strftime("%Y%m%d%H%M")))
    fls_img.save("/tmp/fog_example_msg_ger_fls_{}.png".format(
        time.strftime("%Y%m%d%H%M")))
    overview.save("/tmp/fog_example_msg_ger_overview_{}.png".format(
        time.strftime("%Y%m%d%H%M")))
    snow_rgb.save("/tmp/fog_example_msg_ger_snow_rgb_{}.png".format(
        time.strftime("%Y%m%d%H%M")))
    daymicro_rgb.save("/tmp/fog_example_msg_ger_daymicro_rgb_{}.png".format(
        time.strftime("%Y%m%d%H%M")))
    #germ_scene["HRV"].show()
Esempio n. 2
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