Skip to content

Instantly share code, notes, and snippets.

@pllim
Last active June 15, 2018 18:00
Show Gist options
  • Save pllim/6f9337fc73e08c32333b2d6ed2401e68 to your computer and use it in GitHub Desktop.
Save pllim/6f9337fc73e08c32333b2d6ed2401e68 to your computer and use it in GitHub Desktop.
Simple Multi-Extension FITS Image
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from astropy.io import fits"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"data = np.arange(100).reshape(10, 10)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"prihdu = fits.PrimaryHDU()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"prihdu.header['mykey'] = 'somevalue'"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"imhdu = fits.ImageHDU(data)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"hdulist = fits.HDUList([prihdu, imhdu])"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Filename: (No file associated with this HDUList)\n",
"No. Name Ver Type Cards Dimensions Format\n",
" 0 PRIMARY 1 PrimaryHDU 5 () \n",
" 1 1 ImageHDU 7 (10, 10) int64 \n"
]
}
],
"source": [
"hdulist.info()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"SIMPLE = T / conforms to FITS standard \n",
"BITPIX = 8 / array data type \n",
"NAXIS = 0 / number of array dimensions \n",
"EXTEND = T \n",
"MYKEY = 'somevalue' "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hdulist[0].header"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n",
" [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],\n",
" [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],\n",
" [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],\n",
" [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],\n",
" [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],\n",
" [60, 61, 62, 63, 64, 65, 66, 67, 68, 69],\n",
" [70, 71, 72, 73, 74, 75, 76, 77, 78, 79],\n",
" [80, 81, 82, 83, 84, 85, 86, 87, 88, 89],\n",
" [90, 91, 92, 93, 94, 95, 96, 97, 98, 99]])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hdulist[1].data"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"hdulist.writeto('myimage.fits', overwrite=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@pllim
Copy link
Author

pllim commented Jun 15, 2018

Don't leave comments here, I won't get notified (GitHub bug).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment