This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
timeseries_2varplot.py
135 lines (112 loc) · 3.5 KB
/
timeseries_2varplot.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env
"""
timeseries_2varplot.py
History:
--------
2016-08-03: Initial development stage. Plot single variable against time for EcoFOCI instruments
Move netCDF tools to wrapper functions in class of module io_util.EcoFOCI_netCDF_read
"""
# System Stack
import datetime, sys, os
import argparse
# Science Stack
import numpy as np
# User Stack
from calc.EPIC2Datetime import EPIC2Datetime, get_UDUNITS
from plots.instrument_plot import Timeseries2varPlot
from io_utils.EcoFOCI_netCDF_read import EcoFOCI_netCDF
__author__ = "Shaun Bell"
__email__ = "[email protected]"
__created__ = datetime.datetime(2014, 9, 11)
__modified__ = datetime.datetime(2014, 9, 11)
__version__ = "0.1.0"
__status__ = "Development"
__keywords__ = "timeseries", "mooring", "epic", "netcdf"
"""-------------------------------- helper routines---------------------------------------"""
def is_in_dic(var, dic):
for cmd_var in var:
if not cmd_var in dic.keys():
print("Epic Key {0} not in data file... exiting".format(cmd_var))
sys.exit()
"""--------------------------------main Routines---------------------------------------"""
parser = argparse.ArgumentParser(description="Timeseries plotting")
parser.add_argument("DataPath", metavar="DataPath", type=str, help="full path to file")
parser.add_argument(
"epickey",
metavar="epickey",
nargs="+",
type=str,
help="epic key codes of data parameters to plot",
)
parser.add_argument("instname", metavar="instname", type=str, help="instrument name")
parser.add_argument(
"-fp",
"--full_path",
action="store_true",
help="provides full path to program: used if run as script",
)
args = parser.parse_args()
# read in 1d data file
ncfile = args.DataPath
df = EcoFOCI_netCDF(args.DataPath)
global_atts = df.get_global_atts()
vars_dic = df.get_vars()
# check that variable is in data file and exit if not
is_in_dic(args.epickey, vars_dic)
ncdata = df.ncreadfile_dic()
df.close()
nctime = (
get_UDUNITS(EPIC2Datetime(ncdata["time"], ncdata["time2"]), "days since 0001-1-1")
+ 1.0
)
# filter data to convert 1e35 -> np.nan
ncdata[args.epickey[0]][
np.where(ncdata[args.epickey[0]][:, 0, 0, 0] >= 1e30), 0, 0, 0
] = np.nan
ncdata[args.epickey[1]][
np.where(ncdata[args.epickey[1]][:, 0, 0, 0] >= 1e30), 0, 0, 0
] = np.nan
p1 = Timeseries2varPlot(plotstyle="k-")
try:
t1 = p1.add_title(
mooringid=global_atts["MOORING"],
lat=ncdata["lat"][0],
lon=ncdata["lon"][0],
depth=ncdata["depth"][0],
instrument=args.instname,
)
except KeyError:
t1 = p1.add_title(
mooringid=global_atts["MOORING"],
lat=ncdata["latitude"][0],
lon=ncdata["longitude"][0],
depth=ncdata["depth"][0],
instrument=args.instname,
)
plt1, fig1 = p1.plot(
nctime,
ncdata[args.epickey[0]][:, 0, 0, 0],
ncdata[args.epickey[1]][:, 0, 0, 0],
ylabel=args.epickey[0],
ylabel2=args.epickey[1],
)
t = fig1.suptitle(t1)
t.set_y(0.06)
fig1.autofmt_xdate()
DefaultSize = fig1.get_size_inches()
fig1.set_size_inches((DefaultSize[0] * 2, DefaultSize[1]))
if not args.full_path:
plt1.savefig(
"images/" + ncfile.split("/")[-1] + ".png", bbox_inches="tight", dpi=(300)
)
else:
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
plt1.savefig(
parent_dir
+ "/EcoFOCI_MooringAnalysis/images/"
+ ncfile.split("/")[-1]
+ ".png",
bbox_inches="tight",
dpi=(300),
)
plt1.close()