예제 #1
0
def atd9():
    """
    Verify that transformation preserve flux.

    The test creates a mosaic from an input AstroData object and displays it 
    in the DS9 display. Using IRAF imexam we measure objects that are on the
    the middle block for GMOS or the lower left block for GSAOI. We also measure
    the same objects in the input amplifers. We calculate the magnitude difference.

    """
    from astrodata import AstroData
    from gempy.adlibrary.mosaicAD import MosaicAD
    #    This is the default Mosaic function
    from gempy.mosaic.gemMosaicFunction import gemini_mosaic_function
    try:
        from stsci.numdisplay import display
    except ImportError:
        from numdisplay import display

    print '\n atd9 REQUIREMENT.......'
    print ('***** From a given AstroData object, the system shall conserve flux'
           ' after "transforming"')

    ad = AstroData(file)
    #    Now make a mosaicAD object using the input ad
    #    and the default mosaic function named 
    #    gemini_mosaic_function.
    mo = MosaicAD(ad, gemini_mosaic_function)

    mosaic_data = mo.mosaic_image_data()
    display(mosaic_data,frame=1)

    #    display input amplifier 3. Assumning that there is one
    #    amplifier per block
    display(ad['SCI',3].data,frame=2)
예제 #2
0
def atd6():
    """
    Verify that a MosaicAD method can create a block from a given extension name.

    The test creates a mosaic ndarray from the MosaicAD method mosaic_image_data 
    with the block parameter value (0,0), indicating to output the lower left block.

    NOTE: Having one amp per block, the actual extension data is not the same 
          as the block since it would be trim by the DATASEC image section.

    gmos_file='../data/gS20120420S0033.fits'
    gsaoi_file='../data/guS20120413S0048.fits'
    """
        
    from astrodata import AstroData
    from gempy.adlibrary.mosaicAD import MosaicAD
    #    This is the default Mosaic function
    from gempy.mosaic.gemMosaicFunction import gemini_mosaic_function
    print '\n atd6 REQUIREMENT.......'
    print ('***** From a given AstroData object, the system shall create a block from '
          'a given extension name')

    gmos_file='../data/gS20120420S0033.fits'
    gsaoi_file='../data/guS20120413S0048.fits'

    for file in [gmos_file,gsaoi_file]:
        ad = AstroData(file)
        print 'Instrument: ',ad.instrument()
        mo = MosaicAD(ad, gemini_mosaic_function)
        #    Now use the mosaic_image_data method to generate
        #    an output block by using the parameter block and
        #    value as a tuple (col,row) (0-based) of the block
        #    you want returned. For GMOS the block values are
        #    (0,0), (1,0), (2,0).

        block=(1,0)
        block_data = mo.mosaic_image_data(block=block,tile=True)
         
        #    Get the shape: (height, width) in pixels.
        print 'block_data.shape:',block_data.shape

        extn = block[0] + block[1]*mo.geometry.mosaic_grid[0] + 1
        print 'Input shape for 1-amp per detector:',ad['SCI',extn].data.shape

        #    Check values of the lower 2x2 pixels
        print 'Output block [0:2,0:2] pixels:\n',block_data[:2,:2]
        if ad.instrument() == 'GSAOI':
            # GSAOI FITS extension 1 correspond to block (1,0)
            # and extension 2 to block (0,0). DETSEC image section
            # indicates this.
            extn = [2,1,3,4][extn-1]

        # To get the correct segment we need to look at
        # DATASEC, in case the data is trimm -as it appears in data_list.
        x1,x2,y1,y2 = ad.data_section().as_dict()['SCI',extn]
        print 'Input amp DATASEC[x1:x1+2 pixels:\n',\
              ad['SCI',extn].data[x1:x1+2,y1:y1+2]
        print '\n'
