예제 #1
0
def pp_wavelength_channel(chann, head, wave, l, AO, psfvars, adrval, newsize,
                          outspax, adr_switch):
    '''Function to take input datacube and process it iteratively through
    each wavelength channel as follows:
    - Generate PSF array for given channel
    - Add effect of ADR to channel
    - Convolve cube channel with PSF
    - Frebin up to chosen output spaxel scale

    Inputs:

        chann: cube channel
        head: Datacube header
        wave: wavelength [um]
        l: iteration no.
        out_cube: Empty output cube
        AO: AO mode [LTAO, SCAO, Gaussian]
        psfvars: list containing [psfparams, psfspax, psfsize,
                                  [D,eps], res_jitter, seeing, user_psf,
                                  user_psflams]
        adrval: ADR value
        newsize: tuple containing (x_newsize, y_newsize) array sizes
        outspax: tuple containing (x, y) output spaxel scales
        adr_switch: On or OFF. Turns ADR effect on or off

    Output:

        cube: Processed cube
        head: Updated header
        inspax: Input spaxel scale (mas, mas)
        outspax: Output spaxel scale (mas, mas)

    '''

    #Create PSF channel
    #If user PSF and 2D image
    upsf = psfvars[-2]
    upsflams = psfvars[-1]
    if type(upsf) != str and type(upsflams) == str:
        psf = upsf
    #If User PSF and 3D cube
    elif type(upsf) != str and type(upsflams) != str:
        #Interpolate PSF cube
        interp = interp1d(upsflams, upsf, axis=0)
        psf = interp(wave)

    elif AO == 'LTAO' or AO == 'SCAO' or AO == 'GLAO':
        psf = create_psf_channel(psfvars[0], l, psfvars[1],
                                 (head['CDELT1'], head['CDELT2']), psfvars[2],
                                 psfvars[3], psfvars[4])

    elif AO == 'Gaussian':
        psf = create_Gausspsf_channel(wave, psfvars[5], psfvars[3], psfvars[4],
                                      psfvars[2], False, psfvars[1],
                                      (head['CDELT1'], head['CDELT2']))

    else:
        print 'AO = ', AO
        raise ValueError('AO choice or user_PSF error!')

    #Create instrument PSF array
    instpsf = create_instpsf(psfvars[2], psfvars[1], outspax,
                             (head['CDELT1'], head['CDELT2']))

    #Add ADR effect to channel
    if adr_switch == 'ON':
        chann = add_ADR(chann, head, adrval, 'spline3')

    #Convolve cube channel with PSF channel
    chann = psf_convolve(chann, psf)

    #Convolve cube channel with instrument PSF
    chann = psf_convolve(chann, instpsf)

    #Frebin datacube up to output spaxel scale
    newsize = (int(newsize[0]), int(newsize[1]))
    chann *= (head['CDELT1'] * head['CDELT2'] * 1.E-6)
    chann = frebin(chann, (newsize[0], newsize[1]), total=True)
    chann /= (outspax[0] * outspax[1] * 1.E-6)

    #"Correct" ADR effect
    if adr_switch == 'ON':
        adrhead = head.copy()
        adrhead['CDELT1'] = outspax[0]
        adrhead['CDELT2'] = outspax[1]
        chann = add_ADR(chann, adrhead, -1. * adrval, 'spline3')

    return chann, l
