def runMTCDmosaicPre(id, s3_location): gbdx = Interface() if (id == -2): # do the mosaicing of 1 and 2 images1 = getS3location(gbdx, s3_location + "/1") images2 = getS3location(gbdx, s3_location + "/2") tsk = gbdx.Task('mtcdvrt', images1=images1, images2=images2, id="pre") elif (id == -3): # do the mosaicing of 1, 2 snd 3 images1 = getS3location(gbdx, s3_location + "/1") images2 = getS3location(gbdx, s3_location + "/2") images3 = getS3location(gbdx, s3_location + "/3") tsk = gbdx.Task('mtcdvrt', images1=images1, images2=images2, images3=images3, id="pre") else: print("Wrong id in runMTCDmosaicPre", id) return 1 workflow = gbdx.Workflow([tsk]) workflow.savedata(tsk.outputs.data, location=s3_location + "/image2image/") workflow.execute() print('MTCD mosaic start', id, images1, workflow.id) waitForWorkflow(workflow) print('MTCD mosaic done ' + images1 + ' ' + images2 + ' ' + str(id) + ' ' + str(workflow.status) + ' at ' + str(datetime.now())) if (not workflow.status["event"] == "succeeded"): print('MTCD mosaic failed') return 1 return 0
def aopImage(catalog_id, s3_location, local_dir=None, panPixelSize=0.5, clip=None): gbdx = Interface() isWV1 = catalog_id.startswith('102') if (isWV1): print( "WARNING is a WV1 image and MS or Pansharpened image can't be ordered" ) isSWIR = catalog_id.startswith('104A') if (isSWIR): print("ERROR SWIR image can't be orthorectified") return order_id = order(gbdx, catalog_id) data = gbdx.ordering.status(order_id)[0]['location'] gdalwarpOptions = " -r near --config GDAL_CACHEMAX 4000 -wm 4000 -co TILED=TRUE -co COMPRESS=PACKBITS -co BIGTIFF=YES " aoptask = gbdx.Task("AOP_Strip_Processor", data=data, enable_acomp=True, enable_pansharpen=False, enable_dra=False, ortho_epsg='UTM', bands='MS', ortho_pixel_size=str(4 * panPixelSize), ortho_dem_specifier=dem) if (clip is not None): clipTask = gbdx.Task("gdalcrop", image=aoptask.outputs.data, crop=clip + ' -tr ' + str(4 * panPixelSize) + ' ' + str(4 * panPixelSize) + gdalwarpOptions, ship='false') workflow = gbdx.Workflow([aoptask, clipTask]) workflow.savedata(clipTask.outputs.cropped, location=s3_location + 'MS') else: workflow = gbdx.Workflow([aoptask]) workflow.savedata(aoptask.outputs.data, location=s3_location + 'MS') workflow.execute() print('AOP is processing image ' + catalog_id + ' MS workflow id is ' + workflow.id) waitForWorkflow(workflow) print('MS image ' + catalog_id + ' ' + str(workflow.status) + ' at ' + str(datetime.now())) if local_dir == '': return if (local_dir is not None): print('Downloading AOP images') if not os.path.exists(local_dir): os.makedirs(local_dir) gbdx.s3.download(location=s3_location, local_dir=local_dir) print('Image downloaded' + catalog_id + ' at ' + str(datetime.now())) return
def changePrep(catalog_id, s3_location, clip=None): size = '2' gbdx = Interface() isWV1 = catalog_id.startswith('102') if (isWV1 and (ms or pansharpen or pansharpenship)): print("ERROR Image is a WV1 image.") return isSWIR = catalog_id.startswith('104A') if (isSWIR): print("ERROR Image is a WV1 image.") return order_id = order(gbdx, catalog_id) data = gbdx.ordering.status(order_id)[0]['location'] gdalwarpOptions = " -r near --config GDAL_CACHEMAX 4000 -wm 4000 -co TILED=TRUE -co COMPRESS=PACKBITS -co BIGTIFF=YES " gdalwarpOptions = " -r near -co TILED=TRUE -co COMPRESS=PACKBITS -co BIGTIFF=YES " aoptask = gbdx.Task("AOP_Strip_Processor", data=data, enable_acomp=True, enable_pansharpen=False, enable_dra=False, ortho_epsg='UTM', bands='MS', ortho_pixel_size=size) #aoptask = gbdx.Task("AOP_Strip_Processor", data=data, enable_acomp=False, enable_pansharpen=False, enable_dra=False, ortho_epsg='UTM', bands='MS', ortho_pixel_size='16') topoTask = gbdx.Task("topo-correction", image=aoptask.outputs.data) topoTask.impersonation_allowed = True cloudTask = gbdx.Task("CloudPuncher", image=topoTask.outputs.data, maskOnly='false') #cloudTask = gbdx.Task("CloudPuncher", image = aoptask.outputs.data, maskOnly = 'false') if (clip is not None): ##################################################################################################################################################################################### clipTask = gbdx.Task('gdalcrop', image=cloudTask.outputs.mask, crop=clip + ' -tr ' + size + ' ' + size + gdalwarpOptions, ship='false') workflow = gbdx.Workflow([aoptask, topoTask, cloudTask, clipTask]) workflow.savedata(clipTask.outputs.cropped, location=s3_location) else: workflow = gbdx.Workflow([aoptask, topoTask, cloudTask]) workflow.savedata(cloudTask.outputs.mask, location=s3_location) workflow.execute() print('AOP is processing image ' + catalog_id + ' MS workflow id is ' + workflow.id) waitForWorkflow(workflow) print('MS image ' + catalog_id + ' ' + str(workflow.status) + ' wfl id ' + workflow.id + ' at ' + str(datetime.now())) if (not workflow.status["event"] == "succeeded"): print("workflow.status", workflow.status, workflow.status["event"] == "succeeded") return 1 return 0
def runMTCDmosaic(id, s3_location): gbdx = Interface() images = getS3location(gbdx, s3_location + "/" + str(id)) tsk = gbdx.Task('mtcdvrt', images1=images, id=str(id)) workflow = gbdx.Workflow([tsk]) workflow.savedata(tsk.outputs.data, location=s3_location + "/image2image/") workflow.execute() print('MTCD mosaic start', id, images, workflow.id) waitForWorkflow(workflow) print('MTCD mosaic done ' + images + ' ' + str(id) + ' ' + str(workflow.status) + ' at ' + str(datetime.now())) if (not workflow.status["event"] == "succeeded"): print('MTCD mosaic failed') return 1 return 0
def runMTCD(s3_locationPre, s3_locationPost, out_s3_location): gbdx = Interface() preimage = getS3location(gbdx, s3_locationPre) postimage = getS3location(gbdx, s3_locationPost) tsk = gbdx.Task('mtcd', preimage=preimage, postimage=postimage) workflow = gbdx.Workflow([tsk]) workflow.savedata(tsk.outputs.data, location=out_s3_location) workflow.execute() print('MTCD image pair start ' + s3_locationPre + ' ' + s3_locationPost + ' ' + out_s3_location + ' ' + str(workflow.id) + ' at ' + str(datetime.now())) waitForWorkflow(workflow) print('MTCD image pair done ' + s3_locationPre + ' ' + s3_locationPost + ' ' + out_s3_location + ' ' + str(workflow.status) + ' at ' + str(datetime.now())) if (not workflow.status["event"] == "succeeded"): return 1 return 0
def image2image(ref_image_s3_dir, image_s3_dir, output_s3, source_filename=None, reference_filename=None, clip=None, pixelSize=2, fileName=None): gbdx = Interface() full_ref_image_s3_dir = getS3location(gbdx, ref_image_s3_dir) full_image_s3_dir = getS3location(gbdx, image_s3_dir) task = gbdx.Task("image2image", reference_directory=full_ref_image_s3_dir, source_directory=full_image_s3_dir, source_filename=source_filename, reference_filename=reference_filename) task.timeout = 36000 if (clip is not None): clipTask1 = gbdx.Task("gdalcrop", image=task.outputs.out, crop=clip + ' -tr ' + str(pixelSize) + ' ' + str(pixelSize), ship='False', updateName='False', fileName=fileName) workflow = gbdx.Workflow([task, clipTask1]) workflow.savedata(clipTask1.outputs.cropped, location=output_s3) else: workflow = gbdx.Workflow([task]) workflow.savedata(task.outputs.out, location=output_s3) workflow.execute() print('image2Image ' + ref_image_s3_dir + ' ' + image_s3_dir + ' ' + output_s3 + ' ' + fileName + ' workflow ' + str(workflow.id) + ' started at ' + str(datetime.now())) waitForWorkflow(workflow) print('image2Image ' + str(workflow.id) + ' ' + ref_image_s3_dir + ' ' + image_s3_dir + ' ' + output_s3 + ' ' + str(workflow.status) + ' at ' + str(datetime.now())) if (not workflow.status["event"] == "succeeded"): return 1 return 0