#!/usr/bin/env python

import numpy as np
import calendar
import os
import glob
import re

command = ("gfortran ModisCaliopCollocatedPixels.f90"
           " -I/hdf-4.2.4-snap4/hdf4/include -L/hdf-4.2.4-snap4/hdf4/lib"
           " -lmfhdf -ldf -ljpeg -lz"
           " -o ModisCaliopCollocatedPixels")

os.system(command)

year = 2008
month = 1

path_to_myd03 = '/Volumes/Data/Myd03/'
path_to_01km_clay = '/Volumes/Data/Caliop/01km_CLay/'
path_to_results = '/Users/marchant/Desktop/CollocatedModisCaliopPixels_db/'

caliop_re = re.compile("T(.*)-(.*)-(.*).hdf")

for day in np.arange(calendar.monthrange(int(year),int(month))[1]):
#for i in range(8,calendar.monthrange(int(year),int(month))[1],1):

	d = str(year) + '/' + str(year) + '_' + "%02d" % month + '_' + "%02d" % (day+1) + '/'

	path_to_myd03_day = path_to_myd03 + d
	path_to_01km_clay_day = path_to_01km_clay + d
	
	list_of_myd03_files = glob.glob(path_to_myd03_day + '/*hdf' )
	list_of_01km_clay_files = glob.glob(path_to_01km_clay_day + '/*hdf' )

	for modis_granule_name in list_of_myd03_files:

			#offset = len(path_to_myd03_day)
			#modis_granule_hour = int( modis_granule_name[offset+15:offset+17] )
			#modis_granule_minute = int( modis_granule_name[offset+17:offset+19] )

			hm = modis_granule_name.split('.')[2]

			modis_granule_hour = int(hm[0:2])
			modis_granule_minute = int(hm[2:4])
						
			#-----find caliop files -----#
			minimum = 1000
			find_one = 0
			for caliop_granule_name in list_of_01km_clay_files:
					
				#offset = len(path_to_01km_clay_day)
				#caliop_granule_hour = int(caliop_granule_name[offset+47:offset+49])
				#caliop_granule_minute = int(caliop_granule_name[offset+50:offset+52])
				#print caliop_granule_hour, caliop_granule_minute
			
				obj = caliop_re.search(caliop_granule_name)
			
				caliop_granule_hour = int(obj.group(1))
				caliop_granule_minute = int(obj.group(2))
							
				difference = modis_granule_hour * 60 + modis_granule_minute - \
				            (caliop_granule_hour * 60 + caliop_granule_minute)
		
				if (difference < minimum ) and ( difference > 0 ):
						minimum = difference
						tmp_02 = caliop_granule_name
						find_one = 1

				print modis_granule_name
				print modis_granule_hour, modis_granule_minute
				print caliop_granule_name
				print caliop_granule_hour, caliop_granule_minute

			#----- create collocated caliop-modis pixel file -----#
			
			if ( find_one == 1 ):
					command = 'ModisCaliopCollocatedPixels' + ' ' + \
					           tmp_02 + ' ' + modis_granule_name
					os.system(command)
					command = 'mv calmod_index_' + "%02d" % modis_granule_hour + \
					          "%02d" % modis_granule_minute + ' ' + path_to_results + d
					os.system(command)

			print 'MODIS granule done !'
			print '--------------------'
	print 'Day ' + str(day+1) + ' done'

About / Au sujet de

Ben
Created:
24 avril 2017 20:09:55

Updated:
24 avril 2017 20:09:55

License / Licence

MIT License

Abstract / Résumé