-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_finish_timefile
executable file
·59 lines (47 loc) · 1.85 KB
/
create_finish_timefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import netCDF4 as nc
import sys
from argparse import ArgumentParser
def copy_atts(infile, outfile, varname, target=None):
if not target:
target=varname
var = infile.variables[varname]
atts = {x: var.getncattr(x) for x in var.ncattrs() if x not in ["_FillValue"]}
outfile.variables[target].setncatts(atts)
def create_finish_timefile(startfile, endfile, outputfile):
sf=nc.Dataset(startfile, 'r')
ef=nc.Dataset(endfile, 'r')
of=nc.Dataset(outputfile, 'w')
of.createDimension('time', None)
of.createDimension('nb2',2)
ot=of.createVariable('time',sf.variables['time'].dtype, ('time',))
otb=of.createVariable('time_bnds',sf.variables['time'].dtype, ('time','nb2'))
ot[0] = 0.5*(sf.variables['time'][0] + ef.variables['time'][0])
otb[0,0] = sf.variables['time'][0]
otb[0,1] = ef.variables['time'][0]
copy_atts(sf, of, 'time')
copy_atts(sf, of, 'time', 'time_bnds')
of.variables['time_bnds'].standard_name='time_bounds'
of.close()
def parse_args():
parser = ArgumentParser()
parser.description = "Scatterplot two variables from a set of files"
parser.add_argument("FILES", nargs='*')
parser.add_argument("-v", "--verbose",
help='''Be verbose''', action="store_true")
parser.add_argument("-s", "--start",
help='''backup file for start of run''', required=True)
parser.add_argument("-e", "--end",
help='''File with enddate''',required=True)
parser.add_argument("-o", "--output",
help='''output file to save to''', required=True)
options = parser.parse_args()
return options
def main(argv):
options = parse_args()
if options.verbose:
fu.debug = True
fu.debug_cerr(dir(options))
create_finish_timefile(options.start, options.end, options.output)
if __name__ == "__main__":
main(sys.argv)