Authors: Andy Tzanidakis, James Davenport, Eric Bellm Date: 03.10.222 For general questions or inquiries, please reach out to Andy ([email protected])


Motivation


The Zwicky Transient Facility (ZTF) is revolutionizing our understanding of the transient universe. In this homework you will be using real data collected from ZTF and you will get to experience the thrill of looking through light curves including a very important technique known as the Lomb-Scargle Periodogram (LSP) to recover the periodicity of an RR Lyrae star:

Here are some important highlights we will be covering in this noebook:

If you have any questions or concerns about this notebook please reach out to Andy ([email protected]). Without a further ado, let’s do some stellar astronomy! 🎉

TLDR Solutions


As always let’s begin with some packages that we will be using

import numpy as np
from astropy.io import ascii
import matplotlib.pyplot as plt

# FANCY PLOTS!
%matplotlib inline
%config InlineBackend.figure_format = "retina"
from matplotlib import rcParams
rcParams["savefig.dpi"] = 100
rcParams["font.size"] = 20

import astropy.units as u
from tqdm import tqdm
import astropy.constants as constant
import os
from astropy.table import Table
from astropy.time import Time
from astropy.timeseries import TimeSeries, LombScargle
import pandas as pd
from scipy.optimize import curve_fit # for linear fitting

We can also write out at the beginning of our notebook all the functions we will need throughout this homework problem:

def load_ztf_lc(filename):
    """Load a ZTF parquet lightcurve saved by `ztf_query`.
    
    See `ZTF_RRLyrae_data.ipynb` for data retrieval.
    
    Parameters
    ----------
    filename : string
        path to a parquet file saved by `ztf_query`
        
    Returns
    -------
    tbl : `astropy.timeseries.TimeSeries`
        lightcurve 
    mean_ra : `float`
        mean right ascension of the source
    mean_dec : `float`
        mean declination of the source
    """
    
    tbl = pd.read_parquet(filename)
    
    # exclude flagged (bad) data
    tbl = tbl[tbl['catflags'] == 0]
    
    # compute average position for this source
    mean_ra = np.mean(tbl['ra'])
    mean_dec = np.mean(tbl['dec'])
    
    return TimeSeries(time=Time(tbl['hjd'].values,format='jd'),
                      data=Table.from_pandas(tbl[['mag','magerr','filtercode']])), mean_ra, mean_dec

def dist_mod(app_mag, distance, abs_mag):
	""" Calculate distance modulus solving for absolute magnitude.
	     
			Parameters
			----------
			app_mag (float or np.array): apparent magnitude
			distance(float or np.array): distance in parsecs 
      
			Returns
			-------
			absolute_magnitude (float or np.array): absolute magnitude

  """
    return app_mag - 5*np.log10(distance/10)

def abs_mag_calc(app_mag, abs_mag):
	""" Calculate distance modulus solving for absolute magnitude.
	     
			Parameters
			----------
			app_mag (float or np.array): apparent magnitude
			absolute magnitude (float or np.array): absolute magnitude 
      
			Returns
			-------
			distance (float or np.array): distance in parsecs
  """
    return 10**((app_mag-abs_mag+5)/5)

def line(x, a, b, factor=1):
		""" Equation of line including some constant factor.""" 
    return a*(x/factor) + b

I will load my data the same way that it was recommended in the notebook:

rrl_url_path = '<http://jradavenport.github.io/astr421src/12.parquet>'
ts, _, _ = load_ztf_lc(rrl_url_path)

I also wrote a small little function that will take the Pandas ts table and return the photometry for a specific band: