Esmaeilkiani commited on
Commit
a269448
·
verified ·
1 Parent(s): 694f2f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -68
app.py CHANGED
@@ -1,68 +1,31 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import matplotlib.pyplot as plt
4
- from mpl_toolkits.mplot3d import Axes3D
5
-
6
- # Load CSV file
7
- df = pd.read_csv('رشد و ارتفاع مزارع نماینده- هفته 20.csv')
8
-
9
- st.title("داشبورد اداره مزارع")
10
-
11
- # Department selection
12
- department = st.selectbox("انتخاب اداره:", df['اداره'].unique())
13
-
14
- # Variety selection
15
- variety = st.selectbox("انتخاب واریته:", df['واریته'].unique())
16
-
17
- # Filter farms based on selected department and variety
18
- farms = df[(df['اداره'] == department) & (df['واریته'] == variety)]['مزرعه'].unique()
19
-
20
- # Farm selection
21
- farm = st.selectbox("انتخاب مزرعه:", farms)
22
-
23
- # Display farm data
24
- if farm:
25
-   farm_data = df[df['مزرعه'] == farm]
26
-   weekly_height = farm_data['ارتفاع مزرعه'].values
27
-    
28
-   # Display table
29
-   st.write("### ارتفاع هفتگی")
30
-   st.table(pd.DataFrame({'هفته': range(1, len(weekly_height)+1), 'ارتفاع': weekly_height}))
31
-    
32
-   # Display 3D histogram
33
-   fig = plt.figure()
34
-   ax = fig.add_subplot(111, projection='3d')
35
-    
36
-   xpos = [i for i in range(1, len(weekly_height)+1)]
37
-   ypos = [0] * len(weekly_height)
38
-   zpos = [0] * len(weekly_height)
39
-   dx = [1] * len(weekly_height)
40
-   dy = [1] * len(weekly_height)
41
-   dz = weekly_height
42
-    
43
-   ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')
44
-    
45
-   ax.set_xlabel("هفته")
46
-   ax.set_ylabel("Y")
47
-   ax.set_zlabel("ارتفاع")
48
-   st.pyplot(fig)
49
-    
50
-   # Additional features
51
-   st.write("### آمار مزرعه")
52
-   st.write(f"میانگین ارتفاع: {weekly_height.mean():.2f}")
53
-   st.write(f"بیشترین ارتفاع: {weekly_height.max():.2f}")
54
-   st.write(f"کمترین ارتفاع: {weekly_height.min():.2f}")
55
-    
56
-   st.write("### نمودار توزیع ارتفاع")
57
-   fig, ax = plt.subplots()
58
-   ax.hist(weekly_height, bins=10, color='b')
59
-   ax.set_xlabel("ارتفاع")
60
-   ax.set_ylabel("تعداد")
61
-   st.pyplot(fig)
62
-    
63
-   st.write("### نمودار توزیع ارتفاع بر حسب هفته")
64
-   fig, ax = plt.subplots()
65
-   ax.plot(range(1, len(weekly_height)+1), weekly_height, marker='o')
66
-   ax.set_xlabel("هفته")
67
-   ax.set_ylabel("ارتفاع")
68
-   st.pyplot(fig)
 
1
+ import ee
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+ # Authenticate Earth Engine
6
+ service_account = 'earth-engine-service-account@ee-esmaeilkiani1387.iam.gserviceaccount.com'
7
+ credentials = ee.ServiceAccountCredentials(service_account, 'ee-esmaeilkiani1387-1b2c5e812a1d.json')
8
+ ee.Initialize(credentials)
9
+
10
+ # آپلود فایل مختصات
11
+ uploaded_file = st.file_uploader("آپلود فایل مختصات مزارع", type="csv")
12
+ if uploaded_file:
13
+ farms_df = pd.read_csv(uploaded_file)
14
+
15
+ # پردازش اطلاعات هر مزرعه
16
+ for idx, row in farms_df.iterrows():
17
+ lat, lon = row['latitude'], row['longitude']
18
+ location = ee.Geometry.Point(lon, lat)
19
+
20
+ # دریافت تصویر ماهواره‌ای و محاسبه NDVI
21
+ image = ee.ImageCollection('COPERNICUS/S2') \
22
+ .filterBounds(location) \
23
+ .filterDate('2023-01-01', '2023-12-31') \
24
+ .mean()
25
+ ndvi = image.normalizedDifference(['B8', 'B4']).reduceRegion(
26
+ reducer=ee.Reducer.mean(),
27
+ geometry=location,
28
+ scale=30
29
+ )
30
+
31
+ st.write(f"شاخص NDVI برای مزرعه {idx}: {ndvi.getInfo()['nd']}")