Skip to main content

Make a movie with Python-1

In [ ]:
#If we have a directory which includes a number of science images in fits formats, and want to create a movie (using scitools) of these images (suppose they are a time series), first we convert them into png files and then stack them using the python module 'aplpy':
import os
import pyfits
import aplpy
from scitools.std import movie

path1 = '....'                            #your fits images path
path2 = '...'                                #your output png images path
list = os.listdir(path1)            # this will create a list of your images

i= 0
for file in list:
   if file.endswith('.fits'):            #this will choose only fits images if there are other image formats

    Im = aplpy.FITSFigure(path1+file)
    Im.show_grayscale()
    Im.axis_labels.hide()
    Im.tick_labels.hide()
    Im.ticks.hide()
    Im.set_title('Image_'+str(i))
    Im.save(path2+'Image_'+str(i)+'.png')
    i = i+1

movie(path2+"/*.png", fps=1, output_file=path2+'movie') #create the movie, usually in gif format