This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyncdump.py
executable file
·203 lines (173 loc) · 6.03 KB
/
pyncdump.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env python
"""
pyncdump.py
Purpose:
-----
Python alternative to ncdump for metainfo
Usage:
------
pyncdump -i {filename}
History:
========
2020-03-26: EPIC time conversion modified to support python3, format statements modified for python3
2016-11-11: SBELL - move routine from general_utilities and unify class/subroutines with
other EcoFOCI utilities
Compatibility:
==============
python >=3.7 ** tested
python 2.7 ** tested but no longer developed for
"""
# System Stack
import datetime
import os
import argparse
# Science Stack
from netCDF4 import Dataset
import numpy as np
# user stack
from io_utils.EcoFOCI_netCDF_read import EcoFOCI_netCDF
from calc.EPIC2Datetime import EPIC2Datetime
import warnings
warnings.filterwarnings("ignore")
__author__ = "Shaun Bell"
__email__ = "shaun.bell@noaa.gov"
__created__ = datetime.datetime(2016, 11, 12)
__modified__ = datetime.datetime(2016, 11, 12)
__version__ = "0.2.0"
__status__ = "Development"
__keywords__ = "netCDF", "meta", "header"
"""---------------------------------- Main --------------------------------------------"""
try:
os.system("clear")
except:
pass
parser = argparse.ArgumentParser(description="Summary of input .nc file.")
parser.add_argument("infile", metavar="infile", type=str, help="input file path")
args = parser.parse_args()
os.system("clear")
inputpath = args.infile
###nc readin/out
df = EcoFOCI_netCDF(args.infile)
global_atts = df.get_global_atts()
vars_dic = df.get_vars()
ncdata = df.ncreadfile_dic()
# convert epic time
# time2 wont exist if it isnt epic keyed time
if "time2" in vars_dic.keys():
ncdata["datetime"] = EPIC2Datetime(ncdata["time"], ncdata["time2"])
"""----------"""
###screen output
if len(ncdata["time"]) > 1:
print("\n\n\n\n\n\n")
print("Filename - {0} \n").format(inputpath)
for var in vars_dic.keys():
v_atts = df.get_vars_attributes(var)
try:
ncdata[var][ncdata[var] >= 1e34] = np.nan
except:
pass
try:
print(
"\tVariable: {1}\n\t\t Epic Key: {0:_<10} :\t min={2:>15.3f} \t max={3:>15.3f} \t mean={4:>15.3f} \t median={5:>15.3f}".format(
var,
v_atts.long_name,
np.nanmin(ncdata[var]),
np.nanmax(ncdata[var]),
np.nanmean(ncdata[var]),
np.nanmedian(ncdata[var]),
)
)
except:
print(
"\tVariable: {1}\n\t\t Epic Key: {0:_<10} :\t min={2:>15.3f} \t max={3:>15.3f} \t mean={4:>15.3f} \t median={5:>15.3f}".format(
var,
"",
np.nanmin(ncdata[var]),
np.nanmax(ncdata[var]),
np.nanmean(ncdata[var]),
np.nanmedian(ncdata[var]),
)
)
print("\n")
### EPIC standard time conversion - assume time2 dimension exists
if "time2" in vars_dic.keys():
print(" EPIC time conversion:\n")
print("\t Start Time: {:%Y-%m-%d %H:%M:%S}".format(np.min(ncdata["datetime"])))
print("\t End Time: {:%Y-%m-%d %H:%M:%S}".format(np.max(ncdata["datetime"])))
print(
"\t DeltaT based on first two points: {0} seconds".format(
(ncdata["datetime"][1] - ncdata["datetime"][0]).seconds
)
)
print(
"\t DeltaT based on last two points: {0} seconds".format(
(ncdata["datetime"][-1] - ncdata["datetime"][-2]).seconds
)
)
print("\nGlobal Attributes:\n")
for var in global_atts.keys():
try:
print("\t {0}: {1}".format(var, global_atts[var]))
except UnicodeEncodeError:
print("\t {0}: {1}".format(var, "***Unrecognized ASCII characters***"))
print("\n")
print("Variables in file: {list}".format(list=",".join(vars_dic.keys())))
print("\n\n\n")
else:
print("\n\n\n\n\n\n")
print("Filename - {0} \n".format(inputpath))
for var in vars_dic.keys():
v_atts = df.get_vars_attributes(var)
try:
ncdata[var][ncdata[var] >= 1e34] = np.nan
except:
pass
try:
print(
"\tVariable: {1}\n\t\t Epic Key: {0:_<10} :\t min={2:>15.3f} \t max={3:>15.3f} \t mean={4:>15.3f} \t median={5:>15.3f}".format(
var,
v_atts.long_name,
np.nanmin(ncdata[var]),
np.nanmax(ncdata[var]),
np.nanmean(ncdata[var]),
np.nanmedian(ncdata[var]),
)
)
except:
print(
"\tVariable: {1}\n\t\t Epic Key: {0:_<10} :\t min={2:>15.3f} \t max={3:>15.3f} \t mean={4:>15.3f} \t median={5:>15.3f}".format(
var,
"",
np.nanmin(ncdata[var]),
np.nanmax(ncdata[var]),
np.nanmean(ncdata[var]),
np.nanmedian(ncdata[var]),
)
)
print("\n")
### EPIC standard time conversion - assume time2 dimension exists
if "time2" in vars_dic.keys():
print(" EPIC time conversion:\n")
print("\t Cast Time: {:%Y-%m-%d %H:%M:%S}".format(np.min(ncdata["datetime"])))
try:
print(
"\t Depth Interval: {0} dBar".format(
(ncdata["depth"][1] - ncdata["depth"][0])
)
)
except:
print(
"\t Depth Interval: {0} dBar".format(
(ncdata["dep"][1] - ncdata["dep"][0])
)
)
print("\nGlobal Attributes:\n")
for var in global_atts.keys():
try:
print("\t {0}: {1}".format(var, global_atts[var]))
except UnicodeEncodeError:
print("\t {0}: {1}".format(var, "***Unrecognized ASCII characters***"))
print("\n")
print("Variables in file: {list}".format(list=",".join(vars_dic.keys())))
print("\n\n\n")
df.close()