andalusia-fire-allocation / gee_baixar_stack.py
JefersonPMS's picture
Wildfire allocation decision-support dashboard
e7e46ae
Raw
History Blame Contribute Delete
1.07 kB
import ee, json, os, sys, urllib.request
sys.path.insert(0, r'C:/JEFERSON-ARTIGOS/TESE/Aplicativo_streamlit')
import geopandas as gpd
KEY=r'C:/JEFERSON-ARTIGOS/TESE/ee-guiapratico4-3a12b9584ab4.json'
k=json.load(open(KEY)); ee.Initialize(ee.ServiceAccountCredentials(k['client_email'],KEY),project=k['project_id'])
from gee_stack import build_stack
stack=build_stack().toFloat()
g=gpd.read_file(r'C:/JEFERSON-ARTIGOS/TESE/Aplicativo_streamlit/dados/andaluzia.geojson').to_crs(4326)
b=g.total_bounds # minx,miny,maxx,maxy
region=ee.Geometry.Rectangle([float(b[0]),float(b[1]),float(b[2]),float(b[3])])
for sc in [500, 900]:
try:
url=stack.clip(region).getDownloadURL({'scale':sc,'region':region,'format':'GEO_TIFF','crs':'EPSG:4326'})
out=r'C:/JEFERSON-ARTIGOS/TESE/Aplicativo_streamlit/dados/stack_andaluzia.tif'
urllib.request.urlretrieve(url, out)
mb=os.path.getsize(out)/1e6
print(f'OK escala {sc} m | {mb:.1f} MB -> stack_andaluzia.tif'); break
except Exception as e:
print(f'escala {sc} falhou:', repr(e)[:160])