class kcwidrp.primitives.ApplyFlat.ApplyFlat(action, context)[source]

Generic routine to apply flat fielding. Not yet implemented.

class kcwidrp.primitives.ArcOffsets.ArcOffsets(action, context)[source]

Derive offset of each bar relative to reference bar.

Using cross correlation techniques, this routine calculates the relative offsets between the reference bar (loaded as a parameter as config.instrument.REFBAR).

Arcs must be available as context.arcs.

class kcwidrp.primitives.CalcPrelimDisp.CalcPrelimDisp(action, context)[source]

Calculate dispersion based on configuration parameters.

The parameters of the grating equation are calculates as:

alpha = grating_angle - 13 - adjustment_ange (180 for BH, RH and
0 for all other gratings)

beta = camera_angle - alpha

dispersion = cos(beta)/rho/focal_length x (pixel_scale x binning) * 1.e4

class kcwidrp.primitives.CorrectDar.CorrectDar(action, context)[source]

Correct for Differential Atmospheric Refraction

kcwidrp.primitives.CorrectDar.atm_disper(w0, w1, airmass, temperature=10.0, pressure_pa=61100.0, humidity=50.0, co2=400.0)[source]

Calculate atmospheric dispersion at w1 relative to w0

  • w0 (float) – reference wavelength (Angstroms)
  • w1 (float) – offset wavelength (Angstroms)
  • airmass (float) – unitless airmass
  • temperature (float) – atmospheric temperature (C)
  • pressure_pa (float) – atmospheric pressure (Pa)
  • humidity (float) – relative humidity (%)
  • co2 (float) – Carbon-Dioxide (mu-mole/mole)
class kcwidrp.primitives.CorrectDefects.CorrectDefects(action, context)[source]

Remove known bad columns

class kcwidrp.primitives.CorrectGain.CorrectGain(action, context)[source]

Convert raw data numbers to electrons

class kcwidrp.primitives.CorrectIllumination.CorrectIllumination(action, context)[source]

Subtract master bias frame

class kcwidrp.primitives.CreateUncertaintyImage.CreateUncertaintyImage(action, context)[source]

Generate a variance image based on Poisson noise plus readnoise

class kcwidrp.primitives.CubeImage.CubeImage(action, context)[source]

Transform 2D images to 3D data cubes

class kcwidrp.primitives.ExtractArcs.ExtractArcs(action, context)[source]

Use derived traces to extract arc spectra along bars

class kcwidrp.primitives.FindBars.FindBars(action, context)[source]

Find bars in middle row of cont bars image

class kcwidrp.primitives.FitCenter.FitCenter(action, context)[source]

Fit central region

kcwidrp.primitives.FitCenter.pascal_shift(coefficients=None, x0=None)[source]

Shift coefficients to a new reference value (X0)

This should probably go somewhere else, but will be needed here.

class kcwidrp.primitives.FluxCalibrate.FluxCalibrate(action, context)[source]
class kcwidrp.primitives.GenerateMaps.GenerateMaps(action, context)[source]

Generate map images

class kcwidrp.primitives.GetAtlasLines.GetAtlasLines(action, context)[source]

Get relevant atlas line positions and wavelengths

kcwidrp.primitives.GetAtlasLines.findpeaks(x, y, wid, sth, ath, pkg=None, verbose=False)[source]

Find peaks in spectrum

kcwidrp.primitives.GetAtlasLines.gaus(x, a, mu, sigma)[source]

Gaussian fitting function

kcwidrp.primitives.GetAtlasLines.get_line_window(y, c, thresh=0.0, logger=None, strict=False)[source]

Find a window that includes the fwhm of the line

class kcwidrp.primitives.MakeCube.MakeCube(action, context)[source]

Transform 2D images to 3D data cubes


Warp each slice

class kcwidrp.primitives.MakeInvsens.MakeInvsens(action, context)[source]
class kcwidrp.primitives.MakeMasterBias.MakeMasterBias(action, context)[source]

Generate a master bias image from individual bias frames

class kcwidrp.primitives.MakeMasterDark.MakeMasterDark(action, context)[source]

Stack dark frames into master dark

