update app.py
Browse files
app.py
CHANGED
@@ -442,42 +442,45 @@ def aggregate_data_weekly(collection):
|
|
442 |
|
443 |
return ee.ImageCollection(weekly_images)
|
444 |
|
445 |
-
|
446 |
-
# # Extract month and year from the image date
|
447 |
-
# collection = collection.map(lambda image: image.set('month', ee.Date(image.get('system:time_start')).format('YYYY-MM')))
|
448 |
-
|
449 |
-
# # Group images by month
|
450 |
-
# grouped_by_month = collection.aggregate_array('month').distinct()
|
451 |
-
|
452 |
-
# def calculate_monthly_mean(month):
|
453 |
-
# monthly_collection = collection.filter(ee.Filter.eq('month', month))
|
454 |
-
# monthly_mean = monthly_collection.mean()
|
455 |
-
# return monthly_mean.set('month', month)
|
456 |
-
|
457 |
-
# # Calculate the monthly mean for each month
|
458 |
-
# monthly_images = ee.List(grouped_by_month.map(calculate_monthly_mean))
|
459 |
-
|
460 |
-
# return ee.ImageCollection(monthly_images)
|
461 |
-
|
462 |
-
def aggregate_data_for_date_range(collection, start_date, end_date):
|
463 |
# Filter the collection for the specific date range
|
464 |
-
|
465 |
|
466 |
# Extract month and year from the image date
|
467 |
-
|
468 |
|
469 |
# Group images by month
|
470 |
-
grouped_by_month =
|
471 |
|
472 |
def calculate_monthly_mean(month):
|
473 |
-
monthly_collection =
|
474 |
monthly_mean = monthly_collection.mean()
|
475 |
return monthly_mean.set('month', month)
|
476 |
|
477 |
# Calculate the monthly mean for each month
|
478 |
monthly_images = ee.List(grouped_by_month.map(calculate_monthly_mean))
|
479 |
|
480 |
-
return monthly_images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
|
482 |
def aggregate_data_yearly(collection):
|
483 |
# Extract year from the image date
|
|
|
442 |
|
443 |
return ee.ImageCollection(weekly_images)
|
444 |
|
445 |
+
def aggregate_data_monthly(collection, start_date, end_date):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
# Filter the collection for the specific date range
|
447 |
+
collection = collection.filterDate(start_date, end_date)
|
448 |
|
449 |
# Extract month and year from the image date
|
450 |
+
collection = collection.map(lambda image: image.set('month', ee.Date(image.get('system:time_start')).format('YYYY-MM')))
|
451 |
|
452 |
# Group images by month
|
453 |
+
grouped_by_month = collection.aggregate_array('month').distinct()
|
454 |
|
455 |
def calculate_monthly_mean(month):
|
456 |
+
monthly_collection = collection.filter(ee.Filter.eq('month', month))
|
457 |
monthly_mean = monthly_collection.mean()
|
458 |
return monthly_mean.set('month', month)
|
459 |
|
460 |
# Calculate the monthly mean for each month
|
461 |
monthly_images = ee.List(grouped_by_month.map(calculate_monthly_mean))
|
462 |
|
463 |
+
return ee.ImageCollection(monthly_images)
|
464 |
+
|
465 |
+
# def aggregate_data_for_date_range(collection, start_date, end_date):
|
466 |
+
# # Filter the collection for the specific date range
|
467 |
+
# filtered_collection = collection.filterDate(start_date, end_date)
|
468 |
+
|
469 |
+
# # Extract month and year from the image date
|
470 |
+
# filtered_collection = filtered_collection.map(lambda image: image.set('month', ee.Date(image.get('system:time_start')).format('YYYY-MM')))
|
471 |
+
|
472 |
+
# # Group images by month
|
473 |
+
# grouped_by_month = filtered_collection.aggregate_array('month').distinct()
|
474 |
+
|
475 |
+
# def calculate_monthly_mean(month):
|
476 |
+
# monthly_collection = filtered_collection.filter(ee.Filter.eq('month', month))
|
477 |
+
# monthly_mean = monthly_collection.mean()
|
478 |
+
# return monthly_mean.set('month', month)
|
479 |
+
|
480 |
+
# # Calculate the monthly mean for each month
|
481 |
+
# monthly_images = ee.List(grouped_by_month.map(calculate_monthly_mean))
|
482 |
+
|
483 |
+
# return monthly_images
|
484 |
|
485 |
def aggregate_data_yearly(collection):
|
486 |
# Extract year from the image date
|