Skip to content

Commit

Permalink
pybop-team#282 Fix plotting_a_dataset example by installing latest …
Browse files Browse the repository at this point in the history
…pybop
  • Loading branch information
arjxn-py committed Jun 16, 2024
1 parent b9e3d65 commit 20becf7
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions examples/notebooks/Getting Started/plotting_a_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -12,23 +12,16 @@
"Note: you may need to restart the kernel to use updated packages.\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"ERROR: file:///D:/Arjun/PyBOP/examples/notebooks/Getting%20Started does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.\n"
]
}
],
"source": [
"%pip install --upgrade pip ipywidgets pybamm -q\n",
"%pip install pybop -q\n"
"%pip install git+https://github.com/pybop-team/PyBOP.git@develop -q"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -40,21 +33,9 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'pybop.models.lithium_ion' has no attribute 'DFN'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[27], line 4\u001b[0m\n\u001b[0;32m 2\u001b[0m parameter_set \u001b[38;5;241m=\u001b[39m pybop\u001b[38;5;241m.\u001b[39mParameterSet\u001b[38;5;241m.\u001b[39mpybamm(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mChen2020\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 3\u001b[0m parameter_set \u001b[38;5;241m=\u001b[39m pybamm\u001b[38;5;241m.\u001b[39mget_size_distribution_parameters(parameter_set)\n\u001b[1;32m----> 4\u001b[0m synth_model \u001b[38;5;241m=\u001b[39m \u001b[43mpybop\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlithium_ion\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mDFN\u001b[49m(\n\u001b[0;32m 5\u001b[0m parameter_set\u001b[38;5;241m=\u001b[39mparameter_set, options\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mparticle size\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdistribution\u001b[39m\u001b[38;5;124m\"\u001b[39m}\n\u001b[0;32m 6\u001b[0m )\n\u001b[0;32m 8\u001b[0m n_points \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m650\u001b[39m\n\u001b[0;32m 9\u001b[0m t_eval \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mlinspace(\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m1600\u001b[39m \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1000\u001b[39m, n_points)\n",
"\u001b[1;31mAttributeError\u001b[0m: module 'pybop.models.lithium_ion' has no attribute 'DFN'"
]
}
],
"outputs": [],
"source": [
"# Example synthetic data generation\n",
"parameter_set = pybop.ParameterSet.pybamm(\"Chen2020\")\n",
Expand All @@ -76,8 +57,28 @@
" }\n",
")\n",
"synth_model.build(dataset, init_soc=init_soc)\n",
"synth_model.signal = [\"Voltage [V]\"]\n",
"values = synth_model.simulate(t_eval=t_eval, inputs={})\n"
"synth_model.signal = [\"Voltage [V]\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"1024\" height=\"576\" style=\"\" viewBox=\"0 0 1024 576\"><rect x=\"0\" y=\"0\" width=\"1024\" height=\"576\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-de7821\"><g class=\"clips\"><clipPath id=\"clipde7821xyplot\" class=\"plotclip\"><rect width=\"955\" height=\"446\"/></clipPath><clipPath class=\"axesclip\" id=\"clipde7821x\"><rect x=\"59\" y=\"0\" width=\"955\" height=\"576\"/></clipPath><clipPath class=\"axesclip\" id=\"clipde7821y\"><rect x=\"0\" y=\"75\" width=\"1024\" height=\"446\"/></clipPath><clipPath class=\"axesclip\" id=\"clipde7821xy\"><rect x=\"59\" y=\"75\" width=\"955\" height=\"446\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"55\" y=\"71\" width=\"963\" height=\"454\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"minor-gridlayer\"><g class=\"x\"/><g class=\"y\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(242.65,0)\" d=\"M0,75v446\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(426.31,0)\" d=\"M0,75v446\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(609.96,0)\" d=\"M0,75v446\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(793.62,0)\" d=\"M0,75v446\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(977.27,0)\" d=\"M0,75v446\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,510.29)\" d=\"M59,0h955\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,454.31)\" d=\"M59,0h955\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,398.34)\" d=\"M59,0h955\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,342.36)\" d=\"M59,0h955\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,286.38)\" d=\"M59,0h955\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,230.41)\" d=\"M59,0h955\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,174.43)\" d=\"M59,0h955\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,118.45)\" d=\"M59,0h955\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"><path class=\"xzl zl crisp\" transform=\"translate(59,0)\" d=\"M0,75v446\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;\"/></g><g class=\"layer-between\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(59,75)\" clip-path=\"url(#clipde7821xyplot)\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter trace79866d\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M0,22.3L2.94,40.65L4.41,46.7L8.83,58.99L10.3,61.84L16.19,69.65L17.66,70.97L23.54,74.69L25.02,75.34L35.32,78.38L36.79,78.7L76.52,87.74L77.99,88.22L97.12,95.53L98.59,96.17L130.96,111.31L132.43,112.02L185.41,136.71L186.88,137.35L232.5,156.13L233.97,156.7L300.18,181.76L301.66,182.31L369.35,209.14L370.82,209.76L420.85,232.25L422.32,232.95L522.38,279.8L523.85,280.42L565.05,296.51L566.53,297.04L615.08,313.2L616.56,313.66L703.37,339.22L704.85,339.65L788.72,364.65L790.19,365.11L859.35,387.77L860.82,388.28L915.27,408.06L916.74,408.62L955,423.7\" style=\"vector-effect: none; fill: none; stroke: rgb(99, 110, 250); stroke-opacity: 1; stroke-width: 4px; opacity: 1;\"/></g><g class=\"points\"/><g class=\"text\"/></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"538\" transform=\"translate(59,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\">0</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"538\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(242.65,0)\">500</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"538\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(426.31,0)\">1000</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"538\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(609.96,0)\">1500</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"538\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(793.62,0)\">2000</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"538\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(977.27,0)\">2500</text></g></g><g class=\"yaxislayer-above\"><g class=\"ytick\"><text text-anchor=\"end\" x=\"54\" y=\"4.199999999999999\" transform=\"translate(0,510.29)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\">3.3</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"54\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,454.31)\">3.4</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"54\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,398.34)\">3.5</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"54\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,342.36)\">3.6</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"54\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,286.38)\">3.7</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"54\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,230.41)\">3.8</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"54\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,174.43)\">3.9</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"54\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,118.45)\">4</text></g></g><g class=\"overaxes-above\"/></g></g><g class=\"polarlayer\"/><g class=\"smithlayer\"/><g class=\"ternarylayer\"/><g class=\"geolayer\"/><g class=\"funnelarealayer\"/><g class=\"pielayer\"/><g class=\"iciclelayer\"/><g class=\"treemaplayer\"/><g class=\"sunburstlayer\"/><g class=\"glimages\"/><defs id=\"topdefs-de7821\"><g class=\"clips\"/><clipPath id=\"legendde7821\"><rect width=\"74\" height=\"29\" x=\"0\" y=\"0\"/></clipPath></defs><g class=\"layer-above\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"infolayer\"><g class=\"legend\" pointer-events=\"all\" transform=\"translate(940,75)\"><rect class=\"bg\" shape-rendering=\"crispEdges\" width=\"74\" height=\"29\" x=\"0\" y=\"0\" style=\"stroke: rgb(68, 68, 68); stroke-opacity: 1; fill: rgb(255, 255, 255); fill-opacity: 1; stroke-width: 0px;\"/><g class=\"scrollbox\" transform=\"\" clip-path=\"url(#legendde7821)\"><g class=\"groups\"><g class=\"traces\" transform=\"translate(0,14.5)\" style=\"opacity: 1;\"><text class=\"legendtext\" text-anchor=\"start\" x=\"40\" y=\"4.680000000000001\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre;\">Data</text><g class=\"layers\" style=\"opacity: 1;\"><g class=\"legendfill\"/><g class=\"legendlines\"><path class=\"js-line\" d=\"M5,0h30\" style=\"fill: none; stroke: rgb(99, 110, 250); stroke-opacity: 1; stroke-width: 4px;\"/></g><g class=\"legendsymbols\"><g class=\"legendpoints\"/></g></g><rect class=\"legendtoggle\" x=\"0\" y=\"-9.5\" width=\"68.390625\" height=\"19\" style=\"fill: rgb(0, 0, 0); fill-opacity: 0;\"/></g></g></g><rect class=\"scrollbar\" rx=\"20\" ry=\"3\" width=\"0\" height=\"0\" x=\"0\" y=\"0\" style=\"fill: rgb(128, 139, 164); fill-opacity: 1;\"/></g><g class=\"g-gtitle\"/><g class=\"g-xtitle\"><text class=\"xtitle\" x=\"536.5\" y=\"561.3\" text-anchor=\"middle\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 14px; fill: rgb(42, 63, 95); opacity: 1; white-space: pre;\">Time / s</text></g><g class=\"g-ytitle\"><text class=\"ytitle\" transform=\"rotate(-90,18.975,298)\" x=\"18.975\" y=\"298\" text-anchor=\"middle\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 14px; fill: rgb(42, 63, 95); opacity: 1; white-space: pre;\">Voltage [V]</text></g></g></svg>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"values = synth_model.predict(t_eval=t_eval)\n",
"dataset[\"Voltage [V]\"] = values[\"Voltage [V]\"].data\n",
"pybop.plot_dataset(dataset);"
]
}
],
Expand All @@ -97,7 +98,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 20becf7

Please sign in to comment.