{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Jupyter Crash Course" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "## Getting Documentation\n", "\n", "Jupyter uses the IPython kernel when you work with PyARPES. IPython has many conveniences, like allowing you to quickly get the documentation (with ?) or source code of a function (with ??)." ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "import arpes\n", "import pprint\n", "\n", "# Look at help information for the library function `pprint.pprint`\n", "?pprint.pprint" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "You can use this with library functions, PyARPES functions, or your own." ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "from arpes.io import load_example_data\n", "\n", "# Let's look at the full source code for `load_example_data`\n", "??load_example_data" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "You can also use the `help` function to get a terse form of this info." ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "help(pprint.pprint)" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "## Best Practices\n", "'\n", "Try to keep your analysis notebooks short and ensure it's possible to run them top to bottom in a reproducible way.\n", "\n", "One way to make sure this is possible is to use a module stored alongside your code which contains common routines or snippets used in a particular project or analysis.\n", "\n", "In general, sharing code is better than sharing data between notebooks, because it prevents stale dependencies between parts of your analysis.\n", "\n", "A given notebook should have limited scope, ideally to generate a single or a few related figures. If your notebook is getting too long, split it up by using \"Save As\" and deleting relevant cells from each.\n", "\n", "## Maintaining Records of Results\n", "\n", "It's painful to go searching through your notebooks for records of your analysis products. It's probably a good idea to store these out-of-band in a separate piece of software (PowerPoint, Notion, or pencil and paper) so that you can summarize and cross reference. Make sure to annotate which notebooks results came from, however!" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "## Exercises\n", "\n", "1. Look at the Jupyter documentation (https://jupyter.org/documentation) to learn more about either JupyterLab or Jupyter Notebook, depending on which you use.\n", "2. Import `numpy.random.random_sample`, get documentation with `?` and use it to determine how to make a 20 by 20 array of random numbers. What distribution are they drawn from?\n", "3. Plot the distribution of numbers from the previous cell using the `ndarray` method `ravel` and `matplotlib.pyplot.hist`. Use the documentation to determine how to call them. **Hint**: If `arr` is an array, you can get documentation for `.ravel` by using `arr.ravel?`.\n", "4. Make a new cell and run `?`. What gets outputted?" ] } ], "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.9" } }, "nbformat": 4, "nbformat_minor": 5 }