Skip to content

Commit 919b959

Browse files
committed
Fix and standardise command-line arguments for timeseries products
1 parent bb2668f commit 919b959

5 files changed

Lines changed: 68 additions & 56 deletions

File tree

aodntools/timeseries_products/aggregated_timeseries.py

100644100755
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -414,29 +414,28 @@ def main_aggregator(files_to_agg, var_to_agg, site_code, input_dir='', output_di
414414
(var_to_agg + "-" + product_type),
415415
('END-'+ time_end_filename), 'C-' + datetime.utcnow().strftime(file_timeformat)]) + '.nc'
416416
ncout_path = os.path.join(output_dir, output_name)
417-
shutil.move(temp_outfile, os.path.join(output_dir, ncout_path))
417+
shutil.move(temp_outfile, ncout_path)
418418

419419
return ncout_path, bad_files
420420

421421

422422
if __name__ == "__main__":
423423

424-
parser = argparse.ArgumentParser(description="Aggregate ONE variable from ALL instruments from ALL deployments from ONE site")
425-
parser.add_argument('--site', dest='site_code', help='site code, like NRMMAI', required=True)
426-
parser.add_argument('--var', dest='varname', help='variable to aggregate, like TEMP', required=True)
427-
parser.add_argument('--files', dest='filenames',
428-
help='name of the file that contains the source URLs (relative to inpath, if given)',
429-
required=True)
430-
parser.add_argument('--indir', dest='input_dir', help='base path of input files', default='', required=False)
431-
parser.add_argument('--outdir', dest='output_dir', help='path where the result file will be written. Default ./',
432-
default='./', required=False)
433-
parser.add_argument('--download_url', dest='download_url', help='path to the download_url_prefix',
434-
default='', required=False)
435-
parser.add_argument('--opendap_url', dest='opendap_url', help='path to the opendap_url_prefix',
436-
default='', required=False)
424+
parser = argparse.ArgumentParser(
425+
description="Aggregate ONE variable from ALL instruments from ALL deployments from ONE site"
426+
)
427+
parser.add_argument('site_code', help='site code, like NRSMAI')
428+
parser.add_argument('varname', help='variable to aggregate, like TEMP')
429+
parser.add_argument('filenames',
430+
help='path of file listing the source URLs (relative to input_dir, if given)')
431+
parser.add_argument('-i', '--input_dir', help='base path of input files', default='')
432+
parser.add_argument('-o', '--output_dir', help='path where the result file will be written. Default ./',
433+
default='./')
434+
parser.add_argument('--download_url', help='path to the download_url_prefix', default='')
435+
parser.add_argument('--opendap_url', help='path to the opendap_url_prefix', default='')
437436
args = parser.parse_args()
438437

439-
with open(os.path.join(args.input_dir,args.filenames)) as ff:
438+
with open(args.filenames) as ff:
440439
files_to_agg = [line.rstrip() for line in ff]
441440

