Ejemplo n.º 1
0
def trichannel(self):
    """Make a colored image of the difference of three Seviri channels.
    """

    self.check_channels('IR_087', 'IR_108', 'IR_120')

    from trollimage.image import Image as trollimage

    ch_diff = self['IR_087'] - 2 * self['IR_108'] + self['IR_120']

    min_data = ch_diff.data.min()
    max_data = ch_diff.data.max()
    print("min/max", min_data, max_data)

    img = trollimage(ch_diff.data, mode="L", fill_value=(0, 0, 0))

    #from trollimage.colormap import rdbu
    #rdbu.set_range(min_data, max_data)
    #rdbu.set_range(-5, +5)
    #rdbu.reverse()
    #img.colorize(rdbu)

    greys.set_range(-9, -2.5)  # 2.5 according to Mecikalski, 2.2 maybe better?
    greys.reverse()
    cm2 = deepcopy(rainbow)
    cm2.set_range(-2.5, 1.34)
    my_cm = greys + cm2
    greys.set_range(1.34, 6)
    my_cm2 = my_cm + greys
    img.colorize(my_cm2)

    return img
Ejemplo n.º 2
0
def IR_087_minus_IR_108(self):
    """Make a colored image of the difference of two Seviri channels.
    """

    from trollimage.image import Image as trollimage

    self.check_channels('IR_087', 'IR_108')

    ch_diff = self['IR_087'] - self['IR_108']

    min_data = ch_diff.data.min()
    max_data = ch_diff.data.max()
    print("min/max", min_data, max_data)

    img = trollimage(ch_diff.data, mode="L", fill_value=(0, 0, 0))

    #from trollimage.colormap import rdbu
    #rdbu.set_range(min_data, max_data)
    #rdbu.set_range(-5, +5)
    #rdbu.reverse()
    #img.colorize(rdbu)

    greys.set_range(-4, -1.5)
    greys.reverse()
    cm2 = deepcopy(rainbow)
    cm2.set_range(-1.5, 1.5)
    my_cm = greys + cm2
    rdpu.set_range(1.5, 4)
    my_cm2 = my_cm + rdpu
    img.colorize(my_cm2)

    return img
Ejemplo n.º 3
0
def WV_062_minus_WV_073(self):
    """Make a colored image of the difference of two Seviri channels.
    """

    self.check_channels('WV_062', 'WV_073')

    from trollimage.image import Image as trollimage

    ch_diff = self['WV_062'] - self['WV_073']

    min_data = ch_diff.data.min()
    max_data = ch_diff.data.max()
    print("min/max", min_data, max_data)

    img = trollimage(ch_diff.data, mode="L", fill_value=(0, 0, 0))

    #from trollimage.colormap import rdbu
    #rdbu.set_range(min_data, max_data)
    #rdbu.set_range(-20, +20)
    #rdbu.reverse()
    #img.colorize(rdbu)

    greys.set_range(-25, -15)
    greys.reverse()
    cm2 = deepcopy(rainbow)
    cm2.set_range(-15, 5)
    my_cm = greys + cm2
    img.colorize(my_cm)

    return img
Ejemplo n.º 4
0
def sandwich(self):
    """Make a colored 10.8 RGB image with HRV resolution enhacement 
    from Seviri channels.
    """
    from trollimage.image import Image as trollimage

    self.check_channels('IR_108', "HRV")

    ## use trollimage to create black white image
    #img = trollimage(self['IR_108'].data, mode="L")
    img = GeoImage(self["IR_108"].data, self.area, self.time_slot,
                   mode="L")  #, fill_value=0

    # use trollimage to create a color map
    greys.set_range(-30 + 273.15, 30 + 273.15)
    cm2 = deepcopy(rainbow)
    cm2.set_range(-73 + 273.15, -30.00001 + 273.15)
    cm2.reverse()
    my_cm = cm2 + greys

    #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])

    ## colorize the image
    img.colorize(my_cm)

    return img
Ejemplo n.º 5
0
cw.add_borders_to_file(outputFile, swiss, outline="yellow", resolution='i',level=3)

img = Image.open(outputFile)
draw = ImageDraw.Draw(img)
draw.rectangle([(0, 0), (img.size[0], 25)], fill=(0,0,0,200))
font = ImageFont.truetype("/usr/openv/java/jre/lib/fonts/LucidaTypewriterBold.ttf", 18)
draw.text((5, 3),"MSG HRV vs IR10.8 (DayNight) ccs4 20"+yearS+"-"+monthS+"-"+dayS+" "+hourS+":"+minS,(255,255,255),font=font)
img.save(outputFile)

imgarr = np.array(local_scene["IR_108"].data)
imgarr = gaussian_filter(imgarr, sigma=1)
img = Timage(imgarr, mode="L")
#black = greys
#black.colors[0] = np.array([0.,0.,0.])
#black.set_range(-40 + 273.15, 30 + 273.15)
greys.set_range(-30 + 273.15, 30 + 273.15)
#spectral.set_range(-90 + 273.15, -40.00001 + 273.15)
#my_cm = spectral + greys
setvak = cmap_from_text("setvak_rev.rgb", norm=True)
setvak_new = setvak.colors[:,:3]
setvak.colors = setvak_new
setvak.set_range(-73 + 273.15, -30.00001 + 273.15)
my_cm = setvak + greys

