Access Publicly available High Resolution Spectroscopic Data¶

Authors¶

Damien Ségransan (DACE Project Leader)

Nicolas Unger (DACE Data Scientist)

Goals¶

  • Demonstrates how to use the DACE API's to navigate your way through data publicly available through DACE

Keywords¶

dace.spectroscopy, Spectroscopy.query_database, Spectroscopy.download, Spectroscopy.get_timeseries

Requirements¶

Anaconda 3, Python 3.8 or later, IPython 7.8.0
dace-query : 1.1.0 or later

Summary¶

In this example, you will query the DACE observation database, download severale products from the HARPS&CORALIE DRS and finally retrieve the radial velocity time series of a star.

Imports¶

In [1]:
import os
import numpy as np
import matplotlib.pyplot as plt

# Load the dace API spectroscopy module
from dace_query.spectroscopy import Spectroscopy
2023-11-22 17:02:45,076 - WARNING - File .dacerc not found. You are requesting data in public mode. To change this behaviour, create a .dacerc file in your home directory and fill it with your API key. More infos on https://dace.unige.ch

Query the DACE Observation Database¶

Here you'll search for all data publicly available for the star HD40307. We will request the output format to be a pandas DataFrame.

In [2]:
observedTargets = Spectroscopy.query_database(
    limit=1000,
    filters={"public": {"is": True}, "obj_id_catname": {"contains": ["HD106869"]}},
    output_format="pandas",
)
In [3]:
# list the keys of the dictionary  - Un-comment the code below to have the full listing
for col in observedTargets.columns:
    print(col)
obj_id_catname
obj_pos_coordinates_hms_dms
ins_name
prog_id
obj_date_bjd
date_night
ins_drs_version
pub_bibcode
pub_ref
ins_mode
public
db_spectrum_available
obj_id_daceid
spectro_analysis_ca_flx_h
spectro_analysis_ca_flx_r1
spectro_analysis_protn84_err
spectro_analysis_smw
spectro_analysis_ca_flx_k_err
spectro_analysis_ca_flx_r2_err
spectro_analysis_halpha_flx_r2_err
spectro_analysis_halpha_flx_h_err
spectro_analysis_na_err
spectro_analysis_na_flx_r2_err
spectro_analysis_halpha_flx_r1
spectro_analysis_na_flx_d1
spectro_analysis_smw_err
spectro_analysis_halpha
spectro_analysis_na_flx_d1_err
spectro_analysis_na_flx_d2
spectro_analysis_halpha_flx_r1_err
spectro_analysis_na_flx_r2
spectro_analysis_ca_flx_r2
spectro_analysis_na_flx_d2_err
spectro_analysis_ca_flx_h_err
spectro_analysis_na_flx_r1
spectro_analysis_halpha_flx_r2
spectro_analysis_protn84
spectro_analysis_na_flx_r1_err
spectro_analysis_rhk
ins_adc_pos
obj_pos_mudelta
obj_pos_equinox
obj_pos_mualpha
obj_pos_radvel
file_rootpath
photocenter
spectro_cal_thfile
spectro_ccf_contrast_err
spectro_ccf_flux_corrmin
spectro_ccf_bispan_err
spectro_ccf_contrast
spectro_flux_sn60
spectro_ccf_fwhm
spectro_flux_sn40
spectro_flux_sn20
spectro_flux_sn50
spectro_ccf_bispan
texp
spectro_ccf_rv
tpl_name
spectro_ccf_flux_corrmax
spectro_analysis_ca_err
spectro_analysis_rhk_err
spectro_analysis_ca_flx_r1_err
spectro_analysis_halpha_flx_h
spectro_analysis_protm08_err
spectro_analysis_halpha_err
spectro_analysis_ca_flx_k
spectro_analysis_protm08
spectro_analysis_ca
spectro_analysis_na
spectro_drs_qc_chi2
spectro_drs_qc_drift
clim_seeing_x
spectro_drs_qc_saturation
clim_seeing_y
spectro_drs_qc_flux_corr
spectro_drs_qc_drift_mean
spectro_ccf_mask_in_sof
ins_drs_reduction_date
ins_opti_fiber_a
ins_opti_fiber_b
spectro_ccf_asym
spectro_ccf_mask
spectro_cal_drift_noise
spectro_cal_drift_rv
spectro_ccf_fwhm_err
spectro_cal_berv_mx
spectro_ccf_rv_err
spectro_flux_sn10
spectro_flux_sn30
spectro_cal_berv
spectro_drs_qc
clim_airmass
spectro_drs_qc_drift_mean_err
spectro_drs_qc_flux_ratio
spectro_ccf_asym_err
spectro_ccf_continuum
spectro_dprtype
obj_sptype
ins1_adc1_temp
ins1_adc2_temp
ins2_adc1_temp
ins2_adc2_temp
ins3_adc1_temp
ins3_adc2_temp
ins4_adc1_temp
ins4_adc2_temp
th_ar
th_ar1
th_ar2
In [4]:
observedTargets[
    ["obj_id_catname", "obj_date_bjd", "date_night", "ins_name", "file_rootpath"]
]
Out[4]:
obj_id_catname obj_date_bjd date_night ins_name file_rootpath
0 HD106869 54823.823460 2008-12-22 CORALIE07 coralie07/DRS-3.4/reduced/2008-12-22/CORALIE.2...
1 HD106869 54828.779333 2008-12-27 CORALIE07 coralie07/DRS-3.4/reduced/2008-12-27/CORALIE.2...
2 HD106869 57086.758359 2015-03-04 CORALIE14 coralie14/DRS-3.8/reduced/2015-03-04/CORALIE.2...
3 HD106869 53141.588775 2004-05-15 CORALIE98 coralie98/DRS-3.3/reduced/2004-05-15/CORALIE.2...
4 HD106869 52355.778162 2002-03-21 CORALIE98 coralie98/DRS-3.3/reduced/2002-03-21/CORALIE.2...
... ... ... ... ... ...
59 HD106869 51286.702707 1999-04-17 CORALIE98 coralie98/DRS-3.3/reduced/1999-04-17/CORALIE.1...
60 HD106869 51286.714744 1999-04-17 CORALIE98 coralie98/DRS-3.3/reduced/1999-04-17/CORALIE.1...
61 HD106869 52366.664734 2002-04-01 CORALIE98 coralie98/DRS-3.3/reduced/2002-04-01/CORALIE.2...
62 HD106869 54829.839592 2008-12-28 CORALIE07 coralie07/DRS-3.4/reduced/2008-12-28/CORALIE.2...
63 HD106869 51751.469814 2000-07-25 CORALIE98 coralie98/DRS-3.3/reduced/2000-07-25/CORALIE.2...

