pyklip.instruments package

Subpackages

Submodules

pyklip.instruments.CHARIS module

class pyklip.instruments.CHARIS.CHARISData(filepaths, guess_spot_index=0, guess_spot_locs=None, guess_center_loc=None, skipslices=None, PSF_cube=None, update_hdrs=None, sat_fit_method='global', IWA=None, OWA=None, platecal=False, smooth=True, photcal=False)[source]

Bases: Data

A sequence of CHARIS Data. Each CHARISData object has the following fields and functions

Parameters:
  • filepaths – list of filepaths to files

  • skipslices – a list of datacube slices to skip (supply index numbers e.g. [0,1,2,3])

  • PSF_cube – 3D array (nl,ny,nx) with the PSF cube to be used in the flux calculation.

  • update_hrs – if True, update input file headers by making sat spot measurements. If None, will only update if missing hdr info

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

wcs

Array of N wcs astormetry headers for each image.

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

OWA

a floating point scalar (not array). Specifies to outer working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

wv_indices

Array of N indicies specifying the slice of datacube this frame comes frame (accounts of skipslices) You can use this to index into the header to grab info for the respective slice

spot_flux

Array of N of average satellite spot flux for each frame

dn_per_contrast

Flux calibration factor in units of DN/contrast (divide by image to “calibrate” flux) Can also be thought of as the DN of the unocculted star

flux_units

units of output data [DN, contrast]

prihdrs

Array of N primary headers

exthdrs

Array of N extension headers

bad_sat_spots

a list of up to 4 elements indicating if a sat spot is systematically bad. Indexing is based on sat spot x location. Possible values are 0,1,2,3. [0,3] would mark upper left and lower right sat spots bad

readdata()[source]

reread in the data

savedata()[source]

save a specified data in the CHARIS datacube format (in the 1st extension header)

calibrate_output()[source]

calibrates flux of self.output

property IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

property OWA
property PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

calibrate_output(img, spectral=False, units='contrast')[source]

Calibrates the flux of an output image. Can either be a broadband image or a spectral cube depending on if the spectral flag is set.

Assumes the broadband flux calibration is just multiplication by a single scalar number whereas spectral datacubes may have a separate calibration value for each wavelength

Parameters:
  • img – unclaibrated image. If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

  • spectral – if True, this is a spectral datacube. Otherwise, it is a broadband image.

  • units – currently only support “contrast” w.r.t central star

Returns:

calibrated image of the same shape (this is the same object as the input!!!)

Return type:

img

property centers

Image centers. Shape of (N, 2) where the 2nd dimension is [x,y] pixel coordinate (in that order)

centralwave = {}
property filenames

Array of size N for the actual filepath of the file that corresponds to the data

property filenums

Array of size N for the numerical index to map data to file that was passed in

flux_zeropt = {}
fpm_diam = {}
generate_host_star_psfs(boxrad=7)[source]

Generates PSF of the unocculted host star for each frame of input data. Only works on spectral mode data.

Parameters:

boxrad – the halflength of the size of the extracted PSF (in pixels)

Returns:

saves PSFs to self.host_star_psfs as an array of size(N,psfy,psfx) where psfy=psfx=2*boxrad + 1

generate_psfs(boxrad=7, spots_collapse='mean', mask_locs=None, mask_rad=15, mask_ref_ind=0, bg_sub='global')[source]

Generates PSF for each frame of input data. Only works on spectral mode data.

Parameters:
  • boxrad – the halflength of the size of the extracted PSF (in pixels)

  • spots_collapse – the method to collapse the psfs in this frame, currently supports: ‘mean’, ‘median’

  • mask_locs – ndarray, array of approximate [x, y] pixel locations where bright companions are located. To be masked out when calculating background noise level. Shape (2,) or (n, 2), where n is the number of bright sources that needs to be masked.

  • mask_rad – scalar, radius of the mask in pixels.

  • mask_ref_ind – the cube index (range: 0-ncube) in the filelist for which mask_locs are specified, used to account for its movement in the FOV due to field rotation.

  • bg_sub – the method for background estimate, ‘global’, ‘local’, or None. ‘global’ method is the default method. It estimates the background level at the spot using an annulus around the central star. It is less prone to variances on small scales, and generally better for background that is relatively symmetric azimuthally. ‘local’ method estimates the background using a small annulus around the spot. It is prone to speckle variations near the spot, and should be used when the background level is asymmetric.

Returns:

saves PSFs of all frames to self.uncollapsed_psfs. saves time collapsed PSFs to self.psfs as an array of size(nwv,psfy,psfx) where psfy=psfx=2*boxrad + 1

ifs_rotation = 0.0
property input

Input Data. Shape of (N, y, x)

property ivars
lenslet_scale = 0.01615
lenslet_scale_x = -0.01615
lenslet_scale_x_err = 5e-05
lenslet_scale_y = 0.01615
lenslet_scale_y_err = 7e-05
measure_spot_over_star_ratio(opaque_indices=[], boxrad=7, spots_collapse='mean')[source]

Obtain satellite spot flux to primary star flux ratio from unsaturated frames

Parameters:
  • opaque_ind – array of indices of wavelength slices that are opaque and should be interpolated in flux ratio fit

  • spots_collapse – the method to collapse the psfs in this frame, currently supports: ‘mean’, ‘median’

Returns:

array of spot flux / star flux values for all wavelengths

obs_latitude = 19.828611111111112
obs_longitude = -155.48055555555555
property output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

readdata(filepaths, guess_spot_index=0, guess_spot_locs=None, guess_center_loc=None, skipslices=None, PSF_cube=None, update_hdrs=None, sat_fit_method='global', IWA=None, OWA=None, platecal=False, smooth=False, photcal=False)[source]

Method to open and read a list of CHARIS data

Parameters:
  • filespaths – a list of filepaths

  • guess_spot_index – the wavelength index for which the initial guess is given

  • guess_spot_locs – initial guess of the satellite spot pixel indices. If None, will default to rough guesses for the four satellite spots of a typical CHARIS data cube at the first wavelength slice, in [[x, y],…] format

  • guess_center_loc – initial guess of the primary star center in [x, y] format

  • skipslices – a list of wavelenegth slices to skip for each datacube (supply index numbers e.g. [0,1,2,3])

  • PSF_cube – 3D array (nl,ny,nx) with the PSF cube to be used in the flux calculation.

  • update_hrs

    If True, update input file headers with new sat spot measurements. If False, no measuremnets will be carried out and original headers will not be modified If None and sat_fit_method==’global’, all cubes will be updated with new global measurement as

    long as there is a single cube without sat spot measurements.

    If None and sat_fit_method==’local’, only cubes without existing sat spot measurements will be

    updated with new measurements.

  • sat_fit_method – ‘global’ or ‘local’

  • platecal – bool, whether to calibrate the plate scales of the data, since there is no evidence for distortion in the plate scales to first order (x, y axes have different plate scales), this keyword should always be false for now.

  • smooth – bool, whether to smooth final data slightly

  • photcal – bool, whether to photocalibration all frames

  • IWA – a floating point scalar (not array). Specifies to inner working angle in pixels

  • OWA – a floating point scalar (not array). Specifies to outer working angle in pixels

Returns:

Technically none. It saves things to fields of the CHARISData object. See object doc string

ref_spot_contrast = 0.00272
ref_spot_contrast_error_fraction = 0.04779411764705881
ref_spot_contrast_gridamp = 0.025
ref_spot_contrast_wv = 1.55
save_platecal_cubes(modified_data, dims)[source]
savedata(filepath, data, klipparams=None, filetype=None, zaxis=None, more_keywords=None, center=None, astr_hdr=None, fakePlparams=None, user_prihdr=None, user_exthdr=None, extra_exthdr_keywords=None, extra_prihdr_keywords=None)[source]

Save data and header in the first extension header

Note: In principle, the function only works inside klip_dataset(). In order to use it outside of klip_dataset,
you need to define the following attributes:

dataset.output_wcs = np.array([w.deepcopy() if w is not None else None for w in dataset.wcs]) dataset.output_centers = dataset.centers

Parameters:
  • filepath – path to file to output

  • data – 2D or 3D data to save

  • klipparams – a string of klip parameters

  • filetype – filetype of the object (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”)

  • zaxis – a list of values for the zaxis of the datacub (for KL mode cubes currently)

  • more_keywords (dictionary) – a dictionary {key: value, key:value} of header keywords and values which will written into the primary header

  • astr_hdr – wcs astrometry header

  • center – center of the image to be saved in the header as the keywords PSFCENTX and PSFCENTY in pixels. The first pixel has coordinates (0,0)

  • fakePlparams – fake planet params

  • user_prihdr – User defined primary headers to be used instead

  • user_exthdr – User defined extension headers to be used instead

  • extra_exthdr_keywords – Fits keywords to be added to the extension header before saving the file

  • extra_prihdr_keywords – Fits keywords to be added to the primary header before saving the file

spot_ratio = {}
update_input_cubes()[source]

Updates the input spectral data cubes with the current headers. This is useful to permanately save the measured sat spot locations to disk.

property wcs

Array of N wcs astormetry headers for each image.

property wvs

Array of N wavelengths (used for SDI) [in microns]. For polarization data, defaults to “None”

pyklip.instruments.CHARIS.generate_psf(frame, locations, boxrad=5, spots_collapse='mean', bg_sub=None, mask_locs=None, mask_rad=15)[source]

Generates a GPI PSF for the frame based on the satellite spots TODO: normalize psfs? GPI module normalizes these to DN units in the generate_PSF_cube() function.

