/djw_hst_tools

Python scripts for working with HST spectra.

Primary LanguagePythonMIT LicenseMIT

djw_hst_tools

Repository for python scripts for working with HST spectra, based on my work for Program ID 15189. Contents so far:

  • lc_extractor: extracts lightcurves from COS corrtag files

  • stis_combine: stitches STIS echelle spectra together

  • cos_fits_to_dat: turns COS xldsum files into ascii .dat files

lc_extractor

lc_extractor is a script to extract a lightcurve from HST/COS corrtag files.

Requires astropy, matplotlib, numpy.

Saves each FP_POS exposure separately (for FUV exposures)

For each exposure the counts from the A and B segments (FUV) or A, B and C traces (NUV), if present, are combined.

Airglow from Lymman alpha and ~1300A Oi is removed.

Error is photon noise only.

Optional: Plots lightcurve.

"""
Usage: call the function lc_maker()

lc_extractor.lc_maker(file_path=os.getcwd()+'/', save_path=os.getcwd()+'/lightcurves/', bin_time=1., plot=True, save_file='long')

Arguments: 
	- file_path = string, where your corrtag files are. Default is the curret directory.
	- save_path = sring, where you want the output to be saves. 
	Default is a new "lightcurves" directory in the current directory
	- bin_time = float, time in s to bin the lightcurve to. Default is 1.0s.
	- qual_check = boolean, masks out flagged pixels. Default is True.
	- plot = boolean, makes a plot of the combined lightcurve. Default is True.
    - save_file = file name to save the lightcurves as. Default is 'long':
        - 'long' = targname_band_expstart_rootname_bintime_lc.dat'
        - 'short' = rootname_bintime_lc.dat
	
Outputs: 
	- Lightcurve of each exposure saved as [exposure rootname]_[bintime]s_lc.dat.
	Lightcurves saved as time(s since MJD=0) counts(s-1) error(s-1). 

"""

What about STIS? STIS is hard, so I may add it in the future but no promises.

stis_combine

Stitches together STIS echelle spectra with overlapping orders.

At each overlap it interpolates the flux of the order with smaller wavelength bins onto the larger wavelength bins (although the difference is small) and makes a weighted coadd of the fluxes and errors.

Idealy uses x1f files produced using stisblazefix (https://stisblazefix.readthedocs.io). Can use x1d files but these are badly affected by echelle blaze ripple.

"""
Usage:

call stis_echelle_coadd()

If no arguments are called, it will stitch all x1f (or x1d if no x1f files are present) in the working directory, make a new directory in the working directory and save the stiched spectra there.

Arguments:

- files: Array, list of x1f or x1d files to stitch. Default = []

- plot: boolean. Make a plot of the stitched spectrum at the end. Default = True

- nclip: int, points to clip off each echelle order to clear up the order end problems that are inherent to stis data.
         I don't know a reason to change it, but the option is there. Default =5

- file_path: string, path to where the xld/xlf files are. Remember to include a '/' at the end. Default= working directory

- save_path: string, directory to save the stitched spectra in. Remember to include a '/' at the end. Default = new directory 'stitched_spectra' in the working directory

Output:

A .dat file with space-separated columns of wavelength, flux, flux_error and data quality.

The files are named using the x1d/x1f header KEYWORDS as: 'TARGNAME_'INSTRUME_DETECTOR_OPT_ELEM_TDATEOBS:TTIMEOBS_ROOTNAME_stitched.dat'

"""

cos_fits_to_dat

Extracts COS spectra from x1dsum.fits files and saves it as an ascii .dat file with columns wavelength, flux, error, dq

"""
Usage:
    
call the function cos_fits_to_dat.fits_to_dat(files=[], plot=True, file_path=os.getcwd()+'/', save_path=os.getcwd()+'/spectra/', filename='long')

If no arguments are called, it will extract all x1dsum.fits files in the working directory, make a new directory 'spectra' in the working directory and save the .dat files there.
    
Arguments:

- files: Array, list of x1dsum.fits files to stitch. Default = []

- plot: boolean. Make a plot of the stitched spectrum at the end. Default = True

- file_path: string, path to where the xld/xlf files are. Remember to include a '/' at the end. Default= working directory

- save_path: string, directory to save the stitched spectra in. Remember to include a '/' at the end. Default = new directory 'stitched_spectra' in the working directory

- file_name: string, what name to save the .dat file to. Two options built in:
    - 'long' (default) : uses header KEYWORDS to save the file as 'TARGNAME_'INSTRUME_DETECTOR_OPT_ELEM_DATE-OBS:TIME-OBS_ROOTNAME.dat'
    - 'short' : saves the file as 'ROOTNAME.dat'

"""