Here we read a matlab file with minimal metadata, and write a CF-DSG 1.6 timeSeriesProfile netcdf file. We want the file to work seamlessly with ERDDAP, so we add some ERDDAP specific attributes like cdm_timeseries_variables, cdm_profile_variables, and subsetVariables.
In [1]:
import matplotlib.pyplot as plt
import pandas as pd
from scipy.io import loadmat
import datetime as dt
import numpy as np
#conda install -c conda-forge pocean-core
from pocean.dsg.timeseriesProfile.om import OrthogonalMultidimensionalTimeseriesProfile
In [2]:
# wget http://www.satlab.hawaii.edu/onr/adria/data/moorings/nrl/Final/ADCP_matlab/VR4f.mat
d = loadmat('/data/ADRIA/MOORINGS/NRL/VR4f.mat')
In [3]:
times = [dt.datetime(2002,1,1,0,0,0) + dt.timedelta(a) for a in d['timen'].flatten()]
depths = d['mdepth'].flatten()
# Repeat each time for the number of depths
t = np.repeat(times, len(depths))
# Create a profile index, and repeat for number of depths
profile = np.repeat(np.array(range(len(times)), dtype=np.int32) + 1, len(depths))
# Tile the depths for each time
z = np.tile(depths, len(times))
df = pd.DataFrame({
't': t,
'x': 13.0281,
'y': 45.187783,
'z': z,
'un': d['un'].T.flatten()/10., # cm/s to m/s
'vn': d['vn'].T.flatten()/10., # cm/s to m/s
'wn': d['wn'].T.flatten()/10., # cm/s to m/s
'profile': profile,
'station': 'VR4F'
})
df.tail()
Out[3]:
In [4]:
atts={
'global': {
'title': 'ADRIA02 Mooring VR4',
'summary': 'Data from bottom-mounted ADCP',
'institution': 'NRL',
'cdm_timeseries_variables': 'station',
'cdm_profile_variables': 'profile',
'subsetVariables': 'depth'
},
'longitude': {
'units': 'degrees_east',
'standard_name':'longitude'
},
'latitude': {
'units': 'degrees_north',
'standard_name':'latitude'
},
'z': {
'units': 'm',
'standard_name': 'depth',
'positive':'down'
},
'un': {
'units': 'm/s',
'standard_name':'eastward_sea_water_velocity'
},
'vn': {
'units': 'm/s',
'standard_name':'northward_sea_water_velocity'
},
'profile': {
'cf_role': 'profile_id'
}
}
In [5]:
atts['global']
Out[5]:
In [6]:
OrthogonalMultidimensionalTimeseriesProfile.from_dataframe(df, output='/data/ADRIA/MOORINGS/NRL/vr4f.nc',
attributes=atts)
Out[6]: