-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathread_mod_aerosol_and_list_sds.py
63 lines (52 loc) · 2.17 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.Originally Developed by: Justin Roberts-Pierel & Pawan Gupta, 2015 Organization: NASA ARSETTested on Python Version: 3.7Purpose: To print all SDS from an HDF4 fileSee the README associated with this module for more information.=========================================================================================='''from pyhdf import SDimport sys#import numpy as np# =============================================================================# Inputs#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)) #asks if the user would like to continue to the next file, exits if notprint('\nAll valid files given have been processed')2