onfarmview commited on
Commit
ac39321
1 Parent(s): a91ee43

Add application file

Browse files
Files changed (2) hide show
  1. app.py +81 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ # import leafmap.foliumap as geemap
3
+ import geemap.foliumap as geemap
4
+ from streamlit.components.v1 import html
5
+ import ee
6
+ import folium
7
+ import pandas
8
+ # import geemap.foliumap as geemap
9
+ # import ee
10
+ from datetime import date, timedelta, datetime
11
+
12
+
13
+ st.set_page_config(layout="wide")
14
+
15
+ st.sidebar.info(
16
+ """
17
+ URL: <https://onfarmview.com>
18
+
19
+ """
20
+ )
21
+
22
+ st.sidebar.title("Contact")
23
+
24
+ st.sidebar.markdown('<a href="mailto:admin@onfarmview.com">Contact Us</a>', unsafe_allow_html=True)
25
+
26
+ st.title("On Farm View")
27
+
28
+ footer_content = """
29
+
30
+ <p>&copy; 2023 On Farm View. </p>
31
+
32
+ """
33
+
34
+ st.sidebar.markdown(footer_content, unsafe_allow_html=True)
35
+
36
+
37
+ def ee_authenticate(token_name="EARTHENGINE_TOKEN"):
38
+ geemap.ee_initialize(token_name=token_name)
39
+
40
+ def maskCloudAndShadows(image):
41
+ cloudProb = image.select('MSK_CLDPRB')
42
+ snowProb = image.select('MSK_SNWPRB')
43
+ cloud = cloudProb.lt(5)
44
+ snow = snowProb.lt(5)
45
+ scl = image.select('SCL')
46
+ shadow = scl.eq(3); # 3 = cloud shadow
47
+ cirrus = scl.eq(10); # 10 = cirrus
48
+ # Cloud probability less than 5% or cloud shadow classification
49
+ mask = (cloud.And(snow)).And(cirrus.neq(1)).And(shadow.neq(1))
50
+ return image.updateMask(mask).divide(10000)
51
+
52
+ map_center=(-43.525650, 172.639847)
53
+ ee_authenticate(token_name="EARTHENGINE_TOKEN")
54
+
55
+ m = geemap.Map(
56
+ basemap="HYBRID",
57
+ plugin_Draw=True,
58
+ Draw_export=True,
59
+ locate_control=True,
60
+ plugin_LatLngPopup=True,
61
+ center=map_center, zoom=15,
62
+ )
63
+
64
+ ed = date.today()
65
+ sd = ed - timedelta(days=30)
66
+
67
+
68
+ startDate = sd.strftime("%Y-%m-%d") + "T"
69
+ endDate = ed.strftime("%Y-%m-%d") + "T"
70
+
71
+
72
+ se2 = ee.ImageCollection('COPERNICUS/S2_SR').filterDate(
73
+ startDate,endDate).filter(
74
+ ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE",80)).map(maskCloudAndShadows).median()
75
+ band = ['B4','B3','B2']
76
+ rgbViza = {"min":0.0, "max":0.7,"bands":band}
77
+ titlemap = "Sentinel 2 - Natural Color"
78
+ m.addLayer(se2, rgbViza, titlemap)
79
+
80
+ m.to_streamlit(height=650)
81
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ streamlit-folium
3
+ geemap
4
+ leafmap
5
+ click==8