From cd404e61a7ac16166cfa0d1ae203dc59b6854a82 Mon Sep 17 00:00:00 2001 From: helene-pisani-4ss Date: Mon, 1 Jul 2024 15:14:13 +0200 Subject: [PATCH] clean --- src/waveresponse/sandbox.ipynb | 271 --------------------------------- 1 file changed, 271 deletions(-) delete mode 100644 src/waveresponse/sandbox.ipynb diff --git a/src/waveresponse/sandbox.ipynb b/src/waveresponse/sandbox.ipynb deleted file mode 100644 index 2989dd4..0000000 --- a/src/waveresponse/sandbox.ipynb +++ /dev/null @@ -1,271 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Example using only interp2d and RectBivariateSpline" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\helene.pisani\\AppData\\Local\\Temp\\ipykernel_26648\\142980996.py:11: DeprecationWarning: `interp2d` is deprecated in SciPy 1.10 and will be removed in SciPy 1.14.0.\n", - "\n", - "For legacy code, nearly bug-for-bug compatible replacements are\n", - "`RectBivariateSpline` on regular grids, and `bisplrep`/`bisplev` for\n", - "scattered 2D data.\n", - "\n", - "In new code, for regular grids use `RegularGridInterpolator` instead.\n", - "For scattered data, prefer `LinearNDInterpolator` or\n", - "`CloughTocher2DInterpolator`.\n", - "\n", - "For more details see\n", - "`https://scipy.github.io/devdocs/notebooks/interp_transition_guide.html`\n", - "\n", - " f1 = interp2d(xp, yp, z, kind='linear')\n", - "C:\\Users\\helene.pisani\\AppData\\Local\\Temp\\ipykernel_26648\\142980996.py:17: DeprecationWarning: `interp2d` is deprecated in SciPy 1.10 and will be removed in SciPy 1.14.0.\n", - "\n", - "For legacy code, nearly bug-for-bug compatible replacements are\n", - "`RectBivariateSpline` on regular grids, and `bisplrep`/`bisplev` for\n", - "scattered 2D data.\n", - "\n", - "In new code, for regular grids use `RegularGridInterpolator` instead.\n", - "For scattered data, prefer `LinearNDInterpolator` or\n", - "`CloughTocher2DInterpolator`.\n", - "\n", - "For more details see\n", - "`https://scipy.github.io/devdocs/notebooks/interp_transition_guide.html`\n", - "\n", - " r1 = f1(x, y)\n" - ] - } - ], - "source": [ - "from _core import complex_to_polar, polar_to_complex, Grid\n", - "import numpy as np \n", - "from scipy.interpolate import interp2d, RectBivariateSpline\n", - "\n", - "\n", - "yp = np.linspace(0.0, 2.0, 20)\n", - "xp = np.linspace(0.0, 359.0, 20)\n", - "\n", - "z = np.array([[6 * x_i + 7 * y_i for x_i in xp] for y_i in yp])\n", - "\n", - "f1 = interp2d(xp, yp, z, kind='linear')\n", - "f2 = RectBivariateSpline(xp, yp, z.T)\n", - "\n", - "y = np.linspace(0.5, 1.0, 20)\n", - "x = np.linspace(5.0, 15.0, 10)\n", - "\n", - "r1 = f1(x, y)\n", - "r2 = f2(x, y).T\n", - "\n", - "if np.allclose(r1, r2):\n", - " print(True)\n", - "else:\n", - " print(False)" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], - "source": [ - "from scipy.interpolate import RegularGridInterpolator as RGI\n", - "import numpy as np\n", - "\n", - "a = 7\n", - "b = 6\n", - "y = np.linspace(0.0, 2.0, 20)\n", - "x = np.linspace(0.0, 359.0, 20)\n", - "z = np.array([[a * x_i + b * y_i for x_i in x] for y_i in y])\n", - "r = RGI((x, y), z.T, method='linear', bounds_error=False, fill_value=1.0)\n", - "\n", - "ynew = np.linspace(0.5, 1.0, 20)\n", - "xnew = np.linspace(5.0, 15.0, 10)\n", - "xxnew, yynew = np.meshgrid(xnew, ynew, indexing='ij', sparse=True)\n", - "r1 = r((xxnew, yynew))\n", - "r1\n", - "\n", - "r2 = np.array([[a * x_i + b * y_i for x_i in xnew] for y_i in ynew])\n", - "\n", - "if np.allclose(r1.T, r2):\n", - " print(True)\n", - "else:\n", - " print(False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Example comparing interpoalte method old with new. " - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], - "source": [ - "a = 7\n", - "b = 6\n", - "\n", - "yp = np.linspace(0.0, 2.0, 20)\n", - "xp = np.linspace(0.0, 359.0, 10)\n", - "vp = np.array([[a * x_i + b * y_i for x_i in xp] for y_i in yp])\n", - "grid = Grid(yp, xp, vp, freq_hz=True, degrees=True)\n", - "\n", - "y = np.linspace(0.5, 1.0, 20)\n", - "x = np.linspace(5.0, 15.0, 10)\n", - "vals_expect = np.array([[a * x_i + b * y_i for x_i in x] for y_i in y])\n", - "\n", - "vals_out = grid.interpolate(y, x, freq_hz=True, degrees=True)\n", - "vals_out\n", - "\n", - "vals_new = grid.interpolate_new(y,x,freq_hz=True, degrees=True)\n", - "vals_new.T\n", - "\n", - "if np.allclose(vals_out, vals_new.T):\n", - " print(True)\n", - "else:\n", - " print(False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'y' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[2], line 5\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m \n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mscipy\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01minterpolate\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m interp2d, RectBivariateSpline\n\u001b[1;32m----> 5\u001b[0m vals_expect \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marray([[a \u001b[38;5;241m*\u001b[39m x_i \u001b[38;5;241m+\u001b[39m b \u001b[38;5;241m*\u001b[39m y_i \u001b[38;5;28;01mfor\u001b[39;00m x_i \u001b[38;5;129;01min\u001b[39;00m x] \u001b[38;5;28;01mfor\u001b[39;00m y_i \u001b[38;5;129;01min\u001b[39;00m \u001b[43my\u001b[49m])\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m np\u001b[38;5;241m.\u001b[39mallclose(vals_out, vals_expect):\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;01mTrue\u001b[39;00m)\n", - "\u001b[1;31mNameError\u001b[0m: name 'y' is not defined" - ] - } - ], - "source": [ - "\n", - "\n", - "vals_expect = np.array([[a * x_i + b * y_i for x_i in x] for y_i in y])\n", - "if np.allclose(vals_out, vals_expect):\n", - " print(True)\n", - "else:\n", - " print(False)\n", - "print(vals_expect)" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[33.50000002 33.68421054 33.86842107 34.0526316 34.23684212 34.42105265\n", - " 34.60526318 34.7894737 34.97368423 35.15789475 35.34210528 35.52631581\n", - " 35.71052633 35.89473686 36.07894739 36.26315791 36.44736844 36.63157896\n", - " 36.81578949 37.00000002]\n", - "[33.5 33.68421053 33.86842105 34.05263158 34.23684211 34.42105263\n", - " 34.60526316 34.78947368 34.97368421 35.15789474 35.34210526 35.52631579\n", - " 35.71052632 35.89473684 36.07894737 36.26315789 36.44736842 36.63157895\n", - " 36.81578947 37. ]\n", - "False\n" - ] - } - ], - "source": [ - "from _core import complex_to_polar, polar_to_complex, Grid\n", - "import numpy as np \n", - "from scipy.interpolate import interp2d, RectBivariateSpline\n", - "\n", - "y = np.linspace(0.0, 2.0, 20)\n", - "x = np.linspace(0.0, 1.8*np.pi, 20)\n", - "\n", - "z = np.array([[6 * x_i + 7 * y_i for x_i in x] for y_i in y])\n", - "\n", - "grid = Grid(y,x,z, freq_hz=True, degrees=True)\n", - "\n", - "ynew = np.linspace(0.5, 1.0, 20)\n", - "xnew = np.linspace(5.0, 15.0, 10)\n", - "\n", - "r1 = grid.interpolate(ynew,xnew, freq_hz=True, degrees=True)\n", - "# f1 = interp2d(x, y, z, kind='linear')\n", - "f2 = RectBivariateSpline(x, y, z.T)\n", - "\n", - "# r1 = f1(xnew, ynew)\n", - "r2 = f2(xnew, ynew)\n", - "print(r1[0])\n", - "print(r2[0])\n", - "if np.allclose(r1.T, r2.T):\n", - " print(True)\n", - "else:\n", - " print(False)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".venv", - "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.10.7" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}