from itertools import zip_longest from tempfile import tempdir import firebase_admin from firebase_admin import credentials from firebase_admin import db from find_s1_image import find_img_value import pandas as pd from sklearn.metrics import classification_report, confusion_matrix, accuracy_score import statsmodels.api as sm import seaborn as sns sns.set() from zipfile import ZipFile from sklearn.ensemble import RandomForestRegressor from sklearn.model_selection import train_test_split import csv import time import json from find_modis_ndvi import find_modis_ndvi import numpy as np from sklearn.cluster import KMeans from find_study_area_values import find_study_area_values from find_study_area_values3 import find_study_area_values3 from make_area_estimate_image import make_area_estimate_image from make_egypt_estimate_image import make_egypt_estimate_image from sentinelhub import WebFeatureService, BBox, CRS, MimeType, CRS, BBox, WmsRequest,DataCollection import traceback from firebase_admin import firestore from PIL import Image import numpy as np from google.cloud import storage import os from firebase_admin import db from get_mask import get_mask import cv2 import scipy.ndimage from google.oauth2 import service_account import datetime from datetime import date from datetime import timedelta from datetime import datetime import requests import traceback from ftplib import FTP import paramiko import pysftp from gen_geotiff3 import create_geotiff import math storage_client = storage.Client.from_service_account_json("servicekey.json"); bucket_name = 'farmbase-b2f7e.appspot.com' cred = service_account.Credentials.from_service_account_file('servicekey.json') #cred = credentials.Certificate('servicekey.json') bucket = storage_client.bucket(bucket_name) try: firebase_admin.initialize_app(credentials.Certificate('servicekey.json'), {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') db_firestore = firestore.client() from sentinelhub import SHConfig, MimeType, BBox, SentinelHubRequest, SentinelHubDownloadClient, DataCollection, geo_utils # Example usage: def upload_file(source_path, destination_path, expire_minutes=15): storage_client = storage.Client.from_service_account_json('servicekey.json') bucket_name = 'farmbase-b2f7e.appspot.com' bucket = storage_client.get_bucket(bucket_name) blob = bucket.blob(destination_path) storage_url = 'https://farmonaut.com/Images/data_not_found.jpg' try: blob.upload_from_filename(source_path) storage_url = blob.generate_signed_url(version="v4",expiration = timedelta(minutes=expire_minutes), method="GET") return storage_url except: print(traceback.format_exc()) def main(): #storage_client = storage.Client() # req_obj = {} # req_obj["IsReportRequested"] = 1 # db_firestore.collection('ReportZipRequests').document('XSzwRsmzu4OeCm8UvllGn7xsnOk1').set(req_obj) zip_requests_obj = db_firestore.collection(u'GeotifRequests').where('Processed','==',0).get() for temp_d in zip_requests_obj: time_stamp = temp_d.id time_stamp = str(time_stamp) print(temp_d.id) print(temp_d.to_dict()) temp_main_obj = temp_d.to_dict() try: uid = temp_main_obj["UID"] fieldid = temp_main_obj["FieldID"] fieldid = str(fieldid) sensedday = temp_main_obj.get("SensedDay", 0) imagetype = str(temp_main_obj.get("ImageType", 0)) field_obj = db.reference("PaidMonitoredFields").child("PMF").child(uid).child(fieldid).get() longitude_min, latitude_min, longitude_max, latitude_max = float(field_obj["FieldMinLong"]), float(field_obj["FieldMinLat"]), float(field_obj["FieldMaxLong"]), float(field_obj["FieldMaxLat"]) # png_path = detect_barren(bbox, time_interval, output_directory) create_geotiff(uid, fieldid, sensedday,imagetype) url = upload_file((uid + '/'+ fieldid + '_' + imagetype + '.tif'), ('PaidMonitoredFields/' + uid + '/' + fieldid + '/' + str(sensedday) + '/' + imagetype+'.tif')) temp_main_obj["Processed"] = 1 temp_main_obj["URL"] = url db_firestore.collection(u'GeotifRequests').document(time_stamp).set(temp_main_obj) except: print(traceback.format_exc()) db_firestore.collection(u'GeotifRequests').document(time_stamp).delete() #upload_file_ftp(hostname, username, password, local_file_path, remote_directory) #upload_file_ftp(hostname, username, password, local_file_path, remote_directory) i = 0 while i == 0: main() time.sleep(30) # longitude_min, latitude_min, longitude_max, latitude_max =-50.768464422847735,-7.073172070815588,-50.33313117089461,-6.653230308928273 # print(result)