img.colorize(my_cm)
tmpFile = "/tmp/colir.png"
img.save(tmpFile)

outputFile = "/var/tmp/cll/out/PY_colir-ch_"+yearS+monthS+dayS+hourS+minS+".png" 

#background = Image.open(bgFile)
Ejemplo n.º 6
0
def msg1NDVI(dateSnap, avail_times, fldrs):
    """
    What does this function do?
    This definition/function is meant for computing NDVI from SEVIRI data

    Ref: https://nbviewer.jupyter.org/github/pytroll/pytroll-examples/blob/master/satpy/hrit_msg_tutorial.ipynb

    :param dateSnap:
    :param avail_times:
    :param fldrs:
    :return: NDVI
    """

    # Start the logic
    import os, sys, glob
    #from satpy.utils import debug_on
    from satpy.scene import Scene
    from satpy.dataset import combine_metadata
    from datetime import datetime
    from trollimage.colormap import greys, greens
    from trollimage.image import Image
    from myDefinitions import nc_write_sat_level_2, embellish, imResize

    #debug_on()

    print("\n \t \t \t STARTING THE msg1NDVI run @ time: %s \t \t \t \n \n" %
          str(datetime.now()))
    print("\n.Processing Date set is: %s" % dateSnap)

    #  Test whether all data folders are appropriately set or not.
    basDir, datDir, outDir, logDir, webDir, geoTdir, msg1Src, exeDir, GSHHS_ROOT, tmpDir = fldrs
    print("\n.Base directory is set to: %s" % basDir)
    print("\n.Data directory is set to %s" % datDir)
    print("\n.NetCDF output directory is set to: %s" % outDir)
    print("\n.Log directory is set to: %s" % logDir)
    print("\n.Web directory is set to: %s" % webDir)
    print("\n.GeoTiff directory is set to: %s" % geoTdir)
    print("\n.msg1Src directory is set to: %s" % msg1Src)
    print("\n.exeDir directory is set to: %s" % exeDir)
    print("\n.GSHHS directory is set to: %s" % GSHHS_ROOT)
    print("\n.tmpDir directory is set to: %s" % tmpDir)

    avail_times = str(avail_times).split()
    for tt in avail_times:
        # Start for-loop-1
        print("..Started processing for time: %s" % tt)
        searchStr = datDir + 'H-000-MSG1*' + dateSnap + tt + '-*'
        print("\n \t \t Testing 123: \n \n ")
        print(searchStr)
        files = glob.glob(searchStr)
        #print("\n Testing 123: \n")
        #print(files)

        # Start reading filename in satpy
        scn = Scene(filenames=files, reader='hrit_msg')

        #  start the NDVI computation
        scn.load(['VIS006', 0.6])
        scn.load(['VIS008', 0.8])
        ndvi = (scn[0.8] - scn[0.6]) / (scn[0.8] + scn[0.6])
        ndvi.attrs = combine_metadata(scn[0.6], scn[0.8])
        scn['ndvi'] = ndvi

        composite = 'ndvi'
        prodStr = 'NDVI'
        capStr = 'NDVI'

        # resample the data to Indian region
        indScn = scn.resample('India_SC')

        #  save the data
        # # # Save as netCDF data ---- TO BE IMPLEMENTED ----
        # outImgStr1 = outDir + 'ind_MSG-1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.nc'
        # nc_write_sat_level_2(indScn, outImgStr1, prodStr)
        #
        # # Save as Full Resolution GeoTIFF files
        # outImgStr2 = geoTdir + 'ind_MSG-1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.tiff'
        # indScn.save_dataset(composite, filename = outImgStr2, writer = 'geotiff')
        # # Add graphics
        # # img2 = embellish(basDir, GSHHS_ROOT, outImgStr2, capStr, dateSnap, tt)
        # # img2.save(outImgStr2)

        # Save the data as resized png files
        outImgStr3 = tmpDir + 'ind_MSG1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.png'
        outImgStr3w = webDir + 'ind_MSG1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.png'

        #  Apply color palette from trollimage
        ndvi_data = indScn['ndvi'].compute().data
        ndvi_img = Image(ndvi_data, mode="L")
        # greys.set_range(ndvi_data.min(), -0.00001)
        # greens.set_range(0,ndvi_data.max())
        greys.set_range(-0.8, -0.00001)
        greens.set_range(0, 0.8)
        my_cm = greys + greens
        ndvi_img.colorize(my_cm)
        ndvi_img.save(outImgStr3)
        # indScn.save_dataset(composite, filename = outImgStr3, writer = "simple_image")
        outImgStr3 = imResize(outImgStr3)
        # Add graphics
        img3 = embellish(basDir, GSHHS_ROOT, outImgStr3, capStr, dateSnap, tt)
        img3.save(outImgStr3)

        #  move the tmp files to proper web area
        mv2WebCmd = 'mv ' + outImgStr3 + ' ' + outImgStr3w
        os.system(mv2WebCmd)

        print(
            "msg1NDVI() says: Finished with processing of time-slot - %s - at: %s "
            % (tt, str(datetime.now())))