442441
print(main_aggregator(files_to_agg=files_to_agg, var_to_agg=args.varname, site_code=args.site_code,

aodntools/timeseries_products/gridded_timeseries.py

100644100755
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
23
import numpy as np
34
import bisect
45
import argparse
@@ -319,17 +320,24 @@ def grid_variable(input_file, VoI, depth_bins=None, max_separation=50, depth_bin
319320

320321

321322
if __name__ == "__main__":
322-
parser = argparse.ArgumentParser(description="Gridded time series: interpolate ONE variable from ALL instruments from ALL deployments from ONE site into 1hr timestamps and fixed depth bins")
323-
parser.add_argument('--var', dest='var', help='name of the variable to concatenate. Like TEMP, PSAL', default='TEMP', required=False)
324-
parser.add_argument('--file', dest='filename', help='name of the Hourly Time Series Product file that contains the data', default=None, required=False)
325-
parser.add_argument('--depth_bins', dest='depth_bins', help='list of depth where the VoI will be interpolated', default=None, nargs='+', required=False)
326-
parser.add_argument('--max_separation', dest='max_separation', help='maximum difference between instruments to allow interpolation', default=50, required=False)
327-
parser.add_argument('--depth_bins_increment', dest='depth_bins_increment', help='increment in meters for the automatic generated depth bins', default=10, required=False)
328-
parser.add_argument('--indir', dest='input_dir', help='base path of input file. Default .', default='.',
329-
required=False)
330-
parser.add_argument('--outdir', dest='output_dir', help='path where the result file will be written. Default .',
331-
default='.', required=False)
332-
parser.add_argument('--config', dest='config_file', help='JSON configuration file', default=None, required=False)
323+
parser = argparse.ArgumentParser(
324+
description="Gridded time series: interpolate ONE variable from ALL instruments from ALL deployments"
325+
" from ONE site into 1hr timestamps and fixed depth bins"
326+
)
327+
parser.add_argument('input_file',
328+
help='name of the Hourly Time Series Product file that contains the data')
329+
parser.add_argument('-v', '--var', default='TEMP',
330+
help='name of the variable to grid (default TEMP)')
331+
parser.add_argument('--depth_bins', help='list of depth where the variable will be interpolated',
332+
nargs='+', type=float)
333+
parser.add_argument('--max_separation', default=50,
334+
help='maximum difference between instruments to allow interpolation (default 50m)')
335+
parser.add_argument('--depth_bins_increment', default=10,
336+
help='increment in meters for the automatic generated depth bins (default 10)')
337+
parser.add_argument('-i', '--input_dir', help='base path of input files', default='')
338+
parser.add_argument('-o', '--output_dir', help='path where the result file will be written. Default ./',
339+
default='./')
340+
parser.add_argument('--config_file', help='JSON configuration file', default=None)
333341
args = parser.parse_args()
334342

335343
if args.config_file:
@@ -349,8 +357,6 @@ def grid_variable(input_file, VoI, depth_bins=None, max_separation=50, depth_bin
349357
input_dir = args.input_dir
350358
output_dir = args.output_dir
351359

352-
file_name = args.filename
353-
354-
print(grid_variable(input_file=file_name, VoI=VoI, depth_bins=depth_bins,
360+
print(grid_variable(input_file=args.input_file, VoI=VoI, depth_bins=depth_bins,
355361
max_separation=int(max_separation), depth_bins_increment=int(depth_bins_increment),
356362
input_dir=input_dir, output_dir=output_dir))

aodntools/timeseries_products/hourly_timeseries.py

100644100755
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -641,18 +641,25 @@ def hourly_aggregator(files_to_aggregate, site_code, qcflags, input_dir='', outp
641641

642642
if __name__ == "__main__":
643643

644-
parser = argparse.ArgumentParser(description="Concatenate ALL variables from ALL instruments from ALL deployments from ONE site at 1hr time bin")
645-
parser.add_argument('-site', dest='site_code', help='site code, like NRMMAI', required=True)
646-
parser.add_argument('-files', dest='filenames', help='name of the file that contains the source URLs', required=True)
647-
parser.add_argument('-qc', dest='qcflags', help='list of QC flags to select variable values to keep', nargs='+', required=True)
648-
parser.add_argument('-indir', dest='input_dir', help='base path of input files', default='', required=False)
649-
parser.add_argument('-outdir', dest='output_dir', help='path where the result file will be written. Default ./',
650-
default='./', required=False)
644+
parser = argparse.ArgumentParser(
645+
description="Concatenate ALL variables from ALL instruments from ALL deployments from ONE site at 1hr time bin"
646+
)
647+
parser.add_argument('site_code', help='site code, like NRSMAI')
648+
parser.add_argument('filenames',
649+
help='path of file listing the source URLs (relative to input_dir, if given)')
650+
parser.add_argument('--qcflags', default='1,2',
651+
help='QC flags to select variable values to keep (comma-separated, no spaces; default=1,2)')
652+
parser.add_argument('-i', '--input_dir', help='base path of input files', default='')
653+
parser.add_argument('-o', '--output_dir', help='path where the result file will be written. Default ./',
654+
default='./')
655+
parser.add_argument('--download_url', help='path to the download_url_prefix', default='')
656+
parser.add_argument('--opendap_url', help='path to the opendap_url_prefix', default='')
651657
args = parser.parse_args()
652658

653659
with open(args.filenames, 'r') as file:
654660
files_to_aggregate = [i.strip() for i in file.readlines()]
655-
qcflags = [int(i) for i in args.qcflags]
661+
qcflags = [int(i) for i in args.qcflags.split(',')]
656662

657663
hourly_aggregator(files_to_aggregate=files_to_aggregate, site_code=args.site_code, qcflags=qcflags,
658-
input_dir=args.input_dir, output_dir=args.output_path)
664+
input_dir=args.input_dir, output_dir=args.output_dir,
665+
download_url_prefix=args.download_url, opendap_url_prefix=args.opendap_url)

aodntools/timeseries_products/velocity_aggregated_timeseries.py

100644100755
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
23
import os
34
import sys
45
import tempfile
@@ -307,15 +308,14 @@ def velocity_aggregated(files_to_agg, site_code, input_dir='', output_dir='./',
307308
if __name__ == "__main__":
308309

309310
parser = argparse.ArgumentParser(description="Concatenate X,Y,Z velocity variables from ALL instruments from ALL deployments from ONE site")
310-
parser.add_argument('-site', dest='site_code', help='site code, like NRMMAI', required=True)
311-
parser.add_argument('-files', dest='filenames', help='name of the file that contains the source URLs', required=True)
312-
parser.add_argument('-indir', dest='input_dir', help='base path of input files', default='', required=False)
313-
parser.add_argument('-outdir', dest='output_dir', help='path where the result file will be written. Default ./',
314-
default='./', required=False)
315-
parser.add_argument('-download_url', dest='download_url', help='path to the download_url_prefix',
316-
default='', required=False)
317-
parser.add_argument('-opendap_url', dest='opendap_url', help='path to the opendap_url_prefix',
318-
default='', required=False)
311+
parser.add_argument('site_code', help='site code, like NRSMAI')
312+
parser.add_argument('filenames',
313+
help='path of file listing the source URLs (relative to input_dir, if given)')
314+
parser.add_argument('-i', '--input_dir', help='base path of input files', default='')
315+
parser.add_argument('-o', '--output_dir', help='path where the result file will be written. Default ./',
316+
default='./')
317+
parser.add_argument('--download_url', help='path to the download_url_prefix', default='')
318+
parser.add_argument('--opendap_url', help='path to the opendap_url_prefix', default='')
319319

320320
args = parser.parse_args()
321321

aodntools/timeseries_products/velocity_hourly_timeseries.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
23
import argparse
34
import json
45
import os
@@ -320,15 +321,14 @@ def velocity_hourly_aggregated(files_to_agg, site_code, input_dir='', output_dir
320321
if __name__ == "__main__":
321322

322323
parser = argparse.ArgumentParser(description="Concatenate X,Y,Z velocity variables from ALL instruments from ALL deployments from ONE site")
323-
parser.add_argument('--site', dest='site_code', help='site code, like NRMMAI', required=True)
324-
parser.add_argument('--files', dest='filenames', help='name of the file that contains the source URLs', required=True)
325-
parser.add_argument('--indir', dest='input_dir', help='base path of input files', default='', required=False)
326-
parser.add_argument('--outdir', dest='output_dir', help='path where the result file will be written. Default ./',
327-
default='./', required=False)
328-
parser.add_argument('--download_url', dest='download_url', help='path to the download_url_prefix',
329-
default='', required=False)
330-
parser.add_argument('--opendap_url', dest='opendap_url', help='path to the opendap_url_prefix',
331-
default='', required=False)
324+
parser.add_argument('site_code', help='site code, like NRSMAI')
325+
parser.add_argument('filenames',
326+
help='path of file listing the source URLs (relative to input_dir, if given)')
327+
parser.add_argument('-i', '--input_dir', help='base path of input files', default='')
328+
parser.add_argument('-o', '--output_dir', help='path where the result file will be written. Default ./',
329+
default='./')
330+
parser.add_argument('--download_url', help='path to the download_url_prefix', default='')
331+
parser.add_argument('--opendap_url', help='path to the opendap_url_prefix', default='')
332332

333333
args = parser.parse_args()
334334

0 commit comments

Comments
 (0)