From 2f9e69d0f3d45251f5d17ef03e0b6a3c334933d2 Mon Sep 17 00:00:00 2001 From: kgao <kenny.gao@ssec.wisc.edu> Date: Fri, 29 Jul 2016 21:44:35 +0000 Subject: [PATCH] added functionality without -s and -e flag Without -s and -e, it converts each file into a new netcdf file if -o is used, it converts it itno those output filenames otherwise, it uses first stamp to name the files Uh, doesn't do anything about empty .ascii files yet Will have to ask about that --- aosstower/level_a0/nc.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/aosstower/level_a0/nc.py b/aosstower/level_a0/nc.py index 4634288..c412df5 100644 --- a/aosstower/level_a0/nc.py +++ b/aosstower/level_a0/nc.py @@ -188,7 +188,8 @@ def createGiantNetCDF(start, end, inputFiles, outputName, zlib, chunkSize): frame = getData(inputFiles) - frame = frame[start.strftime('%Y-%m-%d %H:%M:%S'): end.strftime('%Y-%m-%d %H:%M:%S')] + if(start and end): + frame = frame[start.strftime('%Y-%m-%d %H:%M:%S'): end.strftime('%Y-%m-%d %H:%M:%S')] firstStamp = dt.strptime(str(list(frame.index)[0]), '%Y-%m-%d %H:%M:%S') @@ -204,6 +205,18 @@ def createGiantNetCDF(start, end, inputFiles, outputName, zlib, chunkSize): ncFile = writeVars(ncFile, frame) ncFile.close() + +def createMultiple(filenames, outputFilenames, zlib, chunkSize): + if(outputFilenames and len(filenames) != len(outputFilenames)): + print('USAGE: number of output filenames must equal number of input filenames when start and end times are not specified') + exit(0) + + for idx, filename in enumerate(filenames): + if(outputFilenames): + createGiantNetCDF(None, None, [filename], outputFilenames[idx], zlib, chunkSize) + + else: + createGiantNetCDF(None, None, [filename], None, zlib, chunkSize) #The purpose of this method is to take a string in the format # YYYY-mm-ddTHH:MM:SS and convert that to a datetime object @@ -235,7 +248,7 @@ def main(): parser.add_argument("input_files", nargs="+", help="aoss_tower level_00 paths") - parser.add_argument('-o', '--output', help="filename pattern or filename. " + + parser.add_argument('-o', '--output', nargs="+", help="filename pattern or filename. " + "Should be along the lines of <filepath>/aoss_tower.YYYY-MM-DD.nc") args = parser.parse_args() @@ -247,6 +260,6 @@ def main(): createGiantNetCDF(args.start_time, args.end_time, args.input_files, args.output, args.zlib, args.chunk_size) else: - createNetCDF(args.input_files, args.ouput) + createMultiple(args.input_files, args.output, args.zlib, args.chunk_size) if __name__ == "__main__": main() -- GitLab