Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
fixed CLI and also made fix to date of nc output file, used datetime.…
Browse files Browse the repository at this point in the history
…now() in filename, now uses end_date. prevents issues in onhm which is run on a UTC clock and MST or CST straddles UTC midnight so this creates issues
  • Loading branch information
rmcd-mscb committed Feb 18, 2021
1 parent 64b30c8 commit 454971e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 3 additions & 2 deletions gridmetetl/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(self, climsource='GridMetSS'):
def write_extract_file(self, ivar, incfile, url, params):
file = requests.get(url, params=params)
file.raise_for_status()
tfile = self.iptpath / (self.fileprefix + ivar + (datetime.now().strftime('%Y_%m_%d')) + '.nc')
tfile = self.iptpath / (self.fileprefix + ivar + (self.end_date.strftime('%Y_%m_%d')) + '.nc')
incfile.append(tfile)
with open(tfile, 'wb') as fh:
fh.write(file.content)
Expand Down Expand Up @@ -185,6 +185,7 @@ def initialize(self, partial, ivars, iptpath, optpath, weights_file, etype=None,
self.numdays = days
self.start_date = start_date
self.end_date = end_date
print(self.end_date, type(self.end_date))
self.fileprefix = fileprefix

print(Path.cwd())
Expand Down Expand Up @@ -429,7 +430,7 @@ def finalize(self):
print(Path.cwd(), flush=True)

ncfile = Dataset(
self.optpath / (self.fileprefix + 'climate_' + str(datetime.now().strftime('%Y_%m_%d')) + '.nc'),
self.optpath / (self.fileprefix + 'climate_' + str(self.end_date.strftime('%Y_%m_%d')) + '.nc'),
mode='w', format='NETCDF4_CLASSIC')

def getxy(pt):
Expand Down
15 changes: 6 additions & 9 deletions gridmetetl/gridmet_etl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Console script for gridmetetl."""
from etl import FpoNHM
from .etl import FpoNHM
import argparse
import sys
import datetime
Expand Down Expand Up @@ -109,10 +109,10 @@ def get_file_prefix(args):
else:
return ''

def main(parser, args):
def main():
"""Console script for gridmetetl."""
my_parser = parser
my_args = args
my_parser = parser()
my_args = args(my_parser)
numdays = None
startdate = None
enddate = None
Expand All @@ -128,7 +128,7 @@ def main(parser, args):
idir = my_args.inpath
odir = my_args.outpath
wght_file = my_args.weightsfile
file_prefix = get_file_prefix(args)
file_prefix = get_file_prefix(my_args)
gm_vars = my_args.variables
partial = my_args.partial
print('starting Script', flush=True)
Expand Down Expand Up @@ -170,7 +170,4 @@ def main(parser, args):


if __name__ == "__main__":
parser = parser()
args = args(parser)

main(parser, args)
sys.exit(main())

0 comments on commit 454971e

Please sign in to comment.