-
Notifications
You must be signed in to change notification settings - Fork 16
/
from_ooi_json-Copy1.py
146 lines (85 loc) · 2.34 KB
/
from_ooi_json-Copy1.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
# coding: utf-8
# # Convert OOI Parsed JSON to NetCDF file
# using CF-1.6, Discrete Sampling Geometry (DSG) conventions, **`featureType=timeSeries`**
# In[1]:
get_ipython().magic('matplotlib inline')
import json
import pandas as pd
import numpy as np
from pyaxiom.netcdf.sensors import TimeSeries
# In[2]:
infile = '/usgs/data2/notebook/data/20170130.superv.json'
infile = '/sand/usgs/users/rsignell/data/ooi/endurance/cg_proc/ce02shsm/D00004/buoy/pwrsys/20170208.pwrsys.json'
outfile = '/usgs/data2/notebook/data/20170208.pwrsys.nc'
with open(infile) as jf:
js = json.load(jf)
df = pd.DataFrame({})
for k, v in js.items():
df[k] = v
df['time'] = pd.to_datetime(df.time, unit='s')
df['depth'] = 0.
df.head()
# In[3]:
df['solar_panel4_voltage'].plot();
# In[4]:
df.index = df['time']
df['solar_panel4_voltage'].plot();
# ### Define the NetCDF global attributes
# In[5]:
global_attributes = {
'institution':'Oregon State University',
'title':'OOI CE02SHSM Pwrsys Data',
'summary':'OOI Pwrsys data from Coastal Endurance Oregon Shelf Surface Mooring',
'creator_name':'Chris Wingard',
'creator_email':'cwingard@coas.oregonstate.edu',
'creator_url':'http://ceoas.oregonstate.edu/ooi'
}
# ### Create initial file
# In[6]:
ts = TimeSeries(
output_directory='.',
latitude=44.64,
longitude=-124.31,
station_name='ce02shsm',
global_attributes=global_attributes,
times=df.time.values.astype(np.int64) // 10**9,
verticals=df.depth.values,
output_filename=outfile,
vertical_positive='down'
)
# ### Add data variables
# In[7]:
df.columns.tolist()
# In[10]:
for c in df.columns:
if c in ts._nc.variables:
print("Skipping '{}' (already in file)".format(c))
continue
if c in ['time', 'lat', 'lon', 'depth', 'cpm_date_time_string']:
print("Skipping axis '{}' (already in file)".format(c))
continue
print("Adding {}".format(c))
try:
ts.add_variable(c, df[c].values)
except:
print('skipping, hit object')
# In[ ]:
df['error_flag3'][0]
# ### Open the NetCDF file and inspect it
# In[ ]:
import netCDF4
nc = netCDF4.Dataset(outfile)
# In[ ]:
nc
# In[ ]:
nc.close()
# In[ ]:
import netCDF4
nc = netCDF4.Dataset(outfile)
# In[ ]:
nc['z']
# In[ ]:
nc['crs']
# In[ ]:
nc['iridium_current']
# In[ ]: