{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Data Carpentry Astronomy Workshop\n", "\n", "Please run this notebook before the workshop. There are three sections:\n", "\n", "1. A short introduction to Jupyter, with pointers to more resources.\n", "\n", "2. `import` statements to check whether you have everything installed that we need.\n", "\n", "3. A cell where you will paste a line of code you copy from Slack, to check for a potential problem with \"smart\" quotes.\n", "\n", "At the end there's a link to a survey where you can let us know you're done, or if you have any problems." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction to Jupyter\n", "\n", "This is a Jupyter notebook, which is a computational document that contains text, code, and results.\n", "\n", "There are several development environments you can use to work with notebooks. Currently the two most common are:\n", "\n", "* Jupyter Classic Notebook, and\n", "\n", "* JupyterLab, which is a newer environment with some improved features, but also some limitations. \n", "\n", "During the workshop, we will use the Classic Notebook environment. If you are new to Jupyter, we suggest you should, too.\n", "\n", "If you are familiar with JupyterLab and you would rather use it for the workshop, that's fine. Just be aware that there will be differences between your environment and ours.\n", "\n", "If you are new to Jupyter, you can [read about it here](https://jupyter.org/try) and follow the tutorial called \"Try Classic Notebook\".\n", "\n", "You also might like [this tutorial from DataQuest](https://www.dataquest.io/blog/jupyter-notebook-tutorial/).\n", "\n", "The following sections introduce the features you will need for the workshop." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Selecting and running cells\n", "\n", "Notebooks are divided into cells that contain either text or code.\n", "\n", "This cell is text; the following cell is code:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "print('Hello')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To select a cell, click in the left margin next to the cell. You should see a blue frame surrounding the selected cell.\n", "\n", "To edit a code cell, click inside the cell. You should see a green frame around the selected cell, and you should see a cursor inside the cell.\n", "\n", "To edit a text cell, double-click inside the cell. Again, you should see a green frame around the selected cell, and you should see a cursor inside the cell.\n", "\n", "Text cells use the Markdown typesetting language, which [you can read about here](https://www.markdownguide.org/).\n", "\n", "To run a cell, hold down Shift and press Enter.\n", "\n", "* If you run a text cell, Jupyter formats the text and displays the result.\n", "\n", "* If you run a code cell, Jupyter runs the code in the cell and displays the result, if any.\n", "\n", "To try it out, select the previous code cell and press Shift-Enter. It should run the code and print `Hello`.\n", "\n", "Then edit this cell, change some of the text, and press Shift-Enter to format it." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Adding and removing cells\n", "\n", "You can add and remove cells from a notebook using the menu at the top of the page and the tool bar below the menu.\n", "\n", "Try the following exercises:\n", "\n", "1. From the Insert menu select \"Insert cell below\" to add a cell below this one. By default, you get a code cell, as you can see in the pull-down menu that says \"Code\".\n", "\n", "2. In the new cell, add a line of Python code and run it.\n", "\n", "3. Add another cell, select the new cell, and then click on the pull-down menu that says \"Code\". Select \"Markdown\". This makes the new cell a text cell.\n", "\n", "4. In the new cell, type some text and format it.\n", "\n", "5. Use the arrow buttons in the tool bar to move cells up and down.\n", "\n", "6. Use the cut, copy, and paste buttons to delete, add, and move cells.\n", "\n", "As you make changes, Jupyter saves your notebook automatically, but if you want to make sure, you can press the save button, which looks like a floppy disk from the 1990s.\n", "\n", "Finally, when you are done with a notebook, select \"Close and Halt\" from the File menu." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Check your installation\n", "\n", "Run the following cells to import the libraries we need for the workshop.\n", "\n", "If any of the libraries are missing, you'll get an error message.\n", "\n", "If you don't get any error messages, you are all set." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from wget import download" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's make sure you have a recent version of Pandas.\n", "\n", "If the following cell causes an error, you probably have an old version of Pandas. Please update it before the workshop." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pd.Series([0]).to_numpy()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "from matplotlib.path import Path\n", "from matplotlib.patches import Polygon" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import astropy.coordinates as coord\n", "import astropy.units as u\n", "from astropy.table import Table" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import gala.coordinates as gc" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Note: running this import statement opens a connection\n", "# to a Gaia server, so it will fail if you are not connected\n", "# to the internet.\n", "\n", "from astroquery.gaia import Gaia" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Check for code-pasting problems\n", "\n", "During the workshop, we might put code on Slack and ask you to cut and paste it into the notebook.\n", "\n", "If you are on a Mac, you might encounter a problem with smart quotes.\n", "\n", "To check, following this link to [our Slack workspace](https://app.slack.com/client/T01GF8N96TD/C01G8AS0QBG/details/pins) and find the pinned message with the setup instructions.\n", "It contains a line of Python code.\n", "\n", "Copy the code from Slack and paste it in the cell below.\n", "If it runs without producing an error, you are all set.\n", "\n", "Otherwise, you might have to change your system settings so it does not convert straight quotes to smart quotes.\n", "If you have trouble with this, let us know and we will provide more details." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Survey\n", "\n", "Please fill out [this survey](https://forms.gle/aWikZ88xA1Rcvsvx8) to let us know when you are done." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }