GPI Tutorial

The following is just duplicated from Basic KLIP Tutorial with GPI, the basic pyKLIP tutorial.

First, you’ll need some reduced GPI datacubes to run KLIP on since pyKLIP does not reduce raw data. If you have raw GPI data you need to reduce, see the GPI Data Reduction Pipeline Documentation page, which has all of the instructions and tutorials to reduce GPI data. After reducing the data, you should have a series of 3-D datacubes where the third dimension is either wavelength or polarization depending on if you are working with spectral or polarimetric data. Regardless, the data should have the satellite spot fluxes and locations measured and stored in the header as we will need these to register and calibrate the datacubes. If you don’t have any GPI data or are simply too lazy to reduce some yourself, you can use the reduced Beta Pic datacubes from the GPI Public Data Release.

Once you have reduced your data, we can identify and convert the GPI data from GPI specific information to standardized information for pyKLIP. These initial steps of reading in and parsing the data are demonstrated below:

import glob
import pyklip.instruments.GPI as GPI

filelist = glob.glob("path/to/dataset/*.fits")
dataset = GPI.GPIData(filelist, highpass=True)

pyklip.instruments.GPI.GPIData returns dataset, an implementation of the abstract class pyklip.instruments.Instrument.Data with standardized fields that are needed to perform the KLIP subtraction, none of which are instrument specific. Please read the docstring for pyklip.instruments.GPI.GPIData for more information on the the fields for GPI data.


If you get an error here, you likely did not reduce the raw GPI data correctly, so please check that the satellite spots were measured and stored in the header.


When reading in the GPI data, the data are no longer automatically high-pass filtered. You should explictly high pass filter the data if desired (we find it is typically good for planet SNR using the optional keyword highpass=True. You can also apply the high-pass filter as pre-processing step before KLIP in pyklip.parallelized.klip_dataset if you don’t want to do it here as it is slower.

Running KLIP

Next, we will perform the actual KLIP subtraction using Angular Differential Imaging and Spectral Differential Imaging (ADI + SDI). To take advantage of the easily parallelizable computation, we will use the pyklip.parallelized module to perform the KLIP subtraction, which uses the python multiprocessing library to parallelize the code (i.e. split the work up across multiple processes on your device).

import pyklip.parallelized as parallelized

parallelized.klip_dataset(dataset, outputdir="path/to/save/dir/", fileprefix="myobject",
                          annuli=9, subsections=4, movement=1, numbasis=[1,20,50,100],
                          calibrate_flux=True, mode="ADI+SDI")

pyklip.parallelized.klip_dataset will save the processed KLIP images in the field dataset.output and as FITS files saved using the directory and fileprefix specified. The FITS files contain two different kinds of outputs. The first is a “KL-mode cube”, a single 3D datacube where the z-axis is all the different KL mode cutoffs used to model the stellar PSF.