I'm attempting to export an image by a time block for a particular census KML using the method below.

Earth Engine is kicking back "internal error". As the error is not very helpful, I am having a hard time diagnosing the issue.

I am using this "https://github.com/acgeospatial/GoogleEarthEngineJs/blob/master/animation_script.js" as a guide which is from this article: "https://www.linkedin.com/pulse/time-series-landsat-data-google-earth-engine-andrew-cutts".

# Import libraries
from sqlalchemy import create_engine
import pandas as pd
import ee
from ee import batch
import ast
import sys, os

# Initialize

# Variables
ImagePath = r'Path here'
fc = ee.FeatureCollection('FeatureCollectionPath')
ShelbyCoKML = ['kml_61243', 'kml_61232', 'kml_61231', 'kml_60125', 'kml_61230', 'kml_61227', 'kml_61229', 'kml_60124', 'kml_61239', 'kml_60127', 'kml_61236', 'kml_60126', 'kml_61237', 'kml_61235', 'kml_61238', 'kml_61233', 'kml_61242', 'kml_61072', 'kml_61057', 'kml_61234', 'kml_61059', 'kml_60103', 'kml_61060', 'kml_60192', 'kml_60193', 'kml_61017', 'kml_61063', 'kml_61016', 'kml_60191', 'kml_61062', 'kml_61061', 'kml_60964', 'kml_60197', 'kml_60966', 'kml_61228', 'kml_60965', 'kml_61067', 'kml_61064', 'kml_60204', 'kml_61058', 'kml_61065', 'kml_61052', 'kml_61066', 'kml_60194', 'kml_61050', 'kml_60189', 'kml_61051', 'kml_60190', 'kml_61045', 'kml_60187', 'kml_60186', 'kml_60184', 'kml_61014', 'kml_60902', 'kml_61041', 'kml_61044', 'kml_61042', 'kml_60901', 'kml_61434', 'kml_61015', 'kml_61055', 'kml_61054', 'kml_61053', 'kml_61056', 'kml_60900', 'kml_61043', 'kml_60999', 'kml_60998', 'kml_61002', 'kml_61001', 'kml_60903', 'kml_61003', 'kml_61000', 'kml_61073', 'kml_61004', 'kml_61075', 'kml_61472', 'kml_60675', 'kml_60677', 'kml_60073', 'kml_61144', 'kml_61146', 'kml_61120', 'kml_61480', 'kml_61482', 'kml_61074', 'kml_61474', 'kml_60218', 'kml_61119', 'kml_61102', 'kml_60105', 'kml_61115', 'kml_61145', 'kml_60111', 'kml_61112', 'kml_60109', 'kml_61117', 'kml_61116', 'kml_61114', 'kml_61113', 'kml_60110', 'kml_61118', 'kml_61106', 'kml_61107', 'kml_61108', 'kml_61076', 'kml_61104', 'kml_61105', 'kml_60107', 'kml_61103', 'kml_60106', 'kml_60202', 'kml_60904', 'kml_61013', 'kml_60905', 'kml_61040', 'kml_61039', 'kml_61049', 'kml_61068', 'kml_60188', 'kml_60961', 'kml_61046', 'kml_61048', 'kml_61038', 'kml_60994', 'kml_60906', 'kml_60185', 'kml_61047', 'kml_60196', 'kml_60962', 'kml_60972', 'kml_60971', 'kml_60973', 'kml_60199', 'kml_60974', 'kml_61109', 'kml_60975', 'kml_60108', 'kml_60201', 'kml_61110', 'kml_61111', 'kml_61149', 'kml_60976', 'kml_61162', 'kml_61244', 'kml_61152', 'kml_61163', 'kml_60996', 'kml_60977', 'kml_60104', 'kml_60997', 'kml_60200', 'kml_60995', 'kml_61008', 'kml_61180', 'kml_61164', 'kml_61195', 'kml_61009', 'kml_61010', 'kml_61011', 'kml_61196', 'kml_61197', 'kml_61199', 'kml_61200', 'kml_61198', 'kml_61240', 'kml_60203', 'kml_61006', 'kml_61007', 'kml_61012', 'kml_61005', 'kml_61435', 'kml_61241', 'kml_60970', 'kml_60198', 'kml_60968', 'kml_60963', 'kml_60960', 'kml_60967', 'kml_60959', 'kml_60969', 'kml_60195', 'kml_60958', 'kml_61226', 'kml_60121', 'kml_61222', 'kml_60122', 'kml_60123', 'kml_61225', 'kml_61223', 'kml_61224', 'kml_61202', 'kml_61201', 'kml_61189', 'kml_61190', 'kml_60118', 'kml_61184', 'kml_61186', 'kml_61191', 'kml_61148', 'kml_61159', 'kml_60114', 'kml_61185', 'kml_61183', 'kml_61188', 'kml_61181', 'kml_61182', 'kml_60120', 'kml_60117', 'kml_61187', 'kml_60115', 'kml_60116', 'kml_61157', 'kml_60113', 'kml_61156', 'kml_61155', 'kml_61154', 'kml_61153', 'kml_61151', 'kml_60112', 'kml_61150', 'kml_61161', 'kml_61160', 'kml_61147', 'kml_61158', 'kml_60652', 'kml_61192', 'kml_60119', 'kml_61193', 'kml_61194', 'kml_60074']
folderName = "GeoImages_DayTime_20190914"