예제 #3
0
def atd2():
    """
    AT-mosaicAD-1  Verify that mosaicAD can create a mosaic from extensions of
    a given name.
    The test uses the MosaicAD method mosaic_image_data  to create a mosaic 
    using the  extension name 'SCI'.
    """
    
    import numpy as np
    from astrodata import AstroData
    from gempy.adlibrary.mosaicAD import MosaicAD
    #    This is a user's Mosaic_function
    from gempy.mosaic.gemMosaicFunction import gemini_mosaic_function

    print '\n atd2 REQUIREMENT.......'
    print ('***** From a given extension name in the input AstroData object, the system'
            ' shall create a    mosaic')

    gmos_file = '../data/gS20120420S0033.fits'

    ad = AstroData(gmos_file)
    mo = MosaicAD(ad, gemini_mosaic_function)
    #    Now use the mosaic_image_data method to create
    #    the mosaic ndarray.
    mosaic_data = mo.mosaic_image_data(extname='SCI') 

    #    Get blocksize, gap_list and number of blocks in x and y 
    #    values from the MosaicGeometry object.
    blksz_x,blksz_y = mo.geometry.blocksize
    gap_dict = mo.geometry.gap_dict
    nblkx,nblky = mo.geometry.mosaic_grid

    #    Success Criteria 1.
    mszx,mszy=0,0
    for k in range(nblkx):
        gx,gy = gap_dict['transform_gaps'][(k,0)]
        mszx += blksz_x + gx
    for k in range(nblky):
        gx,gy = gap_dict['transform_gaps'][(0,k)]
        mszy += blksz_y + gy

    #    print the shape of the resulting mosaic and  (ny,nx)
    print mosaic_data.shape,' should be equal to:',(mszy,mszx)

    #    Success Criteria 2.
    #    Check the mean of the input AD for each 'SCI' extension
    in_mean = []
    for ext in ad['SCI']:
        in_mean.append(np.mean(ext.data))
    print 'Mean of input data:',np.mean(in_mean)

    #    Get the coordinates of data areas. Does not count 
    #    gaps nor no-data areas.
    g = np.where(mo.mask == 0)
    print 'Mean of mosaic:',np.mean(mosaic_data[g])
예제 #4
0
def atd5():
    """
    Verify that mosaicAD gives the correct WCS information for the mosaiced data.

    Given a GMOS input file, the MosaicAD object method as_astrodata
    creates an output AstroData object. This object 'SCI' header have the
    CRPIX1 and CPRIX2 for the reference extension header. The value
    CRPIX1  should match the value explained in the Success Criteria
    section. The value CRPIX2 is unchanged.
    
    Resources:
    gmos_file='../data/gS20120420S0033.fits'
    gsaoi_file='../data/guS20120413S0048.fits'

    ds9 running        

    """
    import pywcs
    try:
        from stsci.numdisplay import display
    except ImportError:
        from numdisplay import display

    print '\n atd5 REQUIREMENT.......'
    print ('***** Given an AstroData object, the system shall update the header keywords '
         ' CRPIX1 and CRPIX2  in the output mosaiced AD object to match the requested '
            'transformations')

    gmos_file='../data/gS20120420S0033.fits'
    gsaoi_file='../data/guS20120413S0048.fits'

    from astrodata import AstroData
    from gempy.adlibrary.mosaicAD import MosaicAD
    #    This is the default Mosaic function
    from gempy.mosaic.gemMosaicFunction import gemini_mosaic_function

    ad = AstroData(gmos_file)
    #    Creates a mosaicAD object using the input ad and the
    #    default mosaic function name gemini_mosaic_function.
    #    'SCI' is the default extname.
    mo = MosaicAD(ad, gemini_mosaic_function)

    #         
    outad = mo.as_astrodata()

    # NOTE: The ref_ext is the left most amplifier in
    #       reference block. For GMOS the reference block
    #       (2,1). E.G. for a 6-amp GMOS exposure the left
    #       most exposure is 3.
    refblk = mo.geometry.ref_block
    col,row = refblk[0], refblk[1]
    amp_per_block = mo._amps_per_block
    ref_ext = col*amp_per_block+1
    ocrpix1 = ad['SCI',ref_ext].header['CRPIX1']
    xgap = mo.geometry.gap_dict['transform_gaps'][col,row][0]
    blksz_x,blksz_y = mo.geometry.blocksize

    #    Success Criteria 1.

    #    Get the x2 value from coords['amp_mosaic_coord'][refblk]
    xoff = mo.coords['amp_mosaic_coord'][max(0,col-1)][1]
    print ocrpix1 + xoff + xgap, 'should match: '
    print outad['SCI',1].header['CRPIX1']

    #    Success Criteria 2.
    #    For a GSAOI file, 
    ad = AstroData(gsaoi_file)

    if ad.instrument() != 'GSAOI':
        print '******** file is not GSAOI ************'
    mo = MosaicAD(ad, gemini_mosaic_function)
    outad = mo.as_astrodata()
    outhdr = outad['SCI'].header 
    inhdr = ad['SCI',2].header 

    #    The values should be the same.
    print 'Crpix1 values (in,out):',inhdr["CRPIX1"],outhdr['CRPIX1']
    print 'Crpix2 values (in,out):',inhdr["CRPIX2"],outhdr['CRPIX2']

    #    Success Criteria 3.
    #    For a GMOS file in extension #2
    hdr = ad['SCI',2].header

    wcs = pywcs.WCS(hdr)

    import pysao

    # Bring up a ds9 display by instantiating the pysao object
    ds9 = pysao.ds9()
    # Display the image
    ds9.view(ad['SCI',2].data, frame=1)

    # display(ad['SCI',2].data,frame=1)
    print 'Click on any object:'
    X,Y,f,k = ds9.readcursor()

    #    Get X,Y values from an object on the ds9 display
    #    Get ra,dec
    ra,dec = wcs.wcs_pix2sky(X,Y,1)

    #    Generate the mosaic_data for this ad using 
    #    as_astrodata method.
    #    Display the mosaic mosaic_data for the 'SCI' extension

    mosaic_data = mo.mosaic_image_data()
    # Display the mosaic
    ds9.view(mosaic_data,frame=2)

    # display(ad['SCI',2].data,frame=1)
    print 'Click on the same object:'
    MX,MY,f,k = ds9.readcursor()

    #display(mosaic_data,frame=2)

    #    Measure X,Y of the same object, named this MX,MY
    #    Get the wcs from the mosaic header

    mhdr = outad['SCI'].header
    mwcs = pywcs.WCS(mhdr)
    mra,mdec = mwcs.wcs_pix2sky(MX,MY,1)
    print 'These RA,DEC should be pretty close:',(ra[0],mra[0]),(dec[0],mdec[0])
