import streamlit as st # import leafmap.foliumap as geemap import geemap.foliumap as geemap from streamlit.components.v1 import html import ee import folium import pandas # import geemap.foliumap as geemap # import ee from datetime import date, timedelta, datetime import os # st.set_page_config(layout="wide") def ee_authenticate(token_name): geemap.ee_initialize(token_name=token_name) os.environ["EARTHENGINE_TOKEN"] == st.secrets["EARTHENGINE_TOKEN"] st.write(os.environ["EARTHENGINE_TOKEN"]) ee_authenticate("1//0g82Zr46QN_hwCgYIARAAGBASNwF-L9IrGuzCU-_xOupeDXg2Py8lCLem-3OD0U-mSZMC9yTVY7_OXfGG3BhePoOPahKU15QEVXM") st.sidebar.info( """ URL: """ ) st.sidebar.title("Contact") st.sidebar.markdown('Contact Us', unsafe_allow_html=True) st.title("On Farm View") footer_content = """

© 2023 On Farm View.

""" st.sidebar.markdown(footer_content, unsafe_allow_html=True) def ee_authenticate(token_name="EARTHENGINE_TOKEN"): geemap.ee_initialize(token_name=token_name) def maskCloudAndShadows(image): cloudProb = image.select('MSK_CLDPRB') snowProb = image.select('MSK_SNWPRB') cloud = cloudProb.lt(5) snow = snowProb.lt(5) scl = image.select('SCL') shadow = scl.eq(3); # 3 = cloud shadow cirrus = scl.eq(10); # 10 = cirrus # Cloud probability less than 5% or cloud shadow classification mask = (cloud.And(snow)).And(cirrus.neq(1)).And(shadow.neq(1)) return image.updateMask(mask).divide(10000) map_center=(-43.525650, 172.639847) ee_authenticate(token_name="EARTHENGINE_TOKEN") m = geemap.Map( basemap="HYBRID", plugin_Draw=True, Draw_export=True, locate_control=True, plugin_LatLngPopup=True, center=map_center, zoom=15, ) ed = date.today() sd = ed - timedelta(days=30) startDate = sd.strftime("%Y-%m-%d") + "T" endDate = ed.strftime("%Y-%m-%d") + "T" se2 = ee.ImageCollection('COPERNICUS/S2_SR').filterDate( startDate,endDate).filter( ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE",80)).map(maskCloudAndShadows).median() band = ['B4','B3','B2'] rgbViza = {"min":0.0, "max":0.7,"bands":band} titlemap = "Sentinel 2 - Natural Color" m.addLayer(se2, rgbViza, titlemap) m.to_streamlit(height=650)