Parameters:
  • frame – 2d frame of data

  • locations – array of (N,2) containing [x,y] coordinates of all N satellite spots

  • boxrad – half length of box to use to pull out PSF

  • spots_collapse – the method to collapse the psfs in this frame, currently supports: ‘mean’, ‘median’

  • bg_sub – str or None, method used to perform background subtraction

  • mask_locs – ndarray, array of approximate [x, y] pixel locations where bright companions are located. To be masked out when calculating background noise level. Shape (2,) or (n, 2), where n is the number of bright sources that needs to be masked.

  • mask_rad – scalar, radius of the mask in pixels.

Returns:

2d frame of size (2*boxrad+1, 2*boxrad+1) with average PSF of satellite spots

Return type:

genpsf

pyklip.instruments.GPI module

class pyklip.instruments.GPI.GPIData(filepaths=None, skipslices=None, highpass=False, meas_satspot_flux=False, numthreads=-1, PSF_cube=None, recalc_wvs=True, recalc_centers=True, bad_sat_spots=None, quiet=False)[source]

Bases: Data

A sequence of GPI Data. Each GPIData object has the following fields and functions

Parameters:
  • filepaths – list of filepaths to files

  • skipslices – a list of datacube slices to skip (supply index numbers e.g. [0,1,2,3])

  • highpass – if True, run a Gaussian high pass filter (default size is sigma=imgsize/10) can also be a number specifying FWHM of box in pixel units

  • meas_satspot_flux – if True, remeasure the satellite spot fluxes (would be down after hp filter)

  • numthreads – Number of threads to be used. Default -1 sequential sat spot flux calc. If None, numthreads = mp.cpu_count().

  • PSF_cube – 3D array (nl,ny,nx) with the PSF cube to be used in the flux calculation.

  • recalc_wvs – if True, uses sat spot positions and the central wavelength to recalculate wavelength solution

  • recalc_centers – if True, uses a least squares fit and the satellite spots to recalculate the img centers

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

wcs

Array of N wcs astormetry headers for each image.

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

wv_indices

Array of N indicies specifying the slice of datacube this frame comes frame (accounts of skipslices) You can use this to index into the header to grab info for the respective slice

spot_flux

Array of N of average satellite spot flux for each frame

dn_per_contrast

Flux calibration factor in units of DN/contrast (divide by image to “calibrate” flux) Can also be thought of as the DN of the unocculted star

flux_units

units of output data [DN, contrast]

prihdrs

Array of N primary GPI headers (these are written by Gemini Observatory + GPI DRP Pipeline)

exthdrs

Array of N extension GPI headers (these are written by GPI DRP Pipeline)

bad_sat_spots

a list of up to 4 elements indicating if a sat spot is systematically bad. Indexing is based on sat spot x location. Possible values are 0,1,2,3. [0,3] would mark upper left and lower right sat spots bad

readdata()[source]

reread in the data

savedata()[source]

save a specified data in the GPI datacube format (in the 1st extension header)

calibrate_output()[source]

calibrates flux of self.output

property IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

property PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

band = 'K2'
bands = ['Y', 'J', 'H', 'K1', 'K2']
calibrate_output(img, spectral=False, units='contrast')[source]

Calibrates the flux of an output image. Can either be a broadband image or a spectral cube depending on if the spectral flag is set.

Assumes the broadband flux calibration is just multiplication by a single scalar number whereas spectral datacubes may have a separate calibration value for each wavelength

Parameters:
  • img – unclaibrated image. If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

  • spectral – if True, this is a spectral datacube. Otherwise, it is a broadband image.

  • units – currently only support “contrast” w.r.t central star

Returns:

calibrated image of the same shape (this is the same object as the input!!!)

Return type:

img

property centers

Image centers. Shape of (N, 2) where the 2nd dimension is [x,y] pixel coordinate (in that order)

