@@ -24,7 +24,7 @@ def track_task_progress(task):
2424 print ("Download Completed!" )
2525
2626# Define a function to download the satellite data from Google Earth Engine
27- def get_landsat_images (Satellite , row , path , point_coordinates , boundary_coordinates , collection_id , start_data , end_date ):
27+ def get_landsat_images (dataFolder , Satellite , row , path , point_coordinates , boundary_coordinates , collection_id , start_data , end_date ):
2828 # Import the Landsat 8 TOA image collection
2929 point = ee .Geometry .Point (point_coordinates )
3030 boundary = ee .Geometry .Rectangle (boundary_coordinates )
@@ -52,17 +52,22 @@ def clip_image_to_geometry(image):
5252
5353 slno = l8images_clip .toList (l8images_clip .size ())
5454 count = 1
55- for i in range (2 ): # range(num_images)
55+ for i in range (num_images ): # range(num_images)
5656 print (count )
5757 selected_image = ee .Image (slno .get (i ))
5858
5959 #Change the bands as per Landsat collection [Example: B3 = Green, B5 = NIR is for Landsat8]
6060 if Satellite == 'L8' :
6161 ndwi = selected_image .normalizedDifference (['B3' , 'B5' ])
62- if (Satellite == 'L7' or Satellite == 'L5' ):
62+ #Thermal = selected_image.select('B10')
63+ if (Satellite == 'L5' ):
6364 ndwi = selected_image .normalizedDifference (['B2' , 'B4' ])
65+ #Thermal = selected_image.select('B6')
66+ if (Satellite == 'L7' ):
67+ ndwi = selected_image .normalizedDifference (['B2' , 'B4' ])
68+ #Thermal = selected_image.select('B6_VCID_1')
6469
65- BQA = selected_image .select ('QA_PIXEL' )
70+ BQA = selected_image .select ('QA_PIXEL' )
6671
6772 # Get the date of acquisition
6873 acquisition_date = selected_image .date ()
@@ -79,7 +84,7 @@ def clip_image_to_geometry(image):
7984 # Define the export parameters for a cloud-optimized GeoTIFF
8085 export_params1 = {
8186 'image' : ndwi ,
82- 'folder' : 'LandsatData' , # Optional: Specify a folder in your Google Drive to save the exported image
87+ 'folder' : dataFolder , # Optional: Specify a folder in your Google Drive to save the exported image
8388 'scale' : 30 , # Optional: Specify the scale/resolution of the exported image in meters
8489 'description' : collection_id [8 :12 ] + '_NDWI_' + date_string .getInfo (),
8590 'crs' : projection ['crs' ],
@@ -98,7 +103,7 @@ def clip_image_to_geometry(image):
98103 # Define the export parameters for a cloud-optimized GeoTIFF
99104 export_params2 = {
100105 'image' : BQA ,
101- 'folder' : 'LandsatData' , # Optional: Specify a folder in your Google Drive to save the exported image
106+ 'folder' : dataFolder , # Optional: Specify a folder in your Google Drive to save the exported image
102107 'scale' : 30 , # Optional: Spatial Resolution
103108 'description' : collection_id [8 :12 ] + '_BQA_' + date_string .getInfo (),
104109 'crs' : projection ['crs' ],
@@ -118,64 +123,74 @@ def clip_image_to_geometry(image):
118123################################### End of Function Definition #######################################
119124
120125
121-
122126if __name__ == "__main__" :
123127
124128 # Set to the current working directory
125129 parent_directory = "H:/My Drive/NUSproject/ReservoirExtraction/Reservoirs/"
126130 os .chdir (parent_directory )
127131 # Name of the reservoir
128- res_name = "Juzishan "
132+ res_name = "NamOu2 "
129133 os .makedirs (res_name , exist_ok = True )
130134 os .chdir (parent_directory + res_name )
131135 # Create a new folder within the working directory to download the data
132- os .makedirs ("LandsatData" , exist_ok = True )
136+ dataFolder = res_name + '_LandsatData'
137+ os .makedirs (dataFolder , exist_ok = True )
138+ print (res_name )
133139
134140 #====================================>> USER INPUT PARAMETERS (Landsat-8 Image Specifications)
135- row = 43
136- path = 131
141+ row = 46
142+ path = 129
137143 Satellite = 'L8'
138144 # A point within the reservoir [longitude, latitude]
139- point_coordinates = [100.420 , 24.66 ]
145+ point_coordinates = [102.4510 , 20.3926 ]
140146 # Example coordinates [longitude, latitude]
141- boundary_coordinates = [100.115 , 24.79 , 100.51 , 24.61 ]
147+ boundary_coordinates = [102.435 , 20.640 , 102.688 , 20.388 ]
142148 collection_id = "LANDSAT/LC08/C02/T1_TOA"
143- start_data = '2001-01 -01'
149+ start_data = '2015-06 -01'
144150 end_date = '2022-12-31'
145- get_landsat_images (Satellite , row , path , point_coordinates , boundary_coordinates , collection_id , start_data , end_date )
151+ print ("-----Landsat-8 data download start-----" )
152+ get_landsat_images (dataFolder , Satellite , row , path , point_coordinates , boundary_coordinates , collection_id , start_data , end_date )
146153 print ("Congratulations...all Landsat-8 files have successfully downloaded!" )
154+ print (res_name )
147155
148156 #====================================>> USER INPUT PARAMETERS (Landsat-7 Image Specifications)
149157 Satellite = 'L7'
150158 collection_id = "LANDSAT/LE07/C02/T1_TOA"
151- start_data = '2005-01 -01'
159+ start_data = '2015-06 -01'
152160 end_date = '2022-12-31'
153- get_landsat_images (Satellite , row , path , point_coordinates , boundary_coordinates , collection_id , start_data , end_date )
161+ print (res_name )
162+ print ("-----Landsat-7 data download start-----" )
163+ get_landsat_images (dataFolder , Satellite , row , path , point_coordinates , boundary_coordinates , collection_id , start_data , end_date )
154164 print ("Congratulations...all Landsat-7 files have successfully downloaded!" )
165+ print (res_name )
155166
156167 #====================================>> USER INPUT PARAMETERS (Landsat-5 Image Specifications)
157168 Satellite = 'L5'
158169 collection_id = "LANDSAT/LT05/C02/T1_TOA"
159- start_data = '2001-01 -01'
170+ start_data = '2015-06 -01'
160171 end_date = '2022-12-31'
161- get_landsat_images (Satellite , row , path , point_coordinates , boundary_coordinates , collection_id , start_data , end_date )
172+ print (res_name )
173+ print ("-----Landsat-5 data download start-----" )
174+ get_landsat_images (dataFolder , Satellite , row , path , point_coordinates , boundary_coordinates , collection_id , start_data , end_date )
162175 print ("Congratulations...all Landsat-5 files have successfully downloaded!" )
176+ print (res_name )
163177
164178
165179
166180# ==== In case of emargency if you want to cancel the running tasks then execute the following
167181
168- # # Get a list of all tasks
182+ # Get a list of all tasks
169183# all_tasks = ee.data.getTaskList()
170184
171185# # Filter out the active tasks
172186# active_tasks = [task for task in all_tasks if task['state'] == 'RUNNING' or task['state'] == 'READY']
173187
174- # Loop through the list of active tasks and cancel each task
188+ # # Loop through the list of active tasks and cancel each task
175189# for task in all_tasks:
176190# task_id = task['id']
177191# ee.data.cancelTask(task_id)
178192# print(f"Cancelled task: {task_id}")
179193
180194
181195
196+
0 commit comments