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
/
Copy pathtimeseries_wpak.py
171 lines (143 loc) · 4.18 KB
/
timeseries_wpak.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python
"""
wpak_plot.py
Python Script to read a designated mooring SFC WX observations
and generate a initial visualizations
History:
--------
2016-11-21: Migrate routine to new EcoFOCI Moorings structure
"""
# System Stack
import datetime, sys, os
import argparse
# Science Stack
import numpy as np
# User Stack
from calc.EPIC2Datetime import EPIC2Datetime, get_UDUNITS
from calc.calc_solar_rad import incoming_solar_rad
from plots.instrument_plot import TimeseriesWPAK
from io_utils.EcoFOCI_netCDF_read import EcoFOCI_netCDF
__author__ = "Shaun Bell"
__email__ = "[email protected]"
__created__ = datetime.datetime(2014, 9, 11)
__modified__ = datetime.datetime(2016, 11, 21)
__version__ = "0.1.0"
__status__ = "Development"
__keywords__ = "timeseries", "mooring", "epic", "netcdf", "wpak"
"""--------------------------------main Routines---------------------------------------"""
parser = argparse.ArgumentParser(description="WPAK plotting")
parser.add_argument("DataPath", metavar="DataPath", type=str, help="full path to file")
parser.add_argument(
"-rad",
"--theoretical_radiation",
action="store_true",
help="compare radiation to theoretical",
)
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 WPAK data file
ncfile = args.DataPath
df = EcoFOCI_netCDF(ncfile)
global_atts = df.get_global_atts()
vars_dic = df.get_vars()
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
for keynames in ncdata.keys():
if keynames not in [
"time",
"time2",
"lat",
"lon",
"latitude",
"longitude",
"depth",
"dep",
]:
ncdata[keynames][
np.where(ncdata[keynames][:, 0, 0, 0] >= 1e30), 0, 0, 0
] = np.nan
p1 = TimeseriesWPAK(stylesheet="seaborn-poster", labelsize=16)
try:
t1 = p1.add_title(
mooringid=global_atts["MOORING"],
lat=ncdata["lat"][0],
lon=ncdata["lon"][0],
depth=ncdata["depth"][0],
instrument="WPAK",
)
except KeyError:
t1 = p1.add_title(
mooringid=global_atts["MOORING"],
lat=ncdata["latitude"][0],
lon=ncdata["longitude"][0],
depth=ncdata["depth"][0],
instrument="WPAK",
)
plt1, fig1 = p1.plot(nctime, ncdata)
t = fig1.suptitle(t1)
t.set_y(0.06)
fig1.autofmt_xdate()
DefaultSize = fig1.get_size_inches()
fig1.set_size_inches((DefaultSize[0] * 4, DefaultSize[1] * 2.5))
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()
### WPAK all parameters plot
if args.theoretical_radiation:
theor_rad = np.ones_like(nctime)
### WPAK all parameters plot
for i, datatime in enumerate(nctime):
theor_rad[i] = incoming_solar_rad(
datatime, ncdata["lat"][0], -1 * ncdata["lon"][0], sol0=1365.0
)
(plt, fig) = p1.plot_rad(
nctime,
ncdata["Qs_133"][:, 0, 0, 0],
theor_rad,
textlabel="Solar Rad",
textlabel2="Theor. Solar Rad",
)
t = fig1.suptitle(t1)
t.set_y(0.06)
fig1.autofmt_xdate()
DefaultSize = fig1.get_size_inches()
fig1.set_size_inches((DefaultSize[0] * 4, DefaultSize[1] * 3))
if not args.full_path:
plt1.savefig(
"images/" + ncfile.split("/")[-1] + "_rad.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]
+ "_rad.png",
bbox_inches="tight",
dpi=(300),
)
plt1.close()