@@ -0,0 +1,1895 @@
+#!/usr/bin/env python%0A#%0A# Given an octant of QSOs, generated by the box2sky code,%0A# add a field giving their g-band apparent magnitude.%0A#%0A#%0Afrom __future__ import print_function,division%0A%0A%0Aimport numpy  as np%0Aimport fitsio as F%0Aimport ndfilehandler as FH%0Aimport sys%0Aimport os%0A%0A%0A__author__ = %22Martin White%22%0A__version__ = %221.0%22%0A__email__  = %22mjwhite@lbl.gov%22%0A%0A%0A%0Adef calc_magnitude(box,octant):%0A    %22%22%22    %0A    Generates the apparent magnitude given the absolute magnitude,%0A    obtained from the %22box%22, and the distance modulus and K-correction.%0A    %22%22%22%0A    # Read the Mi(z=2) magnitudes for the box.%0A    miz2 = FH.read_file(box)%5B'Miz2'%5D%5B:%5D%0A    # Read the index for each QSO in the octant, and get the Mi(z=2).%0A    data = FH.read_file(octant)%0A    zz   = data%5B'Z'%5D%0A    dmod = data%5B'DMOD'%5D%0A    miz2 = miz2%5Bdata%5B'INDX'%5D%5D%0A    # Now convert to apparent i-band magnitude using the k-correction.%0A    # If a tabulated k-correction is available, use that, otherwise%0A    # default to a power-law continuum approximation.%0A    # See discussion in Ross++13, Appendix B and Section 4.%0A    kfile=os.getenv('MOCKINGDESI_BASE')+%22/data/qso-iband-k-correction.txt%22%0A    if os.path.exists(kfile):%0A        print(%22Using K-correction from %22+kfile)%0A        kcorr = np.loadtxt(kfile)%0A        kcorr = np.interp(zz,kcorr%5B:,1%5D,kcorr%5B:,2%5D)%0A    else:%0A        print(%22Using power-law K-correction%22)%0A        alpha = -0.5%0A        kcorr = -2.5*(1+alpha)*np.log10( (1+zz)/(1+2.0) )%0A    magi = miz2 + dmod + kcorr%09# e.g. Ross++13, Eq. 5%0A    magg = magi + 0.255%09%09# e.g. Ross++13, Eq. B7.%0A    # and write the results%0A    data = %7B%7D%0A    data%5B'GMAG'%5D = magg%0A    FH.write_file(octant,data)%0A    #%0A%0A%0A%0Aif __name__==%22__main__%22:%0A    if len(sys.argv)!=3:%0A        raise RuntimeError,%5C%0A          %22Usage: %25s %3Cbox-file-name%3E %3Coct-file-name%3E%22%25sys.argv%5B0%5D%0A    else:%0A      fbox = sys.argv%5B1%5D%0A      foct = sys.argv%5B2%5D%0A      calc_magnitude(fbox,foct)%0A    #%0A

Convert Mi(z=2) to g.