-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextract_field_fvcom.py
More file actions
72 lines (52 loc) · 2.02 KB
/
extract_field_fvcom.py
File metadata and controls
72 lines (52 loc) · 2.02 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
from __future__ import division,print_function
import numpy as np
import scipy as sp
from mytools import *
import matplotlib as mpl
import matplotlib.pyplot as plt
import os, sys
np.set_printoptions(precision=8,suppress=True,threshold=sys.maxsize)
import pandas as pd
import matplotlib.dates as dates
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("grid", help="name of the grid", type=str)
parser.add_argument("name", help="name of the run", type=str)
parser.add_argument("ncfile", help="name of the ncfile", type=str)
parser.add_argument("-f", help="field name", type=str)
parser.add_argument("-l", help="field layer", type=int, default=None)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-t',help='timestep to use',type=int)
group.add_argument('-d',help='datestr to use',type=str)
args = parser.parse_args()
print("The current commandline arguments being used are")
print(args)
name=args.name
grid=args.grid
ncfile=args.ncfile
ncloc=ncfile.rindex('/')
### load the .nc file #####
data = loadnc(ncfile[:ncloc+1],ncfile[ncloc+1:])
print('done load')
if args.f not in data.keys():
print('{} is not a valid field'.format(args.f))
sys.exit()
savepath='{}/{}_{}/field/{}/{}/'.format(datapath,grid,datatype,name,args.f)
if not os.path.exists(savepath): os.makedirs(savepath)
if args.t is None:
args.t=np.argmin(np.fabs(data['time']-dates.datestr2num(args.d)))
args.d=data['Time'][args.t]
if len(data[args.f].shape)==2:
field=data[args.f][args.t,:]
savepath2='{}field_{}_timestep_{}_date_{}.dat'.format(savepath,args.f,args.t,args.d)
elif len(data[args.f].shape)==3:
if args.l is not None:
field=data[args.f][args.t,args.l,:]
savepath2='{}field_{}_layer_{}_timestep_{}_date_{}.dat'.format(savepath,args.f,args.l,args.t,args.d)
else:
field=data[args.f][args.t,:,:].T
savepath2='{}field_{}_timestep_{}_date_{}.dat'.format(savepath,args.f,args.t,args.d)
else:
print('ooops!')
save_array(field,savepath2)
print('Saved')