@@ -0,0 +1,2708 @@
+#!/usr/bin/env python%0A%22%22%22%0A%22%22%22%0A%0Aimport argparse%0Aimport os%0A%0Aimport h5py%0Aimport healpy as hp%0Aimport numpy as np%0A%0Aimport matplotlib.pyplot as plt%0Afrom astropy.io import fits%0A%0Aimport qusp%0A%0Adef main():%0A    # parse command-line arguments%0A    parser = argparse.ArgumentParser(%0A        formatter_class=argparse.ArgumentDefaultsHelpFormatter)%0A    parser.add_argument('--verbose', action='store_true',%0A        help='more verbose output')%0A    parser.add_argument('--input', type=str, default=None,%0A        help='input file name')%0A    parser.add_argument('--output', type=str, default=None,%0A        help='output file name')%0A    parser.add_argument('--mock-version', type=str, default='M3_0_0',%0A        help='version of mocks')%0A    qusp.Paths.add_args(parser)%0A    qusp.target.add_args(parser)%0A    args = parser.parse_args()%0A%0A    # setup boss data directory path%0A    paths = qusp.Paths(**qusp.Paths.from_args(args))%0A    # read target list%0A    target_list = qusp.target.load_target_list_from_args(args)%0A%0A%0A    outfile = h5py.File(args.output, 'w')%0A%0A    outfile_delta = outfile.create_group('delta_field')%0A%0A    mock_root = os.path.join(paths.boss_root, args.mock_version, 'rawlite')%0A%0A    wave_lya = 1216.%0A%0A    n_failed = 0%0A    # loop over targets%0A    for i, target in enumerate(target_list):%0A        if i %25 10000 == 0:%0A            print i%0A%0A        plate, mjd, fiber = (target%5B'plate'%5D, target%5B'mjd'%5D, target%5B'fiber'%5D)%0A        mock_name = os.path.join(mock_root, str(plate), 'mockrawShort-%2504d-%255d-%2504d.fits' %25 (plate, mjd, fiber))%0A%0A        try:%0A            hdulist = fits.open(mock_name)%0A        except IOError:%0A            n_failed += 1%0A            print 'Failed trying to open: %25s (%25d/%25d)' %25 (mock_name, n_failed, i)%0A            continue%0A%0A        z = hdulist%5B0%5D.header%5B'm_z'%5D%0A        ra = hdulist%5B0%5D.header%5B'm_ra'%5D%0A        dec = hdulist%5B0%5D.header%5B'm_dec'%5D%0A%0A        coeff0 = hdulist%5B0%5D.header%5B'coeff0'%5D%0A        coeff1 = hdulist%5B0%5D.header%5B'coeff1'%5D%0A%0A        mock_f = hdulist%5B2%5D.data.field(0)%0A        mock_ivar = np.ones_like(mock_f)%0A%0A        mock_lambda = np.power(10, coeff0 + coeff1*np.arange(len(mock_f)))%0A        absorber_z = mock_lambda/wave_lya - 1%0A%0A        # save delta field along this line of sight%0A        outfile_delta_target = outfile_delta.create_group(target.to_string())%0A        outfile_delta_target.attrs%5B'ra'%5D = ra%0A        outfile_delta_target.attrs%5B'dec'%5D = dec%0A        outfile_delta_target.attrs%5B'z'%5D = z%0A        outfile_delta_target.create_dataset('absorber_z', data=absorber_z, dtype='f4')%0A        outfile_delta_target.create_dataset('absorber_delta', data=mock_f, dtype='f4')%0A        outfile_delta_target.create_dataset('absorber_ivar', data=mock_ivar, dtype='f4')%0A%0A%0Aif __name__ == '__main__':%0A    main()

add mock to hdf5 program