# Calculate CCFs

## Calculate CCFs

### Functions

`EchelleCCFs.calc_ccf_and_var_chunk!`

— Method`calc_ccf_and_var_chunk!( chunk, ccf_plan )`

Convenience function to compute CCF and variance of each "CCF pixel" for one chunk of spectrum, evaluated using mask*shape and line list from `ccf*plan`.

**Inputs:**

`ccf_out`

:`AbstractArray`

to store output`ccf_var_out`

:`AbstractArray`

to store output`chunk`

: ChunkOfSpectrum to compute CCF for`ccf_plan`

: for now, just a BasicCCFPlan that provides line*list, mask*shape and other parameters for calculating CCF

**Optional Arguments:**

`var`

:`AbstractArray`

with variance to use for each pixel (overides value in chunk)`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Returns Named Tuple with:**

`ccf_out`

:`ccf_var_out`

:

`EchelleCCFs.calc_ccf_and_var_chunk`

— Method`calc_ccf_and_var_chunk( chunk, ccf_plan )`

Convenience function to compute CCF and variance of each "CCF pixel" for one chunk of spectrum, evaluated using mask*shape and line list from `ccf*plan`.

**Inputs:**

`ccf_out`

:`AbstractArray`

to store output`ccf_var_out`

:`AbstractArray`

to store output`chunk`

: ChunkOfSpectrum to compute CCF for`ccf_plan`

: for now, just a BasicCCFPlan that provides line*list, mask*shape and other parameters for calculating CCF

**Optional Arguments:**

`var`

:`AbstractArray`

with variance to use for each pixel (overides value in chunk)

`-`

assume*sorted`: if true, skips checking the line*list is sorted by wavelength

**Returns Named Tuple with:**

`ccf_out`

:`ccf_var_out`

:

`EchelleCCFs.calc_ccf_and_var_chunklist`

— Method`calc_ccf_and_var_chunklist ( chunklist, ccf_plans )`

Convenience function to compute CCF based on a spectrum's chunklist.

**Inputs:**

- chunklist
- vector of ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

CCF summed over all chunks in a spectrum's chunklist, evaluated using the line list and mask_shape from the ccf plan for each chunk.

`EchelleCCFs.calc_ccf_chunk!`

— Method`calc_ccf_chunk!( ccf_out, chunk, ccf_plan )`

Convenience function to compute CCF for one chunk of spectrum, evaluated using mask_shape and line list from ccf plan

**Inputs:**

`ccf_out`

:`AbstractArray`

to store output`chunk`

: ChunkOfSpectrum to compute CCF for`ccf_plan`

: for now, just a BasicCCFPlan that provides line*list, mask*shape and other parameters for calculating CCF

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Returns:**

`ccf_out`

`EchelleCCFs.calc_ccf_chunk`

— Method`calc_ccf_chunk( chunk, ccf_plan )`

Convenience function to compute CCF for one chunk of spectrum.

**Inputs:**

`ccf_out`

:`AbstractArray`

to store output`chunk`

: ChunkOfSpectrum to compute CCF for`ccf_plan`

: for now, just a BasicCCFPlan that provides line*list, mask*shape and other parameters for calculating CCF

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength`calc_ccf_var`

: if true also computes estimate of variance for each value of ccf

**Returns:**

- CCF for one chunk of spectrum, evaluated using mask_shape and line list from ccf plan

`EchelleCCFs.calc_ccf_chunklist`

— Method`calc_ccf_chunklist ( chunklist, ccf_plans )`

Convenience function to compute CCF based on a spectrum's chunklist.

**Inputs:**

- chunklist
- vector of ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

CCF summed over all chunks in a spectrum's chunklist, evaluated using the line list and mask_shape from the ccf plan for each chunk.

`EchelleCCFs.calc_ccf_chunklist_timeseries`

— Method`calc_ccf_chunklist_timeseries( chunklist_timeseries, line_list )`

Convenience function to compute CCF for a timeseries of spectra, each with a chunklist. Uses multiple threads if avaliable.

**Inputs:**

- chunklist_timeseries

**Optional Arguments:**

- ccf_plan (BasicCCFPlan())
- verbose (false)

**Return:**

CCF summed over all chunks in a spectrum's chunklist, evaluated using the ccf*plan. Note that the ccf*plan provided is used as a template for creating a custom ccf*plan for each chunk that only includes lines that reliably appear in that order for all spectra in the chunklist*timeseries.

