File size: 2,293 Bytes
ac39321
 
 
 
 
 
 
 
 
 
1d1f497
bed93c5
1d1f497
 
ac39321
7b241a4
f2edd27
 
 
 
aedf263
543eb3b
ac39321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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: <https://onfarmview.com>
    
    """
)

st.sidebar.title("Contact")

st.sidebar.markdown('<a href="mailto:admin@onfarmview.com">Contact Us</a>', unsafe_allow_html=True)

st.title("On Farm View")

footer_content = """
 
    <p>&copy; 2023 On Farm View. </p>

    """

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)