Example #1
0
    def test_grid_agg_file(self):
        from pycoast import ContourWriterAGG
        grid_img = Image.open(
            os.path.join(os.path.dirname(__file__), 'grid_europe_agg.png'))
        grid_data = np.array(grid_img)

        proj4_string = '+proj=stere +lon_0=8.00 +lat_0=50.00 +lat_ts=50.00 +ellps=WGS84'
        area_extent = (-3363403.31, -2291879.85, 2630596.69, 2203620.1)
        area_def = (proj4_string, area_extent)

        cw = ContourWriterAGG(gshhs_root_dir)

        cw.add_coastlines_to_file(grid_file, area_def, resolution='l', level=4)
        cw.add_grid_to_file(grid_file,
                            area_def, (10.0, 10.0), (2.0, 2.0),
                            write_text=False,
                            outline='blue',
                            outline_opacity=255,
                            width=1.0,
                            minor_outline='lightblue',
                            minor_outline_opacity=255,
                            minor_width=0.5,
                            minor_is_tick=False)
        img = Image.open(grid_file)
        res = np.array(img)
        self.failUnless(fft_metric(grid_data, res),
                        'Writing of grid failed for AGG')
Example #2
0
    def test_europe_agg_file(self):
        from pycoast import ContourWriterAGG
        euro_img = Image.open(
            os.path.join(os.path.dirname(__file__), 'contours_europe_agg.png'))
        euro_data = np.array(euro_img)

        proj4_string = '+proj=stere +lon_0=8.00 +lat_0=50.00 +lat_ts=50.00 +ellps=WGS84'
        area_extent = (-3363403.31, -2291879.85, 2630596.69, 2203620.1)
        area_def = (proj4_string, area_extent)
        cw = ContourWriterAGG(gshhs_root_dir)
        cw.add_coastlines_to_file(test_file, area_def, resolution='l', level=4)
        cw.add_rivers_to_file(test_file,
                              area_def,
                              level=5,
                              outline='blue',
                              width=0.5,
                              outline_opacity=127)
        cw.add_borders_to_file(test_file,
                               area_def,
                               outline=(255, 0, 0),
                               width=3,
                               outline_opacity=32)

        img = Image.open(test_file)
        res = np.array(img)
        self.failUnless(fft_metric(euro_data, res),
                        'Writing of contours failed for AGG')
Example #3
0
    def test_coastlines_convert_to_rgba_agg(self):
        from pycoast import ContourWriterAGG
        proj4_string = \
            '+proj=stere +lon_0=8.00 +lat_0=50.00 +lat_ts=50.00 +ellps=WGS84'
        area_extent = (-3363403.31, -2291879.85, 2630596.69, 2203620.1)
        area_def = (proj4_string, area_extent)

        cw = ContourWriterAGG(gshhs_root_dir)
        cw.add_coastlines_to_file(p_file_coasts, area_def, resolution='l', level=4)

        img = Image.open(p_file_coasts)
        image_mode = img.mode
        img.close()

        self.assertTrue(image_mode == 'RGBA', 'Conversion to RGBA failed.')
Example #4
0
    def test_europe_agg_file(self):
        from pycoast import ContourWriterAGG
        euro_img = Image.open(os.path.join(os.path.dirname(__file__),
                                           'contours_europe_agg.png'))
        euro_data = np.array(euro_img)

        proj4_string = '+proj=stere +lon_0=8.00 +lat_0=50.00 +lat_ts=50.00 +ellps=WGS84'
        area_extent = (-3363403.31, -2291879.85, 2630596.69, 2203620.1)
        area_def = (proj4_string, area_extent)
        cw = ContourWriterAGG(gshhs_root_dir)
        cw.add_coastlines_to_file(test_file, area_def, resolution='l', level=4)
        cw.add_rivers_to_file(test_file, area_def, level=5, outline='blue',
                              width=0.5, outline_opacity=127)
        cw.add_borders_to_file(test_file, area_def, outline=(255, 0, 0), width=3,
                               outline_opacity=32)

        img = Image.open(test_file)
        res = np.array(img)
        self.failUnless(fft_metric(euro_data, res), 'Writing of contours failed for AGG')
