Beispiel #1
0
    cmd = 'gdal_translate -of AAIGrid -b {band} {inf} {outf}'.format(
        band=j + 1, inf=inf, outf=lpath)
    ccb.prnt.status(cmd)
    #ccb.run(cmd)

# loop through each of the target files and resample them
ccb.prnt.status('resampling raster data')
for i in range(len(res)):
    #obase = os.path.splitext(inf)[0]
    obase = 'stacked-layers'
    opath = '{dir}{r:06d}-m/{obase}.tif'.format(dir=base,
                                                r=res[i],
                                                obase=obase)
    cmd = 'gdalwarp -multi -tr {res} {res} -r {resample} -co COMPRESS=LZW {inf} {outf}'.format(
        res=res_scaled[i], resample=resample, inf=inf, outf=opath)
    ccb.prnt.status(cmd)
    #ccb.run(cmd)

    # then run the band-by-band extraction
    for j in range(len(layers)):
        lpath = '{dir}{r:06d}-m/{layer}.asc'.format(dir=base,
                                                    r=res[i],
                                                    layer=layers[j])
        cmd = 'gdal_translate -of AAIGrid -b {band} {inf} {outf}'.format(
            band=j + 1, inf=opath, outf=lpath)
        ccb.prnt.status(cmd)
        if j == 2:
            ccb.run(cmd)

# convene a shindig
ccb.prnt.status('done resampling raster data!')
# output scales
scales = [1000, 5000, 10000, 50000, 100000]

# output data format
of = 'AAIGrid'

#####
# first, convert all the nans to 0s in the LAI data
raster_lai_nd = []
for f in raster_lai:
    outf = '{}{}-nonan.tif'.format(scratch, f[:-4])
    raster_lai_nd.append(outf)
    cmd = 'gdal_calc.py -A {} --outfile={} --co=COMPRESS=LZW --calc="nan_to_num(A)"'.format(
        raws + f, outf)
    print(cmd)
    ccb.run(cmd)

#####
# then, get the nodata values from the LST / Cloud data
msk_cld = scratch + 'mask-cld.tif'
msk_lst = scratch + 'mask-lst.tif'
msk_final = scratch + 'mask-final.tif'

cmd = 'otbcli_ManageNoData -usenan true -in {} -out "{}?&gdal:co:COMPRESS=LZW" uint8'.format(
    raw + raster_cld[0], msk_cld)
print(cmd)
ccb.run(cmd)

cmd = 'otbcli_ManageNoData -usenan true -in {} -out "{}?&gdal:co:COMPRESS=LZW" uint8'.format(
    raw + raster_lst[0], msk_lst)
print(cmd)