centralwave = {'H': 1.6473029, 'J': 1.2344508, 'K1': 2.0425281, 'K2': 2.2515272, 'Y': 1.0473831}
config = <configparser.ConfigParser object>
configfile = '/home/docs/checkouts/readthedocs.org/user_builds/pyklip/envs/latest/lib/python3.9/site-packages/pyklip/instruments/GPI.ini'
coronagraph_throughputs = {'H': (array([0.   , 0.007, 0.014, 0.021, 0.028, 0.035, 0.042, 0.049, 0.056,        0.063, 0.07 , 0.077, 0.084, 0.091, 0.098, 0.105, 0.112, 0.119,        0.126, 0.133, 0.14 , 0.147, 0.154, 0.161, 0.168, 0.175, 0.182,        0.189, 0.196, 0.203, 0.21 , 0.217, 0.224, 0.231, 0.238, 0.245,        0.252, 0.259, 0.266, 0.273, 0.28 , 0.287, 0.294, 0.301, 0.308,        0.315, 0.322, 0.329, 0.336, 0.343, 0.35 , 0.357, 0.364, 0.371,        0.378, 0.385, 0.392, 0.399, 0.406, 0.413, 0.42 , 0.427, 0.434,        0.441, 0.448, 0.455, 0.462, 0.469, 0.476, 0.483], dtype='>f8'), array([8.49097439e-04, 8.37072387e-04, 9.94797298e-04, 1.87987893e-03,        4.29712735e-03, 9.01064484e-03, 1.62980489e-02, 2.55382495e-02,        3.51561829e-02, 4.31943901e-02, 4.85002097e-02, 5.21188622e-02,        5.81902996e-02, 7.36763548e-02, 1.06662657e-01, 1.63638448e-01,        2.46742706e-01, 3.52153953e-01, 4.70442971e-01, 5.88925256e-01,        6.95196102e-01, 7.80514848e-01, 8.41778709e-01, 8.81453422e-01,        9.05699680e-01, 9.21635829e-01, 9.34900390e-01, 9.48369923e-01,        9.62256099e-01, 9.75188213e-01, 9.85565766e-01, 9.92533646e-01,        9.96276539e-01, 9.97723707e-01, 9.97998226e-01, 9.97957353e-01,        9.98010674e-01, 9.98201375e-01, 9.98409753e-01, 9.98529165e-01,        9.98538427e-01, 9.98481945e-01, 9.98415341e-01, 9.98368276e-01,        9.98341302e-01, 9.98323042e-01, 9.98305833e-01, 9.98288920e-01,        9.98272863e-01, 9.98254721e-01, 9.98229252e-01, 9.98193858e-01,        9.98151619e-01, 9.98109458e-01, 9.98073293e-01, 9.98044413e-01,        9.98019603e-01, 9.97994101e-01, 9.97964499e-01, 9.97929605e-01,        9.97889579e-01, 9.97845010e-01, 9.97797039e-01, 9.97748019e-01,        9.97701391e-01, 9.97660228e-01, 9.97625336e-01, 9.97594571e-01,        9.97564169e-01, 9.97531267e-01], dtype='>f8')), 'J': (array([0.   , 0.007, 0.014, 0.021, 0.028, 0.035, 0.042, 0.049, 0.056,        0.063, 0.07 , 0.077, 0.084, 0.091, 0.098, 0.105, 0.112, 0.119,        0.126, 0.133, 0.14 , 0.147, 0.154, 0.161, 0.168, 0.175, 0.182,        0.189, 0.196, 0.203, 0.21 , 0.217, 0.224, 0.231, 0.238, 0.245,        0.252, 0.259, 0.266, 0.273, 0.28 , 0.287, 0.294, 0.301, 0.308,        0.315, 0.322, 0.329, 0.336, 0.343, 0.35 , 0.357, 0.364, 0.371,        0.378, 0.385, 0.392, 0.399, 0.406, 0.413, 0.42 , 0.427, 0.434,        0.441, 0.448, 0.455, 0.462, 0.469, 0.476, 0.483], dtype='>f8'), array([9.25064760e-04, 9.59303547e-04, 1.71519818e-03, 4.88162953e-03,        1.21684536e-02, 2.35931347e-02, 3.63247609e-02, 4.60611319e-02,        5.14877388e-02, 5.92210014e-02, 8.45993573e-02, 1.45488848e-01,        2.51472603e-01, 3.95389645e-01, 5.53845771e-01, 6.97504085e-01,        8.04939636e-01, 8.71252045e-01, 9.06585588e-01, 9.26930718e-01,        9.44321630e-01, 9.62527089e-01, 9.79222136e-01, 9.91025469e-01,        9.97002942e-01, 9.98854386e-01, 9.99042027e-01, 9.99120466e-01,        9.99423160e-01, 9.99709810e-01, 9.99812000e-01, 9.99788653e-01,        9.99759579e-01, 9.99768346e-01, 9.99796005e-01, 9.99825147e-01,        9.99855602e-01, 9.99883553e-01, 9.99896453e-01, 9.99889790e-01,        9.99874732e-01, 9.99865000e-01, 9.99862971e-01, 9.99861913e-01,        9.99856444e-01, 9.99845958e-01, 9.99830614e-01, 9.99809744e-01,        9.99784894e-01, 9.99760176e-01, 9.99737097e-01, 9.99711181e-01,        9.99676483e-01, 9.99632841e-01, 9.99586112e-01, 9.99540710e-01,        9.99493859e-01, 9.99438476e-01, 9.99370762e-01, 9.99293813e-01,        9.99214762e-01, 9.99140383e-01, 9.99075449e-01, 9.99022771e-01,        9.98982186e-01, 9.98949328e-01, 9.98917133e-01, 9.98879924e-01,        9.98836315e-01, 9.98788239e-01], dtype='>f8')), 'K1': (array([0.   , 0.007, 0.014, 0.021, 0.028, 0.035, 0.042, 0.049, 0.056,        0.063, 0.07 , 0.077, 0.084, 0.091, 0.098, 0.105, 0.112, 0.119,        0.126, 0.133, 0.14 , 0.147, 0.154, 0.161, 0.168, 0.175, 0.182,        0.189, 0.196, 0.203, 0.21 , 0.217, 0.224, 0.231, 0.238, 0.245,        0.252, 0.259, 0.266, 0.273, 0.28 , 0.287, 0.294, 0.301, 0.308,        0.315, 0.322, 0.329, 0.336, 0.343, 0.35 , 0.357, 0.364, 0.371,        0.378, 0.385, 0.392, 0.399, 0.406, 0.413, 0.42 , 0.427, 0.434,        0.441, 0.448, 0.455, 0.462, 0.469, 0.476, 0.483], dtype='>f8'), array([4.43740966e-04, 4.63263651e-04, 6.12527612e-04, 1.15138792e-03,        2.46611383e-03, 4.98412551e-03, 9.04319870e-03, 1.47361281e-02,        2.17810099e-02, 2.94856331e-02, 3.68670612e-02, 4.29483107e-02,        4.71906427e-02, 4.99528495e-02, 5.28248341e-02, 5.86847162e-02,        7.13856893e-02, 9.50802659e-02, 1.33306487e-01, 1.88054605e-01,        2.59068750e-01, 3.43598022e-01, 4.36701624e-01, 5.32063723e-01,        6.23130818e-01, 7.04292655e-01, 7.71816449e-01, 8.24316974e-01,        8.62678337e-01, 8.89494585e-01, 9.08218907e-01, 9.22269800e-01,        9.34324321e-01, 9.45946134e-01, 9.57581280e-01, 9.68846583e-01,        9.78966600e-01, 9.87200822e-01, 9.93139118e-01, 9.96810130e-01,        9.98617495e-01, 9.99169062e-01, 9.99082127e-01, 9.98834181e-01,        9.98695323e-01, 9.98741342e-01, 9.98919452e-01, 9.99128742e-01,        9.99283706e-01, 9.99345182e-01, 9.99319900e-01, 9.99241102e-01,        9.99145492e-01, 9.99057656e-01, 9.98985814e-01, 9.98926362e-01,        9.98871659e-01, 9.98816057e-01, 9.98757918e-01, 9.98698265e-01,        9.98638226e-01, 9.98577380e-01, 9.98513802e-01, 9.98445348e-01,        9.98371003e-01, 9.98291376e-01, 9.98208138e-01, 9.98122933e-01,        9.98036523e-01, 9.97948661e-01], dtype='>f8')), 'K2': (array([0.   , 0.007, 0.014, 0.021, 0.028, 0.035, 0.042, 0.049, 0.056,        0.063, 0.07 , 0.077, 0.084, 0.091, 0.098, 0.105, 0.112, 0.119,        0.126, 0.133, 0.14 , 0.147, 0.154, 0.161, 0.168, 0.175, 0.182,        0.189, 0.196, 0.203, 0.21 , 0.217, 0.224, 0.231, 0.238, 0.245,        0.252, 0.259, 0.266, 0.273, 0.28 , 0.287, 0.294, 0.301, 0.308,        0.315, 0.322, 0.329, 0.336, 0.343, 0.35 , 0.357, 0.364, 0.371,        0.378, 0.385, 0.392, 0.399, 0.406, 0.413, 0.42 , 0.427, 0.434,        0.441, 0.448, 0.455, 0.462, 0.469, 0.476, 0.483], dtype='>f8'), array([4.74253298e-04, 6.13139462e-04, 1.14431434e-03, 2.37218828e-03,        4.68282734e-03, 8.39309813e-03, 1.35974807e-02, 2.00599860e-02,        2.71957263e-02, 3.41714521e-02, 4.01272254e-02, 4.44867503e-02,        4.72900233e-02, 4.94593568e-02, 5.29080051e-02, 6.04246224e-02,        7.53144911e-02, 1.00839917e-01, 1.39561560e-01, 1.92722309e-01,        2.59821846e-01, 3.38497942e-01, 4.24765367e-01, 5.13580607e-01,        5.99621911e-01, 6.78121032e-01, 7.45570075e-01, 8.00158092e-01,        8.41858923e-01, 8.72175952e-01, 8.93628306e-01, 9.09116028e-01,        9.21316624e-01, 9.32240842e-01, 9.43021540e-01, 9.53943036e-01,        9.64658557e-01, 9.74505555e-01, 9.82820021e-01, 9.89169893e-01,        9.93464754e-01, 9.95940995e-01, 9.97055924e-01, 9.97342269e-01,        9.97274175e-01, 9.97180604e-01, 9.97219577e-01, 9.97405259e-01,        9.97665869e-01, 9.97906533e-01, 9.98056499e-01, 9.98090700e-01,        9.98026852e-01, 9.97907114e-01, 9.97776015e-01, 9.97664174e-01,        9.97582345e-01, 9.97525001e-01, 9.97479135e-01, 9.97433084e-01,        9.97381650e-01, 9.97326394e-01, 9.97272406e-01, 9.97224083e-01,        9.97182253e-01, 9.97143809e-01, 9.97103511e-01, 9.97056647e-01,        9.97001071e-01, 9.96937687e-01], dtype='>f8')), 'Y': (array([0.   , 0.007, 0.014, 0.021, 0.028, 0.035, 0.042, 0.049, 0.056,        0.063, 0.07 , 0.077, 0.084, 0.091, 0.098, 0.105, 0.112, 0.119,        0.126, 0.133, 0.14 , 0.147, 0.154, 0.161, 0.168, 0.175, 0.182,        0.189, 0.196, 0.203, 0.21 , 0.217, 0.224, 0.231, 0.238, 0.245,        0.252, 0.259, 0.266, 0.273, 0.28 , 0.287, 0.294, 0.301, 0.308,        0.315, 0.322, 0.329, 0.336, 0.343, 0.35 , 0.357, 0.364, 0.371,        0.378, 0.385, 0.392, 0.399, 0.406, 0.413, 0.42 , 0.427, 0.434,        0.441, 0.448, 0.455, 0.462, 0.469, 0.476, 0.483], dtype='>f8'), array([0.00126878, 0.00135917, 0.00287518, 0.00872691, 0.02064626,        0.03569239, 0.04721173, 0.05361069, 0.06866578, 0.12011037,        0.23112447, 0.39778805, 0.58427982, 0.74362636, 0.84750364,        0.89977528, 0.92470934, 0.94427994, 0.96538791, 0.98373541,        0.99461201, 0.99850757, 0.99910112, 0.99921351, 0.99951706,        0.99972671, 0.99974038, 0.9997049 , 0.99970786, 0.99973339,        0.99976638, 0.99980435, 0.99982675, 0.9998186 , 0.99979679,        0.99978469, 0.99978277, 0.99977871, 0.99976696, 0.99974748,        0.9997205 , 0.99969075, 0.99966534, 0.99964255, 0.9996124 ,        0.99957165, 0.99952919, 0.99949363, 0.99946411, 0.9994362 ,        0.99940887, 0.99938193, 0.99935295, 0.99932133, 0.99929076,        0.99926393, 0.99923786, 0.99920742, 0.99917087, 0.99912977,        0.9990861 , 0.99904193, 0.99899998, 0.99896186, 0.99892673,        0.99889297, 0.99886043, 0.99882978, 0.99880053, 0.99877085],       dtype='>f8'))}
property filenames

Array of size N for the actual filepath of the file that corresponds to the data

property filenums

Array of size N for the numerical index to map data to file that was passed in

flux_zeropt = {'H': 1.138292e-06, 'J': 3.1868226e-06, 'K1': 5.3415049e-07, 'K2': 3.7012793e-07, 'Y': 5.1508988e-06}
fpm_diam = {'H': 17.37165454417061, 'J': 12.993432667184521, 'K1': 21.608643457382954, 'K2': 21.608643457382954, 'Y': 11.016171174352094}
generate_psf_cube(boxw=20, threshold=0.01, tapersize=0, zero_neg=False, same_wv_only=True)[source]

Generates an average PSF from all frames of input data. Only works on spectral mode data. Overall cube is normalized to have the average sat spot spectrum in DN units. The spectrum is built by combining all the estimated sat spot fluxes. It can take a while as this function is not parallelized…

The center of the PSF is exactly on the central pixel of the PSF. The center pixel index is always (nx/2,nx/2) assuming integer division.

The output PSF cube shape doesn’t depend on the underlying sat spot flux calculation. The sat spot fluxes are only used to set the spectrum of the PSF at the very end.

//!CAUTION 1: I think same_wv_only = False has a bug even in the rescaling of the coordinates //!CAUTION 2: Currently hard coded assuming 37 spectral channels!!!

This function is not compatible with skipslices.

Parameters:
  • boxw – the width the extracted PSF (in pixels). Should be bigger than 20 because there is an interpolation of the background by a plane which is then subtracted to remove linear biases.

  • threshold – fractional pixel value of max pixel value below which everything gets set to 0’s

  • tapersize – if > 0, apply a hann window on the edges with size equal to this argument

  • zero_neg – if True, set all negative values to zero instead

  • same_wv_only – If true (default), it only combines sat spot from the same wavelength. Otherwise it rescales them to each wavelengths. CAUTION: I think same_wv_only = False has a bug even in the rescaling of the coordinates

Returns:

,:] is the PSF for a given wavelength.

Return type:

