I have multiple files in one folder which are called, for example: 049.h11v11.hdf, 049.h11v12.hadf, 049.h11v13.hdf, 065.h11v11.hdf, 065.h12v12.hdf, and so on. The first 3 numbers are the julian day of MODIS LAI (MOD15A2) product.
The objective is to do daily mosaics with about 3 years of modis MOD13A2 products. At this point I have a folder named "LAI", that contains the years folder, e.g 2000, and so on. Those folder contains the .hdf files I named in the last paragraph. So, the idea is that the python code can run for all folders and get all same days and do the mosaic.
So far I've though about something like this:
#Libraries import gdal from gdalconst import * import osgeo import osr import osgeo.gdal as gdal import osgeo.osr as osr import numpy as np import glob import os #Roots: RutaLai="/mnt/discoenred/jorge/scripts/MOD15_A2_mosaic/LAI/" #Create dir if not os.path.exists(RutaLai): os.mkdir(RutaLai) . . #in between this are the reprojection and the multiplication by the LAI factor for each .hdf file. . . #Here is were the mosaic code starts: for raiz, carpetas, archivos in os.walk(RutaLai, topdown=False): arreglo = carpetas diaTemporal = None diaVariable =  diaArreglo =  for carpeta in arreglo: os.chdir(RutaLai+carpeta) #carpeta is defined as as the year taken from the MOD13A2 name, i.e carpeta = x[9:13]+"/" ; were x goes inside a for x in lista2, that just take the year inside the name of the file. (it is inside the code for the LAI factor, I don't put it because its really huge. If it is really needed then I can put it) #Lai images lists lista3=glob.glob("*.hdf") lista3.sort() for archivo in lista3: dia = archivo.split(".") #Definition of temporal day (diaTemporal) variable to avoid error. if (diaTemporal == None): diaTemporal = dia if (diaTemporal == dia): diaVariable.append( dia ) else: if (diaVariable != None): diaArreglo.append( diaVariable ) diaTemporal = dia #RutaDestinoMosaico = RutaMosaic + carpeta + "mosaico_" + ".hdf" #os.system("gdal_merge.py -o "+ RutaDestinoMosaico + " -of ENVI -n 0 '"+archivo1+"' '"+archivo2+"'")
The idea is that the code go to all e.g 049 files in one folder and do the mosaic that will be saved in a folder inside the year called "mosaic".. the files should go like "mosaic_049.hdf" (for the example given above). In order to understand it better I took a screen shot of the directory:
It is important to notice that the picture (inside year "2000") contains the files that are inputs for the mosaic. For this all I'm using a Linux machine with Ubuntu.