{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Openoil sample output netCDF file\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\nfrom datetime import timedelta\nfrom opendrift.readers import reader_netCDF_CF_generic\nfrom opendrift.readers import reader_constant\nfrom opendrift.models.openoil import OpenOil\n\no = OpenOil(loglevel=20, weathering_model='noaa')\n\nrc = reader_constant.Reader({'x_wind': 5,\n 'y_wind': 4})\n\n# Arome\nreader_arome = reader_netCDF_CF_generic.Reader(o.test_data_folder() +\n '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')\n\n# Norkyst\nreader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() +\n '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')\n\no.add_reader([rc, reader_norkyst, reader_arome])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seed oil elements at defined position and time\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "time = [reader_arome.start_time,\n reader_arome.start_time + timedelta(hours=1)]\no.seed_elements(lon=5.05, lat=59.95, radius=1500, number=100,\n time=time, z=0, m3_per_hour=2, oil_type='TAU 1999')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running model\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ncfile = 'openoil_sample_output.nc'\no.run(steps=4*8, time_step=900, time_step_output=3600, outfile=ncfile)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print and plot results\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.plot_oil_budget()\no.plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "ncdump of the output file\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from subprocess import check_output\nargs = [ \"ncdump\", \"-h\", ncfile ]\nncdump = check_output(args).decode().strip()\nprint(ncdump)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. only :: html\n\n .. container:: sphx-glr-download\n\n :download:`Download sample file `\n\n" ] } ], "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.11.6" } }, "nbformat": 4, "nbformat_minor": 0 }