cd /home/epy/notebook/ import os import sys import grass.script as grass from gis import * from IPython.core.display import Image, HTML !export GRASS_TRANSPARENT=TRUE !export GRASS_TRUECOLOR=TRUE !export GRASS_PNG_COMPRESSION=9 !export GRASS_PNG_AUTO_WRITE=TRUE %pylab inline setGenv(location='lonlat') #grass.run_command('r.in.gdal', input='stell_10m.tiff', output='stell10m', flags='oe', overwrite=True) grass.read_command('g.region', rast='stell10m', flags='ap', res=0.0001).strip().split('\n') #grass.run_command('r.mapcalc', expression="stell_na10m=if(abs(stell10m) < 198.3, stell10m)", overwrite=True) #grass.run_command('r.null', map='stell_na10m', setnull=0) #grass.run_command('v.in.ogr', dsn='kdata/points/site1.shp', output='site1', flags='oe', overwrite=True) #grass.run_command('g.region', vect='site1', flags='ap', res=0.0001) #grass.run_command('v.in.region', type='area', output='site1area', overwrite=True) #grass.run_command('g.proj', epsg='32619', location='utm19N_wgs84') setGenv(location='utm19N_wgs84') #grass.run_command('v.proj', input='site1area', location='lonlat', mapset='PERMANENT', overwrite=True) #grass.run_command('v.proj', input='site1', location='lonlat', mapset='PERMANENT', overwrite=True) grass.run_command('g.remove', rast='dtm1') reproj(reg='site1', inp='stell_na10m', out='dtm1', res=10, buff=0, location='lonlat', mapset='PERMANENT') grass.run_command('r.fillnulls', input='dtm1', output='dtm1', overwrite=True) grass.run_command('r.out.png', input='dtm1', output='dtm1.png', overwrite=True) Image(filename='dtm1.png') !g.region rast=dtm1 -p HTML(region('dtm1')[0]) HTML(rasterinfo('dtm1')[0]) grass.run_command('m.nviz.image', elevation_map='dtm1', output='dtm1_3d', perspective=15, height=2000, color_map='dtm1', resolution_fine=1, resolution_coarse=1, format='tif') os.system('convert dtm1_3d.tif dtm1_3d.png') Image(filename='dtm1_3d.png') elev = 'dtm1' sf = 5 cl = 'elev1cl5' clf='elev1cl5nn5' vpoint='site1' img = makemorfo(input=elev,nnwin=9, pmwin=15, resolution=10, overwrite=True, remove=False) # makemorfo(input=layer, overwrite=True) pnglist = morf2png(img) imgslides(pnglist) clusterize(img[3:], cl, k=5, ss=10, ns=500) Image(filename=cl+'.png') grass.run_command('r.neighbors', flags='c', input=cl, output=clf, method='mode', size=sf, overwrite=True) grass.run_command('g.region', rast=clf, flags='ap') grass.run_command('r.out.gdal', input=clf, output=clf+'.tif', format='GTiff', type='Byte', overwrite=True) # makepng doesnt' overwrite and fail silenty makepng(rasterlist=[str(clf)], vectorlist=[str(vpoint)], output=clf+'.png') Image(filename=clf+'.png') grass.run_command('v.db.addcolumn', map=vpoint, columns="depth double precision,morfo int") grass.run_command('v.what.rast', map=vpoint, rast=clf, col='morfo') grass.run_command('v.what.rast', map=vpoint, rast=elev, col='depth') grass.read_command('db.columns', table=vpoint).strip().split('\n') grass.read_command('v.univar', map=vpoint, col='morfo', type='point').strip().split('\n') grass.read_command('v.univar', map=vpoint, col='depth', type='point').strip().split('\n') clf3d = clf+'_3d' grass.run_command('m.nviz.image', elevation_map=elev, output=clf3d, perspective=15, height=2000, color_map=clf, resolution_fine=1, resolution_coarse=1, format='tif') instruction = 'convert %s.tif %s.png' % (clf3d, clf3d) os.system(instruction) Image(filename=clf3d+'.png') gearth() grass.run_command('g.region', rast=clf, flags='ap') grass.run_command('r.out.gdal', input=clf, output=clf+'.tif', format='GTiff', type='Byte', overwrite=True) tif2kml2(clf+'.tif', clf, kmz=True, gtiff=False) inst = "cp %s.tif /var/www/esr/" % clf os.system(inst) print "http://epi.whoi.edu/esr/%s.tif" % clf makeGE(['http://epi.whoi.edu/esr/%s/doc.kml' % clf], clf+'.html', 800, 800) shaded = 'dtm1shd' rgb = 'elevshd' grass.run_command('g.region', rast=elev, flags='ap') grass.run_command('r.shaded.relief', input=elev, altitude=45, azimuth=225, output=shaded, overwrite=True) grass.run_command('r.out.png', input=shaded, output=shaded+'.png', overwrite=True) #Image(filename=shaded+'.png') grass.run_command('r.his', h_map=elev, i_map=shaded, r_map='rr', b_map='bb', g_map='gg', overwrite=True) grass.run_command('r.composite', red='rr', green='gg', blue='bb', output=rgb, overwrite=True) grass.run_command('r.out.png', input=rgb, output=rgb+'.png', overwrite=True) #Image(filename='rgb.png') Image(filename=shaded+'.png') Image(filename=rgb+'.png') cd