From 50c0d42448ea3fa689306556da43809c402c741c Mon Sep 17 00:00:00 2001 From: kgao <kenny.gao@ssec.wisc.edu> Date: Thu, 11 Aug 2016 15:12:18 +0000 Subject: [PATCH] Added -s functionality If -s is specified alone, script creates file from -s to end of the day argparse now allows format YYYY-MM-DD --- aosstower/level_a0/nc.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/aosstower/level_a0/nc.py b/aosstower/level_a0/nc.py index 774f29b..91e7522 100644 --- a/aosstower/level_a0/nc.py +++ b/aosstower/level_a0/nc.py @@ -266,7 +266,10 @@ def createMultiple(filenames, outputFilenames, zlib, chunkSize): def _dt_convert(datetime_str): #parse datetime string, return datetime object - return dt.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S') + try: + return dt.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S') + except: + return dt.strptime(datetime_str, '%Y-%m-%d') def main(): import argparse @@ -280,8 +283,11 @@ def main(): help='each occurrence increases verbosity 1 level through ERROR-WARNING-INFO-DEBUG (default INFO)') #argparse start and end times - parser.add_argument('-s', '--start-time', type=_dt_convert, help="Start time of massive netcdf file") - parser.add_argument('-e', '--end-time', type=_dt_convert, help='End time of massive netcdf file') + parser.add_argument('-s', '--start-time', type=_dt_convert, + help="Start time of massive netcdf file, if only -s is given, a netcdf file for only that day is given" + + ". Formats allowed: \'YYYY-MM-DDTHH:MM:SS\', \'YYYY-MM-DD\'") + parser.add_argument('-e', '--end-time', type=_dt_convert, help='End time of massive netcdf file. Formats allowed:' + + "\'YYYY-MM-DDTHH:MM:SS\', \'YYYY-MM-DD\'") parser.add_argument('-cs', '--chunk-size', type=int, help='chunk Size for the netCDF file') parser.add_argument('-z', '--zlib', action='store_true', help='compress netCDF file with zlib') @@ -302,8 +308,14 @@ def main(): if(result == False): raise IOError('An empty ASCII file was found') - elif(args.start_time or args.end_time): - print('USAGE: start time and end time must both be specified or not specified') + elif(args.start_time): + end_time = args.start_time.replace(hour=23, minute=59, second=59) + result = createGiantNetCDF(args.start_time, end_time, args.input_files, args.output[0], args.zlib, args.chunk_size) + if(result == False): + raise IOError('An empty ASCII file was found') + + elif(args.end_time): + print('USAGE: start time must be specified when end time is specified') else: createMultiple(args.input_files, args.output, args.zlib, args.chunk_size) -- GitLab