예제 #2
0
def wavelength_loop(cube,
                    head,
                    wavels,
                    out_cube,
                    AO,
                    psfvars,
                    adrvals,
                    newsize,
                    outspax,
                    adr_switch='ON'):
    '''Function to take input datacube and process it iteratively through
    each wavelength channel as follows:
    - Generate PSF array for given channel
    - Add effect of ADR to channel
    - Convolve cube channel with PSF
    - Frebin up to chosen output spaxel scale

    Inputs:

        cube: Datacube
        head: Datacube header
        wavels: Wavelength array
        out_cube: Empty output cube
        AO: AO mode [LTAO, SCAO, Gaussian]
        psdvars: list containing [psfparams, psfspax, psfsize, [D,eps],
                                  res_jitter, seeing, user_psf, user_psflams]
        adrvals: array of ADR values
        newsize: tuple containing (x_newsize, y_newsize) array sizes
        outspax: tuple containing (x, y) output spaxel scales
        adr_switch: ON or OFF. Turns ADR effect on or off.

    Output:

        cube: Processed cube
        head: Updated header
        inspax: Input spaxel scale (mas, mas)
        outspax: Output spaxel scale (mas, mas)

    '''
    for l in xrange(len(wavels)):
        #Print percentage bar
        update_progress(n.round(l / float(len(wavels)), 2))

        #Create PSF channel
        #If user PSF and 2D image
        upsf = psfvars[-2]
        upsflams = psfvars[-1]
        if type(upsf) != str and type(upsflams) == str:
            psf = upsf
        #If User PSF and 3D cube
        elif type(upsf) != str and type(upsflams) != str:
            #Interpolate PSF cube
            interp = interp1d(upsflams, upsf, axis=0)
            psf = interp(wavels[l])

        elif AO == 'LTAO' or AO == 'SCAO' or AO == 'GLAO':
            psf = create_psf_channel(psfvars[0], l, psfvars[1],
                                     (head['CDELT1'], head['CDELT2']),
                                     psfvars[2], psfvars[3], psfvars[4])

        elif AO == 'Gaussian':
            psf = create_Gausspsf_channel(wavels[l],
                                          psfvars[5],
                                          psfvars[3],
                                          psfvars[4],
                                          psfvars[2],
                                          Nyquist=False,
                                          psfspax=psfvars[1],
                                          output_spax=(head['CDELT1'],
                                                       head['CDELT2']))

        else:
            print 'AO = ', AO
            raise ValueError('AO choice error!')

        #Create instrument PSF array
        instpsf = create_instpsf(psfvars[2], psfvars[1], outspax,
                                 (head['CDELT1'], head['CDELT2']))

        #Add ADR effect to channel
        if adr_switch == 'ON':
            cube[l, :, :] = add_ADR(cube[l, :, :], head, adrvals[l], 'spline3')

        #Convolve cube channel with PSF channel
        channel = psf_convolve(cube[l, :, :], psf)

        #Convolve cube channel with instrument PSF
        channel = psf_convolve(channel, instpsf)

        #Frebin datacube up to output spaxel scale
        newsize = (int(newsize[0]), int(newsize[1]))
        channel *= (head['CDELT1'] * head['CDELT2'] * 1.E-6)
        channel = frebin(channel, (newsize[0], newsize[1]), total=True)
        channel /= (outspax[0] * outspax[1] * 1.E-6)

        #Correct ADR effect
        if adr_switch == 'ON':
            adrhead = head.copy()
            adrhead['CDELT1'] = outspax[0]
            adrhead['CDELT2'] = outspax[1]
            channel = add_ADR(channel, adrhead, -1. * adrvals[l], 'spline3')

        #Add channel to output cube
        out_cube[l, :, :] = channel

    return out_cube, head
예제 #3
0
def make_psf(chann, head, wave, l, AO, psfvars, adrval, newsize, outspax, adr_switch):
    '''Function to take input datacube and process it iteratively through
    each wavelength channel as follows:
    - Generate PSF array for given channel
    - Add effect of ADR to channel
    - Convolve cube channel with PSF
    - Frebin up to chosen output spaxel scale

    Inputs:

        chann: cube channel
        head: Datacube header
        wave: wavelength [um]
        l: iteration no.
        out_cube: Empty output cube
        AO: AO mode [LTAO, SCAO, Gaussian]
        psfvars: list containing [psfparams, psfspax, psfsize,
                                  [D,eps], res_jitter, seeing, user_psf,
                                  user_psflams]
        adrval: ADR value
        newsize: tuple containing (x_newsize, y_newsize) array sizes
        outspax: tuple containing (x, y) output spaxel scales
        adr_switch: On or OFF. Turns ADR effect on or off

    Output:

        cube: Processed cube
        head: Updated header
        inspax: Input spaxel scale (mas, mas)
        outspax: Output spaxel scale (mas, mas)

    '''

    #Create PSF channel
    #If user PSF and 2D image
    upsf = psfvars[-2]
    upsflams = psfvars[-1]
    if upsf != 'None' and upsflams == 'None':
        psf = upsf
    #If User PSF and 3D cube
    elif upsf != 'None' and upsflams != 'None':
        #Interpolate PSF cube
        interp = interp1d(upsflams, upsf, axis=0)
        psf = interp(wave)

    elif AO == 'LTAO' or AO == 'SCAO' or AO == 'GLAO':
        psf = create_psf_channel(psfvars[0], l, psfvars[1], (head['CDELT1'],head['CDELT2']),
                                 psfvars[2], psfvars[3], psfvars[4])

    elif AO == 'Gaussian':
        psf = create_Gausspsf_channel(wave, psfvars[5], psfvars[3], psfvars[4], psfvars[2], False,
                       psfvars[1], (head['CDELT1'],head['CDELT2']))

    else:
        print 'AO = ', AO
        raise ValueError('AO choice or user_PSF error!')

    #Create instrument PSF array
    instpsf = create_instpsf(psfvars[2], psfvars[1], outspax, (head['CDELT1'],head['CDELT2']))

    return psf, instpsf