print('entered') import os import time import fiona import requests import utm from geopy.geocoders import Nominatim import time import json import pandas as pd from fastkml import kml from socket import * from oct2py import octave from io import BytesIO import base64 import xlrd import csv from statistics import median import math import firebase_admin from firebase_admin import credentials from firebase_admin import db from firebase_admin import messaging import threading import xlsxwriter import numpy as np import datetime import os from numba import jit, cuda from firebase_admin import firestore from make_on_the_go_farm_image import make_on_the_go_farm_image from sentinelhub import ( WebFeatureService, BBox, CRS, MimeType, CRS, BBox, WmsRequest, DataCollection, ) from get_polygon_mask import get_polygon_mask import traceback from google.cloud import storage import os from google.oauth2 import service_account import datetime from datetime import date import traceback from gen_report_new2 import gen_report_new from google.cloud import storage from oauth2client.service_account import ServiceAccountCredentials import os import firebase_admin from firebase_admin import credentials from firebase_admin import db import datetime 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") print('step 1') db_firestore = firestore.client() sentinelSettings = db.reference("SentinelSettings").get() clientID = sentinelSettings["ClientID"] clientSecret = sentinelSettings["ClientSecret"] wmsID = sentinelSettings["WMSID"] rviID = sentinelSettings["RVIID"] demID = sentinelSettings["DEMID"] images_arr = ["NDVI", "NDWI", "NDRE", "LAI", "RVI", "RSM"] day_gap = 5 today = date.today() ndvi_val, ndwi_val = 0, 0 imageDate = today.strftime("%Y%m%d") print('step 2') kkk = 0 uid = '6U2L0EV2mKXXh7xmQBlbyxTgltd2' uid = '6nZRDEmdq7ajeZLJB2K19RhzVPu1' if not os.path.exists(uid): os.makedirs(uid) all_polygons_arr = [] n_tmux = 28 print('step 4') all_polygons_arr = [] missing_polygons_arr = [] main_final_obj = {} polygon_num = 1 iter = 0 field_count = 0 temp_list = db.reference("PaidMonitoredFields").child("PMF").child(uid).get(False, True) for fieldid, tmp in temp_list.items(): polygon_obj = db.reference("PaidMonitoredFields").child("PMF").child(uid).child(fieldid).get() #temp_final_obj = {} try: sensed_days_obj = polygon_obj["SensedDays"] health_obj = polygon_obj["Health"] try: desc = polygon_obj["FieldDescription"] except: desc = polygon_obj["FieldAddress"] # health_obj = polygon_obj["Health"] sensed_days_arr = [] for sensed_day, tmp in sensed_days_obj.items(): sensed_day = sensed_day.replace("-","") latest_day = str(sensed_day) new_date = latest_day[6:] + "-" + latest_day[4:6] + "-" + latest_day[:4] try: all_polygons_arr.append([desc, new_date, health_obj["ndvi"][sensed_day], health_obj["ndwi"][sensed_day], health_obj["ndre"][sensed_day], health_obj["lai"][sensed_day], health_obj["rvi"][sensed_day], health_obj["rsm"][sensed_day], str(fieldid)]) except: print(traceback.format_exc()) except: print(traceback.format_exc()) # with open('missing_polygons.txt', 'w') as f: # # using csv.writer method from CSV package # write = csv.writer(f) # write.writerow(['Field ID', 'Polygon ID']) # write.writerows(missing_polygons_arr) with open('mahindra_new.csv', 'w') as f: # using csv.writer method from CSV package write = csv.writer(f) write.writerow(['FieldName', 'Satellite Visit Date', 'NDVI', 'NDWI', 'NDRE', 'LAI', 'RVI','RSM', 'Field ID']) write.writerows(all_polygons_arr) # with open('all_gavl_polygons.txt', 'w') as f: # # using csv.writer method from CSV package # write = csv.writer(f) # write.writerows(main_final_obj)