I want to make fits from my head

Introduction

I will keep a record when I think that I have become friends with fits, which is often used in astronomical data. I made this from scratch to learn what fits are.

First, fits is a file format often used for astronomical data, and consists of two parts: a header part that stores information such as coordinates and frequencies, and a data part that stores information obtained from observations. For more information on wikipedia ... (escape) https://ja.wikipedia.org/wiki/FITS

Creating fits

Creating fits that I was worried about for some reason. Is this really the way to go? .. .. I want to believe it is good. Here is a script that creates fits with an array of [100, 100] for the time being.

make_fits_1.py


import numpy as np
from astropy.io import fits

x = 100      #x_axis pixel number
y = 100      #y_axis pixel number
z = 100      #z_axis pixel number

###Creating an array###
#3D time
data = np.zeros((z, y, x), dtype=np.float32)
#Two-dimensional time
#data = np.zeros((y, x), dtype=np.float32)

hdu = fits.PrimaryHDU(data = data)

#Save the fits you made
hdu.writeto('make_fits.fits',overwrite=True)

When making fits of 3D cube, change the part of "** Create array **". In this state, the header has not been inserted yet, so even if it is displayed with ds9 etc., it will only come out as dull. スクリーンショット 2019-11-28 0.05.13.png

Let's put in the header. You can now add headers.

Add header

python


hdu.header['keyword'] = 'something' #At the time of keyword
hdu.header['keyword'] = something   #When entering numerical information such as coordinates

As a trial, it has a 100x100 array and WCS: Galactic center position 00:00:00.00 00:00:00.00 gal beamsize 20.0 arcsec gridsize 10.0 arcsec Let's make fits.

make_fits_2.py


import numpy as np
from astropy.io import fits

x = 100      #x_axis pixel number
y = 100      #y_axis pixel number
z = 100      #z_axis pixel number

beamsize = 20.0 #arcsec

###Creating an array###
#3D time
data = np.zeros((z, y, x), dtype=np.float32)
#Two-dimensional time
data = np.zeros((y, x), dtype=np.float32)

hdu = fits.PrimaryHDU(data = data)

#List of headers you want to put
hdu.header['BITPIX']  =                  -64                                                 
hdu.header['NAXIS']   =                    2                                                 
hdu.header['NAXIS1']  =                  x                                                  
hdu.header['NAXIS2']  =                  y
hdu.header['BPA']     = 0.000000
hdu.header['BMAJ']    = beamsize/3600                                                  
hdu.header['BMIN']    = beamsize/3600
hdu.header['EPOCH']   =                 2000                                                                                                    
hdu.header['BUNIT']  = 'K       '                                                                                                    
hdu.header['CTYPE1']  = 'GLON-GLS'                                                            
hdu.header['CRVAL1']  =                  0.0                                                  
hdu.header['CDELT1']  =     -beamsize/2/3600                                                  
hdu.header['CRPIX1']  =                  x/2                                                  
hdu.header['CROTA1']  =                  0.0                                                  
hdu.header['CUNIT1']  = 'deg     '                                                            
hdu.header['CTYPE2']  = 'GLAT-GLS'                                                            
hdu.header['CRVAL2']  =                  0.0                                                  
hdu.header['CDELT2']  =      beamsize/2/3600                                                  
hdu.header['CRPIX2']  =                  y/2                                                  
hdu.header['CROTA2']  =                  0.0                                                  
hdu.header['CUNIT2']  = 'deg     '          

#Save the fits you made
hdu.writeto('make_fits_2.fits',overwrite=True)

Now you have a fits that contains the coordinate information. スクリーンショット 2019-11-28 0.48.52.png

Precautions for making fits (commandments to yourself)

If you make a mistake in the header, the data will be incorrect, so be sure to check it.

Recommended Posts

I want to make fits from my head
I want to make C ++ code from Python code!
I want to make an automation program!
I want to make a parameter list from CloudFormation code (yaml)
I want to make matplotlib a dark theme
I want to connect to PostgreSQL from various languages
I want to have recursion come to my mind
I want to email from Gmail using Python.
[Python] I want to manage 7DaysToDie from Discord! 1/3
I want to perform SageMaker inference from PHP
I want to make a game with Python
I want to use ceres solver from python
[Python] I want to manage 7DaysToDie from Discord! 2/3
[Ansible] I want to call my own function from the template module (macro)
I want to see the file name from DataLoader
[Python3] I want to generate harassment names from Japanese!
[Python] I want to make a nested list a tuple
I want to solve Sudoku (Sudoku)
I want to make a blog editor with django admin
I want to start a lot of processes from python
I want to calculate the allowable downtime from the operating rate
I want to make a click macro with pyautogui (outlook)
I want to install a package from requirements.txt with poetry
I want to send a message from Python to LINE Bot
I want to make the Dictionary type in the List unique
I want to make input () a nice complement in python
I want to understand systemd roughly
I want to scrape images to learn
I want to do ○○ with Pandas
I want to copy yolo annotations
I want to debug with Python
I want to automatically find high-quality parts from the videos I shot
I tried to make Kana's handwriting recognition Part 1/3 First from MNIST
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I want to make the second line the column name in pandas
I want to mess with ALB's default security group from CDK
I want to check the position of my face with OpenCV!
[Twitter] I want to make the downloaded past tweets (of my account) into a beautiful CSV
I want to pin Spyder to the taskbar
I want to get angry with my mom when my memory is tight
I want to detect objects with OpenCV
I want to output to the console coolly
Why I moved from Java to Dart
I want to print in a comprehension
I want to operate DB using Django's ORM from an external application
I want to scrape them all together.
I want to handle the rhyme part1
I want to send a signal only from the sub thread to the main thread
Tips for manipulating numpy.ndarray from c ++ -I want to use an iterator-
I want to blog with Jupyter Notebook
I want to handle the rhyme part3
I want to build a Python environment
I want to use Linux on mac
I came up with a way to make a 3D model from a photo.
I want to pip install with PythonAnywhere
I want to analyze logs with Python
I want to play with aws with python
I want to use the Django Debug Toolbar in my Ajax application
I want to express my feelings with the lyrics of Mr. Children
I want to use IPython Qt Console
I want to display the progress bar