コード例 #1
0
ファイル: JSIM_Loop.py プロジェクト: andrewpaulreeves/JSIM
def wavelength_loop(cube, head, wavels, out_cube, newsize, outspax):
    '''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
        newsize: tuple containing (x_newsize, y_newsize) array sizes
        outspax: output spaxels (x, y) (mas, mas)

    Output:

        cube: Processed cube
        head: Updated header

    '''

    nspec = wp.NIRSpec()
    nspec.pupilopd = None
    print 'OPD = ', nspec.pupilopd

    oversamp = 1000. / float(outspax[0])

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

        #Create PSF channel
        psf = nspec.calcPSF(outfile=None,
                            source=None,
                            filter=None,
                            nlambda=None,
                            monochromatic=wavels[l] * 1.E-6,
                            oversample=oversamp,
                            fov_arcsec=5,
                            rebin=False)

        psf = psf[0].data

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

        #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)

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

    return out_cube, head
コード例 #2
0
def pp_wavelength_loop(cube,
                       head,
                       wavels,
                       out_cube,
                       AO,
                       psfvars,
                       adrvals,
                       newsize,
                       outspax,
                       adr_switch='ON',
                       usecpus=mp.cpu_count() - 1):
    '''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]
        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
        usecpus: no. of CPUs to use

    Output:

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

    '''
    import pprocess as pp

    print 'Using ', usecpus, ' CPUs'
    queue = pp.Queue(limit=usecpus)
    waveloop = queue.manage(pp.MakeParallel(pp_wavelength_channel))

    print "Initialising..."
    for lam in xrange(len(wavels)):
        waveloop(cube[lam, :, :], head, wavels[lam], lam, AO, psfvars,
                 adrvals[lam], newsize, outspax, adr_switch)

    print "Processing..."
    for chan, it in queue:
        update_progress(n.round(it / float(len(wavels)), 2))
        out_cube[it, :, :] = chan

    return out_cube, head
コード例 #3
0
ファイル: JSIM_Loop.py プロジェクト: andrewpaulreeves/JSIM
def wavelength_loop(cube, head, wavels, out_cube, newsize, outspax):
    '''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
        newsize: tuple containing (x_newsize, y_newsize) array sizes
        outspax: output spaxels (x, y) (mas, mas)

    Output:

        cube: Processed cube
        head: Updated header

    '''

    nspec = wp.NIRSpec()
    nspec.pupilopd = None
    print 'OPD = ', nspec.pupilopd

    oversamp = 1000./float(outspax[0])

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

        #Create PSF channel
        psf = nspec.calcPSF(outfile=None, source=None, filter=None, nlambda=None,
                            monochromatic=wavels[l]*1.E-6, oversample=oversamp,
                            fov_arcsec=5, rebin=False)

        psf = psf[0].data

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

        #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)

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

    return out_cube, head
コード例 #4
0
ファイル: JSIM_Loop.py プロジェクト: andrewpaulreeves/JSIM
def pp_wavelength_loop(cube,
                       head,
                       wavels,
                       out_cube,
                       newsize,
                       outspax,
                       usecpus=mp.cpu_count() - 1):
    '''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
        newsize: tuple containing (x_newsize, y_newsize) array sizes
        outspax: tuple containing (x, y) output spaxel scales
        usecpus: no. of CPUs to use

    Output:

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

    '''
    import pprocess as pp

    print 'Using ', usecpus, ' CPUs'
    queue = pp.Queue(limit=usecpus)
    waveloop = queue.manage(pp.MakeParallel(pp_wavelength_channel))

    print "Initialising..."
    for lam in xrange(len(wavels)):
        waveloop(cube[lam, :, :], head, wavels[lam], lam, newsize, outspax)

    print "Processing..."
    for chan, it in queue:
        update_progress(n.round(it / float(len(wavels)), 2))
        out_cube[it, :, :] = chan

    return out_cube, head
コード例 #5
0
ファイル: JSIM_Loop.py プロジェクト: andrewpaulreeves/JSIM
def pp_wavelength_loop(cube, head, wavels, out_cube, newsize, outspax, usecpus=mp.cpu_count()-1):
    '''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
        newsize: tuple containing (x_newsize, y_newsize) array sizes
        outspax: tuple containing (x, y) output spaxel scales
        usecpus: no. of CPUs to use

    Output:

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

    '''
    import pprocess as pp

    print 'Using ', usecpus, ' CPUs'
    queue = pp.Queue(limit=usecpus)
    waveloop = queue.manage(pp.MakeParallel(pp_wavelength_channel))

    print "Initialising..."
    for lam in xrange(len(wavels)):
        waveloop(cube[lam,:,:], head, wavels[lam], lam, newsize, outspax)

    print "Processing..."
    for chan, it in queue:
        update_progress(n.round(it/float(len(wavels)),2))
        out_cube[it,:,:] = chan


    return out_cube, head
コード例 #6
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