Example #5
0
    def test_grid_agg_file(self):
        from pycoast import ContourWriterAGG
        grid_img = Image.open(os.path.join(os.path.dirname(__file__),
                                           'grid_europe_agg.png'))
        grid_data = np.array(grid_img)

        proj4_string = '+proj=stere +lon_0=8.00 +lat_0=50.00 +lat_ts=50.00 +ellps=WGS84'
        area_extent = (-3363403.31, -2291879.85, 2630596.69, 2203620.1)
        area_def = (proj4_string, area_extent)

        cw = ContourWriterAGG(gshhs_root_dir)

        cw.add_coastlines_to_file(grid_file, area_def, resolution='l', level=4)
        cw.add_grid_to_file(grid_file, area_def, (10.0, 10.0), (2.0, 2.0), write_text=False,
                            outline='blue', outline_opacity=255, width=1.0,
                            minor_outline='white', minor_outline_opacity=255, minor_width=0.5,
                            minor_is_tick=False)
        img = Image.open(grid_file)
        res = np.array(img)
        self.failUnless(fft_metric(grid_data, res), 'Writing of grid failed for AGG')
subst = ""
bname = re.sub(regex, subst, bname, 0)
regex = r"(world)"
subst = "global"
bname = re.sub(regex, subst, bname, 0)

outFile="/tmp/"+os.path.basename(bname)
finalFile=outputDirectory+"/"+os.path.basename(bname)
masterImage.save(outFile)

regex = r"\d{10}"
datetime = re.findall(regex, bname)[0]

cw = ContourWriterAGG('/opt/pytroll/shapes')
world = get_area_def('world_plat_1350_675')
cw.add_coastlines_to_file(outFile, world, resolution='l', level=1, outline=(255, 255, 255))
cw.add_coastlines_to_file(outFile, world, resolution='l', level=1, outline=(255, 255, 255))
cw.add_borders_to_file(outFile, world, outline=(255, 255, 255),resolution='i')
cw.add_borders_to_file(outFile, world, outline=(255, 255, 255),resolution='i')

img = Image.open(outFile)
img = img.convert("RGB")
draw = ImageDraw.Draw(img)
print(img.size)
draw.rectangle([(0, 0), (img.size[0], 33)], fill=(255,165,0,200))
font = ImageFont.truetype("/usr/openv/java/jre/lib/fonts/LucidaTypewriterBold.ttf", 28)
textSizeName = draw.textsize("Meteop A+B", font=font)
textSizeDate = draw.textsize(datetime + " - 12h", font=font)
textSizeWho = draw.textsize("EUMETSAT/MeteoSwiss/PyTROLL", font=font)
draw.text((5, 3),"Meteop A+B",(25,25,25),font=font)
draw.text((img.size[0]/2-textSizeDate[0]/2, 3), datetime + " - 12h",(25,25,25),font=font)
Example #7
0
    pal_mch = pal_mch / 255.0
    fig = plt.figure(frameon=False)
    fig.set_size_inches(3.712,3.712)
    ax = plt.Axes(fig, [0., 0., 1., 1.])
    ax.set_axis_off()
    fig.add_axes(ax)
    cm = LinearSegmentedColormap.from_list('ctthpal',pal)
    cm_mch = LinearSegmentedColormap.from_list('ctthpal_mch',pal_mch)
    #ax.imshow(z, cmap=cm)
    ax.imshow(z2, cmap=cm_mch)
    fig.savefig('tmp_'+fname, dpi=1000)
    
    area_src = load_area('/opt/users/cll/PyTroll/etc/areas.def', 'SeviriDiskFull00')
    area_target = load_area('/opt/users/cll/PyTroll/etc/areas.def', 'mpef-ceu')
    
    im = PIL.Image.open('tmp_'+fname)
    #im = PIL.Image.fromarray(z, mode='P')
    #tt=pal2.reshape(pal2.shape[0]*3)
    #im.putpalette(tt)
    z = np.array(im)
    
    os.remove('tmp_'+fname)
    nn = image.ImageContainerNearest(z, area_src, radius_of_influence=50000)
    area_con_quick = nn.resample(area_target)
    scipy.misc.imsave(fname,area_con_quick.image_data)
    
    cw = ContourWriterAGG('/opt/pytroll/shapes')
    cw.add_coastlines_to_file(fname, area_target, resolution='l', level=1, outline=(255, 255, 255))
    cw.add_borders_to_file(fname, area_target, outline=(255, 255, 255),resolution='i')

