Skip to content

Instantly share code, notes, and snippets.

@kwilcox
Created November 11, 2015 20:22
Show Gist options
  • Save kwilcox/9cca7e907815c9b5ee1e to your computer and use it in GitHub Desktop.
Save kwilcox/9cca7e907815c9b5ee1e to your computer and use it in GitHub Desktop.
GliderDAC profiles starting before the previous has ended
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import netCDF4"
]
},
{
"cell_type": "code",
"execution_count": 187,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bad Profile: 3\n",
"Profile end: 2015-07-07 01:22:36.252620\n",
"Next profile start: 2015-07-06 19:05:30.222470\n",
"\n",
"Bad Profile: 4\n",
"Profile end: 2015-07-07 04:01:02.481690\n",
"Next profile start: 2015-07-06 19:18:04.184170\n",
"\n",
"Bad Profile: 7\n",
"Profile end: 2015-07-07 15:18:59.473480\n",
"Next profile start: 2015-07-06 20:11:51.778140\n",
"\n",
"Bad Profile: 8\n",
"Profile end: 2015-07-07 20:38:32.296810\n",
"Next profile start: 2015-07-06 20:25:22.258640\n",
"\n",
"Bad Profile: 11\n",
"Profile end: 2015-07-07 22:56:07.066530\n",
"Next profile start: 2015-07-06 22:15:13.943360\n",
"\n",
"Bad Profile: 12\n",
"Profile end: 2015-07-08 00:13:51.659670\n",
"Next profile start: 2015-07-06 22:28:10.834200\n",
"\n",
"Bad Profile: 13\n",
"Profile end: 2015-07-08 00:31:24.357820\n",
"Next profile start: 2015-07-06 22:41:54.605010\n",
"\n",
"Bad Profile: 14\n",
"Profile end: 2015-07-08 01:11:02.193450\n",
"Next profile start: 2015-07-06 23:34:55.548370\n",
"\n",
"Bad Profile: 16\n",
"Profile end: 2015-07-08 05:54:22.189760\n",
"Next profile start: 2015-07-07 00:20:14.241030\n",
"\n",
"Bad Profile: 18\n",
"Profile end: 2015-07-08 06:57:44.580380\n",
"Next profile start: 2015-07-07 00:50:39.668330\n",
"\n",
"Bad Profile: 19\n",
"Profile end: 2015-07-08 07:41:50.705510\n",
"Next profile start: 2015-07-07 01:20:24.068570\n",
"\n",
"Bad Profile: 20\n",
"Profile end: 2015-07-08 09:16:55.355190\n",
"Next profile start: 2015-07-07 01:51:20.659000\n",
"\n",
"Bad Profile: 21\n",
"Profile end: 2015-07-08 10:03:36.601810\n",
"Next profile start: 2015-07-07 02:21:24.928500\n",
"\n",
"Bad Profile: 22\n",
"Profile end: 2015-07-08 10:26:07.765260\n",
"Next profile start: 2015-07-07 02:36:34.094700\n",
"\n",
"Bad Profile: 23\n",
"Profile end: 2015-07-08 12:03:40.470060\n",
"Next profile start: 2015-07-07 02:51:51.895600\n",
"\n",
"Bad Profile: 25\n",
"Profile end: 2015-07-08 12:27:16.547700\n",
"Next profile start: 2015-07-07 03:59:10.361850\n",
"\n",
"Bad Profile: 26\n",
"Profile end: 2015-07-08 12:50:49.268250\n",
"Next profile start: 2015-07-07 04:14:17.614650\n",
"\n",
"Bad Profile: 27\n",
"Profile end: 2015-07-08 13:13:25.085480\n",
"Next profile start: 2015-07-07 04:19:19.095550\n",
"\n",
"Bad Profile: 28\n",
"Profile end: 2015-07-08 13:38:17.022060\n",
"Next profile start: 2015-07-07 04:44:58.315860\n",
"\n",
"Bad Profile: 29\n",
"Profile end: 2015-07-08 14:37:11.050570\n",
"Next profile start: 2015-07-07 05:24:35.445980\n",
"\n",
"Bad Profile: 30\n",
"Profile end: 2015-07-08 15:25:29.519900\n",
"Next profile start: 2015-07-07 05:39:49.276700\n",
"\n",
"Bad Profile: 31\n",
"Profile end: 2015-07-08 15:50:35.559020\n",
"Next profile start: 2015-07-07 06:10:58.391880\n",
"\n",
"Bad Profile: 32\n",
"Profile end: 2015-07-08 16:14:58.787840\n",
"Next profile start: 2015-07-07 06:26:53.859380\n",
"\n",
"Bad Profile: 33\n",
"Profile end: 2015-07-08 16:40:31.244170\n",
"Next profile start: 2015-07-07 06:32:25.356900\n",
"\n",
"Bad Profile: 34\n",
"Profile end: 2015-07-08 17:36:17.106780\n",
"Next profile start: 2015-07-07 06:48:29.379150\n",
"\n",
"Bad Profile: 35\n",
"Profile end: 2015-07-08 18:27:05.279850\n",
"Next profile start: 2015-07-07 07:31:13.002900\n",
"\n",
"Bad Profile: 36\n",
"Profile end: 2015-07-07 08:45:09.230380\n",
"Next profile start: 2015-07-07 07:48:02.167210\n",
"\n",
"Bad Profile: 37\n",
"Profile end: 2015-07-07 09:01:34.166080\n",
"Next profile start: 2015-07-07 08:31:29.104160\n",
"\n",
"Bad Profile: 39\n",
"Profile end: 2015-07-08 19:44:14.300930\n",
"Next profile start: 2015-07-07 09:49:00.578310\n",
"\n",
"Bad Profile: 40\n",
"Profile end: 2015-07-08 21:11:09.819950\n",
"Next profile start: 2015-07-07 09:54:15.464290\n",
"\n",
"Bad Profile: 41\n",
"Profile end: 2015-07-08 21:37:39.663060\n",
"Next profile start: 2015-07-07 10:57:08.074430\n",
"\n",
"Bad Profile: 42\n",
"Profile end: 2015-07-08 22:59:20.539830\n",
"Next profile start: 2015-07-07 11:36:36.407200\n",
"\n",
"Bad Profile: 43\n",
"Profile end: 2015-07-08 23:24:24.938420\n",
"Next profile start: 2015-07-07 12:15:41.553620\n",
"\n",
"Bad Profile: 44\n",
"Profile end: 2015-07-08 23:48:54.397030\n",
"Next profile start: 2015-07-07 12:37:12.541140\n",
"\n",
"Bad Profile: 45\n",
"Profile end: 2015-07-08 23:50:27.694640\n",
"Next profile start: 2015-07-07 12:59:18.104100\n",
"\n",
"Bad Profile: 46\n",
"Profile end: 2015-07-09 00:15:39.583770\n",
"Next profile start: 2015-07-07 13:22:32.149510\n",
"\n",
"Bad Profile: 47\n",
"Profile end: 2015-07-09 00:41:44.670070\n",
"Next profile start: 2015-07-07 13:45:11.543700\n",
"\n",
"Bad Profile: 48\n",
"Profile end: 2015-07-09 01:06:58.339360\n",
"Next profile start: 2015-07-07 13:52:57.841890\n",
"\n",
"Bad Profile: 61\n",
"Profile end: 2015-07-07 23:53:52.015320\n",
"Next profile start: 2015-07-07 22:52:59.946590\n",
"\n",
"Bad Profile: 70\n",
"Profile end: 2015-07-08 03:31:38.985290\n",
"Next profile start: 2015-07-08 02:30:08.196560\n",
"\n",
"Bad Profile: 90\n",
"Profile end: 2015-07-08 13:13:06.336030\n",
"Next profile start: 2015-07-08 12:23:13.874940\n",
"\n",
"Bad Profile: 95\n",
"Profile end: 2015-07-08 15:25:48.504850\n",
"Next profile start: 2015-07-08 14:33:05.565860\n",
"\n",
"Bad Profile: 108\n",
"Profile end: 2015-07-08 23:24:06.254000\n",
"Next profile start: 2015-07-08 21:32:58.193700\n",
"\n",
"Bad Profile: 127\n",
"Profile end: 2015-07-09 09:57:32.718900\n",
"Next profile start: 2015-07-09 08:28:29.191990\n",
"\n",
"Bad Profile: 129\n",
"Profile end: 2015-07-09 12:00:33.575870\n",
"Next profile start: 2015-07-09 09:25:45.542050\n",
"\n",
"Bad Profile: 134\n",
"Profile end: 2015-07-09 16:13:41.028530\n",
"Next profile start: 2015-07-09 12:56:12.549350\n",
"\n",
"Bad Profile: 136\n",
"Profile end: 2015-07-09 17:12:20.550200\n",
"Next profile start: 2015-07-09 15:10:30.397190\n",
"\n"
]
}
],
"source": [
"with netCDF4.Dataset('./platforms/tests/resources/bass-20150706T151619Z.nc') as nc:\n",
" \n",
" tu = nc.variables['precise_time'].units\n",
" ptime = nc.variables['precise_time'][:]\n",
" row_size = nc.variables['rowSize'][:]\n",
" profile = nc.variables['profile_id'][:]\n",
" \n",
" # Skip the last profile\n",
" for p in list(range(profile.size - 1)):\n",
" num_obs = row_size[p]\n",
" sizes = row_size[0:p+1]\n",
" if sizes.size == 1:\n",
" si = 0\n",
" else:\n",
" si = np.cumsum(sizes[:-1])[-1]\n",
" ei = si + num_obs\n",
" \n",
" p_end = ptime[ei-1]\n",
" next_start = ptime[ei]\n",
" if next_start - p_end < 0:\n",
" print(\"Bad Profile:\", p)\n",
" print(\"Profile end:\", netCDF4.num2date(p_end, units=tu))\n",
" print(\"Next profile start:\", netCDF4.num2date(next_start, units=tu))\n",
" print(\"\")\n",
"\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment