Skip to content

Commit

Permalink
Merge pull request #31 from ocefpaf/use_pytest_style
Browse files Browse the repository at this point in the history
Use pytest style in tests
  • Loading branch information
ocefpaf authored May 24, 2022
2 parents 98df2f3 + f12486a commit ded5620
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 380 deletions.
87 changes: 31 additions & 56 deletions notebooks/ocean_s_coordinate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"url = \"http://geoport.whoi.edu/thredds/dodsC/examples/bora_feb.nc\""
"import dask\n",
"\n",
"dask.config.set(scheduler=\"single-threaded\")\n",
"\n",
"\n",
"url = \"https://geoport.whoi.edu/thredds/dodsC/examples/bora_feb.nc\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from netCDF4 import Dataset\n",
"\n",
"from odvc import get_formula_terms_variables\n",
"\n",
"from odvc.parse_formula_terms import get_formula_terms_variables\n",
"\n",
"nc = Dataset(url)\n",
"\n",
Expand All @@ -34,12 +33,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from odvc import get_formula_terms\n",
"from odvc.parse_formula_terms import get_formula_terms\n",
"\n",
"formula_terms = get_formula_terms(var[0])\n",
"\n",
Expand All @@ -49,13 +46,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from odvc import get_formula_terms_dims\n",
"\n",
"from odvc.parse_formula_terms import get_formula_terms_dims\n",
"\n",
"dims = get_formula_terms_dims(nc, formula_terms)\n",
"\n",
Expand All @@ -65,12 +59,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from odvc import z_shape\n",
"from odvc.parse_formula_terms import z_shape\n",
"\n",
"new_shape = z_shape(nc, dims)\n",
"\n",
Expand All @@ -80,13 +72,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from odvc import prepare_arrays\n",
"\n",
"from odvc.parse_formula_terms import prepare_arrays\n",
"\n",
"arrays = prepare_arrays(nc, formula_terms, new_shape)\n",
"\n",
Expand All @@ -96,9 +85,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"[(var, arr.shape) for var, arr in arrays.items()]"
Expand All @@ -107,14 +94,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from odvc import ocean_s_coordinate\n",
"\n",
"\n",
"z = ocean_s_coordinate(\n",
" arrays[\"s\"],\n",
" arrays[\"eta\"],\n",
Expand All @@ -130,15 +114,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"salt = nc.get_variables_by_attributes(long_name=\"averaged salinity\")[0]\n",
"temp = nc.get_variables_by_attributes(\n",
" long_name=\"averaged potential temperature\"\n",
")[0]\n",
"temp = nc.get_variables_by_attributes(long_name=\"averaged potential temperature\")[0]\n",
"\n",
"s = salt[-1, :, 45, 137]\n",
"t = temp[-1, :, 45, 137]\n",
Expand All @@ -149,19 +129,14 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"scrolled": false
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import mpl_toolkits.axisartist as AA\n",
"from mpl_toolkits.axes_grid1 import host_subplot\n",
"\n",
"import seaborn\n",
"seaborn.set(style='ticks')\n",
"\n",
"\n",
"def adjust_xlim(ax, offset):\n",
" x1, x2 = ax.get_xlim()\n",
Expand All @@ -185,12 +160,12 @@
"ax1.axis[\"bottom\"].toggle(all=False)\n",
"\n",
"ax0.set_ylabel(\"Depth (m)\")\n",
"ax0.set_xlabel(u\"Temperature (\\xb0C)\")\n",
"ax0.set_xlabel(\"Temperature (\\xb0C)\")\n",
"ax1.set_xlabel(r\"Salinity (g kg$^{-1}$)\")\n",
"\n",
"kw = dict(linewidth=2.5)\n",
"l0, = ax0.plot(t, -p, **kw)\n",
"l1, = ax1.plot(s, -p, **kw)\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",
Expand All @@ -202,23 +177,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.8"
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}
Loading

0 comments on commit ded5620

Please sign in to comment.