`EchelleCCFs.calc_ccf_template`

— Methodcalc*ccf*template( ccfs, [ccf*vars] ; assume*normalized = false ) Calculates ccf template Warning: uses maximum CCF for normalization, unless you normalize manually.

`EchelleCCFs.calc_ccf_v_grid`

— Method`calc_ccf_v_grid( plan )`

Return range where CCF is to be evaluated, Centered around plan.v*center going up to at least plan.v*max in steps of size plan.v_step. Units based on those in plan.

`EchelleCCFs.calc_length_ccf_v_grid`

— Method`calc_length_ccf_v_grid( plan )`

Return number of points in the velocity grid (without needing to create the range).

`EchelleCCFs.calc_normalized_ccfs`

— Methodcalc*normalized*ccfs( ccfs ) Normalizes each spectrum by its maximum value.

`EchelleCCFs.calc_order_ccf_and_vars_chunklist!`

— Method`calc_order_ccfs_chunklist ( chunklist_timeseries, list_of_ccf_plans )`

Convenience function to compute separate CCFs for each chunk (potentially an order or view around one or two lines) in a spectrum. CCF is evaluated using line list and mask_shape provided by the ccf plan for each chunk.

**Inputs:**

`chunklist_timeseries`

:`list_of_ccf_plans`

: ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

A 2-d array containing the CCF at each (velocity, chunk)

`EchelleCCFs.calc_order_ccf_and_vars_chunklist`

— Method`calc_order_ccfs_chunklist ( chunklist_timeseries, list_of_ccf_plans )`

Convenience function to compute separate CCFs for each chunk (potentially an order or view around one or two lines) in a spectrum. CCF is evaluated using line list and mask_shape provided by the ccf plan for each chunk.

**Inputs:**

`chunklist_timeseries`

:`list_of_ccf_plans`

: ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

A 2-d array containing the CCF at each (velocity, chunk)

`EchelleCCFs.calc_order_ccfs_chunklist!`

— Method`calc_order_ccfs_chunklist ( chunklist_timeseries, list_of_ccf_plans )`

Convenience function to compute separate CCFs for each chunk (potentially an order or view around one or two lines) in a spectrum. CCF is evaluated using line list and mask_shape provided by the ccf plan for each chunk.

**Inputs:**

`chunklist_timeseries`

:`list_of_ccf_plans`

: ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

A 2-d array containing the CCF at each (velocity, chunk)

`EchelleCCFs.calc_order_ccfs_chunklist`

— Method`calc_order_ccfs_chunklist ( chunklist_timeseries, list_of_ccf_plans )`

Convenience function to compute separate CCFs for each chunk (potentially an order or view around one or two lines) in a spectrum. CCF is evaluated using line list and mask_shape provided by the ccf plan for each chunk.

**Inputs:**

`chunklist_timeseries`

:`list_of_ccf_plans`

: ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

A 2-d array containing the CCF at each (velocity, chunk)

`EchelleCCFs.ccf_1D!`

— Method``ccf_1D!(ccf_out, λs, fluxes; ccf_plan )``

Compute the cross correlation function of a spectrum with a mask. Generalized version that should work with different mask shapes.

**Inputs:**

`ccf_out`

: 1-d array of size length(calc*ccf*v_grid(plan)) to store output`λs`

: 1-d array of wavelengths`fluxes`

: 1-d array of fluxes

**Optional Arguments:**

`plan`

: parameters for computing ccf (BasicCCFPlan())

`EchelleCCFs.ccf_1D!`

— Method``ccf_1D!(ccf_out, ccf_var_out, λs, fluxes, var; ccf_plan )``

Compute the cross correlation function of a spectrum with a mask. Generalized version that should work with different mask shapes.

**Inputs:**

`ccf_out`

: 1-d array of size length(calc*ccf*v_grid(plan)) to store output`ccf_var_out`

: 1-d array of size length(calc*ccf*v_grid(plan)) to store output`λs`

: 1-d array of wavelengths`fluxes`

: 1-d array of fluxes`var`

: 1-d array of flux variances

**Optional Arguments:**

`plan`

: parameters for computing ccf (BasicCCFPlan())

`EchelleCCFs.ccf_1D!`

— Method``ccf_1D!(ccf_out, ccf_covar_out, λs, fluxes, var; ccf_plan )``

Compute the cross correlation function of a spectrum with a mask. Generalized version that should work with different mask shapes. WIP: Generalized version to compute covariance matrix for ccf and optionally to account for LSF

