def procCommands(c): global FILE_SYS global CURR_DIR global CURR_FILE global BUFFER if c == 0: getRoot() return if c == 1: #set current directory checkFileSys() dir_ = getDirectory() if(dir_ == None): print("Directory does not exist") else: CURR_DIR = dir_ return if c == 2: #Print files in current directory if(FILE_SYS == None): print("No file system has been created yet") return if(CURR_DIR != None): for f in CURR_DIR.files: print(f.name) else: print("Current directory is not set") return if c == 3: #Set current file f = getFile() if(f != None): CURR_FILE = h5py.File(f.path,"r") save(CURR_FILE) print(f.name + " has been opened and set as CURR_FILE") else: print("File does not exist") return if c == 4: #display groups if(CURR_FILE == None): print("No file has been set") else: for group in CURR_FILE: print(group) return if c == 5: #Display datasets checkFileSys() if(CURR_FILE == None): print("No file has been set") return name = input("Enter name of group to show names of datasets") d = None try: d = CURR_FILE[name] except StandardError: print("Invalid Group Name") return for data in d: print(data) return if c == 6: #Display BUFFER print("Contents of BUFFER") for thing in BUFFER: print(thing) if c == 7: #print current directory checkFileSys() if(CURR_DIR != None): CURR_DIR.print_d() else: print("Current directory not set") if c == 8: #Flush Buffer BUFFER[:] = [] if c == 9: #place files in buffer given latitudes and longetudes lat_ = input("Enter the latitude you are looking for") long_ = input("Enter the longitude longitude you are looking for") #optional date date = str(input("Enter the date as yymmdd(optional-enter 'n' otherwise)")) if(date == "n"): date = "" if(CURR_DIR == None): print("current directory has not been set") return else: FILE_OBJS = 0 FILE_NAME = 1 FILE_COORDS = 2 FILE_CO2_LEVELS = 3 FILE_TIMES = 4 nam = input("ENTER THE SOURCE (OCO2_L2 , OCO2_LITE, OCO2_L1B, GREYDATANOV): ") #find the files with the correct coords (directory , longitude, latitude, optional date) #output format will be [[file_obj], [file_names], [coords], [type_co2], [times])] #where coords are (x,y), and times are [yyyy, mm , dd , hh , mm , ss] try: if(nam == "OCO2_L2"): files = OCO2_L2.findFilesByCoords(CURR_DIR, long_, lat_,date) elif(nam == "OCO2_L1B"): files = OCO2_L1B.findFilesByCoords(CURR_DIR, long_, lat_,date) elif(nam == "OCO2_LITE"): files = OCO2_LITE.findFilesByCoords(CURR_DIR, long_, lat_,date) elif(nam == "GREYDATANOV"): files = GREY_DATA_NOV.findFilesByCoords(CURR_DIR, long_,lat_,date) #print file names print("The following files will be placed in the buffer: ") for i in range(len(files[FILE_NAME])): print(files[FILE_NAME][i]) save(files[FILE_OBJS][i]) #save(files[FILE_COORDS]) #print points that fall in the coordinate range print("Number of points that fall in the region: " + str(len(files[FILE_COORDS])) ) #write to file? ans = input("Write coords to file?") if(ans == "y"): nam = input("Enter name of file: ") saveCoordsToTextFile(nam, coordsToHamstermapFormat(files[FILE_COORDS] ,[ files[FILE_CO2_LEVELS],files[FILE_TIMES] ] ) ) else: print("Not writing coords to file....") OCO2_LITE.GriddedAvg() #write file names to file? ans = input("Write to file names that fall into the given bounding?") if(ans == "y"): nam = input("Enter name of file: ") saveToTextFile(nam,files[FILE_NAME]) else: print("Not writing file names to file...") except StandardError: print("Error with files") if c == 10: #print data set if CURR_FILE == None: print("Current file not set") return group_n = input("Enter the Group name of this file") data_n = input("Enter the data set name of this group") data_set = None try: data_set = CURR_FILE[group_n][data_n] except StandardError: print("Invalid Group Name") return for thing in data_set: print(thing) print("The following data set is " + str(len(data_set)) + str("rows long") + str(" and ") + str(len(data_set[0])) + str(" wide.")) print("By " + str(len(data_set[0][0][0])) ) if c == 11: #return files that are within a certain km^2 with long,lat at the center pass if c == 12: #Output to file pass if c == 13: #Display long average of file if CURR_FILE == None: print("Current file not set") return print("Average longitude is : " + str(OCO2_L1B.getLongAvg(CURR_FILE))) if c == 14: #display lat. average of file if CURR_FILE == None: print("Current file not set") return print("Average latitude is : " + str(OCO2_L1B.getLatAvg(CURR_FILE))) if c == 15: #run automatic script try: n = input("Enter the file name containing the coords") coords = getCoordsFromFile(n) nam = input("ENTER THE SOURCE (OCO2_L2 , OCO2_LITE, OCO2_L1B): ") #find the files with the correct coords (directory , longitude, latitude, optional date) if(nam == "OCO2_L2"): files = OCO2_L2.findRawFilesByRawCoords(CURR_DIR,coords) elif(nam == "OCO2_L1B"): files = OCO2_L1B.findRawFilesByRawCoords(CURR_DIR,coords) elif(nam == "OCO2_LITE"): files = OCO2_LITE.findRawFilesByRawCoords(CURR_DIR,coords) elif(nam == "GREYDATANOV"): files = GREY_DATA_NOV.findRawFilesByRawCoords(CURR_DIR, coords) except StandardError: print("Invalid filename or source") if c == 16:#compare current files in VFS with Ameriflux (monthly) #try: oco2_src = input("ENTER THE SOURCE (OCO2_LITE, OCO2_L2)") lat_ = input("Enter the latitude you are looking for.") long_ = input("Enter the longitude longitude you are looking for.") #optional date date = str(input("Enter the date as a string yymm(optional-enter 'n' otherwise)")) if(date == "n"): date = "" #co2_data = OCO2_LITE.findFilesByCoords(CURR_DIR, long_, lat_,date) #save current files curr_vfs = FILE_SYS curr_dir = CURR_DIR FLIE_SYS = 0 CURR_DIR = 0 #get ameriflux files... FILE_SYS and CURR_DIR are now ameriflux getRoot() CURR_DIR = FILE_SYS.root files = AMERIFLUX_L2_STD.findCO2ByDate(CURR_DIR, date) print("The following files will be placed in the buffer: ") for i in range(len(files[FILE_NAME])): print(files[FILE_NAME][i]) save(files[FILE_OBJS][i]) #save(files[FILE_COORDS]) #print points that fall in the coordinate range print("Number of points that fall in the region: " + str(len(files[FILE_COORDS])) ) #write to file? ans = input("Write coords to file?") if(ans == "y"): nam = input("Enter name of file: ") saveCoordsToTextFile(nam, coordsToHamstermapFormat(files[FILE_COORDS] ,[ files[FILE_CO2_LEVELS],files[FILE_TIMES] ] ) ) else: print("Not writing coords to file....") #OCO2_LITE.GriddedAvg() #write file names to file? ans = input("Write to file names that fall into the given bounding?") if(ans == "y"): nam = input("Enter name of file: ") saveToTextFile(nam,files[FILE_NAME]) else: print("Not writing file names to file...") #except StandardError: #print("File error") if c == EXIT: print("BYE") sys.exit(0)
def main(): #connect to data base cnx = SQL.connect(user='******', database='sciencedata', password='******') #create Ameriflux entries # Handle.getRoot() # Handle.CURR_DIR = Handle.FILE_SYS.root # files = AMERIFLUX_L2_STD.findCO2ByDate(Handle.CURR_DIR, "201412") # addData(cnx,files,"Ameriflux_TW") # print("Data Complete") # Handle.FILE_SYS = 0 # Handle.CURR_DIR = 0 #create OCO2_LITE Barrow entries # Handle.getRoot() # Handle.CURR_DIR = Handle.FILE_SYS.root # long_ = input("Enter longitude.") # lat_ = input("Enter Latitude.") # files = OCO2_LITE.findFilesByCoords(Handle.CURR_DIR, long_, lat_,"") # addData(cnx,files,"OCO2_Barrow") # print("Data Complete") # Handle.FILE_SYS = 0 # Handle.CURR_DIR = 0 #create OCO2_LITE Twitchell entries # Handle.getRoot() # Handle.CURR_DIR = Handle.FILE_SYS.root # long_ = input("Enter longitude.") # lat_ = input("Enter Latitude.") # files = OCO2_LITE.findFilesByCoords(Handle.CURR_DIR, long_, lat_,"") # addData(cnx,files,"OCO2_Twitchell") # print("Data Complete") # Handle.FILE_SYS = 0 # Handle.CURR_DIR = 0 #create OCO2_LITE Fort Peck entries # Handle.getRoot() # Handle.CURR_DIR = Handle.FILE_SYS.root # long_ = input("Enter longitude.") # lat_ = input("Enter Latitude.") # files = OCO2_LITE.findFilesByCoords(Handle.CURR_DIR, long_, lat_,"") # addData(cnx,files,"OCO2_FortPeck") # print("Data Complete") # Handle.FILE_SYS = 0 # Handle.CURR_DIR = 0 #create OCO2_LITE Fort Peck entries # Handle.getRoot() # Handle.CURR_DIR = Handle.FILE_SYS.root # long_ = input("Enter longitude.") # lat_ = input("Enter Latitude.") # files = OCO2_LITE.findFilesByCoords(Handle.CURR_DIR, long_, lat_,"") # addData(cnx,files,"OCO2_K34") # print("Data Complete") # Handle.FILE_SYS = 0 # Handle.CURR_DIR = 0 #create OCO2_World entries Handle.getRoot() Handle.CURR_DIR = Handle.FILE_SYS.root long_ = input("Enter longitude.") lat_ = input("Enter Latitude.") files = OCO2_LITE.findFilesByCoords(Handle.CURR_DIR, long_, lat_,"") print("Adding data now...") addData(cnx,files,"OCO2_World") print("Data Complete") Handle.FILE_SYS = 0 Handle.CURR_DIR = 0