Spaces:
Runtime error
Runtime error
downloading data starting from 1/1/2024 in a new thread
Browse files- pag/monitor.py +34 -6
pag/monitor.py
CHANGED
|
@@ -11,6 +11,7 @@ import requests
|
|
| 11 |
import process
|
| 12 |
from zipfile import ZipFile
|
| 13 |
import plotly.express as px
|
|
|
|
| 14 |
|
| 15 |
def check_authentication():
|
| 16 |
if not check_password():
|
|
@@ -65,18 +66,45 @@ def get_and_cache_available_dates(_df, field, year, start_date, end_date):
|
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
-
def get_cuarted_df_for_field(df, field, date, metric, clientName):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
curated_date_path = utils.get_curated_location_img_path(clientName, metric, date, field)
|
| 70 |
if curated_date_path is not None:
|
| 71 |
curated_df = gpd.read_file(curated_date_path)
|
|
|
|
| 72 |
else:
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
curated_date_path = utils.get_curated_location_img_path(clientName, metric, date, field)
|
| 77 |
curated_df = gpd.read_file(curated_date_path)
|
| 78 |
return curated_df
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
def track(metric, field_name, src_df, client_name):
|
| 82 |
st.title(":green[Select Date and Start Monitoring]")
|
|
@@ -132,8 +160,8 @@ def track(metric, field_name, src_df, client_name):
|
|
| 132 |
# Get the field data at the selected date
|
| 133 |
with st.spinner('Loading Field Data...'):
|
| 134 |
# Get the metric data and cloud cover data for the selected field and date
|
| 135 |
-
metric_data = get_cuarted_df_for_field(src_df, field_name, date, metric, client_name)
|
| 136 |
-
cloud_cover_data = get_cuarted_df_for_field(src_df, field_name, date, 'CLP', client_name)
|
| 137 |
|
| 138 |
#Merge the metric and cloud cover data on the geometry column
|
| 139 |
field_data = metric_data.merge(cloud_cover_data, on='geometry')
|
|
|
|
| 11 |
import process
|
| 12 |
from zipfile import ZipFile
|
| 13 |
import plotly.express as px
|
| 14 |
+
import threading
|
| 15 |
|
| 16 |
def check_authentication():
|
| 17 |
if not check_password():
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
+
# def get_cuarted_df_for_field(df, field, date, metric, clientName):
|
| 70 |
+
# curated_date_path = utils.get_curated_location_img_path(clientName, metric, date, field)
|
| 71 |
+
# if curated_date_path is not None:
|
| 72 |
+
# curated_df = gpd.read_file(curated_date_path)
|
| 73 |
+
# else:
|
| 74 |
+
# process.Download_image_in_given_date(clientName, metric, df, field, date)
|
| 75 |
+
# process.mask_downladed_image(clientName, metric, df, field, date)
|
| 76 |
+
# process.convert_maske_image_to_geodataframe(clientName, metric, df, field, date, df.crs)
|
| 77 |
+
# curated_date_path = utils.get_curated_location_img_path(clientName, metric, date, field)
|
| 78 |
+
# curated_df = gpd.read_file(curated_date_path)
|
| 79 |
+
# return curated_df
|
| 80 |
+
|
| 81 |
+
def get_cuarted_df_for_field(df, field, date, metric, clientName, dates):
|
| 82 |
curated_date_path = utils.get_curated_location_img_path(clientName, metric, date, field)
|
| 83 |
if curated_date_path is not None:
|
| 84 |
curated_df = gpd.read_file(curated_date_path)
|
| 85 |
+
|
| 86 |
else:
|
| 87 |
+
download_date_date(df, field, [date], metric, clientName,)
|
| 88 |
+
curated_date_path = utils.get_curated_location_img_path(clientName, metric, date, field)
|
| 89 |
+
print("curr selected date processed")
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
dates.remove(date)
|
| 93 |
+
download_thread = threading.Thread(target=download_date_date, name="Downloader", args=(df, field, dates, metric, clientName))
|
| 94 |
+
download_thread.start()
|
| 95 |
+
|
| 96 |
curated_date_path = utils.get_curated_location_img_path(clientName, metric, date, field)
|
| 97 |
curated_df = gpd.read_file(curated_date_path)
|
| 98 |
return curated_df
|
| 99 |
|
| 100 |
+
def download_date_date(df, field, dates, metric, clientName,):
|
| 101 |
+
for date in dates:
|
| 102 |
+
process.Download_image_in_given_date(clientName, metric, df, field, date)
|
| 103 |
+
process.mask_downladed_image(clientName, metric, df, field, date)
|
| 104 |
+
process.convert_maske_image_to_geodataframe(clientName, metric, df, field, date, df.crs)
|
| 105 |
+
print(f"finished downloading prev dates data")
|
| 106 |
+
return
|
| 107 |
+
|
| 108 |
|
| 109 |
def track(metric, field_name, src_df, client_name):
|
| 110 |
st.title(":green[Select Date and Start Monitoring]")
|
|
|
|
| 160 |
# Get the field data at the selected date
|
| 161 |
with st.spinner('Loading Field Data...'):
|
| 162 |
# Get the metric data and cloud cover data for the selected field and date
|
| 163 |
+
metric_data = get_cuarted_df_for_field(src_df, field_name, date, metric, client_name, dates)
|
| 164 |
+
cloud_cover_data = get_cuarted_df_for_field(src_df, field_name, date, 'CLP', client_name, dates)
|
| 165 |
|
| 166 |
#Merge the metric and cloud cover data on the geometry column
|
| 167 |
field_data = metric_data.merge(cloud_cover_data, on='geometry')
|