**Inputs:**

`ccf_out`

: 1-d array of size length(calc*ccf*v_grid(plan)) to store output`ccf_covar_out`

: 2-d array of size length(calc*ccf*v_grid(plan))^2 to store output`λs`

: 1-d array of wavelengths`fluxes`

: 1-d array of fluxes`var`

: 1-d array of flux variances

**Optional Arguments:**

`plan`

: parameters for computing ccf (BasicCCFPlan())

`EchelleCCFs.ccf_1D`

— Method```
`ccf_1D( λs, fluxes; ccf_plan )`
Compute the cross correlation functions of spectra with a mask.
```

**Inputs:**

`λs`

: 1-d array of wavelengths`fluxes`

: 2-d array of fluxes, individual spectra along first dim

**Optional Arguments:**

`ccf_plan`

: parameters for computing ccf (BasicCCFPlan())

**Returns:**

- 2-d array of size (length(calc
*ccf*v_grid(plan)), size(flux, 2))

`EchelleCCFs.ccf_1D`

— Method```
`ccf_1D( λs, fluxes; ccf_plan )`
Compute the cross correlation function of a spectrum with a mask.
```

**Inputs:**

`λs`

: 1-d array of wavelengths`fluxes`

: 1-d array of fluxes

**Optional Arguments:**

`ccf_plan`

: parameters for computing ccf (BasicCCFPlan())

**Returns:**

- 1-d array of size length(calc
*ccf*v_grid(plan))

`EchelleCCFs.ccf_1D`

— Method``ccf_1D( λs, fluxes, vars; ccf_plan )``

Compute the cross correlation function of a spectrum with a mask and its variance^1. ^1 = This version computes the diagonal terms for the ccf variance and neglects covariances due to the line spread function. Can roughly compensate by scaling up the ccf*var*scale from the default of 1. WARNING: Still needs more testing.

**Inputs:**

`λs`

: 1-d array of wavelengths`fluxes`

: 1-d array of fluxes

**Optional Arguments:**

`ccf_plan`

: parameters for computing ccf (BasicCCFPlan())

**Returns:**

- 1-d array of size length(calc
*ccf*v_grid(plan))

### Types

`EchelleCCFs.AbstractCCFMaskShape`

— TypeA struct implementing a specific mask shapes should be a subtype of AbstractCCFMaskShape.

`EchelleCCFs.AbstractCCFPlan`

— TypeA struct implementing a specific plans describing where the CCF is to be evaluated should be a subtype of AbstractCCFPlan.

`EchelleCCFs.AbstractLineList`

— TypeA struct implementing a line list should be a subtype of AbstractLineList.

`EchelleCCFs.BasicCCFPlan`

— TypeBasic plan for computing the CCF roughly between v*center-v*max and v*center+v*max with step size v_step.

`EchelleCCFs.BasicCCFPlan`

— MethodBasicCCFPlan

**Optional arguments:**

`midpoint`

: (`default_v_center`

)`step`

: (`default_v_step`

)`max`

: (`default_v_max`

)

`EchelleCCFs.BasicLineList`

— TypeA basic line list for passing to compute CCFs. Contains (views into) arrays specifying the minimum and maximum wavelength range and weight for each line.

`EchelleCCFs.BasicLineList`

— Method`BasicLineList( λ, weight )`

`EchelleCCFs.CosCCFMask`

— TypeCosCCFMask Cosine mask with one parameter, it's quarter period, i.e., where to truncate it, as a velocity in m/s. Mask weights are stored separately in a line list.

`EchelleCCFs.CosCCFMask`

— MethodFunctor for returning PSF for Δv <= half_width.

`EchelleCCFs.CosCCFMask`

— Method`CosCCFMask( inst )`

`EchelleCCFs.GaussianCCFMask`

— TypeGaussianCCFMask A truncated Gaussian mask with two parameters, its standard deviation and where to truncate it, both as a velocity in m/s. Mask weights are stored separately in a line list.

`EchelleCCFs.GaussianCCFMask`

— MethodFunctor for returning PSF for Δv <= half_width.

`EchelleCCFs.GaussianCCFMask`

— Method`GaussianCCFMask( inst ; scale_factor )`

`EchelleCCFs.SuperGaussianCCFMask`

— TypeSuperGaussianCCFMask A truncated Gaussian mask with two parameters, its standard deviation and where to truncate it, both as a velocity in m/s. Mask weights are stored separately in a line list.

