Skip to content

Commit

Permalink
codestyle (black + black[jupyter])
Browse files Browse the repository at this point in the history
  • Loading branch information
bcliang committed Feb 29, 2024
1 parent 6ab27a2 commit a96439f
Show file tree
Hide file tree
Showing 13 changed files with 1,254 additions and 1,196 deletions.
381 changes: 190 additions & 191 deletions demo/notebook_cyclicvoltammetry.ipynb
Original file line number Diff line number Diff line change
@@ -1,194 +1,193 @@
{
"nbformat": 4,
"nbformat_minor": 2,
"metadata": {
"colab": {
"name": "Gamry-Parser CyclicVoltammetry Example",
"version": "0.3.2",
"provenance": [],
"private_outputs": true,
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
"nbformat": 4,
"nbformat_minor": 2,
"metadata": {
"colab": {
"name": "Gamry-Parser CyclicVoltammetry Example",
"version": "0.3.2",
"provenance": [],
"private_outputs": true,
"collapsed_sections": []
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"source": [
"#@title Imports, initial setup (Ctrl+F9 to run all)\n",
"from google.colab import files \n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"\n",
"try:\n",
" import gamry_parser\n",
"except:\n",
" subprocess.run(\n",
" [\"pip\", \"install\", \"gamry-parser\"], \n",
" encoding=\"utf-8\", \n",
" shell=False)\n",
"finally:\n",
" import gamry_parser\n",
"\n",
"p = parser.CyclicVoltammetry()\n",
" \n",
"print('Done.')"
],
"outputs": [],
"metadata": {
"id": "WF08aBjO8Lvh",
"colab_type": "code",
"cellView": "form",
"colab": {}
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"\"\"\"\n",
"### SCRIPT CONFIGURATION SETTINGS ###\n",
"\"\"\"\n",
"\n",
"\"\"\"\n",
"DATA SOURCE\n",
"\"\"\"\n",
"upload_files = True\n",
"\n",
"\"\"\"\n",
"PLOTTING\n",
"Plots are generated in the notebook. They are not saved / exported.\n",
"\"\"\"\n",
"show_plots = True # do we want to show analysis plots in this notebook?\n",
"compare_curves = 3 # compare a specific curve across files\n",
"\n",
"\n",
"print('Done.')"
],
"outputs": [],
"metadata": {
"id": "qPt8TDQgA0h6",
"colab_type": "code",
"cellView": "code",
"colab": {}
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"#@title DTA File\n",
"if upload_files:\n",
" experiment = files.upload()\n",
"else:\n",
" !wget -c https://raw.githubusercontent.com/bcliang/gamry-parser/master/tests/cv_data.dta\n",
" experiment = [\"cv_data.dta\"]\n",
"\n"
],
"outputs": [],
"metadata": {
"id": "3cK_P2Clmksm",
"colab_type": "code",
"cellView": "form",
"colab": {}
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"#@title Load and Plot Curve Data\n",
"\n",
"for f in experiment:\n",
" p.load(f)\n",
" \n",
" # generate a plot based on the first curve listed in the file.\n",
" data = p.curve(p.curve_count) \n",
" \n",
" # print to screen\n",
" print('Data Preview: Last Curve')\n",
" print(data.iloc[:5])\n",
" \n",
" # matplotlib fig\n",
" if show_plots:\n",
" fig, ax = plt.subplots(figsize=(18,8))\n",
" for i in range(p.curve_count):\n",
" data = p.curve(i)\n",
" trace = ax.plot(data['Vf'], data['Im']*1e6, label=\"curve {}\".format(i))\n",
" \n",
" ax.set_title(\"{}, {} curves\".format(f, p.curve_count), fontsize=18)\n",
" ax.set_xlabel('Potential (V)')\n",
" ax.set_ylabel('Current (A)', fontsize=14)\n",
" plt.show()"
],
"outputs": [],
"metadata": {
"id": "mxwEyYWICCYs",
"colab_type": "code",
"cellView": "form",
"colab": {}
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"#@title Compare a specific curve across loaded files\n",
"\n",
"fig, ax = plt.subplots(figsize=(18,8))\n",
" \n",
"for f in experiment:\n",
" p.load(f)\n",
" \n",
" # generate a plot based on the first curve listed in the file.\n",
" if p.curve_count > compare_curves:\n",
" data = p.curve(compare_curves) \n",
" trace = ax.plot(data['Vf'], data['Im']*1e6, label=\"file {}\".format(f))\n",
" \n",
"ax.set_title(\"CyclicVoltammetry Test, Compare Curve #{}\".format(compare_curves), fontsize=18)\n",
"ax.set_xlabel('Potential (V)')\n",
"ax.set_ylabel('Current (A)', fontsize=14)\n",
"ax.legend()\n",
"plt.show()"
],
"outputs": [],
"metadata": {
"id": "AQc4jnhlURDV",
"colab_type": "code",
"colab": {},
"cellView": "form"
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"#@title Download All Curves, All Experiments\n",
"\n",
"aggreg = pd.DataFrame()\n",
"\n",
"for f in experiment:\n",
" p.load(f)\n",
" \n",
" # use the curves @property to retrieve all curve data\n",
" for df in p.curves:\n",
" aggreg = aggreg.append(df)\n",
" \n",
" \n",
"aggreg.to_csv('results.csv')\n",
"files.download('results.csv')"
],
"outputs": [],
"metadata": {
"id": "ZPXwezuvmgZ0",
"colab_type": "code",
"cellView": "form",
"colab": {}
}
}
]
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"source": [
"# @title Imports, initial setup (Ctrl+F9 to run all)\n",
"from google.colab import files\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"\n",
"try:\n",
" import gamry_parser\n",
"except:\n",
" subprocess.run([\"pip\", \"install\", \"gamry-parser\"], encoding=\"utf-8\", shell=False)\n",
"finally:\n",
" import gamry_parser\n",
"\n",
"p = parser.CyclicVoltammetry()\n",
"\n",
"print(\"Done.\")"
],
"outputs": [],
"metadata": {
"id": "WF08aBjO8Lvh",
"colab_type": "code",
"cellView": "form",
"colab": {}
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"\"\"\"\n",
"### SCRIPT CONFIGURATION SETTINGS ###\n",
"\"\"\"\n",
"\n",
"\"\"\"\n",
"DATA SOURCE\n",
"\"\"\"\n",
"upload_files = True\n",
"\n",
"\"\"\"\n",
"PLOTTING\n",
"Plots are generated in the notebook. They are not saved / exported.\n",
"\"\"\"\n",
"show_plots = True # do we want to show analysis plots in this notebook?\n",
"compare_curves = 3 # compare a specific curve across files\n",
"\n",
"\n",
"print(\"Done.\")"
],
"outputs": [],
"metadata": {
"id": "qPt8TDQgA0h6",
"colab_type": "code",
"cellView": "code",
"colab": {}
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"#@title DTA File\n",
"if upload_files:\n",
" experiment = files.upload()\n",
"else:\n",
" !wget -c https://raw.githubusercontent.com/bcliang/gamry-parser/master/tests/cv_data.dta\n",
" experiment = [\"cv_data.dta\"]\n",
"\n"
],
"outputs": [],
"metadata": {
"id": "3cK_P2Clmksm",
"colab_type": "code",
"cellView": "form",
"colab": {}
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"# @title Load and Plot Curve Data\n",
"\n",
"for f in experiment:\n",
" p.load(f)\n",
"\n",
" # generate a plot based on the first curve listed in the file.\n",
" data = p.curve(p.curve_count)\n",
"\n",
" # print to screen\n",
" print(\"Data Preview: Last Curve\")\n",
" print(data.iloc[:5])\n",
"\n",
" # matplotlib fig\n",
" if show_plots:\n",
" fig, ax = plt.subplots(figsize=(18, 8))\n",
" for i in range(p.curve_count):\n",
" data = p.curve(i)\n",
" trace = ax.plot(data[\"Vf\"], data[\"Im\"] * 1e6, label=\"curve {}\".format(i))\n",
"\n",
" ax.set_title(\"{}, {} curves\".format(f, p.curve_count), fontsize=18)\n",
" ax.set_xlabel(\"Potential (V)\")\n",
" ax.set_ylabel(\"Current (A)\", fontsize=14)\n",
" plt.show()"
],
"outputs": [],
"metadata": {
"id": "mxwEyYWICCYs",
"colab_type": "code",
"cellView": "form",
"colab": {}
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"# @title Compare a specific curve across loaded files\n",
"\n",
"fig, ax = plt.subplots(figsize=(18, 8))\n",
"\n",
"for f in experiment:\n",
" p.load(f)\n",
"\n",
" # generate a plot based on the first curve listed in the file.\n",
" if p.curve_count > compare_curves:\n",
" data = p.curve(compare_curves)\n",
" trace = ax.plot(data[\"Vf\"], data[\"Im\"] * 1e6, label=\"file {}\".format(f))\n",
"\n",
"ax.set_title(\n",
" \"CyclicVoltammetry Test, Compare Curve #{}\".format(compare_curves), fontsize=18\n",
")\n",
"ax.set_xlabel(\"Potential (V)\")\n",
"ax.set_ylabel(\"Current (A)\", fontsize=14)\n",
"ax.legend()\n",
"plt.show()"
],
"outputs": [],
"metadata": {
"id": "AQc4jnhlURDV",
"colab_type": "code",
"colab": {},
"cellView": "form"
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"# @title Download All Curves, All Experiments\n",
"\n",
"aggreg = pd.DataFrame()\n",
"\n",
"for f in experiment:\n",
" p.load(f)\n",
"\n",
" # use the curves @property to retrieve all curve data\n",
" for df in p.curves:\n",
" aggreg = aggreg.append(df)\n",
"\n",
"\n",
"aggreg.to_csv(\"results.csv\")\n",
"files.download(\"results.csv\")"
],
"outputs": [],
"metadata": {
"id": "ZPXwezuvmgZ0",
"colab_type": "code",
"cellView": "form",
"colab": {}
}
}
]
}
Loading

0 comments on commit a96439f

Please sign in to comment.