64 rows × 5 columns

Download HARPS DRS data products¶

Now that you have a complete list of the publicly available data for HD40307, you are able to download all the reduced data of one night and save them as a file in 'HD40307-1998_11_13-download_files.tar.gz'

The raw files can be downloaded using the download_files method by giving the list of file paths. These can be retrieved from the file_rootpath column of the Spectroscopy databse (see above).

In [5]:
# Set current directory as download path
download_path = os.getcwd()
In [6]:
# Let's retireve the file name of the first observation available with CORALIE07
observedTargets.query("ins_name == 'CORALIE07'")["file_rootpath"].iloc[0]
Out[6]:
'coralie07/DRS-3.4/reduced/2008-12-22/CORALIE.2008-12-23T07:42:36.977.fits'
In [7]:
# Download all the raw files
Spectroscopy.download_files(
    files=["coralie07/DRS-3.4/reduced/2008-12-22/CORALIE.2008-12-23T07:42:36.977.fits"],
    file_type="all",
    output_directory=download_path,
    output_filename="HD106869-download_files.tar.gz",
)
2023-11-22 17:02:46,107 - INFO - Downloading file on location : /home/nunger/Dropbox/Postdoc/DACE data import/DACE Tutorials/HD106869-download_files.tar.gz
 Download : 2 MB
2023-11-22 17:02:46,732 - INFO - File downloaded on location : /home/nunger/Dropbox/Postdoc/DACE data import/DACE Tutorials/HD106869-download_files.tar.gz
 Download : 3 MB
Download done

The same thing can be done by downloading the files with the download method by providing the filters. We do the same as above but using filters instead of the file rooth path.

The first argument, file_type, can be used to indicate which type of files are wanted. The options are: ['s1d', 's2d', 'ccf', 'bis', 'guidance', 'all']

In [8]:
Spectroscopy.download(
    "all",
    filters={
        "date_night": {"contains": ["2008-12-22"]},
        "obj_id_catname": {"contains": ["HD106869"]},
    },
    output_directory=download_path,
    output_filename="HD106869-2008-12-22-download.tar.gz",
)
2023-11-22 17:02:47,399 - INFO - Downloading file on location : /home/nunger/Dropbox/Postdoc/DACE data import/DACE Tutorials/HD106869-2008-12-22-download.tar.gz
2023-11-22 17:02:47,817 - INFO - File downloaded on location : /home/nunger/Dropbox/Postdoc/DACE data import/DACE Tutorials/HD106869-2008-12-22-download.tar.gz
 Download : 3 MB
Download done

Retrieve and display HD40307 time series¶

Retrieve the different time series of HD40307 that are extracted from the high resolution spectra. It includes, the radial velocity, the CCF FHWM, the CCF-BIS and different activity indices.

In [9]:
# Get RV time series for a given target
spectro_time_series = Spectroscopy.get_timeseries(
    "HD106869", sorted_by_instrument=False, output_format="pandas"
)

# Remove two outliers that this dataset has
# These were taken on the nights of 2003-03-12 and 2013-01-26
spectro_time_series.drop(
    spectro_time_series.query("date_night == '2003-03-12'").index, inplace=True
)
spectro_time_series.drop(
    spectro_time_series.query("date_night == '2013-01-26'").index, inplace=True
)

date_d = spectro_time_series["rjd"]
rv_mps = spectro_time_series["rv"]
erv_mps = spectro_time_series["rv_err"]

# Display publicly available Radial Velocities as function of time
plt.figure(figsize=(10, 6))
plt.title("HD106869")
plt.errorbar(
    date_d,
    rv_mps - np.median(rv_mps),
    yerr=erv_mps,
    fmt=".",
)
plt.xlabel("Date [bjd]")
plt.ylabel("Radial Velocity [m/s]")
Out[9]:
Text(0, 0.5, 'Radial Velocity [m/s]')

Checking for correlations¶

In [10]:
plt.errorbar(
    rv_mps,
    spectro_time_series["fwhm"],
    yerr=spectro_time_series["fwhm_err"],
    xerr=erv_mps,
    fmt=".",
)
plt.xlabel("Radial Velocity [m/s]")
plt.ylabel("FWHM [km/s]")
plt.title("HD106869")
Out[10]:
Text(0.5, 1.0, 'HD106869')

(c) 2023 Data & Analysis Center for Exoplanets, Univerity of Geneva, Switzerland