TODO: Replace Gaussian with super-Gaussian Warning: Not implemented/tested yet.

`EchelleCCFs.SuperGaussianCCFMask`

— Method`SuperGaussianCCFMask( inst ; scale_factor )`

`EchelleCCFs.SuperGaussianCCFMask`

— MethodFunctor for returning PSF for Δv <= half_width.

`EchelleCCFs.TopHatCCFMask`

— TypeTopHatCCFMask The standard tophat mask with one parameter, it's half width as a velocity in m/s. Mask weights are stored separately in a line list.

`EchelleCCFs.TopHatCCFMask`

— Type`TopHatCCFMask( full_width )`

`

`EchelleCCFs.TopHatCCFMask`

— MethodFunctor for returning constant for any Δv <= width.

`EchelleCCFs.TopHatCCFMask`

— Method`TopHatCCFMask( inst )`

## Internals

`Base.length`

— MethodReturn length of line list.

`EchelleCCFs.calc_ccf_and_covar_chunk!`

— Method`calc_ccf_and_covar_chunk!( chunk, ccf_plan )`

Convenience function to compute CCF and covariance of each pair of "CCF pixels" for one chunk of spectrum, evaluated using mask*shape and line list from `ccf*plan`.

**Inputs:**

`ccf_out`

:`AbstractArray`

to store output`ccf_covar_out`

:`AbstractArray`

to store output`chunk`

: ChunkOfSpectrum to compute CCF for`ccf_plan`

: for now, just a BasicCCFPlan that provides line*list, mask*shape and other parameters for calculating CCF

**Optional Arguments:**

`var`

:`AbstractArray`

with variance to use for each pixel (overides value in chunk)`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Returns Named Tuple with:**

`ccf_out`

:`ccf_covar_out`

:

`EchelleCCFs.calc_ccf_and_covar_chunk`

— Method`calc_ccf_and_covar_chunk( chunk, ccf_plan )`

Convenience function to compute CCF and covariance of each pair of "CCF pixels" for one chunk of spectrum, evaluated using mask*shape and line list from `ccf*plan`.

**Inputs:**

`ccf_out`

:`AbstractArray`

to store output`ccf_covar_out`

:`AbstractArray`

to store output`chunk`

: ChunkOfSpectrum to compute CCF for`ccf_plan`

: for now, just a BasicCCFPlan that provides line*list, mask*shape and other parameters for calculating CCF

**Optional Arguments:**

`var`

:`AbstractArray`

with variance to use for each pixel (overides value in chunk)

`-`

assume*sorted`: if true, skips checking the line*list is sorted by wavelength

**Returns Named Tuple with:**

`ccf_out`

:`ccf_covar_out`

:

`EchelleCCFs.calc_ccf_and_covar_chunklist!`

— Method`calc_ccf_and_covar_chunklist! ( ccf_out, ccf_cocovar_out, chunklist, ccf_plans )`

Convenience function to compute CCF based on a spectrum's chunklist.

**Inputs:**

- chunklist
- vector of ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

CCF summed over all chunks in a spectrum's chunklist, evaluated using the line list and mask_shape from the ccf plan for each chunk.

`EchelleCCFs.calc_ccf_and_covar_chunklist`

— Method`calc_ccf_and_covar_chunklist ( chunklist, ccf_plans )`

Convenience function to compute CCF based on a spectrum's chunklist.

**Inputs:**

- chunklist
- vector of ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

`EchelleCCFs.calc_ccf_and_var_chunklist!`

— Method`calc_ccf_and_var_chunklist! ( ccf_out, ccf_var_out, chunklist, ccf_plans )`

Convenience function to compute CCF based on a spectrum's chunklist.

**Inputs:**

- chunklist
- vector of ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

`EchelleCCFs.calc_ccf_chunklist!`

— Method`calc_ccf_chunklist! ( ccfs_out, chunklist, ccf_plans )`

Convenience function to compute CCF based on a spectrum's chunklist.

**Inputs:**

- chunklist
- vector of ccf plans (one for each chunk)

**Optional Arguments:**

`assume_sorted`

: if true, skips checking the line_list is sorted by wavelength

**Return:**

`EchelleCCFs.calc_doppler_factor`

— Method`calc_doppler_factor(vel)`

` Compute the longitudinal relativistic doppler factor given a velocity in meters per second.

