示例#1
0
def test_run_through_Telescope_methods():
    duet = Telescope()
    duet_offax = Telescope(config='reduced_baseline')
    duet.info()
    duet.update_bandpass()
    duet.calc_radial_profile()
    duet.calc_psf_fwhm()
    duet.update_effarea()
    duet.fluence_to_rate(1 * u.ph / u.s / u.cm**2)
    duet.psf_model()
    duet.compute_psf_norms()
示例#2
0
def sim_galaxy(patch_size,
               pixel_size,
               gal_type=None,
               gal_params=None,
               duet=None,
               band=None,
               duet_no=None):
    '''
        Return 2D array of a Sersic profile to simulate a galaxy

        Required inputs:
        patch_size = Axis sizes of returned galaxy patch in pixels (15,15)
        pixel_size = Angular size of pixel (6 * ur.arcsec)

        Optional inputs:
        gal_type = String that loads a pre-built 'average' galaxy or allows custom definition
        gal_params = Dictionary of parameters for Sersic model: ...
        duet = Telescope instance
        band = duet.bandpass (defaults to DUET1; deprecated)
        duet_no = integer (1 or 2) for DUET bandpass
    '''
    from astropy.modeling.models import Sersic2D
    from astroduet.utils import duet_abmag_to_fluence, duet_no_from_band

    if duet is None:
        duet = Telescope()
    if band is None:
        band = duet.bandpass1
    if duet_no is None:
        duet_no = duet_no_from_band(band)

    x = np.linspace(-(patch_size[0] // 2), patch_size[0] // 2, patch_size[0])
    y = np.linspace(-(patch_size[1] // 2), patch_size[1] // 2, patch_size[1])
    x, y = np.meshgrid(x, y)

    # Takes either a keyword or Sersic profile parameters
    # Typical galaxy parameters based on Bai et al. (2013)
    # Hardcoded for now, to-do: take distance as an input
    if gal_type == 'spiral':
        # A typical spiral galaxy at 100 Mpc
        surface_mag = 26.2 * u.ABmag  # surface brightness (per arcsec**2)
        surface_rate = duet.fluence_to_rate(
            duet_abmag_to_fluence(surface_mag, duet_no,
                                  duet=duet))  # surface count rate at r_eff
        amplitude = surface_rate * pixel_size.value**2  # surface brightness (per pixel)
        r_eff = 16.5 / pixel_size.value
        n = 1
        theta = 0
        ellip = 0.5
        x_0, y_0 = r_eff, 0
    elif gal_type == 'elliptical':
        # A typical elliptical galaxy at 100 Mpc
        surface_mag = 25.0 * u.ABmag
        surface_rate = duet.fluence_to_rate(
            duet_abmag_to_fluence(surface_mag, duet_no,
                                  duet=duet))  # surface count rate at r_eff
        amplitude = surface_rate * pixel_size.value**2  # surface brightness (per pixel)
        r_eff = 12.5 / pixel_size.value
        n = 4
        theta = 0
        ellip = 0.5
        x_0, y_0 = r_eff, 0
    elif gal_type == 'dwarf':
        # A typical dwarf galaxy at 10 Mpc
        surface_mag = 25.8 * u.ABmag
        surface_rate = duet.fluence_to_rate(
            duet_abmag_to_fluence(surface_mag, duet_no,
                                  duet=duet))  # surface count rate at r_eff
        amplitude = surface_rate * pixel_size.value**2  # surface brightness (per pixel)
        r_eff = 70 / pixel_size
        r_eff = r_eff.value
        n = 4
        theta = 0
        ellip = 0.5
        x_0, y_0 = r_eff, 0
    elif (gal_type == 'custom') | (gal_type == None):
        # Get args from gal_params, default to spiral values
        surface_mag = gal_params.get('magnitude', 26) * u.ABmag
        surface_rate = duet.fluence_to_rate(
            duet_abmag_to_fluence(surface_mag, duet_no,
                                  duet=duet))  # surface count rate at r_eff
        amplitude = surface_rate * pixel_size.value**2  # surface brightness (per pixel)
        r_eff = gal_params.get('r_eff', 16.5 / pixel_size.value)
        n = gal_params.get('n', 1)
        theta = gal_params.get('theta', 0)
        ellip = gal_params.get('ellip', 0.5)
        x_0 = gal_params.get('x_0', 16.5 / pixel_size.value)
        y_0 = gal_params.get('y_0', 0)

    mod = Sersic2D(amplitude=amplitude,
                   r_eff=r_eff,
                   n=n,
                   x_0=x_0,
                   y_0=y_0,
                   ellip=ellip,
                   theta=theta)
    gal = mod(x, y)

    return gal
示例#3
0
def imsim_srcdetect_combined(run='050719',
                             gal='spiral',
                             zodi='low',
                             nmags=71,
                             sfb=[20, 30],
                             stack=1):
    """
    Run background estimation, image differencing and source detection on stacked simulated images

    Assumes that the script is run in the directory that contains the run_... directory tree

    Parameters
    ----------
    run: string (date, as in '050719')
        To track runs

    zodi: 'low', 'med' or 'high', default is low

    gal: 'spiral', 'elliptical', 'dwarf', or 'none'

    sfb: [sfb_low, sfb_high], default is [20,30]
        List of lowest and highest surface brightness that have been simulated

    nmags: float, default is 71
        Number of source magnitudes used in image simulations

    stack: int, default is 1
        Number of stacked exposures

    Returns
    -------
    run_gal_zodi_band.fits: fits table with source detection results
    """
    # Get telescope configuration from teldef file:
    with open('run_' + run + '/teldef') as origin:
        for line in origin:
            if 'DUET Telescope State' in line:
                tel = line.split(':')[1].strip('\n').strip()

    # Initialize parameters
    duet = Telescope(config=tel)

    # Set up path
    path1 = 'run_' + run + '/gal_' + gal + '/zodi_' + zodi + '/duet1/'
    path2 = 'run_' + run + '/gal_' + gal + '/zodi_' + zodi + '/duet2/'

    # Make galaxy surface brightness array
    if gal != 'none':
        sfb_arr = np.arange(sfb[0], sfb[1] + 1.).astype(str)

    # Make source magnitude array
    src_arr = np.linspace(20.5 - 0.5 * (nmags - 1) * 0.1,
                          20.5 + 0.5 * (nmags - 1) * 0.1,
                          num=nmags,
                          endpoint=True)  # Currently in steps of 0.1 mag

    # Set up results table
    # columns: galaxy mag, source input mag, source input count rate, distance from galaxy center, reference depth, source detected True/False,
    # if True: retrieved count rate, count rate error; number of false positives
    tab = Table(np.zeros(9),
                names=('galmag', 'srcmag', 'src-ctrate', 'dist', 'ref_depth',
                       'detected', 'ctrate', 'ctrate_err', 'false-pos'),
                dtype=('f8', 'f8', 'f8', 'f8', 'i8', 'b', 'f8', 'f8', 'i8'),
                meta={'name': gal + ' - ' + zodi + 'zodi - combined'})
    print('Finding sources...')
    if gal == 'none':
        reffile1 = run + '_duet1_zodi-' + zodi + '_reference.fits'
        hdu_ref1 = fits.open(path1 + reffile1)
        reffile2 = run + '_duet2_zodi-' + zodi + '_reference.fits'
        hdu_ref2 = fits.open(path2 + reffile2)

        for srcmag in src_arr:
            imfile1 = run + '_duet1_zodi-' + zodi + '_stack-' + str(
                stack) + '_src-' + "{:5.2f}".format(srcmag) + '.fits'
            hdu_im1 = fits.open(path1 + imfile1)
            imfile2 = run + '_duet2_zodi-' + zodi + '_stack-' + str(
                stack) + '_src-' + "{:5.2f}".format(srcmag) + '.fits'
            hdu_im2 = fits.open(path2 + imfile2)

            # Get input countrate
            src_ctrate1 = duet.fluence_to_rate(
                duet_abmag_to_fluence(srcmag * u.ABmag, 1, duet=duet))
            src_ctrate2 = duet.fluence_to_rate(
                duet_abmag_to_fluence(srcmag * u.ABmag, 2, duet=duet))
            src_ctrate_comb = src_ctrate1 + src_ctrate2

            # Run source detection for this set of HDUs:
            tab = run_srcdetect_combined(hdu_ref1=hdu_ref1,
                                         hdu_ref2=hdu_ref2,
                                         hdu_im1=hdu_im1,
                                         hdu_im2=hdu_im2,
                                         tab=tab,
                                         duet=duet,
                                         sfb=np.nan,
                                         srcmag=srcmag,
                                         src_ctrate=src_ctrate_comb)
            hdu_im1.close()
            hdu_im2.close()
        hdu_ref1.close()
        hdu_ref2.close()

    else:
        for sfb in sfb_arr:
            print('SFB: ' + sfb)
            reffile1 = run + '_duet1_' + gal + '_' + sfb + '_zodi-' + zodi + '_reference.fits'
            hdu_ref1 = fits.open(path1 + reffile1)
            reffile2 = run + '_duet2_' + gal + '_' + sfb + '_zodi-' + zodi + '_reference.fits'
            hdu_ref2 = fits.open(path2 + reffile2)

            for srcmag in src_arr:
                imfile1 = run + '_duet1_' + gal + '_' + sfb + '_zodi-' + zodi + '_stack-' + str(
                    stack) + '_src-' + "{:5.2f}".format(srcmag) + '.fits'
                hdu_im1 = fits.open(path1 + imfile1)
                imfile2 = run + '_duet2_' + gal + '_' + sfb + '_zodi-' + zodi + '_stack-' + str(
                    stack) + '_src-' + "{:5.2f}".format(srcmag) + '.fits'
                hdu_im2 = fits.open(path2 + imfile2)
                # Get input countrate
                src_ctrate1 = duet.fluence_to_rate(
                    duet_abmag_to_fluence(srcmag * u.ABmag, 1, duet=duet))
                src_ctrate2 = duet.fluence_to_rate(
                    duet_abmag_to_fluence(srcmag * u.ABmag, 2, duet=duet))
                src_ctrate_comb = src_ctrate1 + src_ctrate2

                # Run source detection for this set of HDUs:
                tab = run_srcdetect_combined(hdu_ref1=hdu_ref1,
                                             hdu_ref2=hdu_ref2,
                                             hdu_im1=hdu_im1,
                                             hdu_im2=hdu_im2,
                                             tab=tab,
                                             duet=duet,
                                             sfb=float(sfb),
                                             srcmag=srcmag,
                                             src_ctrate=src_ctrate)
                hdu_im1.close()
                hdu_im2.close()
            hdu_ref1.close()
            hdu_ref2.close()
    # Save output table
    print('Writing file')
    tab.remove_row(0)
    tab.write('run' + run + '_gal-' + gal + '_zodi-' + zodi + '_stack-' +
              str(stack) + '-combined.fits',
              format='fits',
              overwrite=True)

    print('Done')