Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/home/denis/miniconda/bin/python
- import os
- import glob
- from nansat import Nansat
- import time
- #import sys
- from matplotlib.patches import Polygon
- import matplotlib.pyplot as plt
- plt.switch_backend('agg')
- from shapely.wkt import loads
- from osgeo import ogr
- from mpl_toolkits.basemap import Basemap
- import numpy as np
- import math
- #from scipy.signal import wiener
- ###########################################
- #
- # Process S1 data
- #
- ###########################################
- def draw_screen_poly( lats, lons, m):
- x, y = m( lons, lats )
- xy = zip(x,y)
- poly = Polygon( xy, facecolor='red', alpha=0.5 )
- l = plt.gca().add_patch(poly)
- return l
- def make_quicklook_extent(n, fname):
- # Get scene coverage
- #poly = loads(n.get_border_wkt())
- #p1 = ogr.CreateGeometryFromWkt(poly.wkt)
- # Get Envelope returns a tuple (minX, maxX, minY, maxY)
- #env = p1.GetEnvelope()
- #lons = [env[0], env[1]]
- #lats = [env[2], env[3]]
- lats = n.get_corners()[1]
- lons = n.get_corners()[0]
- plt.clf()
- fig = plt.figure()
- m = Basemap(projection='npstere',lon_0=0.,boundinglat=60,\
- lat_ts=90, resolution='l',rsphere=(6378273.,6356889.))
- m.drawcoastlines(linewidth=0.25)
- m.fillcontinents(color='#B2B2B2')
- # Draw polygon
- draw_screen_poly( lats, lons, m )
- path2file = '%s/ql/%s.jpg' % (out_dir, fname)
- fig.savefig(path2file, dpi=150, transparent=True, bbox_inches='tight', pad_inches=0.1)
- def reproject_gcp_to_stere(n):
- ''' Change projection of GCPs to stereographic add TPS option '''
- lon, lat = n.get_border()
- # reproject Ground Control Points (GCPS) to stereographic projection
- n.reproject_GCPs('+proj=stere +lon_0=%f +lat_0=%f +no_defs' % (lon.mean(), lat.mean()))
- n.vrt.tps = True
- return n
- def proc_file(ifile, out_dir):
- #n = Sentinel1Image(ifile)
- n = Nansat(ifile)
- #n.resize(0.5, eResampleAlg=-1)
- n = reproject_gcp_to_stere(n)
- fout_name = os.path.basename(ifile).split('.')[0]
- start_time = time.time()
- #lats1 = n.get_corners()[1]
- #lons1 = n.get_corners()[0]
- #lats = np.array([x for (y,x) in sorted(zip(lons1,lats1))])
- #lons = np.array([y for (y,x) in sorted(zip(lons1,lats1))])
- #lats = [np.min(lats1), np.max(lats1)]
- #lons = [np.min(lons1), np.max(lons1)]
- # Make ql with spatial extent
- #make_quicklook_extent(n, fout_name)
- #plt.savefig(path2file, dpi=150, transparent=True, bbox_inches='tight', pad_inches=0.1)
- # HV
- try:
- if os.path.isfile('%s/tiff/HV_%s.tif' % (out_dir, fout_name))==False:
- # Make ql with spatial extent
- plt.clf()
- path2file = '%s/ql/%s.jpg' % (out_dir, fout_name)
- n.write_map(path2file, pltshow=True, projection='cyl', resolution='i', continetsColor='lightgray', figureSize=(8, 8))
- print 'Start making HV tiff...'
- print '%s/%s' % (out_dir, fout_name)
- #n.write_figure('%s/HV_%s.tif' % (out_dir, fout_name), bands=[10], clim=[0,0.05], logarithm=True, cmapName='gray')
- n.write_figure('%s/tiff/HV_%s.tif' % (out_dir, fout_name), bands=[10], clim=[0,0.05], logarithm=True, cmapName='gray')
- print 'Complete!\n'
- except:
- print 'No HV data!'
- # HH
- try:
- if os.path.isfile('%s/tiff/HH_%s.tif' % (out_dir, fout_name))==False:
- # Make ql with spatial extent
- plt.clf()
- path2file = '%s/ql/%s.jpg' % (out_dir, fout_name)
- n.write_map(path2file, pltshow=True, projection='cyl', resolution='i', continetsColor='lightgray', figureSize=(8, 8))
- print 'Start making HH...'
- print '%s/%s' % (out_dir, fout_name)
- #n.write_figure('%s/HH_%s.tif' % (out_dir, fout_name),bands=[8], clim=[0,0.4444], logarithm=True, cmapName='gray') #, transparency=[0,0,0])
- n.write_figure('%s/tiff/HH_%s.tif' % (out_dir, fout_name),bands=[8], clim=[0,0.4444], logarithm=True, cmapName='gray') #, transparency=[0,0,0])
- print 'Complete!'
- except:
- print 'No HH data!'
- secs = float(time.time() - start_time)
- mins = secs/60.
- print("--- Processed in %3.1f minutes ---" % (mins))
- return 0
- #ff = sys.argv[1]
- #in_dir = '/mnt/tiris/aux_sat_data/s1/Kara_Pechora/L1'
- out_dir = '/mnt/tiris/aux_sat_data/s1/Kara_Pechora/geotiff'
- in_dir = '/mnt/eos/s1/L1/Kara_Pechora'
- try:
- os.makedirs('%s/ql' % out_dir)
- except:
- pass
- try:
- os.makedirs('%s/tiff' % out_dir)
- except:
- pass
- ffiles = glob.glob('%s/*EW*.zip' % in_dir)
- for ifile in ffiles:
- print ifile
- proc_file(ifile, out_dir)
Advertisement
Add Comment
Please, Sign In to add comment