Merge branch 'main' of https://huggingface.co/spaces/IITGN-GFD/NDVI_PERG into main
Browse files
app.py
CHANGED
@@ -91,6 +91,8 @@ def shape_3d_to_2d(shape):
|
|
91 |
|
92 |
def preprocess_gdf(gdf):
|
93 |
gdf = gdf.to_crs(epsg=7761) # epsg for Gujarat
|
|
|
|
|
94 |
gdf["geometry"] = gdf["geometry"].apply(shape_3d_to_2d)
|
95 |
return gdf
|
96 |
|
@@ -231,8 +233,8 @@ dec_31 = pd.to_datetime(f"{max_year}/12/31", format="%Y/%m/%d")
|
|
231 |
nov_15 = pd.to_datetime(f"{max_year}/11/15", format="%Y/%m/%d")
|
232 |
dec_15 = pd.to_datetime(f"{max_year}/12/15", format="%Y/%m/%d")
|
233 |
input_daterange = st.date_input("Date Range (Ignore year. App will compute indices for all possible years)", (nov_15, dec_15), jan_1, dec_31)
|
234 |
-
min_year = int(st.number_input("Minimum Year", value=
|
235 |
-
max_year = int(st.number_input("Maximum Year", value=max_year, min_value=
|
236 |
|
237 |
# Input: GeoJSON/KML file
|
238 |
file_url = st.query_params.get("file_url", None)
|
@@ -251,13 +253,14 @@ def format_fn(x):
|
|
251 |
input_geometry_idx = st.selectbox("Select the geometry", input_gdf.index, format_func=format_fn)
|
252 |
geometry_gdf = input_gdf[input_gdf.index == input_geometry_idx]
|
253 |
buffer_geometry_gdf = geometry_gdf.copy()
|
254 |
-
buffer_geometry_gdf["geometry"] = buffer_geometry_gdf["geometry"].buffer(buffer)
|
255 |
check_valid_geometry(geometry_gdf)
|
256 |
|
257 |
# Derived Inputs
|
258 |
ee_geometry = ee.Geometry(geometry_gdf.to_crs(4326).geometry.item().__geo_interface__)
|
259 |
ee_feature_collection = ee.FeatureCollection(ee_geometry)
|
260 |
buffer_ee_geometry = ee.Geometry(buffer_geometry_gdf.to_crs(4326).geometry.item().__geo_interface__)
|
|
|
261 |
buffer_ee_feature_collection = ee.FeatureCollection(buffer_ee_geometry)
|
262 |
|
263 |
# visualize the geometry
|
@@ -365,7 +368,7 @@ if "result" in st.session_state:
|
|
365 |
with cols[1]:
|
366 |
year_2 = st.selectbox("Year 2", result_df.index, index=len(result_df.index) - 1, format_func=lambda x: daterange_str_to_year(x))
|
367 |
|
368 |
-
vis_params = {'min': 0, 'max': 1, 'palette': ['white', 'green']} # Example
|
369 |
|
370 |
# Create a colormap and name it as NDVI
|
371 |
colormap = cm.LinearColormap(
|
|
|
91 |
|
92 |
def preprocess_gdf(gdf):
|
93 |
gdf = gdf.to_crs(epsg=7761) # epsg for Gujarat
|
94 |
+
|
95 |
+
|
96 |
gdf["geometry"] = gdf["geometry"].apply(shape_3d_to_2d)
|
97 |
return gdf
|
98 |
|
|
|
233 |
nov_15 = pd.to_datetime(f"{max_year}/11/15", format="%Y/%m/%d")
|
234 |
dec_15 = pd.to_datetime(f"{max_year}/12/15", format="%Y/%m/%d")
|
235 |
input_daterange = st.date_input("Date Range (Ignore year. App will compute indices for all possible years)", (nov_15, dec_15), jan_1, dec_31)
|
236 |
+
min_year = int(st.number_input("Minimum Year", value=2019, min_value=2015, step=1))
|
237 |
+
max_year = int(st.number_input("Maximum Year", value=max_year, min_value=2015, step=1))
|
238 |
|
239 |
# Input: GeoJSON/KML file
|
240 |
file_url = st.query_params.get("file_url", None)
|
|
|
253 |
input_geometry_idx = st.selectbox("Select the geometry", input_gdf.index, format_func=format_fn)
|
254 |
geometry_gdf = input_gdf[input_gdf.index == input_geometry_idx]
|
255 |
buffer_geometry_gdf = geometry_gdf.copy()
|
256 |
+
buffer_geometry_gdf["geometry"] = buffer_geometry_gdf["geometry"].buffer(buffer).difference(geometry_gdf.geometry.unary_union)
|
257 |
check_valid_geometry(geometry_gdf)
|
258 |
|
259 |
# Derived Inputs
|
260 |
ee_geometry = ee.Geometry(geometry_gdf.to_crs(4326).geometry.item().__geo_interface__)
|
261 |
ee_feature_collection = ee.FeatureCollection(ee_geometry)
|
262 |
buffer_ee_geometry = ee.Geometry(buffer_geometry_gdf.to_crs(4326).geometry.item().__geo_interface__)
|
263 |
+
buffer_ee_geometry = buffer_ee_geometry.difference(ee_geometry)
|
264 |
buffer_ee_feature_collection = ee.FeatureCollection(buffer_ee_geometry)
|
265 |
|
266 |
# visualize the geometry
|
|
|
368 |
with cols[1]:
|
369 |
year_2 = st.selectbox("Year 2", result_df.index, index=len(result_df.index) - 1, format_func=lambda x: daterange_str_to_year(x))
|
370 |
|
371 |
+
vis_params = {'min': 0, 'max': 1, 'palette': ['white', 'green']} # Example visualisation for Sentinel-2
|
372 |
|
373 |
# Create a colormap and name it as NDVI
|
374 |
colormap = cm.LinearColormap(
|