Last active
July 12, 2016 17:00
-
-
Save tracek/1bf21ec25a85bb9784c97fdd9f866bee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_against_metadata(met, paths): | |
""" | |
Checks the list of images to ensure that a metadata entry exists for each one | |
if this is not the case, remove that image from the upload list. | |
Also check for blank values in the metadata fields, which will cause Property KeyErrors on GEE | |
Behaviour at the moment is to stop the upload if either type of errors is found, to allow the user to edit the file. | |
:param met - a dictionary of dictionaries containing the metadata entries: | |
:param paths - a list of full filepaths: | |
:return: updated list of full filepaths | |
""" | |
filter_list = [] | |
for filepath in paths: | |
filename = get_filename_from_path(filepath) | |
if filename not in met: | |
# add the file path to the list that should be filtered out | |
filter_list.append(filepath) | |
logging.warning("No metadata exists for image %s: it will not be ingested", filename) | |
# keeping this bit so that the user can specify whether this is a problem TODO | |
result = filter(lambda x: x not in filter_list, paths) | |
if len(filter_list) >0: | |
return None | |
# Now check for empty values in the metadata - these will throw errors on the Earth Engine side | |
for key in met: | |
for k, value in met[key].iteritems(): | |
if value is None or value == '': | |
logging.warning("Found an empty value for item %s - field %s" % (key, k)) | |
return None | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment