def watermask(water_in, radar_in, outName, outShp): bandDefns = [] bandDefns.append(BandDefn('VV', radar_in, 1)) bandDefns.append(BandDefn('water', water_in, 1)) gdalformat = 'KEA' imagecalc.bandMath(outName, '(VV<-18)&&(water==12)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns)
def wetvegmask(water_in, radar_in, outName, outShp): bandDefns = [] bandDefns.append(BandDefn('VVVH', radar_in, 3)) bandDefns.append(BandDefn('water', water_in, 1)) gdalformat = 'KEA' imagecalc.bandMath(outName, '(VVVH<0.45)&&(water>=2)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns)
def bandMath(inputImageVV,inputImageVH,outputImage): gdalformat = 'GTiff' datatype = rsgislib.TYPE_32FLOAT expression = 'b1/b2' bandDefns = [] bandDefns.append(BandDefn('b1', inputImageVV, 1)) bandDefns.append(BandDefn('b2', inputImageVH, 1)) imagecalc.bandMath(outputImage, expression, gdalformat, datatype, bandDefns)
def wetvegmask(water_in, radar_in, outName, outShp): print("Reading raster datasets as arrays....") # define bands bandDefns = [] bandDefns.append(BandDefn('VVVH', radar_in, 3)) bandDefns.append(BandDefn('water', water_in, 1)) # conditional statement to select semi-permanent water with high VV:VH difference print("Running conditional statement....") gdalformat = 'KEA' imagecalc.bandMath(outName, '(VVVH<0.45)&&(water>=2)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns)
def bandMath(inputImage, outputImage): gdalformat = 'GTiff' datatype = rsgislib.TYPE_32FLOAT expression = '(g-nir)/(g+nir)' # expression = '(nir-r)/(nir+r)' bandDefns = [] bandDefns.append(BandDefn('g', inputImage, 4)) bandDefns.append(BandDefn('r', inputImage, 3)) bandDefns.append(BandDefn('nir', inputImage, 2)) bandDefns.append(BandDefn('swir', inputImage, 1)) imagecalc.bandMath(outputImage, expression, gdalformat, datatype, bandDefns)
def watermask(water_in, radar_in, outName, outShp): print("Reading raster datasets as arrays....") # define bands bandDefns = [] bandDefns.append(BandDefn('VV', radar_in, 1)) bandDefns.append(BandDefn('water', water_in, 1)) # conditional statement to select permanent water with low backscatter print("Running conditional statement....") gdalformat = 'KEA' imagecalc.bandMath(outName, '(VV<-18)&&(water==12)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns)
#bandDefns.append(BandDefn('b20170117', inputImage, 2)) bandNames = imageutils.getBandNames(inputImage) # band names bandNum = numpy.arange(1, len(bandNames) + 1) # band numbers # print out all the various bandDefns functions #for b, num in zip(bandNames,bandNum): # band='"'+b+'"' # #bandDefns.append(BandDefn(band, inputImage, num)) # print("bandDefns.append(BandDefn("+band+",inputImage," +str(num)+"))") print('') print('Reading in the relevant bands') print('It took {0:0.1f} minutes'.format((time.time() - start) / 60)) bandDefns = [] bandDefns.append(BandDefn('b20170105', inputImage, 1)) bandDefns.append(BandDefn('b20170117', inputImage, 2)) bandDefns.append(BandDefn('b20170129', inputImage, 3)) bandDefns.append(BandDefn('b20170222', inputImage, 4)) bandDefns.append(BandDefn('b20170306', inputImage, 5)) bandDefns.append(BandDefn('b20170318', inputImage, 6)) bandDefns.append(BandDefn('b20170423', inputImage, 7)) bandDefns.append(BandDefn('b20170423', inputImage, 8)) bandDefns.append(BandDefn('b20170505', inputImage, 9)) bandDefns.append(BandDefn('b20170517', inputImage, 10)) bandDefns.append(BandDefn('b20170529', inputImage, 11)) bandDefns.append(BandDefn('b20170610', inputImage, 12)) bandDefns.append(BandDefn('b20170622', inputImage, 13)) bandDefns.append(BandDefn('b20170704', inputImage, 14)) bandDefns.append(BandDefn('b20170728', inputImage, 15)) bandDefns.append(BandDefn('b20170809', inputImage, 16))
# print("Running conditional statement....") # gdalformat = 'KEA' # imagecalc.bandMath(outName, '(VV<-15)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns) # # outName=radar_in.replace('.tif','_sel_lt15dB.kea') # # high_dB(radar_in, outName) listFiles = glob.glob('*sel_lt15dB.kea') listFiles = sorted(listFiles) bandDefns = [] for img in listFiles: band = band = '"' + img.split('.')[0] + '"' bandDefns.append(BandDefn(band, img, 1)) expression = '(' + listFiles[0].split('.')[0] for img in listFiles[1:len(listFiles)]: expression += ' + ' expression += img.split('.')[0] expression += ') / ' + str(len(listFiles)) gdalformat = 'KEA' imagecalc.bandMath(outName, expression, gdalformat, rsgislib.TYPE_8UINT, bandDefns) imagecalc.bandMath( outName, '(S1B_IW_GRDH_1SDV_20170105T165713_Sigma0_stack_lee_sel_lt15dB.kea + S1B_IW_GRDH_1SDV_20170117T165713_Sigma0_stack_lee_sel_lt15dB.kea + S1B_IW_GRDH_1SDV_20170129T165713_Sigma0_stack_lee_sel_lt15dB.kea) / 3', gdalformat, rsgislib.TYPE_8UINT, bandDefns)
vc=HAfilein, vcrst=outHiRISEArast) print(gdalrastcmd_HiA) subprocess.call(gdalrastcmd_HiA, shell=True) # stretch image to byte 8-bit by linear MinMax imageutils.stretchImage(outND4, outND4_s, False, '', False, True, 'GTiff', rsgislib.TYPE_8INT, imageutils.STRETCH_LINEARMINMAX) # do the same for DTMs datatype = rsgislib.TYPE_32FLOAT expression = 'b1+9999' bandDefns = [] bandDefns.append(BandDefn('b1', outDTM, 1)) imagecalc.bandMath(outDTM_a, expression, 'GTiff', datatype, bandDefns) imagecalc.imageStats(outDTM_a, statsDTM, True) if not (MGSmode): # LnK datatype = rsgislib.TYPE_32FLOAT minLnKH = 12.0 expression = 'max(b1, {m}) - {m}'.format(m=minLnKH) bandDefns = [] bandDefns.append(BandDefn('b1', rastVecPolysLnK, 1)) imagecalc.bandMath(rastVecPolysLnK_a, expression, 'GTiff', datatype, bandDefns) imagecalc.imageStats(rastVecPolysLnK_a, statsLnKHead, True)
maskVV = maskVV[maskVV < 0] threshold = filters.threshold_otsu(maskVV) #threshold=np.std(maskVV)+np.mean(maskVV) ds1 = None print('') print('Threshold: ' + str(threshold)) print('') #################################################################### #apply threshold print("Running conditional statement....") gdalformat = 'KEA' bandDefns = [] bandDefns.append(BandDefn('class', classification, 1)) bandDefns.append(BandDefn('vvAvgMask', clumpsMean, 1)) condition = '(class==1)&&(vvAvgMask>' + str(threshold) + ')?2:class' imagecalc.bandMath(outClass, condition, gdalformat, rsgislib.TYPE_8UINT, bandDefns) ''' #resampling output to match each other inProcessImg=outClass #inProcessImg='S1B_IW_GRDH_1SDV_20170517T165715_Sigma0_stack_lee_clumps2_erf_clumptrain_mode_std.kea' gdalformat = 'KEA' rsgislib.imageutils.resampleImage2Match(inRefImg, inProcessImg, outSnap, gdalformat,interpMethod='nearestneighbour', datatype=rsgislib.TYPE_8UINT) #add GUF mask inFile=outSnap outFile=inFile.replace('.kea','_guf.kea') gdalformat = 'KEA'
def colour_SM_image(inimage, colourimage, max_value=0.5, band=1): """ Colour image """ try: import rsgislib from rsgislib import imagecalc from rsgislib.imagecalc import BandDefn from rsgislib import rastergis except ImportError: raise ImportError("Could not import RSGISLib, required" " to colour image") if max_value == 0.5: # Add class field: bandDefns = [] bandDefns.append(BandDefn('SM', inimage, band)) expression = [] expression.append('0.00') expression.append('(SM > 0.00) && (SM <= 0.05)? 1 : 0') expression.append('(SM > 0.05) && (SM <= 0.10)? 2 : 0') expression.append('(SM > 0.10) && (SM <= 0.15)? 3 : 0') expression.append('(SM > 0.15) && (SM <= 0.20)? 4 : 0') expression.append('(SM > 0.20) && (SM <= 0.25)? 5 : 0') expression.append('(SM > 0.25) && (SM <= 0.30)? 6 : 0') expression.append('(SM > 0.30) && (SM <= 0.35)? 7 : 0') expression.append('(SM > 0.35) && (SM <= 0.40)? 8 : 0') expression.append('(SM > 0.40) && (SM <= 0.45)? 9 : 0') expression.append('(SM > 0.45) && (SM <= 0.50)? 10 : 0') gdalformat = get_gdal_format(colourimage) datatype = rsgislib.TYPE_8INT temp_dir = tempfile.mkdtemp(prefix='soilscape_upscaling') colourbase = os.path.basename(colourimage) colourbase, colourext = os.path.splitext(colourbase) colour = [] for i in range(11): colour.append( os.path.join(temp_dir, "{}_{}{}".format(colourbase, i + 1, colourext))) imagecalc.bandMath(colour[i], expression[i], gdalformat, datatype, bandDefns) bandDefns = [] for i in range(11): SMclass = 'SM' + str(i) bandDefns.append(BandDefn(SMclass, colour[i], 1)) if i == 0: expression = SMclass else: expression = expression + '+' + SMclass imagecalc.bandMath(colourimage, expression, gdalformat, datatype, bandDefns) shutil.rmtree(temp_dir) # Populate stats (converts to RAT): rastergis.populateStats(colourimage, False, False, True, ratband=1) # Add class field: bandStats = [] bandStats.append(rastergis.BandAttStats(band=1, maxField="SMclass")) rastergis.populateRATWithStats(colourimage, colourimage, bandStats, ratband=1) field = 'SMclass' classcolours = {} colourCat = collections.namedtuple('ColourCat', ['red', 'green', 'blue', 'alpha']) for i in range(11): classcolours[i] = colourCat(red=0, green=0, blue=0, alpha=255) classcolours[0] = colourCat(red=0, green=0, blue=0, alpha=255) classcolours[1] = colourCat(red=165, green=0, blue=38, alpha=255) classcolours[2] = colourCat(red=215, green=48, blue=39, alpha=255) classcolours[3] = colourCat(red=244, green=109, blue=67, alpha=255) classcolours[4] = colourCat(red=253, green=174, blue=97, alpha=255) classcolours[5] = colourCat(red=254, green=224, blue=144, alpha=255) classcolours[6] = colourCat(red=224, green=243, blue=248, alpha=255) classcolours[7] = colourCat(red=171, green=217, blue=233, alpha=255) classcolours[8] = colourCat(red=116, green=173, blue=209, alpha=255) classcolours[9] = colourCat(red=69, green=117, blue=180, alpha=255) classcolours[10] = colourCat(red=49, green=54, blue=149, alpha=255) rastergis.colourClasses(colourimage, field, classcolours) else: raise ValueError('Failed to find colours for specified max_value')
import gdal, rsgislib, os, subprocess, glob import numpy as np #from rsgislib import vectorutils, imagecalc import rsgislib.imagecalc from rsgislib.imagecalc import BandDefn # radar_in='/Users/Andy/Documents/Zambia/RemoteSensing/Sentinel_1/GRD/Out/Subset/S1B_IW_GRDH_1SDV_20170318T165713_Sigma0_stack_lee3.tif' # outName='/Users/Andy/Documents/Zambia/RemoteSensing/WB_classification/Supporting_data/global_surface_water/mask_barotseland_ltm8_20170318.tif' # read water mask as array #print("Reading raster datasets as arrays....") #inImg='/Users/Andy/Documents/Zambia/RemoteSensing/Sentinel_1/GRD/Out/Subset/2017/classified_stack_2017_occurrence_v2.kea' #outName=inImg.replace('.kea','_perm_water.kea') #list=sorted(glob.glob('*.tif')) inImg = 'ESACCI_LC_Map.tif' #for inImg in listImg: bandDefns = [] bandDefns.append(BandDefn('inImg', inImg, 1)) print('Processing: ' + inImg) # conditional statement # print("Running conditional statement....") #outName='./binary/'+inImg.replace('.tif','_water.tif') outName = 'africa_wetland.kea' gdalformat = 'KEA' rsgislib.imagecalc.bandMath(outName, '(inImg==5)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns)
try: guf_num=[] if (x==g1_x and y==g1_y): guf_num.append('guf1') print('Found a match: guf1') elif (x==g2_x and y==g2_y): guf_num.append('guf2') print('Found a match: guf2') elif (x==g3_x and y==g3_y): guf_num.append('guf3') print('Found a match: guf3') else: pass print('') print("Running conditional statement....") gdalformat = 'KEA' bandDefns = [] bandDefns.append(BandDefn('class', inFile, 1)) bandDefns.append(BandDefn('urban', eval(guf_num[0]), 1)) condition='(class==3)&&(urban>0)?2:class' imagecalc.bandMath(outFile, condition, gdalformat, rsgislib.TYPE_8UINT, bandDefns) except: print('No matching GUF for: ' + inFile) pass
#################################################################### # snap permanent water inProcessImg=permWater inRefImg=inputImage outSnap=permWater.replace('.kea','_'+inputImage.split('/')[-1].split('_')[4]+'_snap.kea') gdalformat = 'KEA' rsgislib.imageutils.resampleImage2Match(inRefImg, inProcessImg, outSnap, gdalformat,interpMethod='nearestneighbour', datatype=rsgislib.TYPE_8UINT) #################################################################### # add permanent water mask permWaterMask=outSnap bandDefns = [] bandDefns.append(BandDefn('class', outCert, 1)) bandDefns.append(BandDefn('permWat', permWaterMask, 1)) condition='(permWat==1)?1:class' gdalformat = 'kea' imagecalc.bandMath(outimage, condition, gdalformat, rsgislib.TYPE_8UINT, bandDefns) # remove the intermediate certainty classifcation image try: os.remove(outCert) except Exception: pass ########################################################################################### # select dry season images and apply refinement
'OutClass_mode_cert_sel_names', names, colType=gdal.GFT_String) # export rat column: mode with certainty to image gdalformat = 'GTiff' datatype = rsgislib.TYPE_8INT fields = ['OutClass_mode_cert_sel'] rastergis.exportCols2GDALImage(clumps, outImage, gdalformat, datatype, fields) #bandmath to add permananent water pixels bandDefns = [] bandDefns.append(BandDefn('class', outImage, 1)) bandDefns.append(BandDefn('permWater', waterPerm, 1)) imagecalc.bandMath(outImage, '(permWater>=5)?1:class', 'GTiff', rsgislib.TYPE_8UINT, bandDefns) ratDataset = None # clumps=None # add colourtable #cmd='gdaldem color-relief ' + outImage + ' /Users/Andy/Documents/Zambia/RemoteSensing/WB_classification/gdaldem_wb_class_colours.txt ' + outImage #subprocess.call(cmd) os.system('afplay /System/Library/Sounds/Tink.aiff') except Exception: print('') print('............................................') print('Failed: ' + clumps)
maskVV = maskVV[maskVV < 0] #threshold=filters.threshold_otsu(maskVV) threshold = np.std(maskVV) + np.mean(maskVV) ds1 = None print('') print('Threshold: ' + str(threshold)) print('') #################################################################### #apply threshold print("Running conditional statement....") gdalformat = 'KEA' bandDefns = [] bandDefns.append(BandDefn('class', classification, 1)) bandDefns.append(BandDefn('vvAvgMask', clumpsMean, 1)) condition = '(class==1)&&(vvAvgMask>' + str(threshold) + ')?2:class' imagecalc.bandMath(outClass, condition, gdalformat, rsgislib.TYPE_8UINT, bandDefns) #resampling output to match each other inProcessImg = outClass rsgislib.imageutils.resampleImage2Match(inRefImg, inProcessImg, outImg, gdalFormat, interpMethod='nearestneighbour', datatype=rsgislib.TYPE_8UINT)
# radar_in='/Users/Andy/Documents/Zambia/RemoteSensing/Sentinel_1/GRD/Out/Subset/S1B_IW_GRDH_1SDV_20170318T165713_Sigma0_stack_lee3.tif' # outName='/Users/Andy/Documents/Zambia/RemoteSensing/WB_classification/Supporting_data/global_surface_water/mask_barotseland_ltm8_20170318.tif' # read water mask as array print("Reading raster datasets as arrays....") #ndvi='/Users/Andy/Documents/Zambia/RemoteSensing/Sentinel_2/GEE/S2_composite_aug_sep_2017_ndvi_snapped.tif' #seasonality='/Users/Andy/Documents/Zambia/RemoteSensing/WB_classification/Supporting_data/global_surface_water/seasonality_barotseland_snapped.tif' hand = '/Users/Andy/Documents/Zambia/FloodModelling/HAND/HAND_Main_Channel_Only_120m_snapped.tif' #ls_image='/Users/Andy/Documents/Zambia/RemoteSensing/Sentinel_2/GEE/S2_composite_aug_sep_2017_swir_snapped.tif' sel = '/Users/Andy/Documents/Zambia/RemoteSensing/WB_classification/Supporting_data/sand_exclusion_layer/S1B_IW_GRDH_1SDV_2017_sel_2.kea' outName = '/Users/Andy/Documents/Zambia/RemoteSensing/WB_classification/Supporting_data/sand_exclusion_layer/sel_hand_sand_mask.kea' bandDefns = [] #bandDefns.append(BandDefn('water', seasonality, 1)) bandDefns.append(BandDefn('hand', hand, 1)) #bandDefns.append(BandDefn('ndvi', ndvi, 1)) #bandDefns.append(BandDefn('swir', ls_image, 1)) bandDefns.append(BandDefn('sel', sel, 1)) # conditional statement to select semi-permanent water with high VV:VH difference print("Running conditional statement....") gdalformat = 'KEA' #imagecalc.bandMath(outName, '(ndvi>0.06)&&(ndvi<=0.12)&&(water==0)&&(hand>5)&&(swir>2000)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns) imagecalc.bandMath(outName, '(sel>60)&&(sel<94)&&(hand>5)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns) ''' file_read=gdal.Open(inFile) mask=np.array(file_read.GetRasterBand(1).ReadAsArray())
bandNames = [] for img in images: bandNames.append('b' + img.split('-')[0] + img.split('-')[1] + img.split('-')[2].split('_')[0]) # print out all the various bandDefns functions for b, i in zip(bandNames, images): print("bandDefns.append(BandDefn( '" + b + "','" + i + "'," + str(1) + "))") print('Reading in the masks') #print('It took {0:0.1f} minutes'.format((time.time() - start) / 60)) bandDefns = [] bandDefns.append(BandDefn('b01032018b', '01-03-2018b_water.kea', 1)) bandDefns.append(BandDefn('b01102016b', '01-10-2016b_water.kea', 1)) bandDefns.append(BandDefn('b04082018b', '04-08-2018b_water.kea', 1)) bandDefns.append(BandDefn('b05022018b', '05-02-2018b_water.kea', 1)) bandDefns.append(BandDefn('b05062018b', '05-06-2018b_water.kea', 1)) bandDefns.append(BandDefn('b06032017b', '06-03-2017b_water.kea', 1)) bandDefns.append(BandDefn('b06042018b', '06-04-2018b_water.kea', 1)) bandDefns.append(BandDefn('b06112016b', '06-11-2016b_water.kea', 1)) bandDefns.append(BandDefn('b07122017b', '07-12-2017b_water.kea', 1)) bandDefns.append(BandDefn('b08102017b', '08-10-2017b_water.kea', 1)) bandDefns.append(BandDefn('b09082017b', '09-08-2017b_water.kea', 1)) bandDefns.append(BandDefn('b10022017b', '10-02-2017b_water.kea', 1)) bandDefns.append(BandDefn('b11042017b', '11-04-2017b_water.kea', 1)) bandDefns.append(BandDefn('b11072018b', '11-07-2018b_water.kea', 1)) bandDefns.append(BandDefn('b12012018b', '12-01-2018b_water.kea', 1)) bandDefns.append(BandDefn('b12052018b', '12-05-2018b_water.kea', 1))
import rsgislib from rsgislib import imagecalc from rsgislib.imagecalc import BandDefn outputImage = '/Users/Andy/Documents/Zambia/RemoteSensing/Sentinel_1/GRD/Out/Subset/S1B_IW_GRDH_1SDV_20170821T165721_Sigma0_VVdivVH.tif' gdalformat = 'GTiff' datatype = rsgislib.TYPE_32FLOAT expression = 'b1/b2' bandDefns = [] bandDefns.append( BandDefn( 'b1', '/Users/Andy/Documents/Zambia/RemoteSensing/Sentinel_1/GRD/Out/Subset/S1B_IW_GRDH_1SDV_20170821T165721_Sigma0_VV_dB.tif', 1)) bandDefns.append( BandDefn( 'b2', '/Users/Andy/Documents/Zambia/RemoteSensing/Sentinel_1/GRD/Out/Subset/S1B_IW_GRDH_1SDV_20170821T165721_Sigma0_VH_dB.tif', 1)) imagecalc.bandMath(outputImage, expression, gdalformat, datatype, bandDefns)
slope='/Users/Andy/Documents/Zambia/FloodModelling/Data/DEMs/SRTM/barotse_srtm_5x5_slope.tif' hand='/Users/Andy/Documents/Zambia/FloodModelling/HAND/GEE_hand/hand90_1000.tif' outShp='/Users/Andy/Documents/Zambia/RemoteSensing/WB_classification/Supporting_data/global_surface_water/barotseland_srtm_utm_lee_slope_gt1_5_wgs84.shp' outShp2='/Users/Andy/Documents/Zambia/RemoteSensing/WB_classification/Supporting_data/global_surface_water/barotseland_srtm_utm_lee_slope_gt1_5_wgs84_pxl1.shp' # snapping slopeSnap='/Users/Andy/Documents/Zambia/FloodModelling/Data/DEMs/SRTM/srtm_arc1_barotseland_5x5_slope_snap.kea' inRefImg=hand # base raster to snap to gdalFormat = 'KEA' #rsgislib.imageutils.resampleImage2Match(inRefImg, slope, slopeSnap, gdalFormat, interpMethod='nearestneighbour', datatype=None) # perform resampling/snap bandDefns = [] bandDefns.append(BandDefn('slope', slopeSnap, 1)) bandDefns.append(BandDefn('hand', hand, 1)) outName='/Users/Andy/Documents/Zambia/FloodModelling/Data/DEMs/SRTM/srtm_arc1_barotseland_5x5_slope_gt3_and_hand_gt30.kea' gdalformat = 'KEA' imagecalc.bandMath(outName, '(slope>3)&&(hand>30)&&(hand<1000)?1:0', gdalformat, rsgislib.TYPE_8UINT, bandDefns) # option to vectorize the output inputImg=outName rsgislib.vectorutils.polygoniseRaster(inputImg, outShp, imgBandNo=1, maskImg=None, imgMaskBandNo=1) cmd="ogr2ogr -where PXLVAL='1' '%s' '%s'" %(outShp,outShp2) subprocess.call(cmd, shell=True)
os.system(cmd) cmd='gdal_calc.py -A %s --A_band=2 --outfile=%s --calc="nan_to_num(A)"' %(inputImage,b2) os.system(cmd) cmd='gdal_calc.py -A %s --A_band=3 --outfile=%s --calc="nan_to_num(A)"' %(inputImage,b3) os.system(cmd) gdalformat = 'KEA' # define the output names b1_nan=b1.replace('.tif','_b1_nan.tif') b2_nan=b2.replace('.tif','_b2_nan.tif') b3_nan=b3.replace('.tif','_b3_nan.tif') bandDefns = [] bandDefns.append(BandDefn('b1', b1, 1)) imagecalc.bandMath(b1_nan, '(b1==0.0)?-999:b1', gdalformat, rsgislib.TYPE_32FLOAT, bandDefns) bandDefns = [] bandDefns.append(BandDefn('b2', b2, 1)) imagecalc.bandMath(b2_nan, '(b2==0.0)?-999:b2', gdalformat, rsgislib.TYPE_32FLOAT, bandDefns) bandDefns = [] bandDefns.append(BandDefn('b3', b3, 1)) imagecalc.bandMath(b3_nan, '(b3==0.0)?-999:b3', gdalformat, rsgislib.TYPE_32FLOAT, bandDefns) gdalformat='GTiff' gdaltype = rsgislib.TYPE_32FLOAT imageutils.stackImageBands([b1_nan,b2_nan,b3_nan], ['VV','VH','VVdivVH'] , nanOut, None, -999, gdalformat, gdaltype) try: os.remove(b1) os.remove(b2)
#bandDefns.append(BandDefn('b20170105', inputImage, 1)) #bandDefns.append(BandDefn('b20170117', inputImage, 2)) bandNames = imageutils.getBandNames(inputImage) # band names bandNum = numpy.arange(1, len(bandNames) + 1) # band numbers # print out all the various bandDefns functions ''' for band, num in zip(bandNames,bandNum): band='"+band+"' bandDefns.append(BandDefn(band, inputImage, num)) print("bandDefns.append(BandDefn('"+band+"',inputImage," +str(num)+"))") ''' for b, num in zip(bandNames, bandNum): band = '"' + b + '"' bandDefns.append(BandDefn(band, inputImage, num)) print("bandDefns.append(BandDefn(" + band + ",inputImage," + str(num) + "))") #bandDefns = [] #bandDefns.append(BandDefn('b20170105',inputImage,1)) #bandDefns.append(BandDefn('b20170117',inputImage,2)) #bandDefns.append(BandDefn('b20170129',inputImage,3)) #bandDefns.append(BandDefn('b20170222',inputImage,4)) #bandDefns.append(BandDefn('b20170306',inputImage,5)) #bandDefns.append(BandDefn('b20170318',inputImage,6)) #bandDefns.append(BandDefn('b20170423',inputImage,7)) #bandDefns.append(BandDefn('b20170423',inputImage,8)) #bandDefns.append(BandDefn('b20170505',inputImage,9)) #bandDefns.append(BandDefn('b20170517',inputImage,10)) #bandDefns.append(BandDefn('b20170529',inputImage,11))