# -*- coding: utf-8 -*- """@author: lucas.candido""" print("FUNÇÕES PRESENTES NO SCRIPT:Sentinel, NasaPower, Referencia, Cultura") def Sentinel(user, password, area, inicio, fim, output): """user: usuario ESA (string) password: senha ESA (string) area: arquivo .geojson com informacoes da area de interesse inicio: data de inicio de interesse yyyymmdd (string) fim: data final de interesse yyyymmdd (string) output: diretorio de destino com .xlsx contendo informacoes gerais""" from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt api = SentinelAPI (user, password, 'https://scihub.copernicus.eu/dhus') print("login realizado com sucesso") footprint = geojson_to_wkt(read_geojson(area)) print("realizando busca para {} entre as datas {} e {}, com cobertura de nuvens entre 0% e 30%...".format(area,inicio,fim)) products = api.query (footprint,date=(inicio, fim),platformname="Sentinel-2", cloudcoverpercentage= (0,30), producttype = "S2MSI2A") products_df = api.to_dataframe(products) products_df.insert(0,"Index",range(0,len(products_df))) products_df['CENAS'] = products_df['title'].apply(lambda row: row.split("_")[5]) products_df['DATAS'] = products_df['title'].apply(lambda row: row.split("_")[2][0:8]) cenas = products_df.groupby(['CENAS']).size().reset_index().rename(columns={0:'contagem'}) print("CENAS LOCALIZADAS NO SHAPE:") print(cenas) print("N de cenas:{}".format(cenas.shape[0])) n_cenas = cenas.shape[0] datas= products_df.groupby(['DATAS']).size().reset_index().rename(columns={0:'contagem'}) datas= datas.loc[(datas['contagem']>=n_cenas)] print("DATAS QUE POSSUEM IMAGENS EM TODAS CENAS:") for data in datas['DATAS']: nuvens = products_df.loc[(products_df['DATAS']==data)] nuvens = nuvens[['DATAS','cloudcoverpercentage']] nuvens = nuvens.groupby(['DATAS']).mean() nuvens.reset_index(inplace=True) nuvens.sort_values(by=['cloudcoverpercentage'],inplace=True) print(nuvens) print("N de datas:{}".format(datas.shape[0])) n0 = int(input("Digite para quantas datas diferentes serao feitos downloads:")) datas_escolhidas = [] for n in range (0,n0): n1 = input("Digite a data N{} (YYYYMMDD):".format(n+1)) datas_escolhidas.append(n1) for cena in cenas['CENAS']: print("###DOWNLOAD PARA CENA {}###".format(cena)) products_df2 = products_df.loc[(products_df['CENAS']==cena)] for d in datas_escolhidas: products_df2 = products_df2.loc[(products_df2['DATAS']==d)] products_df2 = products_df2[['Index','cloudcoverpercentage']] products_df2.sort_values(by=['cloudcoverpercentage'],inplace=True) print("Imagens disponiveis na cena {} na data {}".format(cena,d)) print(products_df2) n2 = int(input("Digite o 'Index' da imagem de interesse:")) download = products_df.loc[(products_df['Index']==n2)] api.download_all(download.index,directory_path = output) print("Imagem baixada com sucesso!") return "SENTINEL2 BEM-SUCEDIDO" ################################################################################################################### def NasaPower (datai, dataf, output, parametros= "PRECTOT,T2M,T2M_MAX,T2M_MIN,ALLSKY_SFC_SW_DWN,ALLSKY_TOA_SW_DWN", usercommunity = "SB"): """datai = data de início YYYYMMDD(string) dataf = data final YYYYMMDD (string) parametros = parametros separados por virgulas. Ex: "PRECTOT,T2M_MAX,T2M_MIN" (string) output = diretório de destino (string)""" print("Data de início YYYYMMDD:{}".format(datai)) print("Data de término YYYYMMDD:{}".format(dataf)) print("Diretório de destino:{}".format(output)) print("Parâmetros:{}".format(parametros)) print("User community:{}".format(usercommunity)) import requests as rq import pandas as pd import json import glob import numpy as np import csv print("Carregando DataFrame com dados da malha...") localizacao = pd.DataFrame(np.array([[-15.25, -56.25, 25.98, 'Mato Grosso', '8', 72.0], [-15.25, -55.75, 25.26, 'N/D', '0', 0], [-15.25, -55.25, 24.13, 'N/D', '0', 0], [-15.25, -54.75, 23.41, 'Mato Grosso', '8', 72.0], [-15.25, -54.25, 23.35, 'N/D', '0', 0], [-15.25, -53.75, 23.63, 'N/D', '0', 0], [-15.25, -53.25, 24.57, 'N/D', '0', 0], [-15.25, -52.75, 24.84, 'N/D', '0', 0], [-15.25, -52.25, 25.47, 'N/D', '0', 0], [-15.25, -51.75, 26.4, 'N/D', '0', 0], [-15.25, -51.25, 26.55, 'N/D', '0', 0], [-15.25, -50.75, 26.22, 'N/D', '0', 0], [-15.25, -50.25, 25.09, 'N/D', '0', 0], [-15.25, -49.75, 24.28, 'Goiás Norte', '12', 91.0], [-15.25, -49.25, 24.1, 'Goiás Norte', '12', 91.0], [-15.25, -48.75, 24.03, 'Goiás Norte', '12', 91.0], [-15.25, -48.25, 22.98, 'Goiás Norte', '12', 91.0], [-15.25, -47.75, 22.36, 'Goiás Norte', '12', 91.0], [-15.25, -47.25, 22.46, 'Goiás Norte', '12', 91.0], [-15.25, -46.75, 22.94, 'Minas Norte', '10', 90.0], [-15.25, -46.25, 22.86, 'N/D', '0', 0], [-15.25, -45.75, 23.07, 'N/D', '0', 0], [-15.25, -45.25, 23.82, 'N/D', '0', 0], [-15.25, -44.75, 24.4, 'N/D', '0', 0], [-15.25, -44.25, 24.81, 'N/D', '0', 0], [-15.25, -43.75, 25.75, 'N/D', '0', 0], [-15.75, -56.25, 26.56, 'N/D', '0', 0], [-15.75, -55.75, 25.82, 'Mato Grosso', '8', 72.0], [-15.75, -55.25, 24.6, 'Mato Grosso', '8', 72.0], [-15.75, -54.75, 23.98, 'N/D', '0', 0], [-15.75, -54.25, 24.02, 'N/D', '0', 0], [-15.75, -53.75, 23.76, 'N/D', '0', 0], [-15.75, -53.25, 24.43, 'N/D', '0', 0], [-15.75, -52.75, 24.59, 'N/D', '0', 0], [-15.75, -52.25, 25.03, 'N/D', '0', 0], [-15.75, -51.75, 25.73, 'N/D', '0', 0], [-15.75, -51.25, 25.85, 'N/D', '0', 0], [-15.75, -50.75, 25.62, 'N/D', '0', 0], [-15.75, -50.25, 24.51, 'Goiás Norte', '12', 91.0], [-15.75, -49.75, 23.71, 'Goiás Norte', '12', 91.0], [-15.75, -49.25, 23.37, 'Goiás Norte', '12', 91.0], [-15.75, -48.75, 22.62, 'Goiás Norte', '12', 91.0], [-15.75, -48.25, 22.24, 'Goiás Norte', '12', 91.0], [-15.75, -47.75, 21.74, 'Goiás Norte', '12', 91.0], [-15.75, -47.25, 21.84, 'Goiás Norte', '12', 91.0], [-15.75, -46.75, 22.56, 'Minas Norte', '10', 90.0], [-15.75, -46.25, 23.16, 'Minas Norte', '10', 90.0], [-15.75, -45.75, 23.7, 'Minas Norte', '10', 90.0], [-15.75, -45.25, 24.4, 'N/D', '0', 0], [-15.75, -44.75, 24.49, 'N/D', '0', 0], [-15.75, -44.25, 24.27, 'N/D', '0', 0], [-15.75, -43.75, 25.07, 'N/D', '0', 0], [-16.25, -56.25, 27.11, 'N/D', '0', 0], [-16.25, -55.75, 26.78, 'Mato Grosso', '8', 72.0], [-16.25, -55.25, 25.7, 'Mato Grosso', '8', 72.0], [-16.25, -54.75, 25.07, 'N/D', '0', 0], [-16.25, -54.25, 24.89, 'N/D', '0', 0], [-16.25, -53.75, 23.92, 'N/D', '0', 0], [-16.25, -53.25, 23.98, 'N/D', '0', 0], [-16.25, -52.75, 24.17, 'N/D', '0', 0], [-16.25, -52.25, 24.48, 'N/D', '0', 0], [-16.25, -51.75, 24.76, 'N/D', '0', 0], [-16.25, -51.25, 24.73, 'N/D', '0', 0], [-16.25, -50.75, 24.71, 'N/D', '0', 0], [-16.25, -50.25, 24.02, 'Goiás Norte', '12', 91.0], [-16.25, -49.75, 23.32, 'Goiás Norte', '12', 91.0], [-16.25, -49.25, 22.71, 'Goiás Norte', '12', 91.0], [-16.25, -48.75, 21.77, 'Goiás Norte', '12', 91.0], [-16.25, -48.25, 21.94, 'Goiás Norte', '12', 91.0], [-16.25, -47.75, 21.83, 'Goiás Norte', '12', 91.0], [-16.25, -47.25, 22.13, 'Minas Norte', '10', 90.0], [-16.25, -46.75, 22.82, 'Minas Norte', '10', 90.0], [-16.25, -46.25, 23.17, 'Minas Norte', '10', 90.0], [-16.25, -45.75, 24.01, 'Minas Norte', '10', 90.0], [-16.25, -45.25, 24.51, 'Minas Norte', '10', 90.0], [-16.25, -44.75, 24.12, 'Minas Norte', '10', 90.0], [-16.25, -44.25, 23.42, 'N/D', '0', 0], [-16.25, -43.75, 24.11, 'N/D', '0', 0], [-16.75, -56.25, 27.31, 'N/D', '0', 0], [-16.75, -55.75, 27.22, 'N/D', '0', 0], [-16.75, -55.25, 26.35, 'Mato Grosso', '8', 72.0], [-16.75, -54.75, 25.49, 'N/D', '0', 0], [-16.75, -54.25, 24.72, 'N/D', '0', 0], [-16.75, -53.75, 23.34, 'N/D', '0', 0], [-16.75, -53.25, 23.3, 'N/D', '0', 0], [-16.75, -52.75, 23.53, 'Sudoeste de Goiás', '1', 60.0], [-16.75, -52.25, 23.57, 'Sudoeste de Goiás', '1', 60.0], [-16.75, -51.75, 23.44, 'Sudoeste de Goiás', '1', 60.0], [-16.75, -51.25, 23.56, 'N/D', '0', 0], [-16.75, -50.75, 23.8, 'N/D', '0', 0], [-16.75, -50.25, 23.79, 'Goiás Norte', '12', 91.0], [-16.75, -49.75, 23.45, 'Goiás Norte', '12', 91.0], [-16.75, -49.25, 22.78, 'Goiás Norte', '12', 91.0], [-16.75, -48.75, 21.91, 'Goiás Norte', '12', 91.0], [-16.75, -48.25, 22.23, 'Goiás Norte', '12', 91.0], [-16.75, -47.75, 22.09, 'Goiás Norte', '12', 91.0], [-16.75, -47.25, 22.38, 'Goiás Norte', '12', 91.0], [-16.75, -46.75, 23.1, 'Minas Norte', '10', 90.0], [-16.75, -46.25, 23.43, 'Minas Norte', '10', 90.0], [-16.75, -45.75, 23.85, 'Minas Norte', '10', 90.0], [-16.75, -45.25, 24.17, 'Minas Norte', '10', 90.0], [-16.75, -44.75, 23.79, 'Minas Norte', '10', 90.0], [-16.75, -44.25, 23.03, 'Minas Norte', '10', 90.0], [-16.75, -43.75, 23.11, 'N/D', '0', 0], [-17.25, -56.25, 27.38, 'N/D', '0', 0], [-17.25, -55.75, 27.3, 'N/D', '0', 0], [-17.25, -55.25, 26.52, 'Mato Grosso', '8', 72.0], [-17.25, -54.75, 25.29, 'Sudoeste de Goiás', '1', 60.0], [-17.25, -54.25, 23.97, 'Sudoeste de Goiás', '1', 60.0], [-17.25, -53.75, 22.99, 'Sudoeste de Goiás', '1', 60.0], [-17.25, -53.25, 22.79, 'Sudoeste de Goiás', '1', 60.0], [-17.25, -52.75, 22.85, 'Sudoeste de Goiás', '1', 60.0], [-17.25, -52.25, 22.67, 'Sudoeste de Goiás', '1', 60.0], [-17.25, -51.75, 22.36, 'Sudoeste de Goiás', '1', 60.0], [-17.25, -51.25, 22.58, 'Sudeste de Goiás', '2', 80.0], [-17.25, -50.75, 23.49, 'Sudeste de Goiás', '2', 80.0], [-17.25, -50.25, 24.04, 'Sudeste de Goiás', '2', 80.0], [-17.25, -49.75, 23.86, 'Sudeste de Goiás', '2', 80.0], [-17.25, -49.25, 23.14, 'Sudeste de Goiás', '2', 80.0], [-17.25, -48.75, 22.6, 'Goiás Norte', '12', 91.0], [-17.25, -48.25, 22.55, 'Goiás Norte', '12', 91.0], [-17.25, -47.75, 22.17, 'Goiás Norte', '12', 91.0], [-17.25, -47.25, 22.38, 'Minas Norte', '10', 90.0], [-17.25, -46.75, 23.19, 'Minas Norte', '10', 90.0], [-17.25, -46.25, 23.64, 'Minas Norte', '10', 90.0], [-17.25, -45.75, 23.39, 'Minas Norte', '10', 90.0], [-17.25, -45.25, 23.54, 'Minas Norte', '10', 90.0], [-17.25, -44.75, 23.44, 'Minas Norte', '10', 90.0], [-17.25, -44.25, 22.94, 'N/D', '0', 0], [-17.25, -43.75, 22.41, 'N/D', '0', 0], [-17.75, -56.25, 27.39, 'N/D', '0', 0], [-17.75, -55.75, 27.27, 'N/D', '0', 0], [-17.75, -55.25, 26.61, 'N/D', '0', 0], [-17.75, -54.75, 25.59, 'Sudoeste de Goiás', '1', 60.0], [-17.75, -54.25, 24.52, 'Sudoeste de Goiás', '1', 60.0], [-17.75, -53.75, 23.83, 'Sudoeste de Goiás', '1', 60.0], [-17.75, -53.25, 22.47, 'Sudoeste de Goiás', '1', 60.0], [-17.75, -52.75, 22.28, 'Sudoeste de Goiás', '1', 60.0], [-17.75, -52.25, 22.29, 'Sudoeste de Goiás', '1', 60.0], [-17.75, -51.75, 22.21, 'Sudoeste de Goiás', '1', 60.0], [-17.75, -51.25, 22.34, 'Sudeste de Goiás', '2', 80.0], [-17.75, -50.75, 23.55, 'Sudeste de Goiás', '2', 80.0], [-17.75, -50.25, 24.24, 'Sudeste de Goiás', '2', 80.0], [-17.75, -49.75, 24.07, 'Sudeste de Goiás', '2', 80.0], [-17.75, -49.25, 23.38, 'Sudeste de Goiás', '2', 80.0], [-17.75, -48.75, 23.25, 'Sudeste de Goiás', '2', 80.0], [-17.75, -48.25, 22.75, 'Goiás Norte', '12', 91.0], [-17.75, -47.75, 22.2, 'Goiás Norte', '12', 91.0], [-17.75, -47.25, 22.26, 'Minas Norte', '10', 90.0], [-17.75, -46.75, 22.79, 'Minas Norte', '10', 90.0], [-17.75, -46.25, 22.89, 'Minas Norte', '10', 90.0], [-17.75, -45.75, 22.69, 'Minas Norte', '10', 90.0], [-17.75, -45.25, 23.0, 'Minas Norte', '10', 90.0], [-17.75, -44.75, 23.09, 'Minas Norte', '10', 90.0], [-17.75, -44.25, 22.54, 'N/D', '0', 0], [-17.75, -43.75, 21.24, 'N/D', '0', 0], [-18.25, -56.25, 27.34, 'N/D', '0', 0], [-18.25, -55.75, 27.13, 'N/D', '0', 0], [-18.25, -55.25, 26.56, 'N/D', '0', 0], [-18.25, -54.75, 25.82, 'N/D', '0', 0], [-18.25, -54.25, 25.04, 'N/D', '0', 0], [-18.25, -53.75, 24.32, 'Sudoeste de Goiás', '1', 60.0], [-18.25, -53.25, 22.52, 'Sudoeste de Goiás', '1', 60.0], [-18.25, -52.75, 22.13, 'Sudoeste de Goiás', '1', 60.0], [-18.25, -52.25, 22.32, 'Sudoeste de Goiás', '1', 60.0], [-18.25, -51.75, 22.65, 'Sudoeste de Goiás', '1', 60.0], [-18.25, -51.25, 23.03, 'Sudoeste de Goiás', '1', 60.0], [-18.25, -50.75, 23.8, 'Sudeste de Goiás', '2', 80.0], [-18.25, -50.25, 24.42, 'Sudeste de Goiás', '2', 80.0], [-18.25, -49.75, 24.35, 'Sudeste de Goiás', '2', 80.0], [-18.25, -49.25, 23.71, 'Sudeste de Goiás', '2', 80.0], [-18.25, -48.75, 23.2, 'Sudeste de Goiás', '2', 80.0], [-18.25, -48.25, 22.72, 'Goiás Norte', '12', 91.0], [-18.25, -47.75, 22.19, 'Goiás Norte', '12', 91.0], [-18.25, -47.25, 21.82, 'Minas Norte', '10', 90.0], [-18.25, -46.75, 21.7, 'Minas Norte', '10', 90.0], [-18.25, -46.25, 21.76, 'Minas Norte', '10', 90.0], [-18.25, -45.75, 22.34, 'Minas Norte', '10', 90.0], [-18.25, -45.25, 22.91, 'Minas Norte', '10', 90.0], [-18.25, -44.75, 23.13, 'Minas Norte', '10', 90.0], [-18.25, -44.25, 22.44, 'N/D', '0', 0], [-18.25, -43.75, 20.11, 'N/D', '0', 0], [-18.75, -55.75, 27.02, 'N/D', '0', 0], [-18.75, -55.25, 26.22, 'N/D', '0', 0], [-18.75, -54.75, 25.34, 'N/D', '0', 0], [-18.75, -54.25, 24.64, 'N/D', '0', 0], [-18.75, -53.75, 23.98, 'N/D', '0', 0], [-18.75, -53.25, 22.78, 'Sudoeste de Goiás', '1', 60.0], [-18.75, -52.75, 22.34, 'Sudoeste de Goiás', '1', 60.0], [-18.75, -52.25, 22.46, 'Sudoeste de Goiás', '1', 60.0], [-18.75, -51.75, 22.98, 'Sudeste de Goiás', '2', 80.0], [-18.75, -51.25, 23.75, 'Sudeste de Goiás', '2', 80.0], [-18.75, -50.75, 24.37, 'Sudeste de Goiás', '2', 80.0], [-18.75, -50.25, 24.61, 'Sudeste de Goiás', '2', 80.0], [-18.75, -49.75, 24.33, 'Sudeste de Goiás', '2', 80.0], [-18.75, -49.25, 23.58, 'Sudeste de Goiás', '2', 80.0], [-18.75, -48.75, 22.63, 'Sudeste de Goiás', '2', 80.0], [-18.75, -48.25, 22.1, 'Sudeste de Goiás', '2', 80.0], [-18.75, -47.75, 21.6, 'Minas Norte', '10', 90.0], [-18.75, -47.25, 21.16, 'Centro Mineiro', '13', 100.0], [-18.75, -46.75, 20.88, 'Centro Mineiro', '13', 100.0], [-18.75, -46.25, 21.01, 'Minas Norte', '10', 90.0], [-18.75, -45.75, 22.19, 'Centro Mineiro', '13', 100.0], [-18.75, -45.25, 22.86, 'Minas Norte', '10', 90.0], [-18.75, -44.75, 23.08, 'Minas Norte', '10', 90.0], [-18.75, -44.25, 22.48, 'Minas Norte', '10', 90.0], [-18.75, -43.75, 20.23, 'N/D', '0', 0], [-19.25, -55.75, 27.07, 'N/D', '0', 0], [-19.25, -55.25, 26.03, 'N/D', '0', 0], [-19.25, -54.75, 24.82, 'N/D', '0', 0], [-19.25, -54.25, 23.93, 'N/D', '0', 0], [-19.25, -53.75, 23.52, 'N/D', '0', 0], [-19.25, -53.25, 23.02, 'Sudoeste de Goiás', '1', 60.0], [-19.25, -52.75, 22.99, 'Sudoeste de Goiás', '1', 60.0], [-19.25, -52.25, 23.04, 'Sudoeste de Goiás', '1', 60.0], [-19.25, -51.75, 23.23, 'Triângulo Mineiro', '6', 75.0], [-19.25, -51.25, 24.09, 'Sudeste de Goiás', '2', 80.0], [-19.25, -50.75, 24.63, 'Triângulo Mineiro', '6', 75.0], [-19.25, -50.25, 24.47, 'Sudeste de Goiás', '2', 80.0], [-19.25, -49.75, 23.93, 'Sudeste de Goiás', '2', 80.0], [-19.25, -49.25, 23.24, 'Sudeste de Goiás', '2', 80.0], [-19.25, -48.75, 22.48, 'Sudeste de Goiás', '2', 80.0], [-19.25, -48.25, 21.7, 'Ribeirão Preto', '3', 95.0], [-19.25, -47.75, 20.99, 'Centro Mineiro', '13', 100.0], [-19.25, -47.25, 20.63, 'Centro Mineiro', '13', 100.0], [-19.25, -46.75, 20.63, 'Centro Mineiro', '13', 100.0], [-19.25, -46.25, 20.66, 'Centro Mineiro', '13', 100.0], [-19.25, -45.75, 21.9, 'Centro Mineiro', '13', 100.0], [-19.25, -45.25, 22.45, 'Centro Mineiro', '13', 100.0], [-19.25, -44.75, 22.46, 'Centro Mineiro', '13', 100.0], [-19.25, -44.25, 21.91, 'N/D', '0', 0], [-19.25, -43.75, 20.58, 'N/D', '0', 0], [-19.75, -55.75, 26.82, 'N/D', '0', 0], [-19.75, -55.25, 25.81, 'N/D', '0', 0], [-19.75, -54.75, 24.43, 'N/D', '0', 0], [-19.75, -54.25, 23.33, 'N/D', '0', 0], [-19.75, -53.75, 23.29, 'N/D', '0', 0], [-19.75, -53.25, 23.42, 'N/D', '0', 0], [-19.75, -52.75, 23.58, 'N/D', '0', 0], [-19.75, -52.25, 23.6, 'N/D', '0', 0], [-19.75, -51.75, 23.66, 'N/D', '0', 0], [-19.75, -51.25, 24.29, 'Triângulo Mineiro', '6', 75.0], [-19.75, -50.75, 24.58, 'Triângulo Mineiro', '6', 75.0], [-19.75, -50.25, 24.4, 'Triângulo Mineiro', '6', 75.0], [-19.75, -49.75, 23.96, 'Triângulo Mineiro', '6', 75.0], [-19.75, -49.25, 23.45, 'Triângulo Mineiro', '6', 75.0], [-19.75, -48.75, 23.05, 'Triângulo Mineiro', '6', 75.0], [-19.75, -48.25, 22.54, 'Ribeirão Preto', '3', 95.0], [-19.75, -47.75, 21.53, 'Ribeirão Preto', '3', 95.0], [-19.75, -47.25, 20.58, 'Centro Mineiro', '13', 100.0], [-19.75, -46.75, 20.14, 'Centro Mineiro', '13', 100.0], [-19.75, -46.25, 20.59, 'Centro Mineiro', '13', 100.0], [-19.75, -45.75, 21.66, 'Centro Mineiro', '13', 100.0], [-19.75, -45.25, 21.85, 'Centro Mineiro', '13', 100.0], [-19.75, -44.75, 21.64, 'N/D', '0', 0], [-19.75, -44.25, 21.15, 'N/D', '0', 0], [-19.75, -43.75, 20.13, 'N/D', '0', 0], [-20.25, -55.75, 26.0, 'N/D', '0', 0], [-20.25, -55.25, 25.31, 'Mato Grosso do Sul', '9', 82.0], [-20.25, -54.75, 24.13, 'Mato Grosso do Sul', '9', 82.0], [-20.25, -54.25, 23.08, 'N/D', '0', 0], [-20.25, -53.75, 23.34, 'N/D', '0', 0], [-20.25, -53.25, 23.63, 'N/D', '0', 0], [-20.25, -52.75, 23.78, 'N/D', '0', 0], [-20.25, -52.25, 23.95, 'N/D', '0', 0], [-20.25, -51.75, 24.23, 'Araçatuba', '17', 75.0], [-20.25, -51.25, 24.6, 'Araçatuba', '17', 75.0], [-20.25, -50.75, 24.47, 'Triângulo Mineiro', '6', 75.0], [-20.25, -50.25, 24.22, 'Triângulo Mineiro', '6', 75.0], [-20.25, -49.75, 23.89, 'Triângulo Mineiro', '6', 75.0], [-20.25, -49.25, 23.6, 'Triângulo Mineiro', '6', 75.0], [-20.25, -48.75, 23.58, 'Ribeirão Preto', '3', 95.0], [-20.25, -48.25, 23.28, 'Ribeirão Preto', '3', 95.0], [-20.25, -47.75, 22.25, 'Ribeirão Preto', '3', 95.0], [-20.25, -47.25, 21.13, 'Ribeirão Preto', '3', 95.0], [-20.25, -46.75, 20.45, 'Centro Mineiro', '13', 100.0], [-20.25, -46.25, 20.68, 'Centro Mineiro', '13', 100.0], [-20.25, -45.75, 21.32, 'Centro Mineiro', '13', 100.0], [-20.25, -45.25, 21.15, 'Centro Mineiro', '13', 100.0], [-20.25, -44.75, 20.81, 'N/D', '0', 0], [-20.25, -44.25, 20.39, 'N/D', '0', 0], [-20.25, -43.75, 19.5, 'N/D', '0', 0], [-20.75, -55.75, 25.13, 'N/D', '0', 0], [-20.75, -55.25, 24.61, 'N/D', '0', 0], [-20.75, -54.75, 23.78, 'Mato Grosso do Sul', '9', 82.0], [-20.75, -54.25, 23.12, 'Mato Grosso do Sul', '9', 82.0], [-20.75, -53.75, 23.45, 'N/D', '0', 0], [-20.75, -53.25, 23.48, 'N/D', '0', 0], [-20.75, -52.75, 23.68, 'N/D', '0', 0], [-20.75, -52.25, 24.04, 'N/D', '0', 0], [-20.75, -51.75, 24.4, 'N/D', '0', 0], [-20.75, -51.25, 24.5, 'Araçatuba', '17', 75.0], [-20.75, -50.75, 24.22, 'Araçatuba', '17', 75.0], [-20.75, -50.25, 23.92, 'Catanduva', '14', 85.0], [-20.75, -49.75, 23.64, 'Catanduva', '14', 85.0], [-20.75, -49.25, 23.44, 'Catanduva', '14', 85.0], [-20.75, -48.75, 23.38, 'Ribeirão Preto', '3', 95.0], [-20.75, -48.25, 23.17, 'Ribeirão Preto', '3', 95.0], [-20.75, -47.75, 22.4, 'Ribeirão Preto', '3', 95.0], [-20.75, -47.25, 21.5, 'Ribeirão Preto', '3', 95.0], [-20.75, -46.75, 20.82, 'Centro Mineiro', '13', 100.0], [-20.75, -46.25, 20.6, 'Centro Mineiro', '13', 100.0], [-20.75, -45.75, 20.86, 'Centro Mineiro', '13', 100.0], [-20.75, -45.25, 20.59, 'Centro Mineiro', '13', 100.0], [-20.75, -44.75, 20.21, 'N/D', '0', 0], [-20.75, -44.25, 19.81, 'N/D', '0', 0], [-20.75, -43.75, 19.23, 'N/D', '0', 0], [-21.25, -55.75, 24.1, 'N/D', '0', 0], [-21.25, -55.25, 23.83, 'Mato Grosso do Sul', '9', 82.0], [-21.25, -54.75, 23.65, 'Mato Grosso do Sul', '9', 82.0], [-21.25, -54.25, 23.48, 'Mato Grosso do Sul', '9', 82.0], [-21.25, -53.75, 23.35, 'Mato Grosso do Sul', '9', 82.0], [-21.25, -53.25, 23.44, 'N/D', '0', 0], [-21.25, -52.75, 23.59, 'N/D', '0', 0], [-21.25, -52.25, 23.92, 'N/D', '0', 0], [-21.25, -51.75, 24.24, 'Araçatuba', '17', 75.0], [-21.25, -51.25, 24.0, 'Araçatuba', '17', 75.0], [-21.25, -50.75, 23.75, 'Araçatuba', '17', 75.0], [-21.25, -50.25, 23.62, 'Araçatuba', '17', 75.0], [-21.25, -49.75, 23.56, 'Catanduva', '14', 85.0], [-21.25, -49.25, 23.42, 'Catanduva', '14', 85.0], [-21.25, -48.75, 23.02, 'Catanduva', '14', 85.0], [-21.25, -48.25, 22.7, 'Ribeirão Preto', '3', 95.0], [-21.25, -47.75, 22.26, 'Ribeirão Preto', '3', 95.0], [-21.25, -47.25, 21.43, 'São Carlos', '16', 66.0], [-21.25, -46.75, 20.49, 'São Carlos', '16', 66.0], [-21.25, -46.25, 20.24, 'Centro Mineiro', '13', 100.0], [-21.25, -45.75, 20.44, 'Centro Mineiro', '13', 100.0], [-21.25, -45.25, 20.2, 'Centro Mineiro', '13', 100.0], [-21.25, -44.75, 19.8, 'N/D', '0', 0], [-21.25, -44.25, 19.41, 'N/D', '0', 0], [-21.25, -43.75, 19.13, 'N/D', '0', 0], [-21.75, -55.75, 22.89, 'Mato Grosso do Sul', '9', 82.0], [-21.75, -55.25, 23.1, 'Mato Grosso do Sul', '9', 82.0], [-21.75, -54.75, 23.61, 'Mato Grosso do Sul', '9', 82.0], [-21.75, -54.25, 23.71, 'Mato Grosso do Sul', '9', 82.0], [-21.75, -53.75, 23.28, 'Mato Grosso do Sul', '9', 82.0], [-21.75, -53.25, 23.35, 'Mato Grosso do Sul', '9', 82.0], [-21.75, -52.75, 23.49, 'N/D', '0', 0], [-21.75, -52.25, 23.72, 'N/D', '0', 0], [-21.75, -51.75, 23.86, 'Presidente Prudente', '11', 55.0], [-21.75, -51.25, 23.55, 'Presidente Prudente', '11', 55.0], [-21.75, -50.75, 23.18, 'Araçatuba', '17', 75.0], [-21.75, -50.25, 23.0, 'Araçatuba', '17', 75.0], [-21.75, -49.75, 22.98, 'Araçatuba', '17', 75.0], [-21.75, -49.25, 22.99, 'Araçatuba', '17', 75.0], [-21.75, -48.75, 22.79, 'São Carlos', '16', 66.0], [-21.75, -48.25, 22.02, 'São Carlos', '16', 66.0], [-21.75, -47.75, 21.8, 'São Carlos', '16', 66.0], [-21.75, -47.25, 21.38, 'São Carlos', '16', 66.0], [-21.75, -46.75, 20.48, 'São Carlos', '16', 66.0], [-21.75, -46.25, 19.22, 'N/D', '0', 0], [-21.83, -47.75, 21.8, 'São Carlos', '16*', 55.0], [-22.25, -55.75, 22.24, 'N/D', '0', 0], [-22.25, -55.25, 22.47, 'Mato Grosso do Sul', '9', 82.0], [-22.25, -54.75, 23.13, 'Mato Grosso do Sul', '9', 82.0], [-22.25, -54.25, 23.45, 'Mato Grosso do Sul', '9', 82.0], [-22.25, -53.75, 23.3, 'Mato Grosso do Sul', '9', 82.0], [-22.25, -53.25, 23.31, 'Mato Grosso do Sul', '9', 82.0], [-22.25, -52.75, 23.42, 'Mato Grosso do Sul', '9', 82.0], [-22.25, -52.25, 23.46, 'Presidente Prudente', '11', 55.0], [-22.25, -51.75, 23.39, 'Presidente Prudente', '11', 55.0], [-22.25, -51.25, 23.25, 'Presidente Prudente', '11', 55.0], [-22.25, -50.75, 22.82, 'Presidente Prudente', '11', 55.0], [-22.25, -50.25, 22.39, 'Assis', '15', 60.0], [-22.25, -49.75, 22.11, 'Assis', '15', 60.0], [-22.25, -49.25, 22.02, 'São Carlos', '16', 66.0], [-22.25, -48.75, 22.05, 'São Carlos', '16', 66.0], [-22.25, -48.25, 21.58, 'São Carlos', '16', 66.0], [-22.25, -47.75, 21.4, 'São Carlos', '16', 66.0], [-22.25, -47.25, 21.15, 'Piracicaba', '5', 80.0], [-22.25, -46.75, 20.35, 'Piracicaba', '5', 80.0], [-22.25, -46.25, 18.45, 'Piracicaba', '5', 80.0], [-22.75, -55.75, 22.17, 'N/D', '0', 0], [-22.75, -55.25, 22.17, 'Mato Grosso do Sul', '9', 82.0], [-22.75, -54.75, 22.61, 'Mato Grosso do Sul', '9', 82.0], [-22.75, -54.25, 23.01, 'Mato Grosso do Sul', '9', 82.0], [-22.75, -53.75, 23.25, 'Mato Grosso do Sul', '9', 82.0], [-22.75, -53.25, 23.22, 'Paraná', '4', 55.0], [-22.75, -52.75, 23.02, 'Paraná', '4', 55.0], [-22.75, -52.25, 22.86, 'Paraná', '4', 55.0], [-22.75, -51.75, 22.8, 'Paraná', '4', 55.0], [-22.75, -51.25, 22.76, 'Assis', '15', 60.0], [-22.75, -50.75, 22.52, 'Assis', '15', 60.0], [-22.75, -50.25, 22.19, 'Ourinhos', '7', 94.0], [-22.75, -49.75, 21.77, 'Ourinhos', '7', 94.0], [-22.75, -49.25, 21.28, 'São Carlos', '16', 66.0], [-22.75, -48.75, 20.81, 'São Carlos', '16', 66.0], [-22.75, -48.25, 21.1, 'Piracicaba', '5', 80.0], [-22.75, -47.75, 21.17, 'Piracicaba', '5', 80.0], [-22.75, -47.25, 20.84, 'Piracicaba', '5', 80.0], [-22.75, -46.75, 20.02, 'Piracicaba', '5', 80.0], [-22.75, -46.25, 18.68, 'N/D', '0', 0], [-23.25, -55.75, 22.3, 'N/D', '0', 0], [-23.25, -55.25, 22.09, 'Mato Grosso do Sul', '9', 82.0], [-23.25, -54.75, 22.31, 'Mato Grosso do Sul', '9', 82.0], [-23.25, -54.25, 22.67, 'Mato Grosso do Sul', '9', 82.0], [-23.25, -53.75, 22.99, 'Mato Grosso do Sul', '9', 82.0], [-23.25, -53.25, 22.73, 'Paraná', '4', 55.0], [-23.25, -52.75, 22.59, 'Paraná', '4', 55.0], [-23.25, -52.25, 22.41, 'Paraná', '4', 55.0], [-23.25, -51.75, 22.07, 'Paraná', '4', 55.0], [-23.25, -51.25, 21.54, 'Paraná', '4', 55.0], [-23.25, -50.75, 21.55, 'Ourinhos', '7', 94.0], [-23.25, -50.25, 21.65, 'Ourinhos', '7', 94.0], [-23.25, -49.75, 21.45, 'Ourinhos', '7', 94.0], [-23.25, -49.25, 20.9, 'Ourinhos', '7', 94.0], [-23.25, -48.75, 20.26, 'Ourinhos', '7', 94.0], [-23.25, -48.25, 20.4, 'Piracicaba', '5', 80.0], [-23.25, -47.75, 20.44, 'Piracicaba', '5', 80.0], [-23.25, -47.25, 20.09, 'Piracicaba', '5', 80.0], [-23.25, -46.75, 19.49, 'N/D', '0', 0], [-23.25, -46.25, 19.24, 'N/D', '0', 0], [-23.75, -55.75, 22.66, 'N/D', '0', 0], [-23.75, -55.25, 22.25, 'N/D', '0', 0], [-23.75, -54.75, 22.3, 'N/D', '0', 0], [-23.75, -54.25, 22.62, 'Mato Grosso do Sul', '9', 82.0], [-23.75, -53.75, 22.66, 'Paraná', '4', 55.0], [-23.75, -53.25, 22.27, 'Paraná', '4', 55.0], [-23.75, -52.75, 21.98, 'Paraná', '4', 55.0], [-23.75, -52.25, 21.85, 'Paraná', '4', 55.0], [-23.75, -51.75, 21.58, 'Paraná', '4', 55.0], [-23.75, -51.25, 20.49, 'N/D', '0', 0], [-23.75, -50.75, 20.3, 'Ourinhos', '7', 94.0], [-23.75, -50.25, 20.47, 'Ourinhos', '7', 94.0], [-23.75, -49.75, 20.48, 'Ourinhos', '7', 94.0], [-23.75, -49.25, 20.16, 'Ourinhos', '7', 94.0], [-23.75, -48.75, 19.71, 'Ourinhos', '7', 94.0], [-23.75, -48.25, 19.75, 'Piracicaba', '5', 80.0], [-23.75, -47.75, 19.77, 'N/D', '0', 0], [-23.75, -47.25, 19.68, 'N/D', '0', 0], [-23.75, -46.75, 19.81, 'N/D', '0', 0], [-23.75, -46.25, 20.83, 'N/D', '0', 0], [-24.25, -55.75, 22.81, 'N/D', '0', 0], [-24.25, -55.25, 22.37, 'N/D', '0', 0], [-24.25, -54.75, 22.47, 'N/D', '0', 0], [-24.25, -54.25, 22.8, 'N/D', '0', 0], [-24.25, -53.75, 22.01, 'N/D', '0', 0], [-24.25, -53.25, 21.7, 'N/D', '0', 0], [-24.25, -52.75, 21.05, 'N/D', '0', 0], [-24.25, -52.25, 20.64, 'N/D', '0', 0], [-24.25, -51.75, 20.45, 'N/D', '0', 0], [-24.25, -51.25, 19.92, 'N/D', '0', 0], [-24.25, -50.75, 19.53, 'N/D', '0', 0], [-24.25, -50.25, 19.12, 'N/D', '0', 0], [-24.25, -49.75, 18.95, 'N/D', '0', 0], [-24.25, -49.25, 19.04, 'N/D', '0', 0], [-24.25, -48.75, 19.11, 'N/D', '0', 0], [-24.25, -48.25, 19.75, 'N/D', '0', 0], [-24.25, -47.75, 20.42, 'N/D', '0', 0], [-24.25, -47.25, 20.92, 'N/D', '0', 0], [-24.25, -46.75, 21.42, 'N/D', '0', 0], [-24.25, -46.25, 22.45, 'N/D', '0', 0]]),columns=['LAT','LON','T_Normal','NomeRegional','NumRegional','CAD']) localizacao['LAT'] = localizacao['LAT'].apply(float) localizacao['LON'] = localizacao['LON'].apply(float) localizacao['T_Normal'] = localizacao['T_Normal'].apply(float) localizacao['NomeRegional'] = localizacao['NomeRegional'].apply(str) localizacao['NumRegional'] = localizacao['NumRegional'].apply(str) localizacao['CAD'] = localizacao['CAD'].apply(float) print("DataFrame carregado com sucesso") i=1 for x,y in zip(localizacao['LON'],localizacao['LAT']): print("Procurando arquivo nasapower {}{}.csv no diretório de destino...".format(y,x)) if output+"\\nasapower {}{}.csv".format(y,x) in glob.glob(output+"\\nasapower*"): pass else: while True: try: solicitacao = rq.get("https://power.larc.nasa.gov/api/temporal/daily/point?start="+datai+"&end="+dataf+"&latitude="+str(y)+"&longitude="+str(x)+"&community=ag¶meters="+parametros+"&format=csv&header=true") response = solicitacao.status_code print("Status Code: {}".format(response)) if response == 200: break except Exception as inst: print (inst) data = solicitacao.text conversao = json.loads(data) download= rq.get(conversao['outputs']['csv']) open(output+"\\nasapower {}.csv".format(str(y)+str(x)),'wb').write(download.content) print("Arquivo nasapower {},{} baixado com sucesso ({})".format(y,x,i)) i += 1 print("Todas localidades baixadas com sucesso") print("Concatenando todas as tabelas geradas...") all_data = [] for tabela in glob.glob(output+"\\nasapower*"): all_data.append(pd.read_csv(tabela, skiprows = 15, sep = ',', header = 0)) ETP = pd.concat (all_data) ETP.to_csv(output+"\concat.csv", index=False) print("Tabela concatenada (concat.csv) gerada com sucesso no diretório de destino") ETP.LAT = ETP.LAT.round(2) ETP.LON = ETP.LON.round(2) print("Estabelecendo campo DATA MMDD") ETP = ETP.merge(localizacao, on = ('LAT','LON')) ETP['MO'] = ETP['MO'].apply(str) ETP['MO'] = ETP['MO'].apply(lambda row: row.zfill(2)) ETP['DY'] = ETP['DY'].apply(str) ETP['DY'] = ETP['DY'].apply(lambda row: row.zfill(2)) ETP['DATA'] = ETP.apply(lambda row: row['MO']+row['DY'], axis=1) ETP = ETP[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','DATA']] ETP.reset_index(inplace=True) linhas = ETP.shape[0] print("nº de linhas:{}".format(linhas)) print ("Calculando parâmetros 'I' e 'a'...") ETP['I']= ETP.apply(lambda row: (12*((0.2*(row['T_Normal']))**1.514)), axis=1) ETP['a']= ETP.apply(lambda row: 0.49239 + 1.7912*(row['I']/100) - 7.71*((row['I']**2)/100000) + 6.75*((row['I']**3)/10000000), axis=1) ETP['Tef']= ETP.apply(lambda row: 0.36*((3*(row['T2M_MAX']))-row['T2M_MIN']), axis=1) print("Cálculo bem sucedido") print("calculando ETt...") ETP['ETt']= ETP.apply(lambda row: (16*((10*row['Tef']/row['I'])**row['a']))/30 if row['Tef'] >= 0 and row['Tef'] <= 26.5 else (-415.85+(32.24*row['Tef'])-(0.43*((row['Tef'])**2)))/30, axis=1) print("ETt calculada com sucesso") corr = pd.DataFrame(np.array([[0,1.04,0.94,1.04,1.01,1.04,1.01,1.04,1.04,1.01,1.04,1.01,1.04], [-5,1.06,0.95,1.04,1,1.02,0.99,1.02,1.03,1,1.05,1.03,1.06], [-10,1.08,0.97,1.05,0.99,1.01,0.96,1,1.01,1,1.06,1.05,1.1], [-15.,1.12,0.98,1.05,0.98,0.98,0.94,0.97,1,1,1.07,1.07,1.12], [-20,1.14,1,1.05,0.97,0.96,0.91,0.95,0.99,1,1.08,1.09,1.15], [-22,1.14,1,1.05,0.97,0.95,0.9,0.94,0.99,1,1.09,1.1,1.16], [-23,1.15,1,1.05,0.97,0.95,0.89,0.94,0.98,1,1.09,1.1,1.17], [-24,1.16,1.01,1.05,0.96,0.94,0.89,0.93,0.98,1,1.1,1.11,1.17], [-25,1.17,1.01,1.05,0.96,0.94,0.88,0.93,0.98,1,1.1,1.11,1.18], [-26,1.17,1.01,1.05,0.96,0.94,0.87,0.92,0.98,1,1.1,1.11,1.18], [-27,1.18,1.02,1.05,0.96,0.93,0.87,0.92,0.97,1,1.11,1.12,1.19], [-28,1.19,1.02,1.06,0.95,0.93,0.86,0.91,0.97,1,1.11,1.13,1.2], [-29,1.19,1.03,1.06,0.95,0.92,0.86,0.9,0.96,1,1.12,1.13,1.2], [-30,1.2,1.03,1.06,0.95,0.92,0.85,0.9,0.96,1,1.12,1.14,1.21], [-31,1.2,1.03,1.06,0.95,0.91,0.84,0.89,0.96,1,1.12,1.14,1.22], [-32,1.21,1.03,1.06,0.95,0.91,0.84,0.89,0.95,1,1.12,1.15,1.23]]),columns=['Lat S', '1', '2','3','4','5','6','7','8','9','10','11','12']) print("Consultando fator de correção para cada latitude e mês") ETP['MO'] = ETP['MO'].apply(int) ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 1), 'CORR'] = corr.iloc[0][1] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 2), 'CORR'] = corr.iloc[0][2] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 3), 'CORR'] = corr.iloc[0][3] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 4), 'CORR'] = corr.iloc[0][4] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 5), 'CORR'] = corr.iloc[0][5] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 6), 'CORR'] = corr.iloc[0][6] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 7), 'CORR'] = corr.iloc[0][7] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 8), 'CORR'] = corr.iloc[0][8] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 9), 'CORR'] = corr.iloc[0][9] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 10), 'CORR'] = corr.iloc[0][10] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 11), 'CORR'] = corr.iloc[0][11] ETP.loc[(ETP.LAT > -2,5) and (ETP.MO == 12), 'CORR'] = corr.iloc[0][12] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 1), 'CORR'] = corr.iloc[1][1] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 2), 'CORR'] = corr.iloc[1][2] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 3), 'CORR'] = corr.iloc[1][3] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 4), 'CORR'] = corr.iloc[1][4] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 5), 'CORR'] = corr.iloc[1][5] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 6), 'CORR'] = corr.iloc[1][6] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 7), 'CORR'] = corr.iloc[1][7] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 8), 'CORR'] = corr.iloc[1][8] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 9), 'CORR'] = corr.iloc[1][9] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 10), 'CORR'] = corr.iloc[1][10] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 11), 'CORR'] = corr.iloc[1][11] ETP.loc[(ETP.LAT <= -2.5) & (ETP.LAT > -7.5) & (ETP.MO == 12), 'CORR'] = corr.iloc[1][12] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 1), 'CORR'] = corr.iloc[2][1] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 2), 'CORR'] = corr.iloc[2][2] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 3), 'CORR'] = corr.iloc[2][3] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 4), 'CORR'] = corr.iloc[2][4] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 5), 'CORR'] = corr.iloc[2][5] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 6), 'CORR'] = corr.iloc[2][6] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 7), 'CORR'] = corr.iloc[2][7] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 8), 'CORR'] = corr.iloc[2][8] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 9), 'CORR'] = corr.iloc[2][9] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 10), 'CORR'] = corr.iloc[2][10] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 11), 'CORR'] = corr.iloc[2][11] ETP.loc[(ETP.LAT <= -7.5) & (ETP.LAT > -12.5) & (ETP.MO == 12), 'CORR'] = corr.iloc[2][12] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 1), 'CORR'] = corr.iloc[3][1] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 2), 'CORR'] = corr.iloc[3][2] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 3), 'CORR'] = corr.iloc[3][3] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 4), 'CORR'] = corr.iloc[3][4] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 5), 'CORR'] = corr.iloc[3][5] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 6), 'CORR'] = corr.iloc[3][6] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 7), 'CORR'] = corr.iloc[3][7] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 8), 'CORR'] = corr.iloc[3][8] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 9), 'CORR'] = corr.iloc[3][9] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 10), 'CORR'] = corr.iloc[3][10] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 11), 'CORR'] = corr.iloc[3][11] ETP.loc[(ETP.LAT <= -12.5) & (ETP.LAT > -17.5) & (ETP.MO == 12), 'CORR'] = corr.iloc[3][12] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 1), 'CORR'] = corr.iloc[4][1] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 2), 'CORR'] = corr.iloc[4][2] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 3), 'CORR'] = corr.iloc[4][3] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 4), 'CORR'] = corr.iloc[4][4] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 5), 'CORR'] = corr.iloc[4][5] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 6), 'CORR'] = corr.iloc[4][6] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 7), 'CORR'] = corr.iloc[4][7] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 8), 'CORR'] = corr.iloc[4][8] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 9), 'CORR'] = corr.iloc[4][9] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 10), 'CORR'] = corr.iloc[4][10] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 11), 'CORR'] = corr.iloc[4][11] ETP.loc[(ETP.LAT <= -17.5) & (ETP.LAT >= -20) & (ETP.MO == 12), 'CORR'] = corr.iloc[4][11] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 1), 'CORR'] = corr.iloc[4][1] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 2), 'CORR'] = corr.iloc[4][2] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 3), 'CORR'] = corr.iloc[4][3] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 4), 'CORR'] = corr.iloc[4][4] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 5), 'CORR'] = corr.iloc[4][5] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 6), 'CORR'] = corr.iloc[4][6] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 7), 'CORR'] = corr.iloc[4][7] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 8), 'CORR'] = corr.iloc[4][8] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 9), 'CORR'] = corr.iloc[4][9] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 10), 'CORR'] = corr.iloc[4][10] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 11), 'CORR'] = corr.iloc[4][11] ETP.loc[(ETP.LAT.round(0) == -21) & (ETP.MO == 12), 'CORR'] = corr.iloc[4][12] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 1), 'CORR'] = corr.iloc[4][1] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 2), 'CORR'] = corr.iloc[4][2] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 3), 'CORR'] = corr.iloc[4][3] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 4), 'CORR'] = corr.iloc[4][4] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 5), 'CORR'] = corr.iloc[4][5] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 6), 'CORR'] = corr.iloc[4][6] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 7), 'CORR'] = corr.iloc[4][7] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 8), 'CORR'] = corr.iloc[4][8] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 9), 'CORR'] = corr.iloc[4][9] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 10), 'CORR'] = corr.iloc[4][10] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 11), 'CORR'] = corr.iloc[4][11] ETP.loc[(ETP.LAT.round(0) == -20) & (ETP.MO == 12), 'CORR'] = corr.iloc[4][12] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 1), 'CORR'] = corr.iloc[5][1] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 2), 'CORR'] = corr.iloc[5][2] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 3), 'CORR'] = corr.iloc[5][3] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 4), 'CORR'] = corr.iloc[5][4] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 5), 'CORR'] = corr.iloc[5][5] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 6), 'CORR'] = corr.iloc[5][6] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 7), 'CORR'] = corr.iloc[5][7] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 8), 'CORR'] = corr.iloc[5][8] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 9), 'CORR'] = corr.iloc[5][9] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 10), 'CORR'] = corr.iloc[5][10] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 11), 'CORR'] = corr.iloc[5][11] ETP.loc[(ETP.LAT.round(0) == -22) & (ETP.MO == 12), 'CORR'] = corr.iloc[5][12] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 1), 'CORR'] = corr.iloc[6][1] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 2), 'CORR'] = corr.iloc[6][2] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 3), 'CORR'] = corr.iloc[6][3] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 4), 'CORR'] = corr.iloc[6][4] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 5), 'CORR'] = corr.iloc[6][5] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 6), 'CORR'] = corr.iloc[6][6] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 7), 'CORR'] = corr.iloc[6][7] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 8), 'CORR'] = corr.iloc[6][8] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 9), 'CORR'] = corr.iloc[6][9] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 10), 'CORR'] = corr.iloc[6][10] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 11), 'CORR'] = corr.iloc[6][11] ETP.loc[(ETP.LAT.round(0) == -23) & (ETP.MO == 12), 'CORR'] = corr.iloc[6][12] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 1), 'CORR'] = corr.iloc[7][1] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 2), 'CORR'] = corr.iloc[7][2] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 3), 'CORR'] = corr.iloc[7][3] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 4), 'CORR'] = corr.iloc[7][4] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 5), 'CORR'] = corr.iloc[7][5] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 6), 'CORR'] = corr.iloc[7][6] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 7), 'CORR'] = corr.iloc[7][7] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 8), 'CORR'] = corr.iloc[7][8] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 9), 'CORR'] = corr.iloc[7][9] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 10), 'CORR'] = corr.iloc[7][10] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 11), 'CORR'] = corr.iloc[7][11] ETP.loc[(ETP.LAT.round(0) == -24) & (ETP.MO == 12), 'CORR'] = corr.iloc[7][12] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 1), 'CORR'] = corr.iloc[8][1] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 2), 'CORR'] = corr.iloc[8][2] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 3), 'CORR'] = corr.iloc[8][3] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 4), 'CORR'] = corr.iloc[8][4] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 5), 'CORR'] = corr.iloc[8][5] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 6), 'CORR'] = corr.iloc[8][6] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 7), 'CORR'] = corr.iloc[8][7] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 8), 'CORR'] = corr.iloc[8][8] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 9), 'CORR'] = corr.iloc[8][9] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 10), 'CORR'] = corr.iloc[8][10] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 11), 'CORR'] = corr.iloc[8][11] ETP.loc[(ETP.LAT.round(0) == -25) & (ETP.MO == 12), 'CORR'] = corr.iloc[8][12] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 1), 'CORR'] = corr.iloc[9][1] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 2), 'CORR'] = corr.iloc[9][2] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 3), 'CORR'] = corr.iloc[9][3] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 4), 'CORR'] = corr.iloc[9][4] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 5), 'CORR'] = corr.iloc[9][5] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 6), 'CORR'] = corr.iloc[9][6] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 7), 'CORR'] = corr.iloc[9][7] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 8), 'CORR'] = corr.iloc[9][8] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 9), 'CORR'] = corr.iloc[9][9] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 10), 'CORR'] = corr.iloc[9][10] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 11), 'CORR'] = corr.iloc[9][11] ETP.loc[(ETP.LAT.round(0) == -26) & (ETP.MO == 12), 'CORR'] = corr.iloc[9][12] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 1), 'CORR'] = corr.iloc[10][1] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 2), 'CORR'] = corr.iloc[10][2] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 3), 'CORR'] = corr.iloc[10][3] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 4), 'CORR'] = corr.iloc[10][4] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 5), 'CORR'] = corr.iloc[10][5] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 6), 'CORR'] = corr.iloc[10][6] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 7), 'CORR'] = corr.iloc[10][7] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 8), 'CORR'] = corr.iloc[10][8] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 9), 'CORR'] = corr.iloc[10][9] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 10), 'CORR'] = corr.iloc[10][10] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 11), 'CORR'] = corr.iloc[10][11] ETP.loc[(ETP.LAT.round(0) == -27) & (ETP.MO == 12), 'CORR'] = corr.iloc[10][12] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 1), 'CORR'] = corr.iloc[11][1] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 2), 'CORR'] = corr.iloc[11][2] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 3), 'CORR'] = corr.iloc[11][3] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 4), 'CORR'] = corr.iloc[11][4] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 5), 'CORR'] = corr.iloc[11][5] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 6), 'CORR'] = corr.iloc[11][6] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 7), 'CORR'] = corr.iloc[11][7] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 8), 'CORR'] = corr.iloc[11][8] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 9), 'CORR'] = corr.iloc[11][9] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 10), 'CORR'] = corr.iloc[11][10] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 11), 'CORR'] = corr.iloc[11][11] ETP.loc[(ETP.LAT.round(0) == -28) & (ETP.MO == 12), 'CORR'] = corr.iloc[11][12] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 1), 'CORR'] = corr.iloc[12][1] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 2), 'CORR'] = corr.iloc[12][2] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 3), 'CORR'] = corr.iloc[12][3] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 4), 'CORR'] = corr.iloc[12][4] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 5), 'CORR'] = corr.iloc[12][5] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 6), 'CORR'] = corr.iloc[12][6] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 7), 'CORR'] = corr.iloc[12][7] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 8), 'CORR'] = corr.iloc[12][8] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 9), 'CORR'] = corr.iloc[12][9] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 10), 'CORR'] = corr.iloc[12][10] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 11), 'CORR'] = corr.iloc[12][11] ETP.loc[(ETP.LAT.round(0) == -29) & (ETP.MO == 12), 'CORR'] = corr.iloc[12][12] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 1), 'CORR'] = corr.iloc[13][1] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 2), 'CORR'] = corr.iloc[13][2] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 3), 'CORR'] = corr.iloc[13][3] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 4), 'CORR'] = corr.iloc[13][4] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 5), 'CORR'] = corr.iloc[13][5] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 6), 'CORR'] = corr.iloc[13][6] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 7), 'CORR'] = corr.iloc[13][7] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 8), 'CORR'] = corr.iloc[13][8] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 9), 'CORR'] = corr.iloc[13][9] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 10), 'CORR'] = corr.iloc[13][10] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 11), 'CORR'] = corr.iloc[13][11] ETP.loc[(ETP.LAT.round(0) == -30) & (ETP.MO == 12), 'CORR'] = corr.iloc[13][12] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 1), 'CORR'] = corr.iloc[14][1] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 2), 'CORR'] = corr.iloc[14][2] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 3), 'CORR'] = corr.iloc[14][3] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 4), 'CORR'] = corr.iloc[14][4] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 5), 'CORR'] = corr.iloc[14][5] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 6), 'CORR'] = corr.iloc[14][6] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 7), 'CORR'] = corr.iloc[14][7] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 8), 'CORR'] = corr.iloc[14][8] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 9), 'CORR'] = corr.iloc[14][9] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 10), 'CORR'] = corr.iloc[14][10] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 11), 'CORR'] = corr.iloc[14][11] ETP.loc[(ETP.LAT.round(0) == -31) & (ETP.MO == 12), 'CORR'] = corr.iloc[14][12] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 1), 'CORR'] = corr.iloc[15][1] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 2), 'CORR'] = corr.iloc[15][2] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 3), 'CORR'] = corr.iloc[15][3] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 4), 'CORR'] = corr.iloc[15][4] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 5), 'CORR'] = corr.iloc[15][5] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 6), 'CORR'] = corr.iloc[15][6] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 7), 'CORR'] = corr.iloc[15][7] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 8), 'CORR'] = corr.iloc[15][8] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 9), 'CORR'] = corr.iloc[15][9] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 10), 'CORR'] = corr.iloc[15][10] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 11), 'CORR'] = corr.iloc[15][11] ETP.loc[(ETP.LAT.round(0) == -32) & (ETP.MO == 12), 'CORR'] = corr.iloc[15][12] print("Fator de correção consultado com sucesso") print("Calculando ETP e P-ETP...") ETP['ETP']=ETP.apply(lambda row: row['CORR']*row['ETt'], axis=1) ETP['P_ETP']=ETP.apply(lambda row: row['PRECTOT']-row['ETP'], axis=1) ETP = ETP[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','ETt','CORR','ETP','P_ETP','DATA']] print("Calculo bem-sucedido") att = input("Deseja atualizar sua BD NasaPower? S/N: ") if att == "S" or att == "s": while True: try: path = input("Digite o diretório para a BD a ser atualizada: ") bd = pd.read_csv(path) ETP= pd.concat([ETP,bd]) print("BD NasaPower atualizada!") ETP['DATA'] = ETP['DATA'].apply(str) ETP['DATA'] = ETP['DATA'].apply(lambda row: row.zfill(4)) break except BaseException: print("ERRO. Digite novamente o diretório!") else: pass ETP = ETP.sort_values(by=['LAT','LON','YEAR','DATA']) print("Gerando planilha ETP.csv no diretório de destino...") ETP.to_csv(output+"\ETP_{}.csv".format(dataf), index=False) print("ETP.csv gerada com sucesso!") return "SUCESSO!" ################################################################################################################### def Referencia (ETP, output): """ETP: tabela ETP_YYYYMMDD.csv com dados para cálculo do balanço hídrico (string) output: diretório de destino (string)""" print ("Tabela ETP:{}".format(ETP)) print ("Diretório de destino:{}".format(output)) import pandas as pd import numpy as np ETPinput = pd.read_csv(ETP) ETPinput.LAT = ETPinput.LAT.round(2) ETPinput.LON = ETPinput.LON.round(2) ETPinput['DATA'] = ETPinput['DATA'].apply(str) ETPinput['NumRegional'] = ETPinput['NumRegional'].apply(str) ETPinput['DATA'] = ETPinput['DATA'].apply(lambda row: row.zfill(4)) ETPinput = ETPinput.sort_values(by=['LAT','LON','YEAR','DATA']) ETPinput = ETPinput.reset_index() print("Dataframe carregado") inpr = input("Deseja gerar balanço de referência para os pontos localizados DENTRO de regionais S/N: ") if inpr == "S" or inpr=="s": df = ETPinput.loc[(ETPinput['NumRegional'] != "0")] print("Gerando balanço de referência para ponto dentro de regionais...") inp_ano = int(input("Desejar calcular o balanço a partir de qual ano? YYYY: ")) df = df.loc[(df['YEAR']>=inp_ano)] linhas = df.shape[0] df.reset_index(inplace=True) anof = df.at[linhas-1,'YEAR'] dataf = df.at[linhas-1,'DATA'] print("Calculando Negativo acumulado, ARM e ALT...") for p in range(0,linhas): if df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101" and df.at[p,'P_ETP'] >= 0: df.at[p,'ARM'] = df.at[p,'CAD'] df.at[p,'NEG_ACUM'] = 0 elif df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101" and df.at[p,'P_ETP'] < 0: df.at[p,'NEG_ACUM'] = df.at[p,'P_ETP'] df.at[p,'ARM'] = df.at[p,'CAD']*np.exp(df.at[p,'NEG_ACUM']/df.at[p,'CAD']) else: pass for p in range(0,linhas): if df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101": pass elif df.at[p-1,'P_ETP'] >= 0 and df.at[p,'P_ETP'] < 0 and df.at[p-1,'ARM'] == df.at[p,'CAD']: df.at[p,'NEG_ACUM'] = df.at[p,'P_ETP'] df.at[p,'ARM'] = df.at[p,'CAD']*np.exp(df.at[p,'NEG_ACUM']/df.at[p,'CAD']) elif df.at[p-1,'P_ETP'] >= 0 and df.at[p,'P_ETP'] < 0 and df.at[p-1,'ARM'] != df.at[p,'CAD']: df.at[p,'NEG_ACUM'] = df.at[p,'P_ETP'] + df.at[p-1,'NEG_ACUM'] df.at[p,'ARM'] = df.at[p,'CAD']*np.exp(df.at[p,'NEG_ACUM']/df.at[p,'CAD']) elif df.at[p-1,'P_ETP'] < 0 and df.at[p,'P_ETP'] < 0: df.at[p,'NEG_ACUM'] = df.at[p,'P_ETP'] + df.at[p-1,'NEG_ACUM'] df.at[p,'ARM'] = df.at[p,'CAD']*np.exp(df.at[p,'NEG_ACUM']/df.at[p,'CAD']) elif df.at[p-1,'P_ETP'] >= 0 and df.at[p,'P_ETP'] >= 0: df.at[p,'ARM'] = df.at[p-1,'ARM'] + df.at[p,'P_ETP'] if df.at[p,'ARM'] >= df.at[p,'CAD']: df.at[p,'ARM'] = df.at[p,'CAD'] df.at[p,'NEG_ACUM'] = 0 else: df.at[p,'NEG_ACUM'] = df.at[p,'CAD']*np.log(df.at[p,'ARM']/df.at[p,'CAD']) elif df.at[p-1,'P_ETP'] < 0 and df.at[p,'P_ETP'] >= 0: df.at[p,'ARM'] = df.at[p-1,'ARM'] + df.at[p,'P_ETP'] if df.at[p,'ARM'] >= df.at[p,'CAD']: df.at[p,'ARM'] = df.at[p,'CAD'] df.at[p,'NEG_ACUM'] = 0 else: df.at[p,'NEG_ACUM'] = df.at[p,'CAD']*np.log(df.at[p,'ARM']/df.at[p,'CAD']) else: print("verificar index {}".format(p)) for p in range(0,linhas): if df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101" and df.at[p,'P_ETP'] < 0: df.at[p,'ALT'] = df.at[p,'ARM'] - df.at[p,'CAD'] elif df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101" and df.at[p,'P_ETP'] >= 0: df.at[p,'ALT'] = 0 else: df.at[p,'ALT'] = df.at[p,'ARM'] - df.at[p-1,'ARM'] print("Negativo acumulado, ARM e ALT calculados com sucesso") print("Calculando ETR, DEF e EXC...") df['ETR']= df.apply(lambda row: row['ETP'] if row['P_ETP'] >= 0 else row['PRECTOT']+ abs(row['ALT']), axis=1) df['DEF']= df.apply(lambda row: row['ETP'] - row['ETR'], axis=1) df['EXC']= df.apply(lambda row: row['P_ETP']-row['ALT'] if row['ARM'] == row['CAD'] else 0, axis=1) df.EXC = df.EXC.round(3) df.DEF = df.DEF.round(3) print("ETR, DEF e EXC calculados com sucesso") df = df[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','ETt','CORR','ETP','P_ETP','ETR','NEG_ACUM','ARM','ALT','DEF','EXC','DATA']] df['NumRegional'] = df['NumRegional'].apply(str) df.to_csv(output+"\BHregional_{}_{}{}.csv".format(inp_ano,anof,dataf),index=False) print("Planilha com pontos dentro de regionais gerada com sucesso no diretório de destino BHregional_{}_{}{}.csv".format(inp_ano,anof,dataf)) print("Gerando compilado mensal das 5 últimas safras...") compilado = df.loc[((df['YEAR']==2015) & (df['MO'] >= 4)) | (df['YEAR'] >= 2016)] df_def = compilado[['LAT','LON','YEAR','MO','NumRegional','DEF','EXC']] df_arm = compilado[['LAT','LON','YEAR','MO','NumRegional','ARM']] deficit = [] arm = [] coordenadas = compilado.groupby(['LAT','LON']).size().reset_index().rename(columns={0:'contagem'}) for x,y in zip(coordenadas['LON'],coordenadas['LAT']): def_ = df_def.loc[(df_def['LON'] == x) & (df_def['LAT'] == y)] def_ = def_.groupby(['LAT','LON','YEAR','MO','NumRegional']).sum() def_.reset_index(inplace=True) deficit.append(def_) arm_ = df_arm.loc[(df_arm['LON'] == x) & (df_arm['LAT'] == y)] arm_ = arm_.groupby(['LAT','LON','YEAR','MO','NumRegional']).mean() arm_.reset_index(inplace=True) arm.append(arm_) def_final = pd.concat(deficit) arm_final = pd.concat(arm) final = def_final.merge(arm_final, on=('LAT','LON','YEAR','MO','NumRegional')) final.loc[((final['YEAR'] == 2015) & (final['MO'] >= 4)) | ((final['YEAR'] == 2016) & (final['MO'] <= 3)), 'SAFRA'] = "15/16" final.loc[((final['YEAR'] == 2016) & (final['MO'] >= 4)) | ((final['YEAR'] == 2017) & (final['MO'] <= 3)), 'SAFRA'] = "16/17" final.loc[((final['YEAR'] == 2017) & (final['MO'] >= 4)) | ((final['YEAR'] == 2018) & (final['MO'] <= 3)), 'SAFRA'] = "17/18" final.loc[((final['YEAR'] == 2018) & (final['MO'] >= 4)) | ((final['YEAR'] == 2019) & (final['MO'] <= 3)), 'SAFRA'] = "18/19" final.loc[((final['YEAR'] == 2019) & (final['MO'] >= 4)) | ((final['YEAR'] == 2020) & (final['MO'] <= 3)), 'SAFRA'] = "19/20" final.loc[((final['YEAR'] == 2020) & (final['MO'] >= 4)) | ((final['YEAR'] == 2021) & (final['MO'] <= 3)), 'SAFRA'] = "20/21" final['LAT'] = final['LAT'].apply(str) final['LON'] = final['LON'].apply(str) final['MO'] = final['MO'].apply(str) final['YEAR'] = final['YEAR'].apply(str) final['DATA'] = final.apply(lambda row: row['MO']+"/"+row['YEAR'], axis=1) final['SALDO'] = final.apply(lambda row: row['EXC'] - row['DEF'], axis=1) final['DEF(-1)']= final.apply(lambda row: -row['DEF'], axis=1) final['ID_COORDENADA']= final.apply(lambda row: row['LAT']+row['LON'],axis=1) final = final[['LAT','LON','NumRegional','SAFRA','YEAR','MO','DEF','EXC','ARM','DATA','SALDO','DEF(-1)','ID_COORDENADA']] print(final) final.rename(columns={"YEAR":"ANO","MO":"MES","NumRegional":"Regional"},inplace=True) print(final) final.to_excel(output+"\BHregional_compilado_{}{}.xlsx".format(anof,dataf),index=False,merge_cells=False) print("Planilha com pontos dentro de regionais gerada com sucesso no diretório de destino BHregional_compilado_{}{}.csv".format(anof,dataf)) else: pass inpf = input("Deseja gerar balanço de referência para os pontos localizados FORA de regionais S/N: ") if inpf == "S" or inpf == "s": CAD = int(input("Qual será a CAD utilizada?: ")) df = ETPinput.loc[(ETPinput['NumRegional'] == "0")] df = df.assign(CAD = CAD) inp_ano = int(input("Desejar calcular o balanço a partir de qual ano? YYYY: ")) df = df.loc[(df['YEAR']>=inp_ano)] linhas = df.shape[0] df.reset_index(inplace=True) anof = df.at[linhas-1,'YEAR'] dataf = df.at[linhas-1,'DATA'] print("Calculando Negativo acumulado, ARM e ALT...") for p in range(0,linhas): if df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101" and df.at[p,'P_ETP'] >= 0: df.at[p,'ARM'] = df.at[p,'CAD'] df.at[p,'NEG_ACUM'] = 0 elif df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101" and df.at[p,'P_ETP'] < 0: df.at[p,'NEG_ACUM'] = df.at[p,'P_ETP'] df.at[p,'ARM'] = df.at[p,'CAD']*np.exp(df.at[p,'NEG_ACUM']/df.at[p,'CAD']) else: pass for p in range(0,linhas): if df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101": pass elif df.at[p-1,'P_ETP'] >= 0 and df.at[p,'P_ETP'] < 0 and df.at[p-1,'ARM'] == df.at[p,'CAD']: df.at[p,'NEG_ACUM'] = df.at[p,'P_ETP'] df.at[p,'ARM'] = df.at[p,'CAD']*np.exp(df.at[p,'NEG_ACUM']/df.at[p,'CAD']) elif df.at[p-1,'P_ETP'] >= 0 and df.at[p,'P_ETP'] < 0 and df.at[p-1,'ARM'] != df.at[p,'CAD']: df.at[p,'NEG_ACUM'] = df.at[p,'P_ETP'] + df.at[p-1,'NEG_ACUM'] df.at[p,'ARM'] = df.at[p,'CAD']*np.exp(df.at[p,'NEG_ACUM']/df.at[p,'CAD']) elif df.at[p-1,'P_ETP'] < 0 and df.at[p,'P_ETP'] < 0: df.at[p,'NEG_ACUM'] = df.at[p,'P_ETP'] + df.at[p-1,'NEG_ACUM'] df.at[p,'ARM'] = df.at[p,'CAD']*np.exp(df.at[p,'NEG_ACUM']/df.at[p,'CAD']) elif df.at[p-1,'P_ETP'] >= 0 and df.at[p,'P_ETP'] >= 0: df.at[p,'ARM'] = df.at[p-1,'ARM'] + df.at[p,'P_ETP'] if df.at[p,'ARM'] >= df.at[p,'CAD']: df.at[p,'ARM'] = df.at[p,'CAD'] df.at[p,'NEG_ACUM'] = 0 else: df.at[p,'NEG_ACUM'] = df.at[p,'CAD']*np.log(df.at[p,'ARM']/df.at[p,'CAD']) elif df.at[p-1,'P_ETP'] < 0 and df.at[p,'P_ETP'] >= 0: df.at[p,'ARM'] = df.at[p-1,'ARM'] + df.at[p,'P_ETP'] if df.at[p,'ARM'] >= df.at[p,'CAD']: df.at[p,'ARM'] = df.at[p,'CAD'] df.at[p,'NEG_ACUM'] = 0 else: df.at[p,'NEG_ACUM'] = df.at[p,'CAD']*np.log(df.at[p,'ARM']/df.at[p,'CAD']) else: print("verificar index {}".format(p)) for p in range(0,linhas): if df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101" and df.at[p,'P_ETP'] < 0: df.at[p,'ALT'] = df.at[p,'ARM'] - df.at[p,'CAD'] elif df.at[p,'YEAR'] == inp_ano and df.at[p,'DATA'] == "0101" and df.at[p,'P_ETP'] >= 0: df.at[p,'ALT'] = 0 else: df.at[p,'ALT'] = df.at[p,'ARM'] - df.at[p-1,'ARM'] print("Negativo acumulado, ARM e ALT calculados com sucesso") print("Calculando ETR, DEF e EXC...") df['ETR']= df.apply(lambda row: row['ETP'] if row['P_ETP'] >= 0 else row['PRECTOT']+ abs(row['ALT']), axis=1) df['DEF']= df.apply(lambda row: row['ETP'] - row['ETR'], axis=1) df['EXC']= df.apply(lambda row: row['P_ETP']-row['ALT'] if row['ARM'] == row['CAD'] else 0, axis=1) df.EXC = df.EXC.round(3) df.DEF = df.DEF.round(3) print("ETR, DEF e EXC calculados com sucesso") df = df[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','CAD','ETt','CORR','ETP','P_ETP','ETR','NEG_ACUM','ARM','ALT','DEF','EXC','DATA']] df.to_csv(output+"\BH{}_{}_{}{}.csv".format(CAD,inp_ano,anof,dataf),index=False) print("Planilha com pontos fora de regionais gerada com sucesso no diretório de destino BH{}_{}_{}{}.csv".format(CAD,inp_ano,anof,dataf)) print("Gerando compilado mensal das 5 últimas safras...") compilado = df.loc[((df['YEAR']==2015) & (df['MO'] >= 4)) | (df['YEAR'] >= 2016)] df_def = compilado[['LAT','LON','YEAR','MO','DEF','EXC']] df_arm = compilado[['LAT','LON','YEAR','MO','ARM']] deficit = [] arm = [] coordenadas = compilado.groupby(['LAT','LON']).size().reset_index().rename(columns={0:'contagem'}) for x,y in zip(coordenadas['LON'],coordenadas['LAT']): def_ = df_def.loc[(df_def['LON'] == x) & (df_def['LAT'] == y)] def_ = def_.groupby(['LAT','LON','YEAR','MO']).sum() def_.reset_index(inplace=True) deficit.append(def_) arm_ = df_arm.loc[(df_arm['LON'] == x) & (df_arm['LAT'] == y)] arm_ = arm_.groupby(['LAT','LON','YEAR','MO']).mean() arm_.reset_index(inplace=True) arm.append(arm_) def_final = pd.concat(deficit) arm_final = pd.concat(arm) final = def_final.merge(arm_final, on=('LAT','LON','YEAR','MO')) final.loc[((final['YEAR'] == 2015) & (final['MO'] >= 4)) | ((final['YEAR'] == 2016) & (final['MO'] <= 3)), 'SAFRA'] = "15/16" final.loc[((final['YEAR'] == 2016) & (final['MO'] >= 4)) | ((final['YEAR'] == 2017) & (final['MO'] <= 3)), 'SAFRA'] = "16/17" final.loc[((final['YEAR'] == 2017) & (final['MO'] >= 4)) | ((final['YEAR'] == 2018) & (final['MO'] <= 3)), 'SAFRA'] = "17/18" final.loc[((final['YEAR'] == 2018) & (final['MO'] >= 4)) | ((final['YEAR'] == 2019) & (final['MO'] <= 3)), 'SAFRA'] = "18/19" final.loc[((final['YEAR'] == 2019) & (final['MO'] >= 4)) | ((final['YEAR'] == 2020) & (final['MO'] <= 3)), 'SAFRA'] = "19/20" final.loc[((final['YEAR'] == 2020) & (final['MO'] >= 4)) | ((final['YEAR'] == 2021) & (final['MO'] <= 3)), 'SAFRA'] = "20/21" final['LAT'] = final['LAT'].apply(str) final['LON'] = final['LON'].apply(str) final['MO'] = final['MO'].apply(str) final['YEAR'] = final['YEAR'].apply(str) final['DATA'] = final.apply(lambda row: row['MO']+"/"+row['YEAR'], axis=1) final['SALDO'] = final.apply(lambda row: row['EXC'] - row['DEF'], axis=1) final['DEF(-1)']= final.apply(lambda row: -row['DEF'], axis=1) final['ID_COORDENADA']= final.apply(lambda row: row['LAT']+row['LON'],axis=1) final = final[['LAT','LON','SAFRA','YEAR','MO','DEF','EXC','ARM','DATA','SALDO','DEF(-1)','ID_COORDENADA']] final.rename(columns={"YEAR":"ANO","MO":"MES"},inplace=True) final.to_excel(output+"\BH{}_compilado_{}{}.xlsx".format(CAD,anof,dataf),index=False,merge_cells=False) print("Planilha com pontos fora de regionais gerada com sucesso no diretório de destino BH{}_compilado_{}{}.csv".format(CAD,anof,dataf)) else: pass return "SUCESSO!" ################################################################################################################### def Cultura(ETP, output): """ETP: planilha ETP_YYYYMMDD.csv output: diretório de destino""" import pandas as pd import numpy as np print("Planilha ETP:{}".format(ETP)) print("Diretório de destino:{}".format(output)) ETPinput = ETP datai = input("Qual a data de plantio/colheita? MMDD: ") anoi = int(input("Qual o ano de plantio/colheita? YYYY: ")) ETPinput = pd.read_csv(ETP) ETPinput.LAT = ETPinput.LAT.round(2) ETPinput.LON = ETPinput.LON.round(2) ETPinput['DATA'] = ETPinput['DATA'].apply(str) ETPinput['NumRegional'] = ETPinput['NumRegional'].apply(str) ETPinput['DATA'] = ETPinput['DATA'].apply(lambda row: row.zfill(4)) ETPinput = ETPinput.sort_values(by=['LAT','LON','YEAR','DATA']) ETPinput = ETPinput.reset_index() inpr = input("Deseja gerar balanço de cultura para pontos DENTRO de regionais? S/N: ") if inpr == "s" or inpr =="S": Selecao = ETPinput.loc[(ETPinput['NumRegional']!="0")] print("Dataframe carregado") all_data = [] coordenadas = Selecao.groupby(['LAT','LON']).size().reset_index().rename(columns={0:'contagem'}) cana = input("Qual o ciclo de cultura? 'soca' p/ cana soca; 'planta12' p/ cana planta de 12 meses; 'planta15' p/ cana planta de 15 meses/; 'planta18' p/ cana planta de 18 meses: ") if cana == "soca" or cana == "planta12": print("calculando balanço de cultura...") i = 1 for x,y in zip(coordenadas['LON'],coordenadas['LAT']): print ("{},{}({})".format(y,x,i)) localizacao = Selecao.loc[(Selecao['LON'] == x) & (Selecao['LAT'] == y)] periodo = localizacao.loc[(localizacao['YEAR'] == anoi) | (localizacao['YEAR'] == anoi+1)] periodo = periodo.reset_index() linhastotal = periodo.shape[0] plantio = periodo[(periodo['YEAR'] == anoi) & (periodo['DATA'] == datai)].index[0] for p in range(0,linhastotal): if p < plantio: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 elif p >= plantio and p < plantio+30: periodo.at[p,'Kc'] = 0.5 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 1 elif p >= plantio+30 and p < plantio+60: periodo.at[p,'Kc'] = 0.8 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 2 elif p >= plantio+60 and p < plantio+75: periodo.at[p,'Kc'] = 1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 3 elif p >= plantio+75 and p < plantio+125: periodo.at[p,'Kc'] = 1.1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 4 elif p >= plantio+125 and p < plantio+305: periodo.at[p,'Kc'] = 1.2 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 5 elif p >= plantio+305 and p < plantio+335: periodo.at[p,'Kc'] = 0.95 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 6 elif p >= plantio+335 and p < plantio+365: periodo.at[p,'Kc'] = 0.65 periodo.at[p,'Ky'] = 0.1 periodo.at[p,'FASE'] = 7 else: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 periodo['ETc']= periodo.apply(lambda row: row['ETP']*row['Kc'], axis=1) periodo['P_ETc']= periodo.apply(lambda row: row['PRECTOT']-row['ETc'], axis=1) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) else: pass for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101": pass elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] == periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] != periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) else: print("verificar index {}".format(p)) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p,'CAD'] elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ALT'] = 0 else: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p-1,'ARM'] periodo['ETR']= periodo.apply(lambda row: row['ETc'] if row['P_ETc'] >= 0 else row['PRECTOT']+ abs(row['ALT']), axis=1) periodo['DEF']= periodo.apply(lambda row: row['ETc'] - row['ETR'], axis=1) periodo['EXC']= periodo.apply(lambda row: row['P_ETc']-row['ALT'] if row['ARM'] == row['CAD'] else 0, axis=1) periodo.EXC = periodo.EXC.round(3) periodo.DEF = periodo.DEF.round(3) periodo = periodo.iloc[plantio:plantio+365] all_data.append(periodo) i += 1 final = pd.concat(all_data) final = final[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','FASE','Ky','Kc','ETc','P_ETc','ETR','NEG_ACUM','ARM','ALT','DEF','EXC','DATA']] final.to_csv(output+"\Cultura_{}_{}{}.csv".format(cana,anoi,datai),index=False) print("Planilha com balanço de cultura Cultura_{}_{}{}.csv gerada com sucesso no diretório de destino.".format(cana,anoi,datai)) elif cana == "planta15": print("calculando balanço de cultura...") i = 1 for x,y in zip(coordenadas['LON'],coordenadas['LAT']): print ("{},{}({})".format(y,x,i)) localizacao = Selecao.loc[(Selecao['LON'] == x) & (Selecao['LAT'] == y)] periodo = localizacao.loc[(localizacao['YEAR'] == anoi) | (localizacao['YEAR'] == anoi+1) | (localizacao['YEAR'] == anoi+2)] periodo = periodo.reset_index() linhastotal = periodo.shape[0] plantio = periodo[(periodo['YEAR'] == anoi) & (periodo['DATA'] == datai)].index[0] for p in range(0,linhastotal): if p < plantio: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 elif p >= plantio and p < plantio+30: periodo.at[p,'Kc'] = 0.5 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 1 elif p >= plantio+30 and p < plantio+60: periodo.at[p,'Kc'] = 0.8 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 2 elif p >= plantio+60 and p < plantio+80: periodo.at[p,'Kc'] = 1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 3 elif p >= plantio+80 and p < plantio+120: periodo.at[p,'Kc'] = 1.1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 4 elif p >= plantio+120 and p = plantio+380 and p < plantio+420: periodo.at[p,'Kc'] = 0.95 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 6 elif p >= plantio+420 and p < plantio+450: periodo.at[p,'Kc'] = 0.65 periodo.at[p,'Ky'] = 0.1 periodo.at[p,'FASE'] = 7 else: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 periodo['ETc']= periodo.apply(lambda row: row['ETP']*row['Kc'], axis=1) periodo['P_ETc']= periodo.apply(lambda row: row['PRECTOT']-row['ETc'], axis=1) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) else: pass for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101": pass elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] == periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] != periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) else: print("verificar index {}".format(p)) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p,'CAD'] elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ALT'] = 0 else: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p-1,'ARM'] periodo['ETR']= periodo.apply(lambda row: row['ETc'] if row['P_ETc'] >= 0 else row['PRECTOT']+ abs(row['ALT']), axis=1) periodo['DEF']= periodo.apply(lambda row: row['ETc'] - row['ETR'], axis=1) periodo['EXC']= periodo.apply(lambda row: row['P_ETc']-row['ALT'] if row['ARM'] == row['CAD'] else 0, axis=1) periodo.EXC = periodo.EXC.round(3) periodo.DEF = periodo.DEF.round(3) periodo = periodo.iloc[plantio:plantio+450] all_data.append(periodo) i += 1 final = pd.concat(all_data) final = final[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','FASE','Ky','Kc','ETc','P_ETc','ETR','NEG_ACUM','ARM','ALT','DEF','EXC','DATA']] final.to_csv(output+"\Cultura_{}_{}{}.csv".format(cana,anoi,datai),index=False) print("Planilha com balanço de cultura Cultura_{}_{}{}.csv gerada com sucesso no diretório de destino.".format(cana,anoi,datai)) elif cana == "planta18": print("calculando balanço de cultura...") i = 1 for x,y in zip(coordenadas['LON'],coordenadas['LAT']): print ("{},{}({})".format(y,x,i)) localizacao = Selecao.loc[(Selecao['LON'] == x) & (Selecao['LAT'] == y)] periodo = localizacao.loc[(localizacao['YEAR'] == anoi) | (localizacao['YEAR'] == anoi+1) | (localizacao['YEAR'] == anoi+2)] periodo = periodo.reset_index() linhastotal = periodo.shape[0] plantio = periodo[(periodo['YEAR'] == anoi) & (periodo['DATA'] == datai)].index[0] for p in range(0,linhastotal): if p < plantio: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 elif p >= plantio and p < plantio+40: periodo.at[p,'Kc'] = 0.5 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 1 elif p >= plantio+40 and p < plantio+80: periodo.at[p,'Kc'] = 0.8 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 2 elif p >= plantio+80 and p < plantio+110: periodo.at[p,'Kc'] = 1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 3 elif p >= plantio+110 and p < plantio+160: periodo.at[p,'Kc'] = 1.1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 4 elif p >= plantio+160 and p < plantio+460: periodo.at[p,'Kc'] = 1.2 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 5 elif p >= plantio+460 and p < plantio+510: periodo.at[p,'Kc'] = 0.95 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 6 elif p >= plantio+510 and p < plantio+540: periodo.at[p,'Kc'] = 0.65 periodo.at[p,'Ky'] = 0.1 periodo.at[p,'FASE'] = 7 else: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 periodo['ETc']= periodo.apply(lambda row: row['ETP']*row['Kc'], axis=1) periodo['P_ETc']= periodo.apply(lambda row: row['PRECTOT']-row['ETc'], axis=1) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) else: pass for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101": pass elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] == periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] != periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) else: print("verificar index {}".format(p)) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p,'CAD'] elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ALT'] = 0 else: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p-1,'ARM'] periodo['ETR']= periodo.apply(lambda row: row['ETc'] if row['P_ETc'] >= 0 else row['PRECTOT']+ abs(row['ALT']), axis=1) periodo['DEF']= periodo.apply(lambda row: row['ETc'] - row['ETR'], axis=1) periodo['EXC']= periodo.apply(lambda row: row['P_ETc']-row['ALT'] if row['ARM'] == row['CAD'] else 0, axis=1) periodo.EXC = periodo.EXC.round(3) periodo.DEF = periodo.DEF.round(3) periodo = periodo.iloc[plantio:plantio+540] all_data.append(periodo) i += 1 final = pd.concat(all_data) final = final[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','FASE','Ky','Kc','ETc','P_ETc','ETR','NEG_ACUM','ARM','ALT','DEF','EXC','DATA']] final.to_csv(output+"\Cultura_{}_{}{}.csv".format(cana,anoi,datai),index=False) print("Planilha com balanço de cultura Cultura_{}_{}{}.csv gerada com sucesso no diretório de destino.".format(cana,anoi,datai)) else: print("Por favor, selecione um parâmetro válido para o ciclo") print ("Gerando compilado de Déficit de Evapotranspiração (DEF_ET) por fase do ciclo...") final = final[['LAT','LON','ETc','ETR','Ky','FASE','DEF']] final = final.loc[(final['FASE'] != 0)] final = final.groupby(['LAT','LON','FASE','Ky']).sum() final.reset_index(inplace=True) final['DEF_ET %'] = final.apply(lambda row: (1-(row['ETR']/row['ETc']))*100, axis=1) final.to_excel(output+"\CulturaCompilado_{}_{}{}.xlsx".format(cana,anoi,datai),index=False,merge_cells=False) print("Balanço de cultura compilado por fases do ciclo da cultura CulturaCompilado_{}_{}{}.xlsx gerado no diretório de destino".format(cana,anoi,datai)) else: pass inpf = input("Deseja gerar balanço de cultura para pontos FORA de regionais? S/N: ") if inpf == "S" or inpf == "s": Selecao = ETPinput.loc[(ETPinput['NumRegional']=="0")] CAD = int(input("Digite a CAD desejada: ")) Selecao = Selecao.assign(CAD = CAD) print("Dataframe carregado") all_data = [] coordenadas = Selecao.groupby(['LAT','LON']).size().reset_index().rename(columns={0:'contagem'}) cana = input("Qual o ciclo de cultura? 'soca' p/ cana soca; 'planta12' p/ cana planta de 12 meses; 'planta15' p/ cana planta de 15 meses/; 'planta18' p/ cana planta de 18 meses: ") if cana == "soca" or cana == "planta12": print("calculando balanço de cultura...") i = 1 for x,y in zip(coordenadas['LON'],coordenadas['LAT']): print ("{},{}({})".format(y,x,i)) localizacao = Selecao.loc[(Selecao['LON'] == x) & (Selecao['LAT'] == y)] periodo = localizacao.loc[(localizacao['YEAR'] == anoi) | (localizacao['YEAR'] == anoi+1)] periodo = periodo.reset_index() linhastotal = periodo.shape[0] plantio = periodo[(periodo['YEAR'] == anoi) & (periodo['DATA'] == datai)].index[0] for p in range(0,linhastotal): if p < plantio: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 elif p >= plantio and p < plantio+30: periodo.at[p,'Kc'] = 0.5 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 1 elif p >= plantio+30 and p < plantio+60: periodo.at[p,'Kc'] = 0.8 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 2 elif p >= plantio+60 and p < plantio+75: periodo.at[p,'Kc'] = 1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 3 elif p >= plantio+75 and p < plantio+125: periodo.at[p,'Kc'] = 1.1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 4 elif p >= plantio+125 and p < plantio+305: periodo.at[p,'Kc'] = 1.2 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 5 elif p >= plantio+305 and p < plantio+335: periodo.at[p,'Kc'] = 0.95 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 6 elif p >= plantio+335 and p < plantio+365: periodo.at[p,'Kc'] = 0.65 periodo.at[p,'Ky'] = 0.1 periodo.at[p,'FASE'] = 7 else: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 periodo['ETc']= periodo.apply(lambda row: row['ETP']*row['Kc'], axis=1) periodo['P_ETc']= periodo.apply(lambda row: row['PRECTOT']-row['ETc'], axis=1) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) else: pass for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101": pass elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] == periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] != periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) else: print("verificar index {}".format(p)) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p,'CAD'] elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ALT'] = 0 else: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p-1,'ARM'] periodo['ETR']= periodo.apply(lambda row: row['ETc'] if row['P_ETc'] >= 0 else row['PRECTOT']+ abs(row['ALT']), axis=1) periodo['DEF']= periodo.apply(lambda row: row['ETc'] - row['ETR'], axis=1) periodo['EXC']= periodo.apply(lambda row: row['P_ETc']-row['ALT'] if row['ARM'] == row['CAD'] else 0, axis=1) periodo.EXC = periodo.EXC.round(3) periodo.DEF = periodo.DEF.round(3) periodo = periodo.iloc[plantio:plantio+365] all_data.append(periodo) i += 1 final = pd.concat(all_data) final = final[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','FASE','Ky','Kc','ETc','P_ETc','ETR','NEG_ACUM','ARM','ALT','DEF','EXC','DATA']] final.to_csv(output+"\Cultura{}_{}_{}{}.csv".format(CAD,cana,anoi,datai),index=False) print("Planilha com balanço de cultura Cultura{}_{}_{}{}.csv gerada com sucesso no diretório de destino.".format(CAD,cana,anoi,datai)) elif cana == "planta15": print("calculando balanço de cultura...") i = 1 for x,y in zip(coordenadas['LON'],coordenadas['LAT']): print ("{},{}({})".format(y,x,i)) localizacao = Selecao.loc[(Selecao['LON'] == x) & (Selecao['LAT'] == y)] periodo = localizacao.loc[(localizacao['YEAR'] == anoi) | (localizacao['YEAR'] == anoi+1) | (localizacao['YEAR'] == anoi+2)] periodo = periodo.reset_index() linhastotal = periodo.shape[0] plantio = periodo[(periodo['YEAR'] == anoi) & (periodo['DATA'] == datai)].index[0] for p in range(0,linhastotal): if p < plantio: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 elif p >= plantio and p < plantio+30: periodo.at[p,'Kc'] = 0.5 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 1 elif p >= plantio+30 and p < plantio+60: periodo.at[p,'Kc'] = 0.8 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 2 elif p >= plantio+60 and p < plantio+80: periodo.at[p,'Kc'] = 1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 3 elif p >= plantio+80 and p < plantio+120: periodo.at[p,'Kc'] = 1.1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 4 elif p >= plantio+120 and p = plantio+380 and p < plantio+420: periodo.at[p,'Kc'] = 0.95 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 6 elif p >= plantio+420 and p < plantio+450: periodo.at[p,'Kc'] = 0.65 periodo.at[p,'Ky'] = 0.1 periodo.at[p,'FASE'] = 7 else: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 periodo['ETc']= periodo.apply(lambda row: row['ETP']*row['Kc'], axis=1) periodo['P_ETc']= periodo.apply(lambda row: row['PRECTOT']-row['ETc'], axis=1) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) else: pass for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101": pass elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] == periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] != periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) else: print("verificar index {}".format(p)) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p,'CAD'] elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ALT'] = 0 else: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p-1,'ARM'] periodo['ETR']= periodo.apply(lambda row: row['ETc'] if row['P_ETc'] >= 0 else row['PRECTOT']+ abs(row['ALT']), axis=1) periodo['DEF']= periodo.apply(lambda row: row['ETc'] - row['ETR'], axis=1) periodo['EXC']= periodo.apply(lambda row: row['P_ETc']-row['ALT'] if row['ARM'] == row['CAD'] else 0, axis=1) periodo.EXC = periodo.EXC.round(3) periodo.DEF = periodo.DEF.round(3) periodo = periodo.iloc[plantio:plantio+450] all_data.append(periodo) i += 1 final = pd.concat(all_data) final = final[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','FASE','Ky','Kc','ETc','P_ETc','ETR','NEG_ACUM','ARM','ALT','DEF','EXC','DATA']] final.to_csv(output+"\Cultura{}_{}_{}{}.csv".format(CAD,cana,anoi,datai),index=False) print("Planilha com balanço de cultura Cultura{}_{}_{}{}.csv gerada com sucesso no diretório de destino.".format(CAD,cana,anoi,datai)) elif cana == "planta18": print("calculando balanço de cultura...") i = 1 for x,y in zip(coordenadas['LON'],coordenadas['LAT']): print ("{},{}({})".format(y,x,i)) localizacao = Selecao.loc[(Selecao['LON'] == x) & (Selecao['LAT'] == y)] periodo = localizacao.loc[(localizacao['YEAR'] == anoi) | (localizacao['YEAR'] == anoi+1) | (localizacao['YEAR'] == anoi+2)] periodo = periodo.reset_index() linhastotal = periodo.shape[0] plantio = periodo[(periodo['YEAR'] == anoi) & (periodo['DATA'] == datai)].index[0] for p in range(0,linhastotal): if p < plantio: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 elif p >= plantio and p < plantio+40: periodo.at[p,'Kc'] = 0.5 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 1 elif p >= plantio+40 and p < plantio+80: periodo.at[p,'Kc'] = 0.8 periodo.at[p,'Ky'] = 0.75 periodo.at[p,'FASE'] = 2 elif p >= plantio+80 and p < plantio+110: periodo.at[p,'Kc'] = 1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 3 elif p >= plantio+110 and p < plantio+160: periodo.at[p,'Kc'] = 1.1 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 4 elif p >= plantio+160 and p < plantio+460: periodo.at[p,'Kc'] = 1.2 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 5 elif p >= plantio+460 and p < plantio+510: periodo.at[p,'Kc'] = 0.95 periodo.at[p,'Ky'] = 0.5 periodo.at[p,'FASE'] = 6 elif p >= plantio+510 and p < plantio+540: periodo.at[p,'Kc'] = 0.65 periodo.at[p,'Ky'] = 0.1 periodo.at[p,'FASE'] = 7 else: periodo.at[p,'Kc'] = 1 periodo.at[p,'FASE'] = 0 periodo['ETc']= periodo.apply(lambda row: row['ETP']*row['Kc'], axis=1) periodo['P_ETc']= periodo.apply(lambda row: row['PRECTOT']-row['ETc'], axis=1) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) else: pass for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101": pass elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] == periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] < 0 and periodo.at[p-1,'ARM'] != periodo.at[p,'CAD']: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'P_ETc'] + periodo.at[p-1,'NEG_ACUM'] periodo.at[p,'ARM'] = periodo.at[p,'CAD']*np.exp(periodo.at[p,'NEG_ACUM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] >= 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) elif periodo.at[p-1,'P_ETc'] < 0 and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ARM'] = periodo.at[p-1,'ARM'] + periodo.at[p,'P_ETc'] if periodo.at[p,'ARM'] >= periodo.at[p,'CAD']: periodo.at[p,'ARM'] = periodo.at[p,'CAD'] periodo.at[p,'NEG_ACUM'] = 0 else: periodo.at[p,'NEG_ACUM'] = periodo.at[p,'CAD']*np.log(periodo.at[p,'ARM']/periodo.at[p,'CAD']) else: print("verificar index {}".format(p)) for p in range(0,linhastotal): if periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] < 0: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p,'CAD'] elif periodo.at[p,'YEAR'] == anoi and periodo.at[p,'DATA'] == "0101" and periodo.at[p,'P_ETc'] >= 0: periodo.at[p,'ALT'] = 0 else: periodo.at[p,'ALT'] = periodo.at[p,'ARM'] - periodo.at[p-1,'ARM'] periodo['ETR']= periodo.apply(lambda row: row['ETc'] if row['P_ETc'] >= 0 else row['PRECTOT']+ abs(row['ALT']), axis=1) periodo['DEF']= periodo.apply(lambda row: row['ETc'] - row['ETR'], axis=1) periodo['EXC']= periodo.apply(lambda row: row['P_ETc']-row['ALT'] if row['ARM'] == row['CAD'] else 0, axis=1) periodo.EXC = periodo.EXC.round(3) periodo.DEF = periodo.DEF.round(3) periodo = periodo.iloc[plantio:plantio+540] all_data.append(periodo) i += 1 final = pd.concat(all_data) final = final[['LAT','LON','YEAR','MO','DY','PRECTOT','T2M_MAX','T2M_MIN','T_Normal','ALLSKY_SFC_SW_DWN','ALLSKY_TOA_SW_DWN','NomeRegional','NumRegional','CAD','FASE','Ky','Kc','ETc','P_ETc','ETR','NEG_ACUM','ARM','ALT','DEF','EXC','DATA']] final.to_csv(output+"\Cultura{}_{}_{}{}.csv".format(CAD,cana,anoi,datai),index=False) print("Planilha com balanço de cultura Cultura{}_{}_{}{}.csv gerada com sucesso no diretório de destino.".format(CAD,cana,anoi,datai)) else: print("Por favor, selecione um parâmetro válido para o ciclo") print ("Gerando compilado de Déficit de Evapotranspiração (DEF_ET) por fase do ciclo...") final = final[['LAT','LON','ETc','ETR','Ky','FASE','DEF']] final = final.loc[(final['FASE'] != 0)] final = final.groupby(['LAT','LON','FASE','Ky']).sum() final.reset_index(inplace=True) final['DEF_ET %'] = final.apply(lambda row: (1-(row['ETR']/row['ETc']))*100, axis=1) final.to_excel(output+"\CulturaCompilado{}_{}_{}{}.xlsx".format(CAD,cana,anoi,datai),index=False,merge_cells=False) print("Balanço de cultura compilado por fases do ciclo da cultura CulturaCompilado{}_{}_{}{}.xlsx gerado no diretório de destino".format(CAD,cana,anoi,datai)) else: pass return "SUCESSO"