-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_mod_aerosol_and_list_sds.py
52 lines (47 loc) · 1.86 KB
/
read_mod_aerosol_and_list_sds.py
1
'''Module: read_mod_aerosol_and_list_sds.py==========================================================================================Disclaimer: The code is for demonstration purposes only. Users are responsible to check for accuracy and revise to fit their objective.Author: Justin Roberts-Pierel, 2015 Organization: NASA ARSETPurpose: To print all SDS from an HDF4 fileSee the README associated with this module for more information.=========================================================================================='''#import necessary modulesfrom pyhdf import SDimport numpy as np#This uses the file "fileList.txt", containing the list of files, in order to read the filestry: fileList=open('fileList.txt','r')except: print('Did not find a text file containing file names (perhaps name does not match)') sys.exit()#loops through all files listed in the text filefor FILE_NAME in fileList: FILE_NAME=FILE_NAME.strip() user_input=input('Would you like to process\n' + FILE_NAME + '\n\n(Y/N)') if(user_input == 'N' or user_input == 'n'): continue else: if '3K' in FILE_NAME: #then this is a 3km MODIS file print('\nThis is a MODIS 3km file. Here is a list of SDS in your file:\n') elif 'L2' in FILE_NAME: print('\nThis is a MODIS 10km file. Here is a list of SDS in your file:\n') else: print('The file named :',FILE_NAME, ' is not a valid MODIS file (Or is named incorrectly). \n') continue try: # open the hdf file for reading hdf=SD.SD(FILE_NAME) except: print('Unable to open file: \n' + FILE_NAME + '\n Skipping...') continue #extract the list of SDS in the hdf4 file datasets=hdf.datasets() #Print the list for i,v in enumerate(datasets): print('{0}. {1}'.format(i+1,v)) print ('') #asks if the user would like to continue to the next file, exits if notprint('\nAll valid files given have been processed')