From 97dd14147aed83c00a1978450ca322491698a8a6 Mon Sep 17 00:00:00 2001 From: Saima Siddiqui Date: Sat, 28 May 2022 23:19:20 -0400 Subject: [PATCH 01/12] Changes to the FITS-header Tutorial --- tutorials/FITS-header/FITS-header.ipynb | 260 +++++++++++++++++------- tutorials/FITS-header/requirements.txt | 1 - 2 files changed, 190 insertions(+), 71 deletions(-) mode change 100755 => 100644 tutorials/FITS-header/FITS-header.ipynb delete mode 100644 tutorials/FITS-header/requirements.txt diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb old mode 100755 new mode 100644 index 4293ed815..70946ee79 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -2,12 +2,14 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "UxTXN1HZmv2R" + }, "source": [ "# Edit a FITS header\n", "\n", "## Authors\n", - "Adrian Price-Whelan, Adam Ginsburg, Stephanie T. Douglas, Kelle Cruz\n", + "Adrian Price-Whelan, Adam Ginsburg, Stephanie T. Douglas, Kelle Cruz, Saima Siddiqui, Zihao Chen, Lúthien Liu\n", "\n", "## Learning Goals\n", "* Read a FITS file \n", @@ -18,16 +20,21 @@ "## Keywords\n", "FITS, file input/output\n", "\n", + "## Companion Content\n", + "To learn more about the FITS file format check out: https://docs.astropy.org/en/stable/io/fits/index.html#\n", + "\n", "## Summary\n", - "This tutorial describes how to read in and edit a FITS header, and then write \n", - "it back out to disk. For this example we're going to change the `OBJECT` \n", - "keyword." + "The FITS file is a useful way of storing and archiving information through multidimensional arrays. Within a FITS file format, the header contains “cards'' of information including a keyword, a value, and a comment as a way to introduce the data block that follows. Together, the header and data are contained together as a header data unit, or HDU. \n", + "\n", + "In this tutorial we will begin with exploring the different ways we can read information in an FITS file, how to read and edit the header, and then write it out back to disk. For this example we're going to change the `OBJECT` keyword.\n" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "FMaYcumxmv2U" + }, "outputs": [], "source": [ "from astropy.io import fits" @@ -35,154 +42,228 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "kZZYBsrSmv2Y" + }, "source": [ - "``astropy.io.fits`` provides a lot of flexibility for reading FITS \n", - "files and headers, but most of the time the convenience functions are\n", - "the easiest way to access the data. ``fits.getdata()`` reads only the \n", - "data from a FITS file, but with the `header=True` keyword argument will\n", - "also read the header. " + "The `astropy.io.fits` package provides a lot of flexibility for reading FITS files and headers. `fits.getheader()` is a dedicated function for reading the header. In this example, we are reading the primary HDU (which has the HDU number 0). The output will show you all the cards that the primary HDU has. " ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "rYWSDikzmv2Z" + }, "outputs": [], "source": [ - "data, header = fits.getdata(\"input_file.fits\", header=True)" + "hdu_number = 0 # HDU means header data unit\n", + "fits.getheader('input_file.fits', hdu_number)" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "MGu5Yf7qoF9c" + }, "source": [ - "There is also a dedicated function for reading only the \n", - "header:" + "**Thought Question:** *How many cards does the primary HDU have?* " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "qkFwDQUCmv2Y" + }, + "source": [ + "Most of the time, the convenience functions are the easiest way to access the data. `fits.getdata()` reads only the data from a FITS file, but with the `header=True` keyword argument will also read the header. " ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "i6xdEI3wmv2Y" + }, "outputs": [], "source": [ - "hdu_number = 0 # HDU means header data unit\n", - "fits.getheader('input_file.fits', hdu_number)" + "data, header = fits.getdata(\"input_file.fits\", header=True)" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "ZcYnmVjOmv2Z" + }, "source": [ - "But `getdata()` can get both the data and the header, so it's a useful \n", - "command to remember. Since the primary HDU of a FITS file must contain image data, \n", - "the data is now stored in a ``numpy`` array. The header is stored in an \n", - "object that acts like a standard Python dictionary. " + "Now we know `getdata()` can get both the data and the header, so it's a useful \n", + "command to remember. The primary HDU of a FITS file must contain image data, \n", + "so the data is now stored in a ``numpy`` array. The header is stored in an \n", + "object that acts like a standard Python dictionary. \n", + "\n", + "This is escpecially important if the FITS file you're examining and editing might have multiple HDU's (extensions), in which case you can specify the extension like this:" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "saJh59aemv2c" + }, "outputs": [], "source": [ - "# But hdu_number = 0 is the PRIMARY HDU.How many HDUs are in this file?\n", - "fits_inf = fits.open(\"input_file.fits\")\n", - "fits_inf.info() \n", - "fits_inf[0].header" + "data1, header1 = fits.getdata(\"input_file.fits\", ext=1, header=True)" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "iAa7NjKtmv2d" + }, "source": [ - "Using ``fits.open`` allows us to look more generally at our data. ``fits_inf[0].header`` gives us the same output as ``fits.getheader``. What will you learn if you type ``fits_inf[1].header``? Based on ``fits_inf.info()`` can you guess what will happen if you type ``fits_inf[2].header``?" + "This will get you the data and header associated with the `index=1` extension \n", + "in the FITS file. Without specifying a number, `getdata()` will get the \n", + "0th extension (equivalent to saying `ext=0`)." ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "ml2DVqgRlJwQ" + }, "source": [ - "Now let's change the header to give it the correct object:" + "There are alot of other useful commands to remember for reading FITS files:" ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "cell_type": "markdown", + "metadata": { + "id": "LXnCQLIqltzv" + }, "source": [ - "header['OBJECT'] = \"M31\"" + "1. `fits.open` allows us to look more generally at our data." ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "tbmPXHehmO8q" + }, "source": [ - "Finally, we have to write out the FITS file. Again, the convenience \n", - "function for this is the most useful command to remember:" + "2. `fits.getheader` will give you the same output as `fits_inf[0].header`. By changing the HDU number to `fits_inf[1]header`, what will the output be? " ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "YKrZaxbRmv2a" + }, "outputs": [], "source": [ - "fits.writeto('output_file.fits', data, header, overwrite=True)" + "# But hdu_number = 0 is the PRIMARY HDU. How many HDUs are in this file?\n", + "fits_inf = fits.open(\"input_file.fits\")\n", + "fits_inf.info() \n", + "fits_inf[0].header" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "z_ddsyRUoVu8" + }, "source": [ - "That's it; you're done!" + "**Thought Question:** *How many HDUS are in this file? Were you right about the number of cards in the primary HDU?*" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "AKTWFAyeopR4" + }, "source": [ - "Two common and more complicated cases are worth mentioning (but if your needs \n", - "are much more complex, you should consult the full documentation http://docs.astropy.org/en/stable/io/fits/). \n", - "\n", - "The first complication is that the FITS file you're examining and \n", - "editing might have multiple HDU's (extensions), in which case you can \n", - "specify the extension like this:" + "**Thought Question:** *What will happen if you type* `fits_inf[2].header`*?*" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UFYUH450mv2b" + }, + "source": [ + "Now that we know how to read out FITS files, let's change the header. The header is always changed via it’s keyword. The keywords are the 8 letter word to the left when you extract the header info. Lets change change the header to give the correct OBJECT:" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "LOP18OR0mv2b" + }, "outputs": [], "source": [ - "data1, header1 = fits.getdata(\"input_file.fits\", ext=1, header=True)" + "header['OBJECT'] = \"M31\"" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "tHfDDzD9o8Ty" + }, "source": [ - "This will get you the data and header associated with the `index=1` extension \n", - "in the FITS file. Without specifying a number, `getdata()` will get the \n", - "0th extension (equivalent to saying `ext=0`)." + "The keyword OBJECT was in the primary HDU. \n", + "\n", + "
\n", + "\n", + "NOTE: If we wanted to change a header in another HDU, we could do it by executing the following code. \n", + "\n", + "```\n", + "hdr = hdul[1].header\n", + "hdr[‘EXAMPLE’] = ‘example :)’\n", + "```\n", + "\n", + "This won't actually run becasue we dont have a EXAMPLE keyword in HDU 1, but this could be useful in the future.\n", + "
" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "2EPX5zxGmv2b" + }, "source": [ - "Another useful tip is if you want to overwrite an existing FITS \n", + "Finally, we have to write out the FITS file. Again, the convenience \n", + "function for this is the most useful command to remember:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Po_Z9nGXmv2c" + }, + "outputs": [], + "source": [ + "fits.writeto('output_file.fits', data, header, overwrite=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "wXTmxWCSmv2d" + }, + "source": [ + "If you want to overwrite an existing FITS \n", "file. By default, `writeto()` won't let you do this, so you need to \n", - "explicitly give it permission using the `clobber` keyword argument:" + "explicitly give it permission using the `overwrite` keyword argument:" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "Sif3LGBgmv2d" + }, "outputs": [], "source": [ "fits.writeto('output_file.fits', data, header, overwrite=True)" @@ -190,15 +271,37 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "2HujAZ7Amv2c" + }, + "source": [ + "That's it; you're done!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "51Y--P-Zmv2c" + }, + "source": [ + "For more complicated cases, you should consult the full documentation http://docs.astropy.org/en/stable/io/fits/. \n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-CxqVv7Vmv2d" + }, "source": [ - "A final example is if you want to make a small change to a FITS file, like updating a header keyword, but you don't want to read in and write out the whole file, which can take a while. Instead you can use the `mode='update'` read mode to do this:" + "An helpful tip is if you want to make a small change to a FITS file, like updating a header keyword, but you don't want to read in and write out the whole file, which can take a while. Instead you can use the `mode='update'` read mode to do this:" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "KbM8RWxOmv2d" + }, "outputs": [], "source": [ "with fits.open('input_file.fits', mode='update') as filehandle:\n", @@ -207,14 +310,18 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "K1_WE8Obmv2e" + }, "source": [ "## Exercise" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "RSdvjG_1mv2e" + }, "source": [ "Read in the file you just wrote and add three header keywords:\n", "\n", @@ -228,7 +335,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "6YjEp_temv2e" + }, "outputs": [], "source": [] } @@ -242,6 +351,16 @@ "name": "", "published": true }, + "colab": { + "collapsed_sections": [], + "name": "FITS-header.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -251,7 +370,8 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3" + "pygments_lexer": "ipython3", + "version": "3.9.12" } }, "nbformat": 4, diff --git a/tutorials/FITS-header/requirements.txt b/tutorials/FITS-header/requirements.txt deleted file mode 100644 index ae8bed802..000000000 --- a/tutorials/FITS-header/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -astropy From df222833dca264b861d198221c6e1aea975edc7d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 29 May 2022 03:51:48 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tutorials/FITS-header/FITS-header.ipynb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index 70946ee79..45c29fbff 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -356,11 +356,6 @@ "name": "FITS-header.ipynb", "provenance": [] }, - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -370,8 +365,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.12" + "pygments_lexer": "ipython3" } }, "nbformat": 4, From cc0529c188de051d9f4dc7e5d8793d6a96c0af57 Mon Sep 17 00:00:00 2001 From: Lia Corrales Date: Fri, 10 Jun 2022 13:50:27 -0400 Subject: [PATCH 03/12] Update tutorials/FITS-header/FITS-header.ipynb fixed quotations Co-authored-by: Matt Craig --- tutorials/FITS-header/FITS-header.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index 45c29fbff..cf3349a2d 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -24,7 +24,7 @@ "To learn more about the FITS file format check out: https://docs.astropy.org/en/stable/io/fits/index.html#\n", "\n", "## Summary\n", - "The FITS file is a useful way of storing and archiving information through multidimensional arrays. Within a FITS file format, the header contains “cards'' of information including a keyword, a value, and a comment as a way to introduce the data block that follows. Together, the header and data are contained together as a header data unit, or HDU. \n", + "FITS is a useful way of storing and archiving information through multidimensional arrays. Within a FITS file format, the header contains "cards" of information including a keyword, a value, and a comment as a way to introduce the data block that follows. Together, the header and data are contained together as a header data unit, or HDU. \n", "\n", "In this tutorial we will begin with exploring the different ways we can read information in an FITS file, how to read and edit the header, and then write it out back to disk. For this example we're going to change the `OBJECT` keyword.\n" ] From a8cc73b01832cfec092c8bcd645ef154e28dc039 Mon Sep 17 00:00:00 2001 From: Lia Corrales Date: Wed, 15 Jun 2022 14:27:14 -0400 Subject: [PATCH 04/12] Update tutorials/FITS-header/FITS-header.ipynb --- tutorials/FITS-header/FITS-header.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index cf3349a2d..87c0bc649 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -24,7 +24,7 @@ "To learn more about the FITS file format check out: https://docs.astropy.org/en/stable/io/fits/index.html#\n", "\n", "## Summary\n", - "FITS is a useful way of storing and archiving information through multidimensional arrays. Within a FITS file format, the header contains "cards" of information including a keyword, a value, and a comment as a way to introduce the data block that follows. Together, the header and data are contained together as a header data unit, or HDU. \n", + "FITS is a useful way of storing and archiving information through multidimensional arrays. Within a FITS file format, the header contains \"cards\" of information including a keyword, a value, and a comment as a way to introduce the data block that follows. Together, the header and data are contained together as a header data unit, or HDU. \n", "\n", "In this tutorial we will begin with exploring the different ways we can read information in an FITS file, how to read and edit the header, and then write it out back to disk. For this example we're going to change the `OBJECT` keyword.\n" ] From 0458920f5cd88f3cd372614a310ecbc29a777518 Mon Sep 17 00:00:00 2001 From: Saima <104094038+saimafsiddiqui@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:45:25 -0400 Subject: [PATCH 05/12] Update tutorials/FITS-header/FITS-header.ipynb Co-authored-by: Matt Craig --- tutorials/FITS-header/FITS-header.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index 87c0bc649..1b6ee6c8c 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -99,7 +99,7 @@ "Now we know `getdata()` can get both the data and the header, so it's a useful \n", "command to remember. The primary HDU of a FITS file must contain image data, \n", "so the data is now stored in a ``numpy`` array. The header is stored in an \n", - "object that acts like a standard Python dictionary. \n", + "object that acts like a standard Python dictionary, except that the keys are case-insensitive. \n", "\n", "This is escpecially important if the FITS file you're examining and editing might have multiple HDU's (extensions), in which case you can specify the extension like this:" ] From 9e25787b1406f461a3229d3a43c5a6484190a6b4 Mon Sep 17 00:00:00 2001 From: Saima <104094038+saimafsiddiqui@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:45:33 -0400 Subject: [PATCH 06/12] Update tutorials/FITS-header/FITS-header.ipynb Co-authored-by: Matt Craig --- tutorials/FITS-header/FITS-header.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index 1b6ee6c8c..806b646da 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -101,7 +101,7 @@ "so the data is now stored in a ``numpy`` array. The header is stored in an \n", "object that acts like a standard Python dictionary, except that the keys are case-insensitive. \n", "\n", - "This is escpecially important if the FITS file you're examining and editing might have multiple HDU's (extensions), in which case you can specify the extension like this:" + "If the FITS file you're examining and editing might have multiple HDU's (extensions), you can specify the extension like this:" ] }, { From ecb88c1d8dfaa4639099a73df8ecc9ba841e2ebe Mon Sep 17 00:00:00 2001 From: Saima <104094038+saimafsiddiqui@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:46:23 -0400 Subject: [PATCH 07/12] Update tutorials/FITS-header/FITS-header.ipynb Co-authored-by: Matt Craig --- tutorials/FITS-header/FITS-header.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index 806b646da..84d14b05d 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -191,7 +191,7 @@ "id": "UFYUH450mv2b" }, "source": [ - "Now that we know how to read out FITS files, let's change the header. The header is always changed via it’s keyword. The keywords are the 8 letter word to the left when you extract the header info. Lets change change the header to give the correct OBJECT:" + "Now that we know how to read a FITS file, let's change the header. The header is always changed via it’s keyword. The keywords are the 8 letter word to the left when you extract the header info. Let's change the header to give the correct OBJECT:" ] }, { From 58f589000cb7d987d19610cacf1681501c9e8050 Mon Sep 17 00:00:00 2001 From: Saima <104094038+saimafsiddiqui@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:49:27 -0400 Subject: [PATCH 08/12] Update tutorials/FITS-header/FITS-header.ipynb Co-authored-by: Matt Craig --- tutorials/FITS-header/FITS-header.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index 84d14b05d..6da67f550 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -244,7 +244,7 @@ }, "outputs": [], "source": [ - "fits.writeto('output_file.fits', data, header, overwrite=True)" + "fits.writeto('output_file.fits', data, header)" ] }, { From f3900c45c3a08b446bdbe3a142a212c0b71a0cca Mon Sep 17 00:00:00 2001 From: Saima <104094038+saimafsiddiqui@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:54:29 -0400 Subject: [PATCH 09/12] Update tutorials/FITS-header/FITS-header.ipynb Co-authored-by: Matt Craig --- tutorials/FITS-header/FITS-header.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index 6da67f550..6357fd7da 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -97,7 +97,7 @@ }, "source": [ "Now we know `getdata()` can get both the data and the header, so it's a useful \n", - "command to remember. The primary HDU of a FITS file must contain image data, \n", + "command to remember. The primary HDU of a FITS file can contain image data, \n", "so the data is now stored in a ``numpy`` array. The header is stored in an \n", "object that acts like a standard Python dictionary, except that the keys are case-insensitive. \n", "\n", From 1746eeb75442ca0ae89902758382babc4bd6a8b0 Mon Sep 17 00:00:00 2001 From: Saima <104094038+saimafsiddiqui@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:54:45 -0400 Subject: [PATCH 10/12] Update tutorials/FITS-header/FITS-header.ipynb Co-authored-by: Matt Craig --- tutorials/FITS-header/FITS-header.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index 6357fd7da..a8d4f8bd5 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -293,7 +293,7 @@ "id": "-CxqVv7Vmv2d" }, "source": [ - "An helpful tip is if you want to make a small change to a FITS file, like updating a header keyword, but you don't want to read in and write out the whole file, which can take a while. Instead you can use the `mode='update'` read mode to do this:" + "A helpful tip if you want to make a small change to a FITS file, like updating a header keyword, but you don't want to read in and write out the whole file, which can take a while, is to use `mode='update'`:" ] }, { From 616ef9d7adefe328b629e0a7027171b8bc6c65fa Mon Sep 17 00:00:00 2001 From: Saima Date: Fri, 22 Jul 2022 10:07:42 -0400 Subject: [PATCH 11/12] Changes to FITS-header Tutorial --- tutorials/FITS-header/FITS-header.ipynb | 54 ++++++++++--------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index a8d4f8bd5..fcf90b425 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -207,44 +207,27 @@ }, { "cell_type": "markdown", - "metadata": { - "id": "tHfDDzD9o8Ty" - }, + "metadata": {}, "source": [ - "The keyword OBJECT was in the primary HDU. \n", - "\n", - "
\n", - "\n", - "NOTE: If we wanted to change a header in another HDU, we could do it by executing the following code. \n", - "\n", - "```\n", - "hdr = hdul[1].header\n", - "hdr[‘EXAMPLE’] = ‘example :)’\n", - "```\n", - "\n", - "This won't actually run becasue we dont have a EXAMPLE keyword in HDU 1, but this could be useful in the future.\n", - "
" + "The keyword OBJECT was in the primary HDU. We can also change a header in another HDU like this:" ] }, { - "cell_type": "markdown", - "metadata": { - "id": "2EPX5zxGmv2b" - }, + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ - "Finally, we have to write out the FITS file. Again, the convenience \n", - "function for this is the most useful command to remember:" + "hdul = fits.open(\"input_file.fits\")\n", + "hdr = hdul[1].header\n", + "hdr['newcard'] = 'a value'" ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "Po_Z9nGXmv2c" - }, - "outputs": [], + "cell_type": "markdown", + "metadata": {}, "source": [ - "fits.writeto('output_file.fits', data, header)" + "Since the keyword \"newcard\" didn't exist in HDU 1, it is created by attempting to change its value." ] }, { @@ -253,9 +236,8 @@ "id": "wXTmxWCSmv2d" }, "source": [ - "If you want to overwrite an existing FITS \n", - "file. By default, `writeto()` won't let you do this, so you need to \n", - "explicitly give it permission using the `overwrite` keyword argument:" + "Finally, we have to write out the FITS file. Again, the convenience function for this is the most useful command to remember. Note that by default, `writeto()` won't let you overwrite an existing FITS \n", + "file, so you need to explicitly give it permission to do so using the `overwrite` keyword argument:" ] }, { @@ -356,6 +338,11 @@ "name": "FITS-header.ipynb", "provenance": [] }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -365,7 +352,8 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3" + "pygments_lexer": "ipython3", + "version": "3.9.12" } }, "nbformat": 4, From c774a05e19a58176669842abe961b084c035d639 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 Jul 2022 14:15:09 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tutorials/FITS-header/FITS-header.ipynb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tutorials/FITS-header/FITS-header.ipynb b/tutorials/FITS-header/FITS-header.ipynb index fcf90b425..ff8fa7367 100644 --- a/tutorials/FITS-header/FITS-header.ipynb +++ b/tutorials/FITS-header/FITS-header.ipynb @@ -338,11 +338,6 @@ "name": "FITS-header.ipynb", "provenance": [] }, - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -352,8 +347,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.12" + "pygments_lexer": "ipython3" } }, "nbformat": 4,