Example #8
0
tmpFileA = "/tmp/welcome.png"
tmpFileB = "/tmp/welcome-ir.png"
outputFile = "/var/tmp/cll/out/PY_visir-ch_"+yearS+monthS+dayS+hourS+minS+".png" 
bgFile = "/opt/users/cll/cllwork/ccs4.png"
local_scene.save_dataset("hrv_with_ir", tmpFileA)
local_scene.save_dataset("ir108", tmpFileB)

background = Image.open(bgFile)
foreground = Image.open(tmpFileA)
background = background.convert("RGBA")
foreground.putalpha(foreground.convert('L'))
foreground = foreground.convert("RGBA")
Image.alpha_composite(background, foreground).save(outputFile)

cw = ContourWriterAGG('/opt/pytroll/shapes')
cw.add_coastlines_to_file(outputFile, swiss, outline="blue", resolution='h', level=2)
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)
Example #9
0
    #print("---")
    #print(orb.get_lonlatalt(dtobj))
    #print("---")

    #lonlat = orb.get_lonlatalt(dtobj)

    #if lonlat[0] >= -10. and lonlat[0] <= 20. and lonlat[1] >= 40 and lonlat[1] <= 60:

    granule_pass = Pass("Metop-"+satname, glbl.start_time, glbl.end_time, instrument=glbl['natural_color'].sensor)
    if granule_pass.area_coverage(europe) > 0 :
       print("Region over Switzerland, making CCS4 domain...")
       #local_data = glbl.resample("ccs4large")
       local_data = glbl.resample(europe)
       local_data.save_dataset('night_fog', outDir+"METOP-"+satname+"_fog-europe_"+st+".jpg")
       local_data.save_dataset('natural_color', outDir+"METOP-"+satname+"_overview-europe_"+st+".jpg")
       cw.add_coastlines_to_file(outDir+"METOP-"+satname+"_fog-europe_"+st+".jpg", europe, resolution='l', level=1, outline=(255, 255, 255))
       cw.add_coastlines_to_file(outDir+"METOP-"+satname+"_overview-europe_"+st+".jpg", europe, resolution='l', level=1, outline=(255, 255, 255))
       cw.add_borders_to_file(outDir+"METOP-"+satname+"_fog-europe_"+st+".jpg", europe, outline=(255, 255, 255),resolution='i')
       cw.add_borders_to_file(outDir+"METOP-"+satname+"_overview-europe_"+st+".jpg", europe, outline=(255, 255, 255),resolution='i')
       if os.path.getsize(outDir+"METOP-"+satname+"_fog-europe_"+st+".jpg") < 170000:
           os.remove(outDir+"METOP-"+satname+"_fog-europe_"+st+".jpg")
       if os.path.getsize(outDir+"METOP-"+satname+"_overview-europe_"+st+".jpg") < 170000:
           os.remove(outDir+"METOP-"+satname+"_overview-europe_"+st+".jpg")

    print("Making world map...")
    #local_data = glbl.resample("world_plat_1350_675")
    local_data = glbl.resample(world)
    local_data.save_dataset('night_fog', outDir+"METOP-"+satname+"_fog-world_"+st+".jpg")
    local_data.save_dataset('natural_color', outDir+"METOP-"+satname+"_overview-world_"+st+".jpg")
    local_data.save_dataset('natural_color', outDirTmp+"METOP-"+satname+"_overview-world_"+st+".jpg")
    cw.add_coastlines_to_file(outDir+"METOP-"+satname+"_fog-world_"+st+".jpg", world, resolution='l', level=1, outline=(255, 255, 255))