A cube of shape 37*boxw*boxw. Each slice [k,

generate_psfs(boxrad=7, time_collapse=True)[source]

Generates PSF for each frame of input data. Only works on spectral mode data.

Parameters:
  • boxrad – the halflength of the size of the extracted PSF (in pixels)

  • time_collapse – if True, averages PSF in time.

Returns:

saves PSFs to self.psfs as an array of size(N_wvs, psfy, psfx) where psfy=psfx=2*boxrad + 1 unless time_collapse=False, in which case it has shape (N_cubes, N_wvs, psfy, psfx).

get_radial_psf(save=None)[source]

Return a pure radial PSF by averaging the original psf. The new PSF is invariant by rotation. A call to generate_psf_cube() is required prior to calling this function. The center pixel index is always (nx/2,nx/2) assuming integer division.

Parameters:

save – Optionally automatically save the radial psf cube as a fits file with filename: save+”-original_radial_PSF_cube.fits”

Returns:

a (37,nx,nx) cube with the radial psf.

Return type:

rad_psf_cube

hdulist = [<astropy.io.fits.hdu.image.PrimaryHDU object>, <astropy.io.fits.hdu.table.BinTableHDU object>]
ifs_rotation = 23.5
property input

Input Data. Shape of (N, y, x)

lenslet_scale = 0.014161
observatory_latitude = -30.24075
property output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

package_directory = '/home/docs/checkouts/readthedocs.org/user_builds/pyklip/envs/latest/lib/python3.9/site-packages/pyklip/instruments'
profile_dir = '/home/docs/checkouts/readthedocs.org/user_builds/pyklip/envs/latest/lib/python3.9/site-packages/pyklip/instruments/GPI_profiles'
profile_filename = '/home/docs/checkouts/readthedocs.org/user_builds/pyklip/envs/latest/lib/python3.9/site-packages/pyklip/instruments/GPI_profiles/gpi_offaxis_throughput_K2.fits'
readdata(filepaths, skipslices=None, highpass=False, meas_satspot_flux=False, numthreads=-1, PSF_cube=None, recalc_wvs=True, recalc_centers=True, bad_sat_spots=None, quiet=False)[source]

Method to open and read a list of GPI data

Parameters:
  • filespaths – a list of filepaths

  • skipslices – a list of wavelenegth slices to skip for each datacube (supply index numbers e.g. [0,1,2,3])

  • highpass – if True, run a Gaussian high pass filter (default size is sigma=imgsize/10) can also be a number specifying FWHM of box in pixel units

  • meas_satspot_flux – if True, remeasure the satellite spot fluxes (would be done after hp filter)

  • numthreads – Number of threads to be used. Default -1 sequential sat spot flux calc. If None, numthreads = mp.cpu_count().

  • PSF_cube – 3D array (nl,ny,nx) with the PSF cube to be used in the flux calculation.

  • recalc_wvs – if True, uses sat spot positions and the central wavelength to recalculate wavelength solution

  • recalc_centers – if True, uses a least squares fit and the satellite spots to recalculate the img centers

  • bad_sat_spots – a list of up to 4 elements indicating if a sat spot is systematically bad.

Returns:

Technically none. It saves things to fields of the GPIData object. See object doc string

savedata(filepath, data, klipparams=None, filetype=None, zaxis=None, more_keywords=None, center=None, astr_hdr=None, fakePlparams=None, user_prihdr=None, user_exthdr=None, extra_exthdr_keywords=None, extra_prihdr_keywords=None)[source]

Save data in a GPI-like fashion. Aka, data and header are in the first extension header

Note: In principle, the function only works inside klip_dataset(). In order to use it outside of klip_dataset,
you need to define the following attributes:

dataset.output_wcs = np.array([w.deepcopy() if w is not None else None for w in dataset.wcs]) dataset.output_centers = dataset.centers

Parameters:
  • filepath – path to file to output

  • data – 2D or 3D data to save

  • klipparams – a string of klip parameters

  • filetype – filetype of the object (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”)

  • zaxis – a list of values for the zaxis of the datacub (for KL mode cubes currently)

  • more_keywords (dictionary) – a dictionary {key: value, key:value} of header keywords and values which will written into the primary header

  • astr_hdr – wcs astrometry header

  • center – center of the image to be saved in the header as the keywords PSFCENTX and PSFCENTY in pixels. The first pixel has coordinates (0,0)

  • fakePlparams – fake planet params

  • user_prihdr – User defined primary headers to be used instead

  • user_exthdr – User defined extension headers to be used instead

  • extra_exthdr_keywords – Fits keywords to be added to the extension header before saving the file

  • extra_prihdr_keywords – Fits keywords to be added to the primary header before saving the file

seps = array([0.   , 0.007, 0.014, 0.021, 0.028, 0.035, 0.042, 0.049, 0.056,        0.063, 0.07 , 0.077, 0.084, 0.091, 0.098, 0.105, 0.112, 0.119,        0.126, 0.133, 0.14 , 0.147, 0.154, 0.161, 0.168, 0.175, 0.182,        0.189, 0.196, 0.203, 0.21 , 0.217, 0.224, 0.231, 0.238, 0.245,        0.252, 0.259, 0.266, 0.273, 0.28 , 0.287, 0.294, 0.301, 0.308,        0.315, 0.322, 0.329, 0.336, 0.343, 0.35 , 0.357, 0.364, 0.371,        0.378, 0.385, 0.392, 0.399, 0.406, 0.413, 0.42 , 0.427, 0.434,        0.441, 0.448, 0.455, 0.462, 0.469, 0.476, 0.483], dtype='>f8')
spectral_collapse(collapse_channels=1, align_frames=True, aligned_center=None, numthreads=None)[source]

GPI wrapper of spectral_collapse(). Adds GPI values to collapse

Collapses the dataset spectrally, bining the data into the desired number of output wavelengths. This bins each cube individually; it does not bin the data tempoarally. If number of wavelengths / output channels is not a whole number, some output channels will have more frames that went into the collapse

Parameters:
  • collapse_channels (int) – number of output channels to evenly-ish collapse the dataset into. Default is 1 (broadband)

  • align_frames (bool) – if True, aligns each channel before collapse so that they are centered properly

  • aligned_center – Array of shape (2) [x_cent, y_cent] for the centering the images to a given value if align_frames is True

  • numthreads (bool,int) – number of threads to parallelize align and scale. If None, use default which is all of them

spot_ratio = {'H': 0.000174, 'J': 0.000184, 'K1': 0.000212, 'K2': 0.0001905, 'Y': 0.00016}
spot_ratio2 = {'J': 0.000147, 'Y': 0.000142}
spot_ratio_h = {'J': 0.000192, 'K1': 0.00018, 'K2': 0.0001905, 'Y': 0.000171}
spot_ratio_h2 = {'J': 0.000141, 'Y': 0.000137}
throughputs = array([4.74253298e-04, 6.13139462e-04, 1.14431434e-03, 2.37218828e-03,        4.68282734e-03, 8.39309813e-03, 1.35974807e-02, 2.00599860e-02,        2.71957263e-02, 3.41714521e-02, 4.01272254e-02, 4.44867503e-02,        4.72900233e-02, 4.94593568e-02, 5.29080051e-02, 6.04246224e-02,        7.53144911e-02, 1.00839917e-01, 1.39561560e-01, 1.92722309e-01,        2.59821846e-01, 3.38497942e-01, 4.24765367e-01, 5.13580607e-01,        5.99621911e-01, 6.78121032e-01, 7.45570075e-01, 8.00158092e-01,        8.41858923e-01, 8.72175952e-01, 8.93628306e-01, 9.09116028e-01,        9.21316624e-01, 9.32240842e-01, 9.43021540e-01, 9.53943036e-01,        9.64658557e-01, 9.74505555e-01, 9.82820021e-01, 9.89169893e-01,        9.93464754e-01, 9.95940995e-01, 9.97055924e-01, 9.97342269e-01,        9.97274175e-01, 9.97180604e-01, 9.97219577e-01, 9.97405259e-01,        9.97665869e-01, 9.97906533e-01, 9.98056499e-01, 9.98090700e-01,        9.98026852e-01, 9.97907114e-01, 9.97776015e-01, 9.97664174e-01,        9.97582345e-01, 9.97525001e-01, 9.97479135e-01, 9.97433084e-01,        9.97381650e-01, 9.97326394e-01, 9.97272406e-01, 9.97224083e-01,        9.97182253e-01, 9.97143809e-01, 9.97103511e-01, 9.97056647e-01,        9.97001071e-01, 9.96937687e-01], dtype='>f8')
property wcs

Array of N wcs astormetry headers for each image.

property wvs

Array of N wavelengths (used for SDI) [in microns]. For polarization data, defaults to “None”

pyklip.instruments.GPI.as2pix(sep_as)[source]
pyklip.instruments.GPI.calc_center(prihdr, exthdr, wvs, ignoreslices=None, skipslices=None, bad_sat_spots=None)[source]

calcualte the center position of a spectral data cube

Parameters:
  • prihdr – primary GPI header

  • exthdr – extention GPI header

  • wvs – wvs of the datacube

  • ignoreslices – slices to ignore in the fit. A list of wavelength slice indicies to ignore if none, ignores slices 0,1, len-2, len-1 (first and last two)

  • skipslices – slices that were already skipped in processing

  • bad_sat_stots – of the 4 sat spots, which are bad and should be ignored. Indexed 0-3 based on x coordinate

Returns:

star center

Return type:

centx, centy

pyklip.instruments.GPI.calc_center_least_squares(xpos, ypos, wvs, orderx, ordery, displacement)[source]

calcualte the center position, linear least squares fit to 4 parameters

Parameters:
  • xpos – array of length n of x positions of satellite spots

  • ypos – array of length n of y positions of satellite spots

  • wvs – the wavelength of each pair of positoins

  • orderx – the x order (can be -1 or 1 in this case. -1 is under the center, 1 is above the center)

  • ordery – the y order (e.g. pos0 is at pox=-1, posy=1).

  • displacment – the displacement from zenith

Returns:

four fit parameters (xcenter, ycenter, adrx, adry). xcenters = xcenter + ardx * displacement

pyklip.instruments.GPI.generate_psf(frame, locations, boxrad=5, medianboxsize=30)[source]

Generates a GPI PSF for the frame based on the satellite spots

Parameters:
  • frame – 2d frame of data

  • location – array of (N,2) containing [x,y] coordinates of all N satellite spots

  • boxrad – half length of box to use to pull out PSF

  • medianboxsize – size in pixels of box for median filter

Returns:

2d frame of size (2*boxrad+1, 2*boxrad+1) with average PSF of satellite spots

Return type:

genpsf

pyklip.instruments.GPI.get_gpi_wavelength_sampling(filter_name)[source]

Return GPI wavelength sampling for a given band.

Parameters:

filter_name – ‘H’, ‘J’, ‘K1’, ‘K2’, ‘Y’. Wavelength samples are linearly spaced between the first and the last wavelength of the band.

Returns:

is the gpi sampling of the considered band in micrometer.

Return type:

wavelengths

pyklip.instruments.GPI.measure_sat_spot_fluxes(img, spots_x, spots_y, psfs_func_list=None, wave_index=None, residuals=False)[source]

Measure satellite spot peak fluxes using a Gaussian matched filter

Parameters:
  • img – 2D frame with 4 sat spots

  • spots_x – list of 4 satellite spot x coordinates

  • spots_y – list of 4 satellite spot y coordinates

  • psfs_func_list – List of spline fit function for the PSF_cube. If None (default) a gaussian fit is used.

  • wave_index – Index of the current wavelength. In [0,36] for GPI. Only used when psfs_func_list is not None.

  • residuals – If True (Default = False) then calculate the residuals of the sat spot fit (gaussian or PSF cube).

Returns:

list of 4 satellite spot fluxes

Return type:

spots_f

pyklip.instruments.GPI.pix2as(sep_pix)[source]
pyklip.instruments.GPI.recalculate_sat_spot_fluxes(dataset, skipslices=None, numthreads=-1, PSF_cube=None, residuals=False)[source]

Recalculate the satellite spots fluxes.

Parameters:
  • dataset – GPIData object.

  • skipslices – a list of datacube slices to skip (supply index numbers e.g. [0,1,2,3]) WARNING! SKIPSLICES features hasn’t been tested with this function.

  • numthreads – Number of threads to be used. Default -1 sequential sat spot flux calc. If None, numthreads = mp.cpu_count().

  • PSF_cube – 3D array (nl,ny,nx) with the PSF cube to be used in the flux calculation.

  • residuals – If True (Default = False) then calculate the residuals of the sat spot fit (gaussian or PSF cube).

Returns:

The list of sat spot fluxes. Can be used to redefine dataset.spot_flux.

Return type:

spot_fluxes

pyklip.instruments.GPI.rescale_wvs(exthdrs, wvs, refwv=None, skipslices=None, bad_sat_spots=None)[source]

Hack to try to fix wavelength scaling issue. This will calculate the scaling between channels, and adjust the wavelength solution such that the scaling comes out linear in scaling vs wavelength. Finicky - requires that all images in the dataset have the same number of wavelength channels :param exthdrs: a list of extension headers, from a pyklip.instrument dataset :param wvs: a list of wvs (can repeat. This function will only look at the first cube’s wavelenghts) :param refwv: integer index of the channel to normalize the scaling :type refwv: optional :param skipslices: list of skipped wavelength slices (needs to be consistent with the ones skipped by wv)

Returns:

Nlambda*Nexthdrs array of wavelengths that produce a linear plot of wavelength vs scaling

Return type:

scaled_wvs

pyklip.instruments.GPI.subtract_satspots(slice, slice_id, spots_xloc_thisslice, spots_yloc_thisslice, center_thisslice, psfs_func_list)[source]

Subtract the satellite spots in a GPI image.

Inputs:

slice: 2d image slice_id: index of the image from the GPI cube. Used to select the correct PSF from psfs_func_list. spots_xloc_thisslice: list of x position of the sat spots spots_yloc_thisslice: list of y position of the sat spots center_thisslice: (x0,y0) image center psfs_func_list: List of spline fit function for the PSF_cube.

Can be computed as follow:

numwv,ny_psf,nx_psf = PSF_cube.shape x_psf_grid, y_psf_grid = np.meshgrid(np.arange(nx_psf * 1.)-nx_psf//2,np.arange(ny_psf* 1.)-ny_psf//2) psfs_func_list = [] from scipy import interpolate for wv_index in range(numwv):

model_psf = PSF_cube[wv_index, :, :] psfs_func_list.append(interpolate.LSQBivariateSpline(x_psf_grid.ravel(),y_psf_grid.ravel(),model_psf.ravel(),

x_psf_grid[0,0:nx_psf-1]+0.5,y_psf_grid[0:ny_psf-1,0]+0.5))

Output: sat spot subtracted image.

pyklip.instruments.Instrument module

class pyklip.instruments.Instrument.Data[source]

Bases: object

Abstract Class with the required fields and methods that need to be implemented

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N input centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

wcs

Array of N wcs astormetry headers for each input image.

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

OWA

(optional) specifies outer working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

output_centers

Array of shape (N,2) for N output centers. Also coresponds to FM centers (does not need to be implemented)

output_wcs

Array of N wcs astrometry headers for each output image (does not need to be implemneted)

creator

(optional) string for creator of the data (used to identify pipelines that call pyklip)

klipparams

(optional) a string that saves the most recent KLIP parameters

flipx

(optional) False by default. Determines whether a relfection about the x axis is necessary to rotate image North-up East left

readdata()[source]

reread in the dadta

savedata()[source]

save a specified data in the GPI datacube format (in the 1st extension header)

calibrate_output()[source]

flux calibrate the output data

abstract property IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

abstract property PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

abstract calibrate_output(img, spectral=False)[source]

Calibrates the flux of an output image. Can either be a broadband image or a spectral cube depending on if the spectral flag is set.

Assumes the broadband flux calibration is just multiplication by a single scalar number whereas spectral datacubes may have a separate calibration value for each wavelength

Parameters:
  • img – unclaibrated image. If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

  • spectral – if True, this is a spectral datacube. Otherwise, it is a broadband image.

Returns:

calibrated image of the same shape

Return type:

calib_img

abstract property centers

Image centers. Shape of (N, 2) where the 2nd dimension is [x,y] pixel coordinate (in that order)

abstract property filenames

Array of size N for the actual filepath of the file that corresponds to the data

abstract property filenums

Array of size N for the numerical index to map data to file that was passed in

abstract property input

Input Data. Shape of (N, y, x)

property numwvs
abstract property output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

abstract readdata(filepaths)[source]

Reads in the data from the files in the filelist and writes them to fields

abstract static savedata(self, filepath, data, klipparams=None, filetype='', zaxis=None, more_keywords=None)[source]

Saves data for this instrument

Parameters:
  • filepath – filepath to save to

  • data – data to save

  • klipparams – a string of KLIP parameters. Write it to the ‘PSFPARAM’ keyword

  • filtype – type of file (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”). Wrriten to ‘FILETYPE’ keyword

  • zaxis – a list of values for the zaxis of the datacub (for KL mode cubes currently)

  • more_keywords (dictionary) – a dictionary {key: value, key:value} of header keywords and values which will written into the primary header

spectral_collapse(collapse_channels=1, align_frames=True, aligned_center=None, numthreads=None, additional_params=None)[source]

Collapses the dataset spectrally, bining the data into the desired number of output wavelengths. This bins each cube individually; it does not bin the data tempoarally. If number of wavelengths / output channels is not a whole number, some output channels will have more frames that went into the collapse

Parameters:
  • collapse_channels (int) – number of output channels to evenly-ish collapse the dataset into. Default is 1 (broadband)

  • align_frames (bool) – if True, aligns each channel before collapse so that they are centered properly

  • aligned_center – Array of shape (2) [x_cent, y_cent] for the centering the images to a given value

  • numthreads (bool,int) – number of threads to parallelize align and scale. If None, use default which is all of them

  • additional_params (list of str) – other dataset parameters to collapse. Assume each variable has first dimension of Nframes

abstract property wcs

Array of N wcs astormetry headers for each image.

abstract property wvs

Array of N wavelengths (used for SDI) [in microns]. For polarization data, defaults to “None”

class pyklip.instruments.Instrument.GenericData(input_data, centers, parangs=None, wvs=None, IWA=0, filenames=None, flipx=False)[source]

Bases: Data

Basic class to interface with a basic direct imaging dataset

Parameters:
  • input_data – either a 1-D list of filenames to read in, or a 3-D cube of all data (N, y, x)

  • centers – array of shape (N,2) for N centers in the format [x_cent, y_cent]

  • parangs – Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

  • wvs – Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

  • IWA – a floating point scalar (not array). Specifies to inner working angle in pixels

  • filenames – Array of size N for the actual filepath of the file that corresponds to the data

  • flipx (boo) – if True, the input images are right-handed (East clockwise of North) and need to be flipped for North-up-East-left

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

wcs

Array of N wcs astormetry headers for each image.

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

property IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

property PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

calibrate_output(img, spectral=False)[source]

Calibrates the flux of an output image. Can either be a broadband image or a spectral cube depending on if the spectral flag is set.

Assumes the broadband flux calibration is just multiplication by a single scalar number whereas spectral datacubes may have a separate calibration value for each wavelength

Parameters:
  • img – unclaibrated image. If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

  • spectral – if True, this is a spectral datacube. Otherwise, it is a broadband image.

Returns:

calibrated image of the same shape

Return type:

calib_img

property centers

Image centers. Shape of (N, 2) where the 2nd dimension is [x,y] pixel coordinate (in that order)

property filenames

Array of size N for the actual filepath of the file that corresponds to the data

property filenums

Array of size N for the numerical index to map data to file that was passed in

property input

Input Data. Shape of (N, y, x)

property output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

readdata(filepaths)[source]

Reads in the data from the files in the filelist and writes them to fields.

savedata(filepath, data, klipparams=None, filetype='', zaxis=None, more_keywords=None)[source]

Saves data for this instrument

Parameters:
  • filepath – filepath to save to

  • data – data to save

  • klipparams – a string of KLIP parameters. Write it to the ‘PSFPARAM’ keyword

  • filtype – type of file (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”). Wrriten to ‘FILETYPE’ keyword

  • zaxis – a list of values for the zaxis of the datacub (for KL mode cubes currently)

  • more_keywords (dictionary) – a dictionary {key: value, key:value} of header keywords and values which will written into the primary header

property wcs

Array of N wcs astormetry headers for each image.

property wvs

Array of N wavelengths (used for SDI) [in microns]. For polarization data, defaults to “None”

pyklip.instruments.MagAO module

class pyklip.instruments.MagAO.MagAOData(filepaths=None, highpass=False)[source]

Bases: object

A sequence of P1640 Data. Each P1640Data object has the following fields and functions :param filepaths: list of filepaths to files :param skipslices: a list of datacube slices to skip (supply index numbers e.g. [0,1,2,3]) :param corefilepaths: a list of filepaths to core (i.e. unocculted) files, for contrast calc :param spot_directory: (None) path to the directory where the spot positions are stored. Defaults to P1640.ini val

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

wcs

Array of N wcs astormetry headers for each image.

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

spot_flux

Array of N of average satellite spot flux for each frame

contrast_scaling

Flux calibration factors (multiply by image to “calibrate” flux)

flux_units

units of output data [DN, contrast]

prihdrs

not used for P1640, set to None

exthdrs

Array of N P1640 headers (these are written by the P1640 cube extraction pipeline)

readdata()[source]

reread in the data

savedata()[source]

save a specified data in the P1640 datacube format (in the 1st extension header)

calibrate_output()[source]

calibrates flux of self.output

property IWA
property OWA
property PAs
band = 'Ys'
bands = ['HA', 'CONT', "z'", "r'", "i'", 'Ys']
calibrate_output(img, spectral=False, units='contrast')[source]
Calibrates the flux of an output image. Can either be a broadband image or a spectral cube depending

on if the spectral flag is set.

Assumes the broadband flux calibration is just multiplication by a single scalar number whereas spectral datacubes may have a separate calibration value for each wavelength

Args:
img: unclaibrated image.

If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

spectral: if True, this is a spectral datacube. Otherwise, it is a broadband image. units: currently only support “contrast” w.r.t central star

Return:

img: calibrated image of the same shape (this is the same object as the input!!!)

property centers
centralwave = {'CONT': 0.6428, 'HA': 0.6564, 'Ys': 0.98584704, "i'": 0.76691462, "r'": 0.62645846, "z'": 0.90969793}
config = <configparser.ConfigParser object>
configfile = '/home/docs/checkouts/readthedocs.org/user_builds/pyklip/envs/latest/lib/python3.9/site-packages/pyklip/instruments/MagAO.ini'
property filenums
property flipx
flux_zeropt = {'CONT': 0.0, 'HA': 0.0, 'Ys': 0.0, "i'": 0.0, "r'": 0.0, "z'": 0.0}
ghstpeak_ratio = {"cont'": 0.0042, "i'": 0.001998, "line'": 0.0042, "z'": 0.00122}
ifs_rotation = -0.497
property input
lenslet_scale = 0.00795
observatory_latitude = -29.0146
property output
package_directory = '/home/docs/checkouts/readthedocs.org/user_builds/pyklip/envs/latest/lib/python3.9/site-packages/pyklip/instruments'
readdata(filepaths, highpass=False)[source]

Method to open and read a list of MagAO data highpass: if True, run a Gaussian high pass filter (default size is sigma=imgsize/10)

can also be a number specifying FWHM of box in pixel units

savedata(filepath, data, klipparams=None, filetype=None, zaxis=None, center=None, astr_hdr=None, fakePlparams=None, more_keywords=None)[source]

Save data in a GPI-like fashion. Aka, data and header are in the first extension header

Inputs: filepath: path to file to output data: 2D or 3D data to save klipparams: a string of klip parameters filetype: filetype of the object (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”) zaxis: a list of values for the zaxis of the datacub (for KL mode cubes currently) astr_hdr: wcs astrometry header (None for NIRC2) center: center of the image to be saved in the header as the keywords PSFCENTX and PSFCENTY in pixels. The first pixel has coordinates (0,0) fakePlparams: fake planet params

property wcs
property wvs

pyklip.instruments.NIRC2 module

class pyklip.instruments.NIRC2.NIRC2Data(filepaths=None, highpass=False, find_star='auto', meas_star_flux=False, guess_star=None)[source]

Bases: Data

A sequence of Keck NIRC2 ADI Data. Each NIRC2Data object has the following fields and functions

Parameters:
  • filepaths – list of filepaths to files

  • highpass – if True, run a Gaussian high pass filter (default size is sigma=imgsize/10) can also be a number specifying FWHM of box in pixel units

  • find_star – (default) ‘auto’ will first try to get the star center coordinates from the FITS header PSFCENTX & PSFCENTY keywords, and if that fails it will do a Radon transform to locate the star via the diffraction spikes (and store the star center in the header for future use). True will force the Radon transform; False will skip the Radon transform even if no center is found in the header.

  • guess_star – (default) None. Otherwise an [x, y] coordinate guess for where the star is for find_star. The code will automatially guess the star location based on the FPM otherwise.

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

wcs

Array of N wcs astormetry headers for each image.

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

creator

string for creator of the data (used to identify pipelines that call pyklip)

klipparams

a string that saves the most recent KLIP parameters

readdata()[source]

reread in the dadta

savedata()[source]

save a specified data in the GPI datacube format (in the 1st extension header)

calibrate_output()[source]

flux calibrate the output data

property IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

property PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

band = 'Ms'
bands = ['J', 'H', 'K', 'Ks', 'Kp', 'Lp', 'Ms']
calibrate_data(units='contrast')[source]

Calibrates the flux of the output of PSF subtracted data.

Parameters:
  • img – unclaibrated image. If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

  • spectral – if True, this is a spectral datacube. Otherwise, it is a broadband image.

  • units – currently only support “contrast” w.r.t central star

Returns:

calibrated image of the same shape (this is the same object as the input!!!)

Return type:

img

calibrate_output(img, spectral=False, units='contrast')[source]

Calibrates the flux of the output of PSF subtracted data.

Assumes the broadband flux calibration is just multiplication by a single scalar number whereas spectral datacubes may have a separate calibration value for each wavelength

Parameters:
  • img – unclaibrated image. If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

  • spectral – if True, this is a spectral datacube. Otherwise, it is a broadband image.

  • units – currently only support “contrast” w.r.t central star

Returns:

calibrated image of the same shape (this is the same object as the input!!!)

Return type:

img

cam = 'wide'
cameras = ['narrow_pre150413', 'narrow_post150413', 'medium', 'wide']
property centers

Image centers. Shape of (N, 2) where the 2nd dimension is [x,y] pixel coordinate (in that order)

centralwave = {'H': 1.633, 'J': 1.248, 'K': 2.196, 'Kp': 2.124, 'Ks': 2.146, 'Lp': 3.776, 'Ms': 4.67}
config = <configparser.ConfigParser object>
configfile = '/home/docs/checkouts/readthedocs.org/user_builds/pyklip/envs/latest/lib/python3.9/site-packages/pyklip/instruments/NIRC2.ini'
property filenames

Array of size N for the actual filepath of the file that corresponds to the data

property filenums

Array of size N for the numerical index to map data to file that was passed in

flux_zeropt = {'H': 1.2e-06, 'J': 3.039e-06, 'K': 4.087e-07, 'Kp': 4.67e-07, 'Ks': 4.461e-07, 'Lp': 5.338e-08, 'Ms': 2.285e-08}
fpm = 'corona2000'
fpm_diam = {'corona100': 0.1, 'corona1000': 1.0, 'corona150': 0.15, 'corona1500': 1.5, 'corona200': 0.2, 'corona2000': 2.0, 'corona300': 0.3, 'corona400': 0.4, 'corona600': 0.6, 'corona800': 0.8}
fpm_yx = {'medium_corona100': (None, None), 'medium_corona1000': (None, None), 'medium_corona150': (None, None), 'medium_corona1500': (None, None), 'medium_corona200': (None, None), 'medium_corona2000': (None, None), 'medium_corona300': (None, None), 'medium_corona400': (None, None), 'medium_corona600': (None, None), 'medium_corona800': (None, None), 'narrow_corona100': (None, None), 'narrow_corona1000': (None, None), 'narrow_corona150': (None, None), 'narrow_corona1500': (None, None), 'narrow_corona200': (465, 511), 'narrow_corona2000': (None, None), 'narrow_corona300': (None, None), 'narrow_corona400': (413, 508), 'narrow_corona600': (426, 507), 'narrow_corona800': (None, None), 'wide_corona100': (None, None), 'wide_corona1000': (None, None), 'wide_corona150': (None, None), 'wide_corona1500': (None, None), 'wide_corona200': (None, None), 'wide_corona2000': (None, None), 'wide_corona300': (None, None), 'wide_corona400': (None, None), 'wide_corona600': (None, None), 'wide_corona800': (None, None)}
fpms = ['corona100', 'corona150', 'corona200', 'corona300', 'corona400', 'corona600', 'corona800', 'corona1000', 'corona1500', 'corona2000']
property input

Input Data. Shape of (N, y, x)

lenslet_scales = {'medium': 0.019829, 'narrow_post150413': 0.009971, 'narrow_pre150413': 0.009952, 'wide': 0.039686}
observatory_latitude = 19.82525
property output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

package_directory = '/home/docs/checkouts/readthedocs.org/user_builds/pyklip/envs/latest/lib/python3.9/site-packages/pyklip/instruments'
pupil = 'open'
pupil_diam = {'incircle': 8.792, 'largehex': 0.0, 'open': 9.96, 'smallhex': 0.0}
pupils = ['incircle', 'largehex', 'smallhex', 'open']
readdata(filepaths, highpass=False, find_star='auto', meas_star_flux=False, guess_star=None)[source]

Method to open and read a list of NIRC2 data

Parameters:
  • filespaths – a list of filepaths

  • highpass – if True, run a Gaussian high pass filter (default size is sigma=imgsize/10) can also be a number specifying FWHM of box in pixel units

  • find_star – (default) ‘auto’ will first try to get the star center coordinates from the FITS header PSFCENTX & PSFCENTY keywords, and if that fails it will do a Radon transform to locate the star via the diffraction spikes (and store the star center in the header for future use). True will force the Radon transform; False will skip the Radon transform even if no center is found in the header.

guess_star: (default) None. Otherwise an [x, y] coordinate guess for where the star is for find_star.

The code will automatially guess the star location based on the FPM otherwise.

Returns:

Technically none. It saves things to fields of the NIRC2Data object. See object doc string

savedata(filepath, data, klipparams=None, filetype=None, zaxis=None, center=None, astr_hdr=None, fakePlparams=None, more_keywords=None)[source]

Save data in a GPI-like fashion. Aka, data and header are in the first extension header

Note: In principle, the function only works inside klip_dataset(). In order to use it outside of klip_dataset,
you need to define the following attribute:

dataset.output_centers = dataset.centers

Inputs:

filepath: path to file to output data: 2D or 3D data to save klipparams: a string of klip parameters filetype: filetype of the object (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”) zaxis: a list of values for the zaxis of the datacub (for KL mode cubes currently) astr_hdr: wcs astrometry header (None for NIRC2) center: center of the image to be saved in the header as the keywords PSFCENTX and PSFCENTY in pixels.

The first pixel has coordinates (0,0)

fakePlparams: fake planet params more_keywords (dictionary) : a dictionary {key: value, key:value} of header keywords and values which will

written into the primary header

property wcs

Array of N wcs astormetry headers for each image.

property wvs

Array of N wavelengths (used for SDI) [in microns]. For polarization data, defaults to “None”

pyklip.instruments.NIRC2.calc_starflux(cube, center)[source]

Fits a 2D Gaussian to an image to calculate the peak pixel value of the central star. The code assumes an unobscurated PSF.

Parameters:
  • cube – 2D image array. Shape is (256,256)

  • center – star center in image in (x,y)

Returns:

Best fit amplitude of the 2D Gaussian.

Return type:

Amplitude

pyklip.instruments.NIRC2.get_pa(hdulist, obsdate=None, rotmode=None, mean_PA=True, write_hdr=True)[source]

Given a FITS data-header unit list (HDUList), returns the NIRC2 PA in [radians]. PA is angle of detector relative to sky; ROTMODE is rotator tracking mode; PARANG is parallactic angle astrometric; INSTANGL is instrument angle; ROTPOSN is rotator physical position. Additional PA offset of -0.252 or -0.262 deg is applied for NIRC2 narrow cam depending on observation date. NOTE that the PA sign is flipped at the very end before output to conform to pyKLIP’s rotation convention.

Inputs:

hdulist: a FITS HDUList (NOT a single HDU). obsdate: date of observation; will try to get from prihdr if not provided. rotmode: ‘vertical angle’ for ADI mode with PA rotating on detector, or

‘position angle’ for mode with PA orientation fixed on detector.

mean_pa: if True (default), return the mean PA during the exposure.

If False, return the PA at the start of the exposure only. Only applies to vertical angle mode.

write_hdr: if True (default), writes keys to file header and saves them.

pyklip.instruments.NIRC2.get_star(hdulist, ctr, obsdate, hp_size=0, im_smooth=0, sp_width=0, spike_angles=None, r_mask='all', rad=100, rad_out=inf, radon_wdw=400, smooth=1, PAadj=0.0, write_hdr=True, pool=None, silent=True)[source]

Runs Radon transform star-finding algorithm on image and (by default) saves the results in the original FITS header.

Inputs:

hdulist: a FITS HDUList (NOT a single HDU). ctr: (y,x) coordinate pair estimate for star position for image [pix]. obsdate: date of observation; will try to get from prihdr if not provided. hp_size: size of high-pass filter box (via Fourier transform) in [pix]. im_smooth: sigma of smoothing Gaussian function in [pix]. sp_width: width of diffraction spike mask in [pix]; default is 0 (no masking). spike_angles: list of discrete angles from the assumed star positions along

which the radon transform will sum intensity to search for the true star position (it picks the maximum sum). These should match the angles of the strongest diffraction spikes [deg].

r_mask: ‘all’ to mask out circle around ctr coords; anything else to do no radial masking. rad: r_mask==’all’ will mask out all r <= rad [pix]. rad_out: r_mask==’all’ will mask out all r > rad_out [pix]. radon_window: half width of the radon sampling region; size_window = image.shape[0]/2 is suggested.

m & M: The sampling region will be (-M*size_window, -m*size_window)U(m*size_window, M*size_window).

smooth: smooth the radon cost function; for one pixel, replace it by the

average of its +/- smooth neighbours; default = 2.

PAadj: optional angle by which to rotate diffraction spike angles in [radians]. write_hdr: (default) True will write the Radon transform star center to the original

FITS header in PSFCENTX & PSFCENTY keywords.

pool: multiprocessing pool for highpass filtering and other parallel uses. silent: (default) True to suppress additional output to stdout.

Outputs:

Returns [X,Y] list of Radon transform star center. Default is to also write the star coordinates to PSFCENTX & PSFCENTY in original FITS header.

pyklip.instruments.NIRC2.make_spikemask(data, hdr, ctr, spike_angles, yy, xx, width=31)[source]

Construct diffraction spike mask from FITS header information.

data: 2-D ndarray image to be masked (just to get size of array). hdr: FITS header for image constructing mask for. ctr: (y,x) coordinates for center of diffraction spike pattern

(usually the estimated star location).

spike_angles: position angles for diffraction spikes in image [radians]. yy: mgrid or indices 2-D array of pixel y-coordinates. xx: mgrid or indices 2-D array of pixel x-coordinates. width: int or float width of spike mask in [pixels]; 0 for no mask.

pyklip.instruments.NIRC2.measure_star_flux(img, star_x, star_y)[source]

Measure star peak fluxes using a Gaussian matched filter

Parameters:
  • img – 2D frame with unobscured, unsaturated PSF

  • star_x – coordinates of the star

  • star_y – coordinates of the star

Returns:

star flux

Return type:

star_f

pyklip.instruments.NIRC2.par_angle(HA, dec, lat)[source]

Compute the parallactic angle, given hour angle (HA [hours]), declination (dec [deg]), and latitude (lat [deg]). Returns parallactic angle in [deg].

pyklip.instruments.P1640 module

pyklip.instruments.SPHERE module

class pyklip.instruments.SPHERE.Ifs(data_cube, psf_cube, info_fits, wavelength_info, keepslices=None, psf_cube_size=21, nan_mask_boxsize=9, IWA=0.15, object_name=None, disable_minimum_filter=False, zeros2nans=False, subtract_psf_background=False)[source]

Bases: Data

A sequence of SPHERE IFS Data.

Parameters:
  • data_cube – FITS file with a 4D-cube (Nfiles, Nwvs, Ny, Nx) with all IFS coronagraphic data Also read spectral cubes and 2D images that have been saved using savedata().

  • psf_cube – FITS file with a 3-D (Nwvs, Ny, Nx) PSF cube

  • info_fits – FITS file with a table in the 1st ext hdr with parallactic angle info

  • wavelenegth_info – FITS file with a 1-D array (Nwvs) of the wavelength sol’n of a cube

  • psf_cube_size – size of the psf cube to save (length along 1 dimension)

  • nan_mask_boxsize – size of box centered around any pixel <= 0 to mask as NaNs

  • IWA – inner working angle of the data in arcsecs

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

ifs_rdp

Reduction algorithm used to obtain the input data.

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

psfs

Spectral cube of size (Nwv, psfy, psfx) where psf_cube_size defines the size of psfy, psfx.

psf_center

[x, y] location of the center of the PSF for a frame in self.psfs

flipx

True by default. Determines whether a relfection about the x axis is necessary to rotate image North-up East left

nfiles

number of datacubes

nwvs

number of wavelengths

property IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

property PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

calibrate_output(img, spectral=False, units='contrast')[source]

Calibrates the flux of an output image. Can either be a broadband image or a spectral cube depending on if the spectral flag is set.

Parameters:
  • img – unclaibrated image. If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

  • spectral – if True, this is a spectral datacube. Otherwise, it is a broadband image.

  • units – currently only support “contrast” w.r.t central star

Returns:

calibrated image of the same shape (this is the same object as the input!!!)

Return type:

img

property centers

Image centers. Shape of (N, 2) where the 2nd dimension is [x,y] pixel coordinate (in that order)

property filenames

Array of size N for the actual filepath of the file that corresponds to the data

property filenums

Array of size N for the numerical index to map data to file that was passed in

property ifs_rdp
property input

Input Data. Shape of (N, y, x)

property output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

platescale = 0.007462
readdata(filepaths)[source]

Reads in the data from the files in the filelist and writes them to fields

savedata(filepath, data, klipparams=None, filetype='', zaxis=None, more_keywords=None)[source]

Save SPHERE Data.

Note: In principle, the function only works inside klip_dataset(). In order to use it outside of klip_dataset,
you need to define the follwing attributes:

dataset.output_centers = dataset.centers

Parameters:
  • filepath – path to file to output

  • data – 2D or 3D data to save

  • klipparams – a string of klip parameters

  • filetype – filetype of the object (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”)

  • zaxis – a list of values for the zaxis of the datacub (for KL mode cubes currently)

  • more_keywords (dictionary) – a dictionary {key: value, key:value} of header keywords and values which will written into the primary header

property wcs

Array of N wcs astormetry headers for each image.

property wvs

Array of N wavelengths (used for SDI) [in microns]. For polarization data, defaults to “None”

class pyklip.instruments.SPHERE.Irdis(data_cube, psf_cube, info_fits, wavelength_str, psf_cube_size=21, IWA=0.08, OWA=None, keepslices=None)[source]

Bases: Data

A sequence of SPHERE IRDIS Data.

Parameters:
  • data_cube – FITS file with a 4D-cube (Nfiles, Nwvs, Ny, Nx) with all IFS coronagraphic data Also read spectral cubes and 2D images that have been saved using savedata().

  • psf_cube – FITS file with a 3-D (Nwvs, Ny, Nx) PSF cube If None, psf_cube = data_cube.replace(“cube_coro”,”cube_psf”)

  • info_fits – FITS file with a table in the 1st ext hdr with parallactic angle info If None, info_fits = data_cube.replace(“cube_coro”,”info”)

  • wavelength_str – string to specifiy the band (e.g. “H2H3”, “K1K2”)

  • psf_cube_size – size of the psf cube to save (length along 1 dimension)

  • IWA – inner working angle of the data in arcsecs

  • OWA – outer working angle of the data in arcsecs

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

OWA

a floating point scalar (not array). Specifies to out working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

psfs

Spectral cube of size (2, psfy, psfx) where psf_cube_size defines the size of psfy, psfx.

psf_center

[x, y] location of the center of the PSF for a frame in self.psfs

flipx

True by default. Determines whether a relfection about the x axis is necessary to rotate image North-up East left

nfiles

number of datacubes

prihdrs

SPHERE headers if reduced by Sphere data center

nwvs

number of wavelengths (i.e. 2 for dual band imaging)

property IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

property OWA
property PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

calibrate_output(img, spectral=False, units='contrast')[source]

Calibrates the flux of an output image. Can either be a broadband image or a spectral cube depending on if the spectral flag is set.

Parameters:
  • img – unclaibrated image. If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

  • spectral – if True, this is a spectral datacube. Otherwise, it is a broadband image.

  • units – currently only support “contrast” w.r.t central star

Returns:

calibrated image of the same shape (this is the same object as the input!!!)

Return type:

img

property centers

Image centers. Shape of (N, 2) where the 2nd dimension is [x,y] pixel coordinate (in that order)

property filenames

Array of size N for the actual filepath of the file that corresponds to the data

property filenums

Array of size N for the numerical index to map data to file that was passed in

property input

Input Data. Shape of (N, y, x)

property output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

platescale = 0.012255
readdata(filepaths)[source]

Reads in the data from the files in the filelist and writes them to fields

savedata(filepath, data, klipparams=None, filetype='', zaxis=None, more_keywords=None)[source]

Save SPHERE Data.

Note: In principle, the function only works inside klip_dataset(). In order to use it outside of klip_dataset,
you need to define the follwing attribute:

dataset.output_centers = dataset.centers

Parameters:
  • filepath – path to file to output

  • data – 2D or 3D data to save

  • klipparams – a string of klip parameters

  • filetype – filetype of the object (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”)

  • zaxis – a list of values for the zaxis of the datacub (for KL mode cubes currently)

  • more_keywords (dictionary) – a dictionary {key: value, key:value} of header keywords and values which will written into the primary header

wavelengths = {'B_H': (1.625, 1.625), 'B_J': (1.245, 1.245), 'B_Ks': (2.182, 2.182), 'B_Y': (1.043, 1.043), 'H2H3': (1.593, 1.667), 'H3H4': (1.667, 1.733), 'J2J3': (1.19, 1.273), 'K1K2': (2.11, 2.251), 'Y2Y3': (1.022, 1.076)}
property wcs

Array of N wcs astormetry headers for each image.

property wvs

Array of N wavelengths (used for SDI) [in microns]. For polarization data, defaults to “None”

pyklip.instruments.osiris module

class pyklip.instruments.osiris.Ifs(data_cube_list, telluric_cube, guess_center=None, recalculate_center_cadi=False, centers=None, psf_cube_size=21, coaddslices=None, nan_mask_boxsize=0, median_filter_boxsize=0, badpix2nan=False, ignore_PAs=True)[source]

Bases: Data

A spectral cube of Osiris IFS Data.

Parameters:
  • data_cube – FITS file list with 3D-cubes (Nwvs, Ny, Nx) with an osiris IFS data

  • telluric_cube – single telluric reference FITS file with a 3D-cube (Nwvs, Ny, Nx) with an osiris IFS data.

  • psf_cube_size – size of the psf cube to save (length along 1 dimension)

  • coaddslices – if not None, combine (addition) slices together to reduce the size of the spectral cube. coaddslices should be an integer corresponding to the number of slices to be combined.

input

Array of shape (N,y,x) for N images of shape (y,x)

centers

Array of shape (N,2) for N centers in the format [x_cent, y_cent]

filenums

Array of size N for the numerical index to map data to file that was passed in

filenames

Array of size N for the actual filepath of the file that corresponds to the data

PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

wvs

Array of N wavelengths of the images (used for SDI) [in microns]. For polarization data, defaults to “None”

IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

psfs

Spectral cube of size (Nwv, psfy, psfx) where psf_cube_size defines the size of psfy, psfx.

psf_center

[x, y] location of the center of the PSF for a frame in self.psfs

flipx

True by default. Determines whether a relfection about the x axis is necessary to rotate image North-up East left

nfiles

number of datacubes

nwvs

number of wavelengths

property IWA

a floating point scalar (not array). Specifies to inner working angle in pixels

property PAs

Array of N for the parallactic angle rotation of the target (used for ADI) [in degrees]

calibrate_output(img, spectral=False, units='contrast')[source]
Calibrates the flux of an output image. Can either be a broadband image or a spectral cube depending

on if the spectral flag is set.

Assumes the broadband flux calibration is just multiplication by a single scalar number whereas spectral datacubes may have a separate calibration value for each wavelength

Args:
img: unclaibrated image.

If spectral is not set, this can either be a 2-D or 3-D broadband image where the last two dimensions are [y,x] If specetral is True, this is a 3-D spectral cube with shape [wv,y,x]

spectral: if True, this is a spectral datacube. Otherwise, it is a broadband image. units: currently only support “contrast” w.r.t central star

Return:

img: calibrated image of the same shape (this is the same object as the input!!!)

property centers

Image centers. Shape of (N, 2) where the 2nd dimension is [x,y] pixel coordinate (in that order)

property filenames

Array of size N for the actual filepath of the file that corresponds to the data

property filenums

Array of size N for the numerical index to map data to file that was passed in

property input

Input Data. Shape of (N, y, x)

property output

Array of shape (b, len(files), len(uniq_wvs), y, x) where b is the number of different KL basis cutoffs

readdata(filepaths)[source]

Reads in the data from the files in the filelist and writes them to fields

savedata(filepath, data, center=None, klipparams=None, filetype='', zaxis=None, more_keywords=None)[source]

Save OSIRIS Data.

Note: In principle, the function only works inside klip_dataset(). In order to use it outside of klip_dataset,
you need to define the following attribute:

dataset.output_centers = dataset.centers

Parameters:
  • filepath – path to file to output

  • data – 2D or 3D data to save

  • center – center of the image to be saved in the header as the keywords PSFCENTX and PSFCENTY in pixels. The first pixel has coordinates (0,0)

  • klipparams – a string of klip parameters

  • filetype – filetype of the object (e.g. “KL Mode Cube”, “PSF Subtracted Spectral Cube”)

  • zaxis – a list of values for the zaxis of the datacub (for KL mode cubes currently)

  • more_keywords (dictionary) – a dictionary {key: value, key:value} of header keywords and values which will written into the primary header

property wcs

Array of N wcs astormetry headers for each image.

property wvs

Array of N wavelengths (used for SDI) [in microns]. For polarization data, defaults to “None”

pyklip.instruments.osiris.casdi_residual(xcen, ycen, input, wvs, nan2zero=False)[source]
pyklip.instruments.osiris.casdi_residual_star(params)[source]

Convert f([1,2]) to f(1,2) call. It allows one to call casdi_residual() with a tuple of parameters.

pyklip.instruments.osiris.determine_mosaic_offsets_from_header(prihdr_list)[source]
pyklip.instruments.osiris.determine_mosaic_offsets_from_speckles(input_list)[source]

Module contents