class kcwidrp.primitives.MakeMasterFlat.MakeMasterFlat(action, context)[source]

Stack flat images and make master flat image

class kcwidrp.primitives.MakeMasterSky.MakeMasterSky(action, context)[source]

Make master sky image

class kcwidrp.primitives.NandshuffSubtractSky.NandshuffSubtractSky(action, context)[source]
class kcwidrp.primitives.ProcessArc.ProcessArc(action, context)[source]
class kcwidrp.primitives.ProcessBias.ProcessBias(action, context)[source]
class kcwidrp.primitives.ProcessContbars.ProcessContbars(action, context)[source]
class kcwidrp.primitives.ProcessDark.ProcessDark(action, context)[source]
class kcwidrp.primitives.ProcessFlat.ProcessFlat(action, context)[source]
class kcwidrp.primitives.ProcessObject.ProcessObject(action, context)[source]
class kcwidrp.primitives.ReadAtlas.ReadAtlas(action, context)[source]

Read in atlas spectrum and derive alignment offset

class kcwidrp.primitives.RectifyImage.RectifyImage(action, context)[source]

Ensure output image has a consistent orientation

class kcwidrp.primitives.RemoveCosmicRays.RemoveCosmicRays(action, context)[source]

Remove cosmic rays and generate a flag image recording their location

class kcwidrp.primitives.SolveArcs.SolveArcs(action, context)[source]

Solve the bar arc wavelengths

class kcwidrp.primitives.SolveGeom.SolveGeom(action, context)[source]

Solve the overall geometry of the IFU

class kcwidrp.primitives.StackFlats.StackFlats(action, context)[source]

Stack flat images

class kcwidrp.primitives.StartBokeh.StartBokeh(action, context)[source]


class kcwidrp.primitives.SubtractBias.SubtractBias(action, context)[source]

Subtract master bias frame

class kcwidrp.primitives.SubtractDark.SubtractDark(action, context)[source]

Subtract master dark frame

class kcwidrp.primitives.SubtractOverscan.SubtractOverscan(action, context)[source]

Fit overscan region and subtract result from image

class kcwidrp.primitives.SubtractScatteredLight.SubtractScatteredLight(action, context)[source]

Subtract scattered light between slices

class kcwidrp.primitives.SubtractSky.SubtractSky(action, context)[source]
class kcwidrp.primitives.TraceBars.TraceBars(action, context)[source]

Derive bar traces

class kcwidrp.primitives.TrimOverscan.TrimOverscan(action, context)[source]

Trim off overscan region

class kcwidrp.primitives.kcwi_file_primitives.ingest_file(action, context)[source]



Return output delta lambda in Angstroms for the given grating


Return CCD section variables useful for processing

Uses FITS keyword NVIDINP to determine how many amplifiers were used to read out the CCD. Then reads the corresponding BSECn, and DSECn keywords, where n is the amplifier number. The indices are converted to Python (0-biased, y axis first) indices and an array is constructed for each of the two useful sections of the CCD as follows:

Bsec[0][0] - First amp, y lower limit Bsec[0][1] - First amp, y upper limit Bsec[0][2] - First amp, x lower limit Bsec[0][3] - First amp, x upper limit Bsec[1][0] - Second amp, y lower limit etc.

Bsec is the full overscan region for the given amplifier and is used to calculate and perform the overscan subtraction.

Dsec is the full CCD region for the given amplifier and is used to trim the image after overscan subtraction has been performed.

Tsec accounts for trimming the image according to Dsec.

Amps are assumed to be organized as follows:

(0,ny) ——— (nx,ny)
3 | 4 |
1 | 2 |

(0,0) ——— (nx, 0)

self: instance of CcdPrimitive class (automatic)
list: (int) y0, y1, x0, x1 for bias section list: (int) y0, y1, x0, x1 for data section list: (int) y0, y1, x0, x1 for trimmed section list: (bool) y-direction, x-direction, True if forward, else False

Return FWHM resolution in Angstroms for the given grating


A reader for KeckData objects. Currently this is a separate function, but should probably be registered as a reader similar to fits_ccddata_reader. Arguments: file – The filename (or pathlib.Path) of the FITS file to open.