def activate_clipped_asset(params): """ Download only the UDM for the assets Extract the relevant part of the UDM to our JSON Check to see if <2% of the pixels are unsuable. If <2% - download clip using the Clips API (as per now) and proceed as normal If >= 2%, skip """ gaia = Gaia() try: aoi_id = params['aoi_id'] planet_item_id = params['planet_item_id'] aoi = Aoi.objects.get_by_id(aoi_id) item_type = params['item_type'] asset_type = params['asset_type'] except Exception as e: return 'AOI, Date, & Planet Item ID must be given' try: if not aoi: return 'AOI not found.' planet_item_details = { 'item_id': planet_item_id, 'item_type': item_type, 'asset_type': asset_type } aoi_json = gaia.create_aoi_json( [aoi.coordinates], planet_item_details ) asset_activation = gaia.activate_clipped_asset(aoi_json) if not asset_activation: activate_clipped_asset.apply_async((params,), countdown=1) return False filepath = './storage/' + str(aoi_id) + '-' + str(planet_item_id) + '/' if not os.path.exists(filepath): os.makedirs(filepath) params['filepath'] = filepath get_clipped_asset.delay(params, asset_activation) return True except: return False
def activate_clipped_asset(params): ''' First step is to activate the planet's item and prepare the folder to download the item later ''' gaia = Gaia() try: aoi_id = params['aoi_id'] planet_item_id = params['planet_item_id'] date = params['date'] except Exception as e: return 'AOI, Date, & Planet Item ID must be given' aoi = Aoi.objects.get_by_id(aoi_id) if not aoi: return 'AOI not found.' planet_item_details = { 'item_id': planet_item_id, 'item_type': 'PSScene4Band', 'asset_type': 'analytic' } aoi_json = gaia.create_aoi_json( [aoi.coordinates], planet_item_details ) asset_activation = gaia.activate_clipped_asset(aoi_json) if not asset_activation: activate_clipped_asset.apply_async((params,), countdown=1) return False filepath = './storage/' + str(aoi_id) + '-' + str(planet_item_id) + '/' if not os.path.exists(filepath): os.makedirs(filepath) params['filepath'] = filepath get_clipped_asset.delay(params, asset_activation) return True