`EchelleCCFs.calc_order_ccf_and_var_chunklist_timeseries`

— Method`calc_order_ccf_and_var_chunklist_timeseries( chunklist_timeseries, ccf_plan )`

Convenience function to compute separate CCFs for each chunk (potentially an order or view around one or two lines) of each spectrum in a timeseries. CCF is evaluated using line list and mask_shape provided by the ccf plan for each chunk. Uses multiple threads if avaliable.

**Inputs:**

- chunklist_timeseries

**Optional Arguments:**

- ccf_plan (BasicCCFPlan())

**Return:**

A 3-d array containing the CCF at each (velocity, chunk, spectrum) Note that the ccf*plan provided is used as a template for creating a custom ccf*plan for each chunk that only includes lines that reliably appear in that order for all spectra in the chunklist_timeseries.

`EchelleCCFs.calc_order_ccf_chunklist_timeseries`

— Method`calc_order_ccf_chunklist_timeseries( chunklist_timeseries, ccf_plan )`

Convenience function to compute separate CCFs for each chunk (potentially an order or view around one or two lines) of each spectrum in a timeseries. CCF is evaluated using line list and mask_shape provided by the ccf plan for each chunk. Uses multiple threads if avaliable.

**Inputs:**

- chunklist_timeseries

**Optional Arguments:**

- ccf_plan (BasicCCFPlan())

**Return:**

A 3-d array containing the CCF at each (velocity, chunk, spectrum) Note that the ccf*plan provided is used as a template for creating a custom ccf*plan for each chunk that only includes lines that reliably appear in that order for all spectra in the chunklist_timeseries.

`EchelleCCFs.find_overlapping_chunks`

— MethodReturn indices of any chunks in df that have overlapping `lambda_hi[i]`

and `lambda_lo[i+1]`

.

`EchelleCCFs.fit_ccf_normalizations`

— Methodcalc*normalized*ccfs( ccfs ) Normalizes each spectrum by fitting a line to the region outside the center

`EchelleCCFs.merge_chunks`

— MethodReturn DataFrame with specifications for each chunk which will contain one or more lines. Input: `line_list`

a DataFrame with: - `lambda_lo`

, `lambda_hi`

, `lambda`

, `depth`

Output: DataFrame with - `lambda_lo`

& `lambda_hi`

: boundaries for chunk - `lambda`

& `line_depths`

: arrays with info about each line

`EchelleCCFs.project_mask!`

— Method`project_mask!( output, λs, ccf_plan; shift_factor )`

Compute the projection of the mask onto the 1D array of wavelengths (λs) at a given shift factor (default: 1). The mask is computed from the ccf*plan, including a line*list and mask*shape (default: tophat). Assumes plan.line*list is already sorted.

`EchelleCCFs.read_linelist_espresso`

— Method`Read line list in ESPRESSO csv format.`

ESPRESSO format: lambda and weight. convert*air*to_vacuum determines whether to convert to vacuum wavelengths. Warning: ESPRESSO masks don't provide line depth and sometimes include one entry for a blend of lines.

`EchelleCCFs.read_linelist_rvspectml`

— MethodRead line list in csv format. format: lambda, weight, lambda*lo, lambdaa*hi. Assumes air to vacuumb wavelength conversion has already been applied.

`EchelleCCFs.read_linelist_vald`

— MethodRead line list in VALD csv format. VALD format: lambda*lo, lambdaa*hi and depth. convert*air*to_vacuum determines whether to convert to vacuum wavelengths.

`EchelleCCFs.read_mask_espresso`

— Method`Read mask in ESPRESSO csv format.`

ESPRESSO format: `lambda`

and `weight`

. Warning: ESPRESSO masks don't provide line depth and sometimes include one entry for a blend of lines.

`EchelleCCFs.read_mask_vald`

— MethodRead mask in VALD csv format. VALD format: `lambda_lo`

, `lambdaa_hi`

and `depth`

.

`EchelleCCFs.λ_air_to_vac`

— MethodConvert air wavelength (in Å) to vacuum wavelength Ref: https://www.astro.uu.se/valdwiki/Air-to-vacuum%20conversion VALD3 tools use the following solution derived by N. Piskunov

`EchelleCCFs.λ_vac_to_air`

— MethodConvert vacuum wavelength (in Å) to air wavelength Ref: Donald Morton (2000, ApJ. Suppl., 130, 403) via https://www.astro.uu.se/valdwiki/Air-to-vacuum%20conversion