Exemple #1
0
def get_clipped_asset(params, asset_activation):
    '''
    Second step is to download the item to the desired path
    '''
    gaia = Gaia()
    filepath = params['filepath']
    success = gaia.get_clipped_asset(asset_activation, filepath)
    if success == 0:
        get_clipped_asset.apply_async((params, asset_activation), countdown=20)
        return False
    elif success == 1:
        generate_analytic_assets.delay(params)
        return True
    else:
        return False
def get_clipped_asset(params, asset_activation):
    '''
    Second step is to download the item to the desired path
    '''
    gaia = Gaia()
    filepath = params['filepath']
    print('filepath ', str(filepath))
    success = gaia.get_clipped_asset(asset_activation, filepath)
    if success == 0:
        get_clipped_asset.apply_async((params, asset_activation), countdown=20)
        return False
    elif success == 1:

        if params['pixels_usability_test_pass'] == 0:
            udm_filename = glob.glob(filepath + '*udm_clip.tif')[0]
            athena = Athena()
            is_cloudy_udm = athena.is_cloudy_udm(udm_filename)
            if is_cloudy_udm > 0:
                # remove that asset and end the process for this asset
                shutil.rmtree(filepath)
                print('Fail cloud test ')
                return  # if udm is > 2 % cloudy then skip processing
            else:
                # remove the current content <croped UDM>and download the remaining asset
                # and then Start the analysis Process

                print('Successfully pass the Cloudy Test')
                params['pixels_usability_test_pass'] = 1
                params['pixels_ratio'] = is_cloudy_udm

                # Gather directory contents
                contents = [os.path.join(filepath, i) for i in os.listdir(filepath)]
                # Iterate and remove each item in the appropriate manner
                [os.remove(i) if os.path.isfile(i) or os.path.islink(i) else shutil.rmtree(i) for i in contents]

                # Update the params['asset_type'] to  analytic
                params['asset_type'] = 'analytic'
                activate_clipped_asset.apply_async((params,), countdown=1)

        elif params['pixels_usability_test_pass'] == 1:
            generate_analytic_assets.delay(params)
        return True
    else:
        return False