示例#1
0
def test_method_count_exts_3():
    ad = AstroData(TESTFILE2)
    sci_exts = 1
    assert sci_exts == ad.count_exts('SCI')
示例#2
0
def test_method_count_exts_1():
    ad = AstroData(TESTFILE)
    ad_len = len(ad)
    assert ad_len == ad.count_exts()
示例#3
0
def test_method_count_exts_3():
    ad = AstroData(TESTFILE2)
    sci_exts = 1
    assert sci_exts == ad.count_exts('SCI')
示例#4
0
def test_method_count_exts_1():
    ad = AstroData(TESTFILE)
    ad_len = len(ad)
    assert ad_len == ad.count_exts()
示例#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:]
    def displayRequest(self, rq):
        print "adcc99:", repr(rq)
        if "display" in rq:
            dispcmd = rq["display"]
            dispcmd.update({"timestamp":datetime.now(),
                            "cmdNum":self.cmdNum})
            self.cmdNum += 1
            rqcopy = copy(rq)

            print "adcc108:", repr(rqcopy)
            if "files" in dispcmd:
                files = dispcmd["files"]
                print "adcc110:", repr(files)
                for basename in files:
                    fileitem = files[basename]
                    ad = AstroData(fileitem["filename"])
                    print "adcc115: loaded ",ad.filename
                    from copy import deepcopy

                    numsci = ad.count_exts("SCI")
                    if numsci > 2:
                        sci = ad[("SCI",2)]                    
                    else:
                        sci = ad[("SCI",1)]
                    data = sci.data
                    mean = data.mean()
                    bottom = data[where(data<mean)].mean()*.80
                    print "adcc140: bottom", bottom
                    top = data[where(data>(1.25*mean))].mean()
                    print "adcc142: top =",top
                    for sci in ad["SCI"]:
                        data = uint32(deepcopy(sci.data))
                        if False:
                            mean = data.mean()
                            bottom = data[where(data<mean)].mean()
                            extver = sci.extver()
                            if extver == 1 or extver ==3:
                                bottom = bottom*1.33
                            print "adcc140: bottom", bottom
                            top = data[where(data>(1.25*mean))].mean()
                            print "adcc142: top =",top
                        bottom = int(bottom)
                        top = int(top)
                        print "adcc164, extver -= %d top,bottom = %d,%d " \
                            %(sci.extver(),top, bottom)
                        abstop = 65535
                        factor = abstop/(top-bottom)
                        data = data - bottom
                        data = data*(factor)
                        im = numpy2im(data)
                        im = im.transpose(Image.FLIP_TOP_BOTTOM)
                        tdir = get_cache_dir("adcc.display")
                        dispname = "sci%d-%s_%d.png" % (sci.extver(), 
                                                     sci.data_label(),
                                                     dispcmd["cmdNum"])
                        nam = os.path.join(tdir, dispname)
                        put_cache_file(dispname, nam)

                        url = "/displaycache/"+dispname
                        baserq = rqcopy["display"]["files"][basename]
                        
                        if "extdict" not in baserq:
                            baserq.update({"extdict":{}})
                        baserq["extdict"].update(
                                             {"SCI%d"%sci.extver(): url }
                                          )
                        rqcopy["display"]["files"][basename].update({"url": None})
                        
                        if os.path.exists(nam):
                            os.remove(nam)
                        im.save(nam, "PNG")

        self.displayCmdHistory.addCmd(rqcopy)
        return