Skip to content

Fitting absorption features in spectra

Daniel Berke edited this page Feb 27, 2022 · 3 revisions

For fitting absorption features in spectra, VarConLib uses the find_transitions.py script. It works on a single star at a time, but will automatically work on each observation of that star. In in order to do it, it makes use of the following directory structure: a top-level directory, currently called by the name of the star, within which are data/reduced directories. Within reduced, are directories corresponding to observing dates, within which is/are the e2ds file(s) from that date which have been prepared as detailed here. For example:

- HD117618/
  - data/
    - reduced/
      - 2005-05-02/
        - HARPS.2005-05-02T03:49:08.735_e2ds_A.fits
      - 2006-01-27/
        - HARPS.2006-01-27T08:31:59.484_e2ds_A.fits
      - 2010-04-21/
        - HARPS.2010-04-21T03:55:19.107_e2ds_A.fits

The processed versions of these files can be downloaded using the following command:

$ curl -OL https://www.dropbox.com/s/pqffpueg9nfbog4/HD117618.zip

This .zip file should be extracted in the directory given as output_dir in the VarConLib config file. In addition, the files containing the coefficients to create the wavelength calibration scale and the blaze function for each observation can be downloaded using the following commands.

$ curl -OL https://www.dropbox.com/s/db6feeh18ujfvjt/HD117618_wavelength_cal_files.zip
$ curl -OL https://www.dropbox.com/s/7n9gsoyk403gxj3/HD117618_blaze_cal_files.zip

These two ZIP archives should be extracted into the directories defined as harps_wavelength_cal_dir and harps_blaze_files_dir in the VarConLib config, respectively.

Other files present in the directories along with the "*e2ds_A.fits" files, if any, are unused and can be ignored (though ZIP archive listed above has had such extraneous files removed).

find_transitions.py will create a directory with the same name as the input directory (in the example above, HD117618) in the data_dir defined in the VarConLib config file. In this directory it will create a log file with a record of what did in the process of fitting absorption features in the star's spectra. It will then proceed to search for each transition in final_transitions_selection.pkl and fit them using the GaussianFit class in varconlib/fitting/model_fits.py.

Overview of flags for find_transitions.py

Example usage: find_transitions.py "/Volumes/External Storage/HARPS/HD117618/" HD117618 --pixel-positions --new-coefficients --integrated-gaussian --create-plots

object_dir : str

  • The directory where a star's data files are stored, as discussed above.

object_name : str

  • The name of the star—in practicality, for most objects this will be the same as the last part of the directory name; I mostly used it to be able to use "Vesta" as the directory name and "Sun" for the object name, in case I also need to get "Sun" observations from another object such as Ceres.

--start, --end : int

  • For stars with a large number of observations (i.e., thousands), this allows running the script on a subset of those observations denoted by start and stop. These numbers are passed to a slice of a Python list, so are 0-indexed, and negative numbers can be used to start at a certain position from the end.

-rv, --radialvelocity : float

  • Without this flag, the radial velocity will be read from each observation's FITS header. This assumes that all FITS files for the same object have the same radial velocity, which was mostly but not entirely true by default in the HARPS data I downloaded. If they don't, or you need to set the radial velocity for some reason (e.g., using observations of Vesta with time-varying barycentric radial velocities) you can use this flag.

--pixel-positions & --new-coefficients & --integrated-gaussian

  • These are simple True/False flags, and should all be set. They are leftovers from development when it wasn't certain that I would using any of the things they enable, but as we settled on using them all three flags should be enabled. It should be a fairly simple bit of work to set them as the default and remove the need of the flags, if desired. --pixel-positions controls whether to include the effects of pixel column width irregularities from Coffinet et al. (2019) --new-coefficients controls whether to use the new wavelength calibrations from the same paper, and --integrated-gaussian controls whether to use an integrated Gaussian function or a regular Gaussian function for the fit.

--update :list of str

  • This flag can be used to update various arrays in the e2ds files prior to fitting them. It assumes that these arrays already exist in the file; if not, the file should be run through HARPSFile2DScience. This simply sets a flag for HARPSFile2DScience when loading the file to rerun the code creating the array(s) listed, which can update them if that code has changed due to, e.g. bug fixes. The allowed list of array names are: WAVE, BARY, PIXLOWER, PIXUPPER, FLUX, ERR, BLAZE, or ALL.

--create-plots

  • A binary flag that controls whether the script creates plots of each fit as it performs it, for checking the quality of the fit.

--create-ccd-plots

  • A binary flag that controls whether to create a plot showing the rough location on the HARPS CCDs of each fit that was performed. This is very slow, and will run for each observation, so it is suggested to use it sparingly (since the location doesn't change much for a single star) and to make use of the start and stop flags to target specific observations.

-s, --single-threaded

  • By default find_transitions.py is multi-threaded, with each thread being able to handle fitting absorption features in a single observation independently. In case this causes issue, this flag can be given to force it to use a single thread sequentially.

-p, --preview

  • This option will show a preview of the observations which would be selected to work on, useful as a check or to see if the right observations have been selected with start and stop.

-v --verbose Controls whether the script prints out additional information while running.