I thought exporting images from GEE should be quite straightforward, turns out I am facing difficulties, and I'm not satisfied with the answers given so far on this platform.
As a minimal example, I want to extract nightlights images at original scale for South Africa:
import ee
try:
ee.Initialize()
except Exception as e:
ee.Authenticate()
ee.Initialize()
# Nightlights
viirs = ee.ImageCollection("NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG").select('avg_rad')
# Boundary of South Africa
sa = ee.FeatureCollection("FAO/GAUL/2015/level0").filter(ee.Filter.eq("ADM0_NAME", "South Africa"))
# Get date to add in file name
def get_date(img):
return img.date().format().getInfo()
# Collection to list
viirs_list = viirs.toList(viirs.size())
# Iterate over images
for i in range(viirs_list.size().getInfo()):
img = ee.Image(viirs_list.get(i))
projection = img.projection().getInfo()
d = get_date(img)[:7] # Data is monthly, so this gets year and month
print(d)
ee.batch.Export.image.toDrive(
image = img,
description = 'Download South Africa Nightlights',
region = sa,
crs = projection["crs"],
crsTransform = projection["transform"],
maxPixels = 1e13,
folder = "south_africa_viirs_dnb_nightlights",
fileNamePrefix = 'south_africa_viirs_dnb_monthly_v1_vcmslcfg__' + d.replace('-', '_'),
fileFormat = 'GeoTIFF').start()
This code runs perfectly, but in my drive I get something very odd:
In particular: why are there different versions of the same image (the constructed names are all unique, as evident from the printout), and what are these numbers appended to the file name?