{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import dask\n", "\n", "dask.config.set(scheduler=\"single-threaded\")\n", "\n", "\n", "url = (\n", " \"http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/\"\n", " \"Forecasts/NECOFS_GOM3_FORECAST.nc\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from netCDF4 import Dataset\n", "\n", "from odvc.parse_formula_terms import get_formula_terms_variables\n", "\n", "nc = Dataset(url)\n", "\n", "var = get_formula_terms_variables(nc)\n", "\n", "var" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from odvc.parse_formula_terms import get_formula_terms\n", "\n", "formula_terms = get_formula_terms(var[0])\n", "\n", "formula_terms" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from odvc.parse_formula_terms import get_formula_terms_dims\n", "\n", "dims = get_formula_terms_dims(nc, formula_terms)\n", "\n", "dims" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from odvc.parse_formula_terms import z_shape\n", "\n", "new_shape = z_shape(nc, dims)\n", "\n", "new_shape" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from odvc.parse_formula_terms import prepare_arrays\n", "\n", "arrays = prepare_arrays(nc, formula_terms, new_shape)\n", "\n", "arrays" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from odvc import ocean_sigma_coordinate\n", "\n", "z = ocean_sigma_coordinate(arrays[\"sigma\"], arrays[\"eta\"], arrays[\"depth\"])\n", "print(z.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "salt = nc.get_variables_by_attributes(\n", " standard_name=\"sea_water_salinity\",\n", ")[0]\n", "temp = nc.get_variables_by_attributes(\n", " standard_name=\"sea_water_potential_temperature\",\n", ")[0]\n", "\n", "s = salt[-1, :, 175]\n", "t = temp[-1, :, 175]\n", "p = z[-1, :, 175]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "from mpl_toolkits import axisartist\n", "from mpl_toolkits.axes_grid1 import host_subplot\n", "\n", "\n", "def adjust_xlim(ax, offset):\n", " x1, x2 = ax.get_xlim()\n", " ax.set_xlim(x1 - offset, x2 + offset)\n", "\n", "\n", "fig = plt.figure(figsize=(6, 9))\n", "fig.subplots_adjust(bottom=0.1, top=0.85)\n", "ax0 = host_subplot(111, axes_class=axisartist.Axes)\n", "\n", "ax0.invert_yaxis()\n", "ax1 = ax0.twiny()\n", "\n", "new_axis0 = ax0.get_grid_helper().new_fixed_axis\n", "new_axis1 = ax1.get_grid_helper().new_fixed_axis\n", "\n", "ax0.axis[\"top\"] = new_axis0(loc=\"top\", axes=ax0, offset=(0, 0))\n", "ax1.axis[\"top\"] = new_axis1(loc=\"top\", axes=ax1, offset=(0, 40))\n", "\n", "ax0.axis[\"bottom\"].toggle(all=False)\n", "ax1.axis[\"bottom\"].toggle(all=False)\n", "\n", "ax0.set_ylabel(\"Depth (m)\")\n", "ax0.set_xlabel(\"Temperature (\\xb0C)\")\n", "ax1.set_xlabel(r\"Salinity (g kg$^{-1}$)\")\n", "\n", "kw = {\"linewidth\": 2.5}\n", "(l0,) = ax0.plot(t, -p, **kw)\n", "(l1,) = ax1.plot(s, -p, **kw)\n", "\n", "adjust_xlim(ax0, offset=0.05)\n", "adjust_xlim(ax1, offset=0.05)\n", "\n", "ax0.axis[\"top\"].label.set_color(l0.get_color())\n", "ax1.axis[\"top\"].label.set_color(l1.get_color())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.7" } }, "nbformat": 4, "nbformat_minor": 1 }