# functions
def get_metadata(kml_number):

    kml_tract = ee.Image(fc.filterMetadata("Name","equals",kml_number))

    kml_tract = ee.Image.getInfo(kml_tract)

    kml_tract_name = kml_tract['features'][0]['properties']['Field_1']

    return kml_tract_name

def ifnull(var, val):
  if var is None:
    return val
  return var

# connect to database
'''database connection stuff here'''
database_data = database_data.loc[:,database_data.columns.intersection(['tract_id','kml_number'])].drop_duplicates()

for iterationKML in ShelbyCoKML:

    for iterYear in range(2000,2019):

        # set vars  
        tract = database_data.loc[database_data.loc[:,'kml_number'] == iterationKML[4:],'tract_id']
        kml = iterationKML

        # Generate Geometry
        Coordinate_List = fc.filterMetadata("Name","equals",kml).geometry().bounds().getInfo()['coordinates']
        geometry = ee.Geometry.Polygon(Coordinate_List)

        # Landat 5 surface reflection data
        L5coll = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR') \
            .filter(ee.Filter.lt('CLOUD_COVER',25)) \
            .select(['B3', 'B2', 'B1']) \

        # Landat 7 surface reflection data, fill in the gaps! See USGS pages for more info

        def LS7Map(image):
            filled1a = image.focal_mean(2, 'square', 'pixels', 1)
            return filled1a.blend(image)

        L7coll = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR') \
            .filter(ee.Filter.lt('CLOUD_COVER',25)) \
            .select(['B3', 'B2', 'B1']) \
            .filterBounds(geometry) \

        # Landat 8 surface reflection data, rename the band names. See USGS pages for more info

        def LS8Map(image):
          return image.rename(['B0', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'B11'])

        L8coll = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \
            .filter(ee.Filter.lt('CLOUD_COVER',5)) \
            .filterBounds(geometry) \
            .map(LS8Map) \
            .select(['B3', 'B2', 'B1'])

        # Merge Collections
        collection_merge = ee.ImageCollection(L5coll.merge(L7coll.merge(L8coll)))

        # filter image collect by date and reduce
        start = ee.Date.fromYMD(iterYear, 1, 1)
        end = start.advance(12, 'month')
        collection_merge = collection_merge.filterDate(start, end).reduce(ee.Reducer.median())

        # clip to the size of the kml
        out = collection_merge.clip(fc.filterMetadata("Name","equals",kml))

        # check to make sure all bands are present
        if len(out.getInfo()['bands']) != 3:



            # define export parameters
            vizParams = {'bands': ['B3_median', 'B2_median', 'B1_median'], 'min': 300, 'max': 1800}

            # filename for export
            FileName = str(iterYear) + '_TractNumber_' + get_metadata(iterationKML).replace('.', '_')

            # visualzie the image
            out = out.visualize(**vizParams)

            # generate job on server
            task = ee.batch.Export.image.toDrive(  
                                image = out ,
                                bands = ['vis-red', 'vis-green', 'vis-blue'] ,
                                description = FileName,
                                folder = folderName,

            # start job

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.