In [1]:
%matplotlib inline
import requests
import pandas as pd
import sys
from cgsn_parsers.parsers.parse_phsen import Parser
In [2]:
# add cgsn-parsers tools to the path (no package yet)
path = os.path.abspath('../')
sys.path.append(path)
In [4]:
#Coastal Endurance - WA Shelf Surface Piercing Profiler Mooring
baseurl = "https://rawdata.oceanobservatories.org/files/CE07SHSM/D00003/cg_data/dcl26/phsen1/"
fname = "20160926.phsen1.log"
In [16]:
# Coastal Pioneer - Central Surface Mooring
baseurl = "https://rawdata.oceanobservatories.org/files/CP01CNSM/D00006/cg_data/dcl26/phsen1/"
fname = "20170116.phsen1.log"
In [17]:
# initialize the Parser object for METBK
phsen = Parser(baseurl + fname)
In [18]:
r = requests.get(phsen.infile, verify=True) # use verify=False for expired certificate
phsen.raw = r.content
In [19]:
len(phsen.raw), phsen.raw[-5:]
Out[19]:
In [20]:
phsen.parse_data()
In [21]:
phsen.data.keys()
Out[21]:
In [22]:
df = pd.DataFrame(phsen.data)
df['dt_utc'] = pd.to_datetime(df.time, unit='s')
df.set_index('dt_utc', drop=True, inplace=True)
del df['dcl_date_time_string']
In [23]:
df.head()
Out[23]:
In [24]:
# Later, can drop time, and maybe dt_utc (not the index)
df.shape, df.columns
Out[24]:
In [13]:
df.dtypes
Out[13]:
In [14]:
#extract a specific element from each list of light_measurements
df['light_0'] = [x[0] for x in df['light_measurements']]
df['light_end'] = [x[-1] for x in df['light_measurements']]
In [15]:
df['light_0'].plot(figsize=(11,5), grid='on');