Hi shouvik jha
See below a snippet which shows how you can use that list you posted to obtain the bands for your calculations:
def main():
import os
import arcpy
lst_ras = ['MOD09A1.MRTWEB.A2012001.005.sur_refl_b01.tif',
'MOD09A1.MRTWEB.A2012001.005.sur_refl_b02.tif',
'MOD09A1.MRTWEB.A2012001.005.sur_refl_b03.tif',
'MOD09A1.MRTWEB.A2012001.005.sur_refl_b04.tif',
'MOD09A1.MRTWEB.A2012001.005.sur_refl_b06.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b01.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b02.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b03.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b04.tif',
'MOD09A1.MRTWEB.A2012009.005.sur_refl_b06.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b01.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b02.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b03.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b04.tif',
'MOD09A1.MRTWEB.A2012017.005.sur_refl_b06.tif']
dct = {}
for ras_name in lst_ras:
date_id = ras_name[16:23]
if date_id in dct:
lst_bands = dct[date_id]
lst_bands.append(ras_name)
dct[date_id] = lst_bands
else:
lst_bands = [ras_name]
dct[date_id] = lst_bands
cnt = 0
for date_id, lst_bands in sorted(dct.items()):
cnt += 1
ras_num = "%03d" % (cnt,)
print ras_num, date_id, lst_bands
b01_name = getBand(lst_bands, 1)
b02_name = getBand(lst_bands, 2)
b03_name = getBand(lst_bands, 3)
b04_name = getBand(lst_bands, 4)
b06_name = getBand(lst_bands, 6)
b01 = os.path.join(ws_bands, b01_name)
b02 = os.path.join(ws_bands, b02_name)
b03 = os.path.join(ws_bands, b03_name)
b04 = os.path.join(ws_bands, b04_name)
b06 = os.path.join(ws_bands, b06_name)
if sum([[1,0][i is None] for i in [b01, b02, b03, b04, b06]]) == 5:
print "Bands found, proceed with calculations..."
pass
def getBand(lst_bands, band_number):
band_id = "b{0}.tif".format("%02d" % (band_number,))
band_found = None
for band in lst_bands:
if band.lower().endswith(band_id):
band_found = band
break
return band_found
if __name__ == '__main__':
main()
If you run the code it will print this:
001 2012001 ['MOD09A1.MRTWEB.A2012001.005.sur_refl_b01.tif', 'MOD09A1.MRTWEB.A2012001.005.sur_refl_b02.tif', 'MOD09A1.MRTWEB.A2012001.005.sur_refl_b03.tif', 'MOD09A1.MRTWEB.A2012001.005.sur_refl_b04.tif', 'MOD09A1.MRTWEB.A2012001.005.sur_refl_b06.tif']
Bands are OK, proceed with calculations
002 2012009 ['MOD09A1.MRTWEB.A2012009.005.sur_refl_b01.tif', 'MOD09A1.MRTWEB.A2012009.005.sur_refl_b02.tif', 'MOD09A1.MRTWEB.A2012009.005.sur_refl_b03.tif', 'MOD09A1.MRTWEB.A2012009.005.sur_refl_b04.tif', 'MOD09A1.MRTWEB.A2012009.005.sur_refl_b06.tif']
Bands are OK, proceed with calculations
003 2012017 ['MOD09A1.MRTWEB.A2012017.005.sur_refl_b01.tif', 'MOD09A1.MRTWEB.A2012017.005.sur_refl_b02.tif', 'MOD09A1.MRTWEB.A2012017.005.sur_refl_b03.tif', 'MOD09A1.MRTWEB.A2012017.005.sur_refl_b04.tif', 'MOD09A1.MRTWEB.A2012017.005.sur_refl_b06.tif']
Bands are OK, proceed with calculations
There is no need to convert the date in any way, you just simply perform the calculations for each "date" on the band of that date.