{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import warnings\n", "warnings.filterwarnings(\"ignore\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# SunPy and Astropy\n", "## Open Development in Astrophysics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Open Source\n", "\n", "* Publically Accessible Code\n", "* Freedoms to run and modify the code (explicitly set by a licence)\n", "* Free as in zero cost" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Open Development\n", "\n", "Where the development of the code is done in the open.\n", "\n", "Including:\n", "\n", "* Bug reports\n", "* Feature Requests\n", "* Commit logs\n", "* Code review\n", "\n", "**Enables anyone to contribute**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![a](sunpyorg.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](./sunpy_header.png)\n", "![](./sunpy_contributors.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](cadair_contribution.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](astropy_header.png)\n", "![](numpy_header.png)\n", "![](skimage_header.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Get Involved!!\n", "\n", "* https://sunpy.org/contribute.html\n", "* http://www.astropy.org/contribute.html\n", "* http://yt-project.org/\n", "* https://numfocus.org/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Demos!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Astropy\n", "\n", "## Units" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import astropy.units as u" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# FITS" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from astropy.io import fits" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fits.open(\"/home/stuart/sunpy/data/hsi_obssumm_20121127_043.2.fits\").info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Coordinates" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from astropy.coordinates import SkyCoord\n", "\n", "sc = SkyCoord.from_name(\"M32\")\n", "sc" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sc.transform_to(\"galactic\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Modeling" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import matplotlib as mpl\n", "mpl.rcParams[\"figure.figsize\"] = [9, 6]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from astropy.modeling.models import Gaussian1D\n", "from astropy.modeling import fitting" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.random.seed(42)\n", "g1 = Gaussian1D(1, 0, 0.2)\n", "g2 = Gaussian1D(2.5, 0.5, 0.1)\n", "x = np.linspace(-1, 1, 200)\n", "y = g1(x) + g2(x) + np.random.normal(0., 0.2, x.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.plot(x, y, \"o\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m2 = Gaussian1D(amplitude=1, mean=0, stddev=0.1) + Gaussian1D(amplitude=2, mean=0.5, stddev=0.1)\n", "fitter = fitting.SLSQPLSQFitter()\n", "gg = fitter(m2, x, y)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.plot(x, y, \"o\")\n", "plt.plot(x, gg(x))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# SunPy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from sunpy.data.sample import AIA_171_ROLL_IMAGE\n", "import sunpy.map\n", "\n", "m = sunpy.map.Map(AIA_171_ROLL_IMAGE)\n", "m.peek()\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Astropy and SunPy 😍" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import astropy.units as u\n", "from astropy.coordinates import SkyCoord" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a_point = SkyCoord(200*u.arcsec, 300*u.arcsec, frame=m.coordinate_frame)\n", "a_point" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "im = m.plot()\n", "ax = plt.gca()\n", "ax.plot_coord(a_point, \"o\", markersize=12)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# TimeSeries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from sunpy.data.sample import GOES_XRS_TIMESERIES" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from sunpy.timeseries import TimeSeries\n", "goes = TimeSeries(GOES_XRS_TIMESERIES)\n", "goes.peek()" ] } ], "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.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }