Esmaeilkianii commited on
Commit
48886cb
·
verified ·
1 Parent(s): 69cbb01

Delete data_handler.py

Browse files
Files changed (1) hide show
  1. data_handler.py +0 -87
data_handler.py DELETED
@@ -1,87 +0,0 @@
1
- import pandas as pd
2
- import streamlit as st
3
- import ee
4
-
5
- @st.cache_data
6
- def load_data(file_path='output (1).csv'):
7
- """Load and preprocess farm data from CSV file"""
8
- try:
9
- df = pd.read_csv(file_path)
10
-
11
- # Convert coordinate columns to numeric
12
- df['طول جغرافیایی'] = pd.to_numeric(df['طول جغرافیایی'], errors='coerce')
13
- df['عرض جغرافیایی'] = pd.to_numeric(df['عرض جغرافیایی'], errors='coerce')
14
-
15
- # Remove rows with invalid coordinates
16
- df = df[~((df['طول جغرافیایی'] == 0) | (df['عرض جغرافیایی'] == 0) |
17
- df['طول جغرافیایی'].isna() | df['عرض جغرافیایی'].isna())]
18
-
19
- # Create display columns
20
- df['مزرعه_نمایشی'] = df['مزرعه'].astype(str)
21
-
22
- return df
23
- except Exception as e:
24
- st.error(f"Error reading CSV file: {e}")
25
- return None
26
-
27
- def filter_by_day(df, day):
28
- """Filter dataframe by day of week"""
29
- return df[df['روزهای هفته'] == day]
30
-
31
- def get_farm_data(df, farm_id):
32
- """Get data for a specific farm"""
33
- farm_data = df[df['مزرعه'] == farm_id]
34
- if len(farm_data) > 0:
35
- return farm_data.iloc[0]
36
- return None
37
-
38
- def create_aoi_from_point(lon, lat, buffer_distance=500):
39
- """Create an area of interest (buffer) around a point"""
40
- point = ee.Geometry.Point([lon, lat])
41
- return point.buffer(buffer_distance)
42
-
43
- def calculate_index_values_for_farms(farms_to_compare, filtered_df, start_date, end_date, indices, get_sentinel_imagery):
44
- """Calculate index values for multiple farms"""
45
- index_values = {}
46
-
47
- for farm_id in farms_to_compare:
48
- farm_data = filtered_df[filtered_df['مزرعه'] == farm_id].iloc[0]
49
- center_lat = farm_data['عرض جغرافیایی']
50
- center_lon = farm_data['طول جغرافیایی']
51
-
52
- point = ee.Geometry.Point([center_lon, center_lat])
53
- aoi = point.buffer(500)
54
-
55
- imagery = get_sentinel_imagery(start_date.strftime('%Y-%m-%d'),
56
- end_date.strftime('%Y-%m-%d'),
57
- aoi)
58
-
59
- if imagery is not None:
60
- # Calculate mean indices
61
- values = {}
62
- for index_name in indices:
63
- mean_value = imagery.select(index_name).reduceRegion(
64
- reducer=ee.Reducer.mean(),
65
- geometry=aoi,
66
- scale=10
67
- ).get(index_name).getInfo()
68
-
69
- if mean_value is not None:
70
- values[index_name] = mean_value
71
-
72
- index_values[farm_id] = values
73
-
74
- return index_values
75
-
76
- def create_comparison_dataframe(farms_to_compare, index_values):
77
- """Create a dataframe for comparing farms"""
78
- comparison_data = []
79
- for farm_id in farms_to_compare:
80
- if farm_id in index_values:
81
- row = {'مزرعه': farm_id}
82
- row.update(index_values[farm_id])
83
- comparison_data.append(row)
84
-
85
- if comparison_data:
86
- return pd.DataFrame(comparison_data)
87
- return None