from PIL import Image import numpy as np from google.cloud import storage from firebase_admin import db def make_area_estimate_image(arr, w, h, study_uid, study_field_id, pred_val): num = 0 new_img = [[0]*w]*h row = 0 column = 0 storage_client = storage.Client() bucket_name = 'farmbase-b2f7e.appspot.com' data = np.zeros((h,w,3), dtype=np.uint8) for i in arr: if i == pred_val: data[row, column] = [0, 255,0] new_img[row][column] = i column = column + 1 if column%w == 0: row = row+1 column = 0 #print(row, column) img = Image.fromarray(data, 'RGB') img.save('area1.png') latestDay = 0 lastDayRef = db.reference('PaidMonitoredFields').child('PMF').child(study_uid).child(study_field_id).child('SensedDays').get() for (x,y) in lastDayRef.items(): if int(x) > int(latestDay): latestDay = x destination_blob_name_dem = 'PaidMonitoredFields/'+study_uid+'/'+study_field_id+'/'+latestDay+'/hybrid' dem_file_name = 'area1.png' bucket = storage_client.get_bucket(bucket_name) blob = bucket.blob(destination_blob_name_dem) blob.upload_from_filename(dem_file_name) #print(new_img)