예제 #5
0
def atd4():
    """
    Verify that a  mosaicAD class  method can create a tiled array from 
    extensions of a given name.

    The test creates a mosaic ndarray using the method mosaic_image_data 
    with the parameter 'tile=True'  which avoids the transformation step.

    """
    from astrodata import AstroData
    from gempy.adlibrary.mosaicAD import MosaicAD
    #     This is the default Mosaic function
    from gempy.mosaic.gemMosaicFunction import gemini_mosaic_function

    print '\n atd4 REQUIREMENT.......'
    print ('***** Given an AstroData object, the system shall tile all IMAGE extensions '
          'matching a given extension name')

    gmos_file='../data/gS20120420S0033.fits'
    gsaoi_file='../data/guS20120413S0048.fits'

    ad = AstroData(gmos_file)
    mo = MosaicAD(ad, gemini_mosaic_function)
    #     Now use the mosaic_image_data method to create
    #     the mosaic tile array from the 'SCI' extname.
    tile_data = mo.mosaic_image_data(tile=True, extname='SCI') 

    # ----- Comparing input and output. GMOS image 

    #     The tester should feel free to verify any input and output
    #     pixel location.

    #     For example: A GMOS image:
    #     The lower left corner (2x2) pixels the first GMOS 
    #     data extension. For a GSAOI is the second extension

    corner_gmos = ad['SCI',1].data   # For a GMOS file    
    print 'ad["SCI",1].data[:2,:2]\n',corner_gmos[:2,:2]

    #     From the output mosaic. We should get the same values.
    print 'tile_data[:2,:2]\n',tile_data[:2,:2]

    # The top right corner of the mosaic
    nexts = ad.count_exts('SCI')
    block = ad['SCI',nexts].data    # There is one amp per block
    print '\nad["SCI",last].data[-2:-2]\n',block[-2:,-2:]

    # The mosaic top corner
    print '\ntile_data[-2:,-2:]\n',tile_data[-2:,-2:]

    # ----- GSAOI data
    ad = AstroData(gsaoi_file)
    mo = MosaicAD(ad, gemini_mosaic_function)

    #     Now use the mosaic_image_data method to create
    #     the mosaic tile array from the 'SCI' extname.
    tile_data = mo.mosaic_image_data(tile=True, extname='SCI') 

    print '\nGSAOI data'
    corner_gsaoi = ad['SCI',2].data   # For a GSAOI file    
    print 'ad["SCI",2].data\n',corner_gsaoi[:2,:2]
    print 'tile_data[:2,:2]\n', tile_data[:2,:2]

    #     The top right corner of the mosaic
    block4 = ad['SCI',4].data    # There is one amp per block
    print '\nblock4[-2:,-2:]\n',block4[-2:,-2:]
    print 'tile_data[-2:,-2:]\n',tile_data[-2:,-2:]