Skip to content

Commit 2bda06c

Browse files
convert process_ccfb_gate_height to click (UNUSED in main cli or pyproject.toml scripts)
1 parent 31bae41 commit 2bda06c

1 file changed

Lines changed: 18 additions & 40 deletions

File tree

dms_datastore/processed/process_ccfb_gate_height.py

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime as dtm
33
import os
44
import numpy as np
5+
import click
56
import vtools.functions.unit_conversions as units
67
import matplotlib.pylab as plt
78
from dms_datastore.read_ts import *
@@ -238,43 +239,9 @@ def heights_inverted_hourly(hills_csv):
238239
#################
239240

240241

241-
242-
243-
244-
def create_arg_parser():
245-
# Argument parsing not really ready yet
246-
import argparse
247-
parser = argparse.ArgumentParser(
248-
description='Convert a csv file with date and five CCFB heights to *.th file.')
249-
parser.add_argument('--infile', type=str,
250-
help='name of the input csv file containing CCFB heights from wonderware')
251-
parser.add_argument('--basefile',type=str,default=None,
252-
help='name of prior file to append')
253-
parser.add_argument('--transition',type=lambda x: pd.to_datetime(x),default=None,
254-
help='Date of transition. This is first day to start using the new data. Default is to truncate the last day of the base file to midnight so any improvements in that file are retained')
255-
parser.add_argument('--appendfile',type=str,default=None,
256-
help='name of prediction file to append')
257-
parser.add_argument('--append_transition',type=lambda x: pd.to_datetime(x),
258-
default=None,
259-
help='Date of transition to secondary file for predictions. This is the first time to use the prediction data. Default is to use the last moment of the new data')
260-
parser.add_argument('--outfile', type=str,default="",
261-
help='name of output *.th file')
262-
parser.add_argument('--preprocess', type=bool,default=True,
263-
help='preprocess Wonderware file for time zone and sparsity, default true')
264-
parser.add_argument('--prepro_out',type=str,help="name of intermediate output file for preprocessor",default="ccf_prepro.csv")
265-
return parser
266-
267-
def main():
268-
parser = create_arg_parser()
269-
args = parser.parse_args()
270-
infile=args.infile
271-
thfile = args.outfile
272-
preprocess = args.preprocess
273-
intermediate = args.prepro_out
274-
basefile = args.basefile
275-
transition = args.transition
276-
appendfile = args.appendfile
277-
append_transition = args.append_transition
242+
def process_ccfb_gate(infile, outfile, preprocess, prepro_out, basefile, transition, appendfile, append_transition):
243+
thfile = outfile
244+
intermediate = prepro_out
278245
# Check that prepend and append files exist
279246
if basefile == thfile:
280247
raise ValueError("basefile and outfile must be different")
@@ -339,11 +306,22 @@ def main():
339306
print(height_ts.last_valid_index())
340307
write_ccf_th(thfile,height_ts)
341308

342-
309+
@click.command()
310+
@click.option('--infile', type=str, help='name of the input csv file containing CCFB heights from wonderware')
311+
@click.option('--basefile', type=str, default=None, help='name of prior file to append')
312+
@click.option('--transition', type=click.DateTime(), default=None, help='Date of transition. This is first day to start using the new data. Default is to truncate the last day of the base file to midnight so any improvements in that file are retained')
313+
@click.option('--appendfile', type=str, default=None, help='name of prediction file to append')
314+
@click.option('--append-transition', 'append_transition', type=click.DateTime(), default=None, help='Date of transition to secondary file for predictions. This is the first time to use the prediction data. Default is to use the last moment of the new data')
315+
@click.option('--outfile', type=str, default='', help='name of output *.th file')
316+
@click.option('--preprocess', type=bool, default=True, help='preprocess Wonderware file for time zone and sparsity, default true')
317+
@click.option('--prepro-out', 'prepro_out', type=str, default='ccf_prepro.csv', help='name of intermediate output file for preprocessor')
318+
def process_ccfb_gate_cli(infile, outfile, preprocess, prepro_out, basefile, transition, appendfile, append_transition):
319+
""" CLI to preprocess CCF data to dated SCHISM format
320+
"""
321+
process_ccfb_gate(infile, outfile, preprocess, prepro_out, basefile, transition, appendfile, append_transition)
343322

344-
345323
if __name__=="__main__":
346-
main()
324+
process_ccfb_gate_cli()
347325
#dfa = pd.read_csv("ccfb_gate_20241106.th",sep="\s+",index_col=0,parse_dates=[0],header=0)
348326
#dfb = pd.read_csv("d:/Delta/BayDeltaSCHISM/data/time_history/ccfb_gate.th",sep="\s+",index_col=0,parse_dates=[0],header=0)
349327
#fig,ax = plt.subplots(1)

0 commit comments

Comments
 (0)