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')
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')
from cll_composites import * debug_on() my_example_nc_file = "MSG2_ccs4_201712250900_rad.nc" fname = "MSG2_ccs4_201712250900_rad.png" fh = Dataset(my_example_nc_file, mode='r') z = fh.variables['HRV'][:] z = z.reshape(640,710) fh.close() fig = plt.figure(frameon=False) fig.set_size_inches(7.1,6.4) ax = plt.Axes(fig, [0., 0., 1., 1.]) ax.set_axis_off() fig.add_axes(ax) ax.imshow(z) fig.savefig(fname, dpi=300) area_src = load_area('/opt/users/cll/PyTroll/etc/areas.def', 'ccs4') area_target = load_area('/opt/users/cll/PyTroll/etc/areas.def', 'SwitzerlandStereo500m') nn = image.ImageContainerNearest(z, area_src, radius_of_influence=5000) 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(ofilePifir, area_def, resolution='i', level=2, outline=(255, 255, 0), fill=(255, 255, 0)) cw.add_borders_to_file(fname, area_target, outline=(255, 255, 255),resolution='i')
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) draw.text((img.size[0]-textSizeWho[0]-5, 3),"EUMETSAT/MeteoSwiss/PyTROLL",(25,25,25),font=font) img.save(outFile)
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) greys.set_range(-30 + 273.15, 30 + 273.15)
imgarr = np.array(local_scene['lscl'].data) from trollimage.image import Image as Timage img = Timage(imgarr, mode="L") img.colorize(rdgy.reverse()) img.save(png_file) # local_scene.save_dataset( 'lscl', png_file ) from pyresample.utils import load_area swiss = load_area("/opt/users/hau/monti-pytroll/etc/areas.def", area) from pycoast import ContourWriterAGG cw = ContourWriterAGG('/opt/users/common/shapes') cw.add_borders_to_file(png_file, swiss, outline="green", resolution='i', level=3, width=2) img = Image.open(png_file) draw = ImageDraw.Draw(img) draw.rectangle([(0, 0), (img.size[0] * 0.7, 25)], fill=(0, 0, 0, 200)) font = ImageFont.truetype( "/usr/openv/java/jre/lib/fonts/LucidaTypewriterBold.ttf", 18) title = start_time.strftime( " " + sat[0:3] + "-" + sat[3] + ', %y-%m-%d %H:%MUTC, low stratus confidence level') draw.text((1, 1), title, "green", font=font) # (255,255,255) img.save(png_file)
#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)) cw.add_coastlines_to_file(outDir+"METOP-"+satname+"_overview-world_"+st+".jpg", world, resolution='l', level=1, outline=(255, 255, 255)) cw.add_borders_to_file(outDir+"METOP-"+satname+"_fog-world_"+st+".jpg", world, outline=(255, 255, 255),resolution='i')
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) textSizeProd = draw.textsize("webproduct", font=font) textSizeDate = draw.textsize("20"+yearS+"-"+monthS+"-"+dayS+" "+hourS+":"+minS+" UTC", font=font) draw.text((5, 3),"Meteosat 11",(25,25,25),font=font) draw.text((img.size[0]-textSizeProd[0]-5,3),"webproduct",(25,25,25),font=font) draw.text((img.size[0]/2-textSizeDate[0]/2, 3),"20"+yearS+"-"+monthS+"-"+dayS+" "+hourS+":"+minS+" UTC",(25,25,25),font=font)
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)