diff --git a/PyDynamic_tutorials/uncertainty/02 Basic interpolation.ipynb b/PyDynamic_tutorials/uncertainty/02 Basic interpolation.ipynb index 7a25c41..3a55ae0 100644 --- a/PyDynamic_tutorials/uncertainty/02 Basic interpolation.ipynb +++ b/PyDynamic_tutorials/uncertainty/02 Basic interpolation.ipynb @@ -1773,6 +1773,143 @@ "name": "#%%\n" } }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.004 0.01 ] [2.47691988 1.41385091] [0.0371538 0.02120776]\n", + "[0.004 0.01 ] [2.47691988 1.41385091] [0.0371538 0.02120776]\n", + "[0.004 0.01 ] [2.47691988 1.41385091] [0.0371538 0.02120776]\n", + "[0.004 0.01 ] [2.47691988 1.41385091] [0.0371538 0.02120776]\n", + "[0.004 0.0055 0.007 0.0085 0.01 ] [2.47691988 3.71268867 4.03891907 3.31838263 1.41385091] [0.0371538 0.0473224 0.04284885 0.04478872 0.02120776]\n", + "[0.004 0.0055 0.007 0.0085 0.01 ] [2.47691988 4.1246116 4.1246116 3.95322654 1.41385091] [0.0371538 0.06186917 0.06186917 0.0592984 0.02120776]\n", + "[0.004 0.0055 0.007 0.0085 0.01 ] [2.47691988 4.1246116 3.95322654 1.41385091 1.41385091] [0.0371538 0.06186917 0.0592984 0.02120776 0.02120776]\n", + "[0.004 0.0055 0.007 0.0085 0.01 ] [2.47691988 2.47691988 4.1246116 3.95322654 1.41385091] [0.0371538 0.0371538 0.06186917 0.0592984 0.02120776]\n", + "[0.004 0.00485714 0.00571429 0.00657143 0.00742857 0.00828571\n", + " 0.00914286 0.01 ] [2.47691988 3.18307347 3.88922707 4.07564444 4.0021937 3.59045859\n", + " 2.50215475 1.41385091] [0.0371538 0.03396776 0.05329567 0.04732865 0.04589666 0.05091741\n", + " 0.02815519 0.02120776]\n", + "[0.004 0.00485714 0.00571429 0.00657143 0.00742857 0.00828571\n", + " 0.00914286 0.01 ] [2.47691988 2.47691988 4.1246116 4.1246116 3.95322654 3.95322654\n", + " 1.41385091 1.41385091] [0.0371538 0.0371538 0.06186917 0.06186917 0.0592984 0.0592984\n", + " 0.02120776 0.02120776]\n", + "[0.004 0.00485714 0.00571429 0.00657143 0.00742857 0.00828571\n", + " 0.00914286 0.01 ] [2.47691988 4.1246116 4.1246116 3.95322654 3.95322654 1.41385091\n", + " 1.41385091 1.41385091] [0.0371538 0.06186917 0.06186917 0.0592984 0.0592984 0.02120776\n", + " 0.02120776 0.02120776]\n", + "[0.004 0.00485714 0.00571429 0.00657143 0.00742857 0.00828571\n", + " 0.00914286 0.01 ] [2.47691988 2.47691988 2.47691988 4.1246116 4.1246116 3.95322654\n", + " 3.95322654 1.41385091] [0.0371538 0.0371538 0.0371538 0.06186917 0.06186917 0.0592984\n", + " 0.0592984 0.02120776]\n", + "[0.004 0.0046 0.0052 0.0058 0.0064 0.007 0.0076 0.0082 0.0088 0.0094\n", + " 0.01 ] [2.47691988 2.9712274 3.46553491 3.95984243 4.09033459 4.03891907\n", + " 3.98750355 3.69928898 2.93747629 2.1756636 1.41385091] [0.0371538 0.03195152 0.03998588 0.05580607 0.05089637 0.04284885\n", + " 0.04902595 0.05341068 0.03657637 0.02317011 0.02120776]\n", + "[0.004 0.0046 0.0052 0.0058 0.0064 0.007 0.0076 0.0082 0.0088 0.0094\n", + " 0.01 ] [2.47691988 2.47691988 4.1246116 4.1246116 4.1246116 4.1246116\n", + " 3.95322654 3.95322654 3.95322654 1.41385091 1.41385091] [0.0371538 0.0371538 0.06186917 0.06186917 0.06186917 0.06186917\n", + " 0.0592984 0.0592984 0.0592984 0.02120776 0.02120776]\n", + "[0.004 0.0046 0.0052 0.0058 0.0064 0.007 0.0076 0.0082 0.0088 0.0094\n", + " 0.01 ] [2.47691988 4.1246116 4.1246116 4.1246116 3.95322654 3.95322654\n", + " 3.95322654 1.41385091 1.41385091 1.41385091 1.41385091] [0.0371538 0.06186917 0.06186917 0.06186917 0.0592984 0.0592984\n", + " 0.0592984 0.02120776 0.02120776 0.02120776 0.02120776]\n", + "[0.004 0.0046 0.0052 0.0058 0.0064 0.007 0.0076 0.0082 0.0088 0.0094\n", + " 0.01 ] [2.47691988 2.47691988 2.47691988 2.47691988 4.1246116 4.1246116\n", + " 4.1246116 3.95322654 3.95322654 3.95322654 1.41385091] [0.0371538 0.0371538 0.0371538 0.0371538 0.06186917 0.06186917\n", + " 0.06186917 0.0592984 0.0592984 0.0592984 0.02120776]\n", + "[0.004 0.00446154 0.00492308 0.00538462 0.00584615 0.00630769\n", + " 0.00676923 0.00723077 0.00769231 0.00815385 0.00861538 0.00907692\n", + " 0.00953846 0.01 ] [2.47691988 2.85715643 3.23739298 3.61762953 3.99786608 4.09824467\n", + " 4.05869427 4.01914387 3.97959347 3.75788996 3.17188019 2.58587043\n", + " 1.99986067 1.41385091] [0.0371538 0.03194769 0.0348658 0.04433185 0.05718147 0.05313978\n", + " 0.04438177 0.04356442 0.05107041 0.05476129 0.04156812 0.02965537\n", + " 0.02129306 0.02120776]\n", + "[0.004 0.00446154 0.00492308 0.00538462 0.00584615 0.00630769\n", + " 0.00676923 0.00723077 0.00769231 0.00815385 0.00861538 0.00907692\n", + " 0.00953846 0.01 ] [2.47691988 2.47691988 2.47691988 4.1246116 4.1246116 4.1246116\n", + " 4.1246116 3.95322654 3.95322654 3.95322654 3.95322654 1.41385091\n", + " 1.41385091 1.41385091] [0.0371538 0.0371538 0.0371538 0.06186917 0.06186917 0.06186917\n", + " 0.06186917 0.0592984 0.0592984 0.0592984 0.0592984 0.02120776\n", + " 0.02120776 0.02120776]\n", + "[0.004 0.00446154 0.00492308 0.00538462 0.00584615 0.00630769\n", + " 0.00676923 0.00723077 0.00769231 0.00815385 0.00861538 0.00907692\n", + " 0.00953846 0.01 ] [2.47691988 4.1246116 4.1246116 4.1246116 4.1246116 3.95322654\n", + " 3.95322654 3.95322654 3.95322654 1.41385091 1.41385091 1.41385091\n", + " 1.41385091 1.41385091] [0.0371538 0.06186917 0.06186917 0.06186917 0.06186917 0.0592984\n", + " 0.0592984 0.0592984 0.0592984 0.02120776 0.02120776 0.02120776\n", + " 0.02120776 0.02120776]\n", + "[0.004 0.00446154 0.00492308 0.00538462 0.00584615 0.00630769\n", + " 0.00676923 0.00723077 0.00769231 0.00815385 0.00861538 0.00907692\n", + " 0.00953846 0.01 ] [2.47691988 2.47691988 2.47691988 2.47691988 2.47691988 4.1246116\n", + " 4.1246116 4.1246116 4.1246116 3.95322654 3.95322654 3.95322654\n", + " 3.95322654 1.41385091] [0.0371538 0.0371538 0.0371538 0.0371538 0.0371538 0.06186917\n", + " 0.06186917 0.06186917 0.06186917 0.0592984 0.0592984 0.0592984\n", + " 0.0592984 0.02120776]\n", + "[0.004 0.004375 0.00475 0.005125 0.0055 0.005875 0.00625 0.006625\n", + " 0.007 0.007375 0.00775 0.008125 0.0085 0.008875 0.00925 0.009625\n", + " 0.01 ] [2.47691988 2.78586208 3.09480427 3.40374647 3.71268867 4.02163087\n", + " 4.10318847 4.07105377 4.03891907 4.00678437 3.97464967 3.79451557\n", + " 3.31838263 2.8422497 2.36611677 1.88998384 1.41385091] [0.0371538 0.03233966 0.03282536 0.03841037 0.0473224 0.05804881\n", + " 0.05464062 0.04639633 0.04284885 0.04511994 0.05245928 0.05560805\n", + " 0.04478872 0.03462178 0.02588766 0.02050702 0.02120776]\n", + "[0.004 0.004375 0.00475 0.005125 0.0055 0.005875 0.00625 0.006625\n", + " 0.007 0.007375 0.00775 0.008125 0.0085 0.008875 0.00925 0.009625\n", + " 0.01 ] [2.47691988 2.47691988 2.47691988 4.1246116 4.1246116 4.1246116\n", + " 4.1246116 4.1246116 4.1246116 3.95322654 3.95322654 3.95322654\n", + " 3.95322654 3.95322654 1.41385091 1.41385091 1.41385091] [0.0371538 0.0371538 0.0371538 0.06186917 0.06186917 0.06186917\n", + " 0.06186917 0.06186917 0.06186917 0.0592984 0.0592984 0.0592984\n", + " 0.0592984 0.0592984 0.02120776 0.02120776 0.02120776]\n", + "[0.004 0.004375 0.00475 0.005125 0.0055 0.005875 0.00625 0.006625\n", + " 0.007 0.007375 0.00775 0.008125 0.0085 0.008875 0.00925 0.009625\n", + " 0.01 ] [2.47691988 4.1246116 4.1246116 4.1246116 4.1246116 4.1246116\n", + " 3.95322654 3.95322654 3.95322654 3.95322654 3.95322654 1.41385091\n", + " 1.41385091 1.41385091 1.41385091 1.41385091 1.41385091] [0.0371538 0.06186917 0.06186917 0.06186917 0.06186917 0.06186917\n", + " 0.0592984 0.0592984 0.0592984 0.0592984 0.0592984 0.02120776\n", + " 0.02120776 0.02120776 0.02120776 0.02120776 0.02120776]\n", + "[0.004 0.004375 0.00475 0.005125 0.0055 0.005875 0.00625 0.006625\n", + " 0.007 0.007375 0.00775 0.008125 0.0085 0.008875 0.00925 0.009625\n", + " 0.01 ] [2.47691988 2.47691988 2.47691988 2.47691988 2.47691988 2.47691988\n", + " 4.1246116 4.1246116 4.1246116 4.1246116 4.1246116 3.95322654\n", + " 3.95322654 3.95322654 3.95322654 3.95322654 1.41385091] [0.0371538 0.0371538 0.0371538 0.0371538 0.0371538 0.0371538\n", + " 0.06186917 0.06186917 0.06186917 0.06186917 0.06186917 0.0592984\n", + " 0.0592984 0.0592984 0.0592984 0.0592984 0.02120776]\n" + ] + } + ], + "source": [ + "# Create plots of interpolated values and uncertainties for the increasing number of\n", + "# interpolation nodes.\n", + "interpolation_dict = {}\n", + "for x_new in x_news:\n", + " for i_kind in (\"linear\", \"nearest\", \"next\", \"previous\"):\n", + " # Conduct the actual interpolation for the current set of interpolation nodes and kind.\n", + " x_new, y_new, uy_new = interp1d_unc(t_new=x_new, t=x, y=y, uy=uy, kind=i_kind)\n", + " print(x_new, y_new, uy_new)\n", + "\n", + " # Create plot of the interpolated values.\n", + " curve_interp = hv.Curve(\n", + " (x_new, y_new),\n", + " timestamp_labels,\n", + " measurement_labels,\n", + " label=\"interpolated values\",\n", + " )\n", + "\n", + " # Create plot of the interpolated uncertainties.\n", + " interp_uncertainties = hv.Spread(\n", + " (x_new, y_new, uy_new),\n", + " vdims=[measurement_labels, \"Associated Uncertainty\"],\n", + " kdims=timestamp_labels,\n", + " label=\"interpolated uncertainties\",\n", + " )\n", + "\n", + " interpolation_dict[x_new.size, i_kind] = curve_interp * interp_uncertainties" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, "outputs": [ { "data": {}, @@ -1789,12 +1926,12 @@ "\n", "\n", "\n", - "
\n", + "
\n", "\n", "