I’m new to python and I’d like some advice on my question.
My aim is to group the images by tile, then, depending on the date and the band number, to do a temporal resampling by band (between individual bands) every two months.
In fact, I’m working on time series of satellite images, i.e. a total of 1836 images or dates. The images are named as follows, for example ( T29PQN_20220507T103631_B01_20m_masked.tif, T29PRP_20220607T103631_B12_20m_masked.tif).
T29PQN: corresponds to the tile numbers, geographical footprints (in total there are T29PPP’, ‘T29PPQ’, ‘T29PQN’, ‘T29PQP’, ‘T29PQQ’, ‘T29PRP’, ‘T29PRQ’).
20220507T103631 = This is the date.
B01 = Band number (there are 12 bands per date). Here’s the code I’m writing:
# list initialization
list_T29PPP = []
list_T29PPQ = []
list_T29PQN = []
list_T29PQP = []
list_T29PQQ = []
list_T29PRP = []
list_T29PRQ = []
list_test = []
# list of tile names
liste_tile = ['T29PPP', 'T29PPQ', 'T29PQN', 'T29PQP', 'T29PQQ', 'T29PRP', 'T29PRQ']
for msk_list in im_msk:
tile_name = msk_list.split('/')[7][0:6] # T29PPP
date_month = msk_list.split('_')[8][4:6] # 05
band_name = msk_list.split('_')[9][:] # B01
msk_file = glob.glob(f"{path_dir}S2A_MSIL2A_*/*{tile_name}*{date_month}*{band_name}*_masked.tif")
print(msk_file)
if tile_name == liste_tile[0]:
if len(msk_file) > 0:
list_T29PPP.append(msk_list)
if tile_name == liste_tile[1]:
if len(msk_file) > 0:
list_T29PPQ.append(msk_list)
if tile_name == liste_tile[2]:
if len(msk_file) > 0:
list_T29PQN.append(msk_list)
if tile_name == liste_tile[3]:
if len(msk_file) > 0:
list_T29PQP.append(msk_list)
if tile_name == liste_tile[4]:
if len(msk_file) > 0:
list_T29PQQ.append(msk_list)
if tile_name == liste_tile[5]:
if len(msk_file) > 0:
list_T29PRP.append(msk_list)
if tile_name == liste_tile[6]:
if len(msk_file) > 0:
list_T29PRQ.append(msk_list)
elif len(msk_file) == 0:
list_test.append(msk_list)
else:
print('No file found')
# Next step:
``
# 1. aggregate for each tile name temporal resampling with 2 months
# 2. Next steps coumpute mean for resampled images
Thanks in advance!