I want to prepocess a batch of Sentinel-2 images using the code provided by ndminhhus. Earth Engine authentication, Py6S, custom module "atmospheric", basically all necessary modules have been installed and updated. The code seems to connect to functions in batch.py. This script uses the GEE Python API method prepare_for_export() (as stated in the documentation). Below are the relevant snippets:

From ndminhhus:

fname = ee.String(img.get('system:index')).getInfo()
export = ee.batch.Export.image.toAsset(\
    description= 'S2_BOA_'+fname,
    assetId = 'users/Bmperezaraujo/Py6S_Harmonisation'+'S2_BOA'+fname,
    region = region,
    scale = 10,
    maxPixels = 1e13)

# uncomment to run the export
print('exporting ' +fname + '--->done')

From batch.py:

def _prepare_image_export_config(image, config, export_destination):
  """Performs all preparation steps for an image export.

    image: The Image to be exported.
    config: All the user-specified export parameters. May be modified.
    export_destination: One of the Task.ExportDestination values.

    A config dict containing all information required for the export.
  # Supply some defaults.
  if (export_destination != Task.ExportDestination.ASSET and
      'fileFormat' not in config):
    config['fileFormat'] = 'GeoTIFF'

  _canonicalize_parameters(config, export_destination)

  image, config = image.prepare_for_export(config)
  # Build an ExportImageRequest. Delete values from "config" as we go so we
  # can check at the end for any leftovers. Any computed objects will be
  # serialised in data.py before the request is sent.
  request = {}
  request['expression'] = image
  if 'description' in config:
    request['description'] = config.pop('description')

  if export_destination == Task.ExportDestination.ASSET:
    asset_export_options = {}
        'earthEngineDestination'] = _build_earth_engine_destination(config)
    # This can only be set by internal users.
    if 'tileSize' in config and 'shardSize' in config:
      raise ee_exception.EEException(
          'Both "shardSize" and "tileSize" cannot be set.')
    if 'tileSize' in config:
      asset_export_options['tileSize'] = {
          'value': int(config.pop('tileSize'))}
    # "shardSize" is the old name for "tileSize".
    if 'shardSize' in config:
      asset_export_options['tileSize'] = {'value': int(config.pop('shardSize'))}
    if 'pyramidingPolicy' in config:
      pyramiding_policy = config.pop('pyramidingPolicy')
      if '.default' in pyramiding_policy:
            'pyramidingPolicy'] = pyramiding_policy.pop('.default').upper()
      if pyramiding_policy:
        asset_export_options['pyramidingPolicyOverrides'] = {
            band: policy.upper() for band, policy in pyramiding_policy.items()
    request['assetExportOptions'] = asset_export_options
    request['fileExportOptions'] = _build_image_file_export_options(
        config, export_destination)

  if 'maxPixels' in config:
    # This field is an Int64Value, so it needs an inner "value" field, and
    # the value itself is a string, not an integer, in the JSON encoding.
    request['maxPixels'] = {'value': str(int(config.pop('maxPixels')))}

  # This can only be set by internal users.
  if 'maxWorkers' in config:
    request['maxWorkers'] = {'value': int(config.pop('maxWorkers'))}

  # Of the remaining fields in ExportImageRequest:
  # - All the values that would go into the PixelGrid should have been folded
  #   into the image's Expression.
  # - The request ID will be populated when the Task is created.
  # We've been deleting config parameters as we handle them. Anything left
  # over is a problem.
  if config:
    raise ee_exception.EEException(
        'Unknown configuration options: {}.'.format(config))

  return request

Upon running my code, I receive the error:

AttributeError: 'Element' object has no attribute 'prepare_for_export'

I have double-checked that my input img is of ee.image.Image type.

I have a functioning GEE Python API.

I checked whether batch has the prepare_for_export method with hasattr(ee.batch, 'prepare_for_export'), but it returned me a negative.

How can I import the missing GEE Python API method?


1 Answer 1


Maybe you can delete the code below:

 dateString = scene_date.strftime("%Y-%m-%d")
 ref = ref.copyProperties(img).set({              
                  'AC_contact':'[email protected]',

Then you try it, it maybe succeed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.