{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Boundary Pass and ONC Central Node Results Time Series\n", "\n", "Assemble time series results for Rich:\n", "\n", "* NEMO-3.6 nowcast-green runs\n", "* full water column\n", "* hourly average results at Boundary Pass location of ONC mooring\n", "* hourly average results at ONC central node\n", "* 1-Jun-2016 through 30-Sep-2016\n", "\n", "After the planned NEMO-3.6 hindcast runs it should be possible to increase the time resolution\n", "to 10 minute averages." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import os\n", "from pathlib import Path\n", "\n", "import arrow\n", "import xarray" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# ONC description of central node location:\n", "# Depth: 297 m\n", "# Latitude: 49.040066666\n", "# Longitude: -123.425825\n", "central_ji = (424, 266)\n", "# ONC description of Boundary Pass mooring location:\n", "# Depth: 230 m\n", "# Latitude: 48.7665\n", "# Longitude: -123.039556\n", "boundary_ji = (343, 289)\n", "\n", "start_date = arrow.get('2016-06-01')\n", "end_date = arrow.get('2016-06-02')\n", "\n", "results_archive = Path('/results/SalishSea/nowcast-green/')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def write_csv(filehandle, time_counter, var):\n", " for i, t in enumerate(time_counter.values):\n", " mat_timestamp = arrow.get((str(t))).format('D-MMM-YYYY HH:mm:ss Z')\n", " line = ', '.join(str(v) for v in var.values[i])\n", " line = ', '.join((mat_timestamp, line))\n", " line = f'{line}\\n'\n", " f.write(line)\n", " print(mat_timestamp)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "datasets = []\n", "for a in arrow.Arrow.range('day', start_date, end_date):\n", " ddmmmyy = a.format('DDMMMYY').lower()\n", " yyyymmdd = a.format('YYYYMMDD')\n", " results_dir = f'{ddmmmyy}'\n", " grid_T_1h = f'SalishSea_1h_{yyyymmdd}_{yyyymmdd}_grid_T.nc'\n", " datasets.append(os.fspath(results_archive/results_dir/grid_T_1h))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "['/results/SalishSea/nowcast-green/01jun16/SalishSea_1h_20160601_20160601_grid_T.nc',\n", " '/results/SalishSea/nowcast-green/02jun16/SalishSea_1h_20160602_20160602_grid_T.nc']" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "datasets" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1-Jun-2016 00:30:00 +0000\n", "1-Jun-2016 01:30:00 +0000\n", "1-Jun-2016 02:30:00 +0000\n", "1-Jun-2016 03:30:00 +0000\n", "1-Jun-2016 04:30:00 +0000\n", "1-Jun-2016 05:30:00 +0000\n", "1-Jun-2016 06:30:00 +0000\n", "1-Jun-2016 07:30:00 +0000\n", "1-Jun-2016 08:30:00 +0000\n", "1-Jun-2016 09:30:00 +0000\n", "1-Jun-2016 10:30:00 +0000\n", "1-Jun-2016 11:30:00 +0000\n", "1-Jun-2016 12:30:00 +0000\n", "1-Jun-2016 13:30:00 +0000\n", "1-Jun-2016 14:30:00 +0000\n", "1-Jun-2016 15:30:00 +0000\n", "1-Jun-2016 16:30:00 +0000\n", "1-Jun-2016 17:30:00 +0000\n", "1-Jun-2016 18:30:00 +0000\n", "1-Jun-2016 19:30:00 +0000\n", "1-Jun-2016 20:30:00 +0000\n", "1-Jun-2016 21:30:00 +0000\n", "1-Jun-2016 22:30:00 +0000\n", "1-Jun-2016 23:30:00 +0000\n", "2-Jun-2016 00:30:00 +0000\n", "2-Jun-2016 01:30:00 +0000\n", "2-Jun-2016 02:30:00 +0000\n", "2-Jun-2016 03:30:00 +0000\n", "2-Jun-2016 04:30:00 +0000\n", "2-Jun-2016 05:30:00 +0000\n", "2-Jun-2016 06:30:00 +0000\n", "2-Jun-2016 07:30:00 +0000\n", "2-Jun-2016 08:30:00 +0000\n", "2-Jun-2016 09:30:00 +0000\n", "2-Jun-2016 10:30:00 +0000\n", "2-Jun-2016 11:30:00 +0000\n", "2-Jun-2016 12:30:00 +0000\n", "2-Jun-2016 13:30:00 +0000\n", "2-Jun-2016 14:30:00 +0000\n", "2-Jun-2016 15:30:00 +0000\n", "2-Jun-2016 16:30:00 +0000\n", "2-Jun-2016 17:30:00 +0000\n", "2-Jun-2016 18:30:00 +0000\n", "2-Jun-2016 19:30:00 +0000\n", "2-Jun-2016 20:30:00 +0000\n", "2-Jun-2016 21:30:00 +0000\n", "2-Jun-2016 22:30:00 +0000\n", "2-Jun-2016 23:30:00 +0000\n", "CPU times: user 7 s, sys: 14.5 s, total: 21.5 s\n", "Wall time: 21.6 s\n" ] } ], "source": [ "%%time\n", "\n", "var = 'vosaline'\n", "locn = central_ji\n", "filepath = Path('central_salinity.csv')\n", "\n", "with filepath.open('wt') as f:\n", " for dataset in datasets:\n", " with xarray.open_dataset(dataset) as ds:\n", " ds_var = ds.data_vars[var].isel(y=locn[0], x=locn[1])\n", " write_csv(f, ds.time_counter, ds_var)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Best observed timings:\n", "\n", "In notebook:\n", "\n", "Using xarray.open_mf_dataset() for 1 day's results:\n", "\n", " CPU times: user 1min 41s, sys: 3min 53s, total: 5min 35s\n", " Wall time: 5min 35s\n", "\n", "Using xarray.open_dataset() for 1 day's results:\n", "\n", " CPU times: user 3.82 s, sys: 756 ms, total: 4.58 s\n", " Wall time: 4.82 s\n", " \n", "From command-line:\n", "\n", "Using xarray.open_mf_dataset() for 1 day's results:\n", "\n", "\n", "Using xarray.open_dataset() for 1 day's results:\n", "\n", " real\t0m11.714s\n", " user\t0m8.140s\n", " sys\t0m2.644s" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Depths" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [], "source": [ "with Path('depths.csv').open('wt') as f:\n", " with xarray.open_dataset(datasets[0]) as ds:\n", " for depth in ds.deptht.values:\n", " f.write(f'{depth}\\n')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "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.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }