Spaces:
Runtime error
Runtime error
Esmaeilkiani
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,68 +1,31 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
import
|
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 |
-
# 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']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|