Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fomightez/f85fe3aa8ccca53b8c7e5557aa44c81e to your computer and use it in GitHub Desktop.
Save fomightez/f85fe3aa8ccca53b8c7e5557aa44c81e to your computer and use it in GitHub Desktop.
Test pyfasma-spc package in modern Jupyter and Python for SO https://stackoverflow.com/q/79476297/8508004
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "1ecb2b47-8131-4dcf-86e7-c919c1467844",
"metadata": {},
"source": [
"### Testing pyfasma-spc package in modern Jupyter with recent Python\n",
"\n",
"(This is in relation to StackOverflow post [here](https://stackoverflow.com/q/79476297/8508004).)\n",
"\n",
"Go to [here](https://gist.github.com/fomightez/6773dedf6d5132795dd4245a18c066eb) and press 'launch binder' to get JupyterLab with a relatively current Python version as this time (3.12).\n",
"\n",
"Open a new notebook using the launcher.\n",
"\n",
"Run the next command in your new notebook to install the package to the current environment."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "2fe48ac2-8cae-4b0f-8ade-63319e45c8c7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting pyfasma-spc\n",
" Downloading pyfasma_spc-0.4.2-py3-none-any.whl.metadata (7.2 kB)\n",
"Requirement already satisfied: matplotlib<4.0,>=3.8 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from pyfasma-spc) (3.10.0)\n",
"Requirement already satisfied: numpy<3.0,>=2.0 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from pyfasma-spc) (2.2.3)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from matplotlib<4.0,>=3.8->pyfasma-spc) (1.3.1)\n",
"Requirement already satisfied: cycler>=0.10 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from matplotlib<4.0,>=3.8->pyfasma-spc) (0.12.1)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from matplotlib<4.0,>=3.8->pyfasma-spc) (4.56.0)\n",
"Requirement already satisfied: kiwisolver>=1.3.1 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from matplotlib<4.0,>=3.8->pyfasma-spc) (1.4.8)\n",
"Requirement already satisfied: packaging>=20.0 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from matplotlib<4.0,>=3.8->pyfasma-spc) (24.2)\n",
"Requirement already satisfied: pillow>=8 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from matplotlib<4.0,>=3.8->pyfasma-spc) (11.1.0)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from matplotlib<4.0,>=3.8->pyfasma-spc) (3.2.1)\n",
"Requirement already satisfied: python-dateutil>=2.7 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from matplotlib<4.0,>=3.8->pyfasma-spc) (2.9.0.post0)\n",
"Requirement already satisfied: six>=1.5 in /srv/conda/envs/notebook/lib/python3.12/site-packages (from python-dateutil>=2.7->matplotlib<4.0,>=3.8->pyfasma-spc) (1.17.0)\n",
"Downloading pyfasma_spc-0.4.2-py3-none-any.whl (25 kB)\n",
"Installing collected packages: pyfasma-spc\n",
"Successfully installed pyfasma-spc-0.4.2\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install pyfasma-spc"
]
},
{
"cell_type": "markdown",
"id": "ae9db400-2879-4fb7-84dc-28b082a9e575",
"metadata": {},
"source": [
"That should have sucessfully installed the package in the current environment."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "29c41d45-b78e-43f3-892c-389036333bcd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cloning into 'pyfasma-spc'...\n",
"remote: Enumerating objects: 800, done.\u001b[K\n",
"remote: Counting objects: 100% (123/123), done.\u001b[K\n",
"remote: Compressing objects: 100% (13/13), done.\u001b[K\n",
"remote: Total 800 (delta 111), reused 113 (delta 110), pack-reused 677 (from 1)\u001b[K\n",
"Receiving objects: 100% (800/800), 6.16 MiB | 30.91 MiB/s, done.\n",
"Resolving deltas: 100% (373/373), done.\n"
]
}
],
"source": [
"# get the repo that has the test_data and the notebook\n",
"!git clone https://github.com/lepa22/pyfasma-spc.git\n",
"# next move the `test_data` directory to current working directory\n",
"!mv ./pyfasma-spc/test_data/ .\n",
"# next move the directory containing the demo notebook to the root directory\n",
"!mv ./pyfasma-spc/notebooks/ ."
]
},
{
"cell_type": "markdown",
"id": "64700547-a4bf-484d-b9e0-683be7a13642",
"metadata": {},
"source": [
"After that runs for a minute or so you should be ready to run the demonstration notebook `spc_test.ipynb`. (You'll know it is done if you see `notebooks` and `test_data` directories listed in the file navigation pane on the left.)\n",
"\n",
"Double-click `notebooks` in the panel on the left to navigate into that directory. You should see `spc_test.ipynb` listed there.\n",
"\n",
"Double-click notebook `spc_test.ipynb` in the panel on the left to open it and then run all the cells.\n",
"\n",
"You'll see the third code cell produces a nice spectra plot!\n",
"\n",
"The 5th cell will error out because that old notebook is written for Python 2. It is easy to update though. Just wrap the the text after every `print` invocation with parantheses. For example the fifth code cell should be the following:\n",
"\n",
"```python\n",
"print (f.fexp)\n",
"print (f.sub[0].subexp)\n",
"```\n",
"\n",
"The sixth code cell should be:\n",
"\n",
"```python\n",
"from time import sleep\n",
"pat = '../test_data/'\n",
"for i in os.listdir(pat):\n",
" if i.lower().endswith('spc'):\n",
" print ('------------')\n",
" print (i)\n",
" f = spc.File(pat+i)\n",
" print (f.xlabel, f.ylabel, f.zlabel)\n",
"```\n",
"\n",
"Edit the others similarly for the rest.\n",
"\n",
"This process should be reproducible in your own situation with some appropriate adjustments.\n",
"\n",
"------\n",
"\n",
"Enjoy!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment