Suppose I have a class that looks like this with 2 methods, 1 main method called ee_loader
and a “helper” method called inside ee_loader
called metadata_updater
:
class ee_util:
def __init__(self, bucket, image, asset_id, project):
"""Instance variable"""
self.bucket = bucket
self.bucket_folder = ''
self.image = image
self.asset_id = asset_id
self.project = project
self.date_dt = datetime.now()
def metadata_updater(self, asset_obj: object, meta_obj: object ):
for k, v in meta_obj.items():
asset_obj['properties'][k] = v
return asset_obj
def ee_loader(self, asset_id: str, filename: str, image_path: str, band_list: list, meta_obj: object):
"""Method for loading assets to EE"""
date_str = self.date_dt.strftime('%Y%m%d')
asset = {
"name": asset_id,
"tilesets": [
{
"id": "data_tileset",
"sources": [{"uris": [image_path]}]
}
],
"bands": [{'id': name,
'tileset_band_index': index,
"tileset_id": "data_tileset"}
for index, name in enumerate(band_list)],
'properties': {'upload_date': datetime.today().strftime('%Y-%m-%d'),
'date_str': date_str,
'file_name': str(filename)
}
}
if meta_obj:
print("Adding metadata to properties.")
asset = self.metadata_updater(asset_obj=asset, meta_obj=metadata)*
else:
print("Accept asset as-is. ")
request_id = ee.data.newTaskId()[0]
taskID = ee.data.startIngestion(request_id, asset)
task_status = ee.data.getTaskStatus(taskID)
print(str(task_status))
I have a metadata object like this that I will pass in once the class is instantiated.:
metadata = {
'annprcp_norm#_standard_name': 'precipitation_amount',
'annprcp_norm#_units': 'millimeter',
'annprcp_std#_standard_name': 'standard_deviation',
'annprcp_std#_units': 'millimeter',
'annprcp_min#_standard_name': 'precipitation_amount',
'annprcp_min#_units': 'millimeter',
'annprcp_max#_standard_name': 'precipitation_amount',
'annprcp_max#_units': 'millimeter',
'annprcp_flag#_standard_name': 'precipitation_amount',
'annprcp_flag#_units': 'number of months'}
I instantiate the class:
my_util = ee_util('my_bucket', 'my_image.tif', 'my_asset_id', 'my_project')
And then I call my ee_loader
method:
my_util.ee_loader('my_asset_id', 'my_filename', 'my_image_path', ['band_1', 'band_2'], metadata)
When I run the last line, I get the following error:
NameError: name 'metadata_updater' is not defined
What am I doing wrong here with my metadata_updater
function inside the class? I though using self
would suffice, but it seems I am missing something.