{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Reading ADV Data with MHKiT" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following example demonstrates a simple workflow for analyzing Acoustic Doppler Velocimetry (ADV) data using MHKiT. MHKiT has brought the DOLfYN codebase in as an MHKiT module for working with ADV and Acoustic Doppler Current Profiler (ADCP) data.\n", " \n", "A typical ADV data workflow is broken down into\n", " 1. Review the raw data\n", " - Check timestamps\n", " - Look at velocity data quality, particularly for spiking\n", " 2. Check for spurious datapoints and remove. Replace bad datapoints using interpolation if desired\n", " 3. Rotate the data into principal flow coordinates (streamwise, cross-stream, vertical)\n", " 4. Average the data into bins, or ensembles, of a set time length (normally 5 to 10 min)\n", " 5. Calculate turbulence statistics (turbulence intensity, TKE, Reynolds stresses) of the measured flowfield\n", "\n", "Start by importing the necessary tools:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "from mhkit import dolfyn\n", "from mhkit.dolfyn.adv import api" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read Raw Instrument Data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "DOLfYN currently only carries support for the Nortek Vector ADV. The example loaded here is a short clip of data from a test deployment to show DOLfN's capabilities.\n", "\n", "Start by reading in the raw datafile downloaded from the instrument. The `dolfyn.read` function reads the raw file and dumps the information into an xarray Dataset, which contains three groups of variables:\n", "\n", "1. Velocity, amplitude, and correlation of the Doppler velocimetry\n", "2. Measurements of the instrument's bearing and environment\n", "3. Orientation matrices DOLfYN uses for rotating through coordinate frames." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reading file data/dolfyn/vector_data01.VEC ...\n", " end of file at 3000000 bytes.\n" ] } ], "source": [ "ds = dolfyn.read('data/dolfyn/vector_data01.VEC')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are two ways to see what's in a Dataset. The first is to simply type the dataset's name to see the standard xarray output. To access a particular variable in a dataset, use dict-style (`ds['vel']`) or attribute-style syntax (`ds.vel`). See the [xarray docs](http://xarray.pydata.org/en/stable/getting-started-guide/quick-overview.html) for more details on how to use the xarray format." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (time: 122912, beam: 3, dir: 3, x: 3, x*: 3, earth: 3, inst: 3)\n", "Coordinates:\n", " * time (time) datetime64[ns] 2012-06-12T12:00:02.968749 ......\n", " * beam (beam) int32 1 2 3\n", " * dir (dir) <U1 'X' 'Y' 'Z'\n", " * x (x) int32 1 2 3\n", " * x* (x*) int32 1 2 3\n", " * earth (earth) <U1 'E' 'N' 'U'\n", " * inst (inst) <U1 'X' 'Y' 'Z'\n", "Data variables: (12/15)\n", " beam2inst_orientmat (x, x*) float64 2.709 -1.34 -1.364 ... -0.3438 -0.3499\n", " batt (time) float32 13.2 13.2 13.2 13.2 ... nan nan nan nan\n", " c_sound (time) float32 1.493e+03 1.493e+03 ... nan nan\n", " heading (time) float32 5.6 10.5 10.51 10.52 ... nan nan nan nan\n", " pitch (time) float32 -31.5 -31.7 -31.69 ... nan nan nan\n", " roll (time) float32 0.4 4.2 4.253 4.306 ... nan nan nan nan\n", " ... ...\n", " vel (dir, time) float32 -1.002 -1.008 -0.944 ... nan nan\n", " amp (beam, time) uint8 104 110 111 113 108 ... 0 0 0 0 0\n", " corr (beam, time) uint8 97 91 97 98 90 95 95 ... 0 0 0 0 0 0\n", " orientation_down (time) bool True True True True ... True True True True\n", " pressure (time) float64 5.448 5.436 5.484 5.448 ... 0.0 0.0 0.0\n", " orientmat (earth, inst, time) float32 0.0832 0.155 ... -0.7065\n", "Attributes: (12/39)\n", " inst_make: Nortek\n", " inst_model: Vector\n", " inst_type: ADV\n", " rotate_vars: ['vel']\n", " n_beams: 3\n", " profile_mode: continuous\n", " ... ...\n", " recorder_size_bytes: 4074766336\n", " vel_range: normal\n", " firmware_version: 3.34\n", " fs: 32.0\n", " coord_sys: inst\n", " has_imu: 0
array(['2012-06-12T12:00:02.968749000', '2012-06-12T12:00:02.999999000',\n", " '2012-06-12T12:00:03.031249000', ..., '2012-06-12T13:04:03.875001000',\n", " '2012-06-12T13:04:03.906251000', '2012-06-12T13:04:03.937501000'],\n", " dtype='datetime64[ns]')
array([1, 2, 3])
array(['X', 'Y', 'Z'], dtype='<U1')
array([1, 2, 3])
array([1, 2, 3])
array(['E', 'N', 'U'], dtype='<U1')
array(['X', 'Y', 'Z'], dtype='<U1')
array([[ 2.70874023, -1.34008789, -1.36376953],\n", " [ 0.0144043 , -2.38354492, 2.39550781],\n", " [-0.3371582 , -0.34375 , -0.34985352]])
array([13.2, 13.2, 13.2, ..., nan, nan, nan], dtype=float32)
array([1492.6, 1492.6, 1492.6, ..., nan, nan, nan], dtype=float32)
array([ 5.6 , 10.5 , 10.5125, ..., nan, nan, nan],\n", " dtype=float32)
array([-31.5 , -31.7 , -31.690626, ..., nan, nan,\n", " nan], dtype=float32)
array([0.4 , 4.2000003, 4.253125 , ..., nan, nan,\n", " nan], dtype=float32)
array([12.67 , 12.679999, 12.679999, ..., nan, nan,\n", " nan], dtype=float32)
array([0, 0, 0, ..., 0, 0, 0], dtype=uint8)
array([117, 117, 0, ..., 0, 0, 0], dtype=uint8)
array([[-1.0020001 , -1.008 , -0.94400007, ..., nan,\n", " nan, nan],\n", " [ 0.097 , 0.068 , 0.066 , ..., nan,\n", " nan, nan],\n", " [ 0.115 , 0.12400001, 0.12200001, ..., nan,\n", " nan, nan]], dtype=float32)
array([[104, 110, 111, ..., 0, 0, 0],\n", " [109, 111, 118, ..., 0, 0, 0],\n", " [111, 107, 103, ..., 0, 0, 0]], dtype=uint8)
array([[97, 91, 97, ..., 0, 0, 0],\n", " [97, 97, 98, ..., 0, 0, 0],\n", " [96, 97, 97, ..., 0, 0, 0]], dtype=uint8)
array([ True, True, True, ..., True, True, True])
array([5.448, 5.436, 5.484, ..., 0. , 0. , 0. ])
array([[[ 0.08320302, 0.155048 , 0.15524618, ..., -0.8397447 ,\n", " -0.8397447 , -0.8397447 ],\n", " [ 0.8485708 , 0.83656424, 0.8366149 , ..., 0.21873687,\n", " 0.21873687, 0.21873687],\n", " [-0.52249855, -0.5254717 , -0.52533245, ..., -0.49697396,\n", " -0.49697396, -0.49697396]],\n", "\n", " [[ 0.9948472 , 0.97360104, 0.9733992 , ..., 0.48448867,\n", " 0.48448867, 0.48448867],\n", " [-0.10121067, -0.21958625, -0.22025378, ..., 0.7150815 ,\n", " 0.7150815 , 0.7150815 ],\n", " [-0.00595242, -0.06231184, -0.06310495, ..., -0.5039139 ,\n", " -0.5039139 , -0.5039139 ]],\n", "\n", " [[-0.05793348, -0.1675142 , -0.16850099, ..., 0.24515234,\n", " 0.24515234, 0.24515234],\n", " [-0.51931095, -0.50193846, -0.5015614 , ..., -0.6639372 ,\n", " -0.6639372 , -0.6639372 ],\n", " [-0.85261935, -0.84852624, -0.84855384, ..., -0.7064614 ,\n", " -0.7064614 , -0.7064614 ]]], dtype=float32)