Example #10
0
#ofileWebproduct = outDir + "/MSG_webproduct_"+yearS+monthS+dayS+hourS+minS+".png"
#ofilePifir = outDir + "/MSG_pifir_"+yearS+monthS+dayS+hourS+minS+".png"
#ofilePifwv = outDir + "/MSG_pifwv_"+yearS+monthS+dayS+hourS+minS+".png"
#ofilePifhrv = outDir + "/MSG_pifhrv_"+yearS+monthS+dayS+hourS+minS+".png"

img_webproduct.save(tmp_fileWebproduct)
img_pifir.save(tmp_filePifir)
img_pifwv.save(tmp_filePifwv)
img_pifhrv.save(tmp_filePifhrv)

area_def = img_pifir.area
area_def_hrv = img_pifhrv.area

cw = ContourWriterAGG('/opt/pytroll/shapes')
cw.add_coastlines_to_file(tmp_fileWebproduct, area_def, resolution='l', level=1, outline=(255, 255, 0))
cw.add_coastlines_to_file(tmp_filePifir, area_def, resolution='l', level=1, outline=(255, 255, 0))
cw.add_coastlines_to_file(tmp_filePifwv, area_def, resolution='l', level=1, outline=(255, 255, 0))
cw.add_coastlines_to_file(tmp_filePifhrv, area_def_hrv, resolution='i', level=1, outline=(255, 255, 0))

cw.add_borders_to_file(tmp_fileWebproduct, area_def, outline=(255, 255, 0),resolution='i')
cw.add_borders_to_file(tmp_filePifir, area_def, outline=(255, 255, 0),resolution='i')
cw.add_borders_to_file(tmp_filePifwv, area_def, outline=(255, 255, 0),resolution='i')
cw.add_borders_to_file(tmp_filePifhrv, area_def_hrv, outline=(255, 255, 0),resolution='i')

img = Image.open(tmp_fileWebproduct)
draw = ImageDraw.Draw(img)
print(img.size)
draw.rectangle([(0, 0), (img.size[0], 25)], fill=(255,165,0,200))
font = ImageFont.truetype("/usr/openv/java/jre/lib/fonts/LucidaTypewriterBold.ttf", 18)
textSizeName = draw.textsize("Meteosat 11", font=font)
Example #11
0
from mpop.projector import get_area_def

debug_on()
fname="msg4-alps-snow.png"
my_area="europe_center"
# Load data by filenames
files = glob("data/H-*")
scn = Scene(reader="hrit_msg", filenames=files)
scn.load(["natural"])
lscn = scn.resample(my_area)
# Save RGB geotiff
lscn.save_dataset("natural", filename=fname)

cw = ContourWriterAGG('/opt/pytroll/shapes')
europe = get_area_def(my_area)
cw.add_coastlines_to_file(fname, europe, resolution='l', level=1, outline=(255, 255, 255))
cw.add_borders_to_file(fname, europe, outline=(255, 255, 255),resolution='i')

img = Image.open(fname)
draw = ImageDraw.Draw(img)
print(img.size)
draw.rectangle([(0, 0), (img.size[0], 25)], fill=(255,165,0,200))
font = ImageFont.truetype("/usr/openv/java/jre/lib/fonts/LucidaTypewriterBold.ttf", 18)
textSizeName = draw.textsize("Meteosat 11", font=font)
textSizeDate = draw.textsize("2018-03-11 10:45 UTC", font=font)
textSizeWho = draw.textsize("EUMETSAT/MeteoSwiss/PyTROLL", font=font)
draw.text((5, 3),"Meteosat 11",(25,25,25),font=font)
draw.text((img.size[0]/2-textSizeDate[0]/2, 3), "2018-03-11 10:45 UTC",(25,25,25),font=font)
draw.text((img.size[0]-textSizeWho[0]-5, 3),"EUMETSAT/MeteoSwiss/PyTROLL",(25,25,25),font=font)
img.save(fname)