示例#1
0
def test_read_refcat():
    
    # Test creation of RefCat object
    # -----------------------------------------
    RC = RefCat()
    assert isinstance(RC , RefCat ), \
        'RefCat did not get created as expected'

    # run the _read_refcat script
    # -----------------------------------------
    # The following is taken from refcat.man
    # - Report all stars within a radius of 1 deg from RA, Dec 180,10.
    # - Request input file extension ".rc2" explicitly and a header line
    # - (1064 stars, output in ATLAS format):
    # >>> refcat 180 10 -rad 1 -dir 00_m_16 -exten rc2 -hdr
    #
    # Query returns results which look like ...
    # 179.755775  10.937336 11.690 11.243 11.109 11.059 10.142 11.472 11.182
    # -----------------------------------------
    ra = 180
    dec = 10
    rad = 1
    mlim = 17
    code = RC.refcat_filepath
    dir = os.path.join(RC.refcat_dir, '00_m_16')
    result = RC._read_refcat(ra, dec, code, dir,
                         rad=rad , mlim=mlim )
    assert isinstance(result, dict), '%r not a dict ' % type(result)
    assert len(result) == 1064

    print('\t Successfully tested *_read_refcat()*')
示例#2
0
def test_download_refcode():
    
    # Test creation of RefCat object
    # -----------------------------------------
    RC = RefCat()
    assert isinstance(RC , RefCat ), \
        'RefCat did not get created as expected'
    
    # run the download script
    # -----------------------------------------
    RC.download_refcode()

    # check that the expected file is present in the refcat directory
    expected_file = os.path.join(RC.refcat_dir ,
                                 'refcat.c')
    assert os.path.isfile( expected_file ), \
        'expected file does not exist ...'
    
    
    print('\t Successfully tested *download_refcode()*')
示例#3
0
def test_fetch_refcat_data_directory():
    
    # Test creation of RefCat object
    # -----------------------------------------
    RC = RefCat()
    assert isinstance(RC , RefCat ), \
        'RefCat did not get created as expected'
    for k,v in RC.__dict__.items():print(k,v)
    # Check RefCat object has expected attributes
    # -----------------------------------------
    assert 'local_dir' in RC.__dict__, \
        ' local_dir not defined in RefCat'
    assert 'refcat_dir' in RC.__dict__, \
        ' refcat_dir not defined in RefCat'

    # We expect the local refcat directory to be in '~/.shifty_data/refcat'
    expectedDirectory = os.path.join(RC._fetch_data_directory(), 'refcat')
    assert RC.refcat_dir == RC._fetch_refcat_data_directory() == expectedDirectory, \
        'expectedDirectory [%r] != RC.tess_dir [%r]' % (expectedDirectory, RC.tess_dir)

    print('\t Successfully tested *_fetch_refcat_data_directory*')
示例#4
0
def test_find_all_stars_on_image():
    
    # Test creation of RefCat object
    # -----------------------------------------
    RC = RefCat()
    assert isinstance(RC , RefCat ), \
        'RefCat did not get created as expected'
    
    # Need to create header, image_data to pass into *find_all_stars_on_image()*
    # -----------------------------------------
    T = loader.TESSImageLoader()
    cpd = { _ : False for _ in ['mask' ,'subtract', 'bad_cad', 'scat', 'strap' ] }
    IDS = T.get_image_data_set( **{'development' : True} , **cpd )
    
    # run the find_all_stars_on_image script
    # -----------------------------------------
    RC.find_all_stars_on_image(IDS.headers[0] , IDS.data[0])



    print('\t Successfully tested *find_all_stars_on_image()*')
示例#5
0
def test_compile_refcat():
    
    # Test creation of RefCat object
    # -----------------------------------------
    RC = RefCat()
    assert isinstance(RC , RefCat ), \
        'RefCat did not get created as expected'
    
    # run the compile script
    # -----------------------------------------
    RC.compile_refcat()

    # check that the expected file is present in the refcat directory
    expected_file = os.path.join(RC.refcat_dir ,
                             'refcat')
    assert expected_file == RC.refcat_filepath, \
        'returned filepath [%r] differs from expected [%r]' % ( RC.refcat_filepath , expected_file )
    assert os.path.isfile( expected_file ), \
        'expected file does not exist ...'

    print('\t Successfully tested *compile_refcat()*')
示例#6
0
    def _mask_stars(self, header , imageData, **kwargs):
        '''
            We want to remove stars in some way
            Barentsen & Payne discussed a simple mask: i.e. set pixels that contain stars to NaN
            This would be done based on GAIA positions
            
            This is *NOT* subtraction (see _subtract_stars below )
            
            Presumably only one of _mask_stars / _subtract_stars / _clip_peaks is required
            
        '''
        
        # Provide a means to only do the refcat search once
        # If NO useful refcat dictionary supplied, do search, otherwise use supplied dictionary
        # - using this implicitly assumes that all of the images are closely aligned (v. similar ra,dec ranges)
        # -
        if 'refcat_dict' not in kwargs or kwargs['refcat_dict'] == {} :
            print('in calc loop')
            kwargs['refcat_dict'] = {}
            ra,dec,pix,int_pix = RefCat().find_all_stars_on_image(header , imageData)
            kwargs['refcat_dict']['ra'], kwargs['refcat_dict']['dec'] , kwargs['refcat_dict']['pix'] , kwargs['refcat_dict']['int_pix'] = ra,dec,pix, int_pix
    
    
        # Need to do something about deciding how big a mask to use, based on the source magnitude
        # Perhaps something from photutils
        # https://photutils.readthedocs.io/en/stable/psf.html
        # http://docs.astropy.org/en/stable/api/astropy.convolution.discretize_model.html
        # Perhaps using the downloaded prf
        print(' ** WARNING: just outputting a single central mask pixel at present ** ')
        

        # mask all of the stars
        # - N.B. this is likely to fail if nPixels > 0 in RefCat().find_all_stars_on_image()
        # - N.B. this alters imageData-in-place ...
        rows, cols = kwargs['refcat_dict']['int_pix'][1] , kwargs['refcat_dict']['int_pix'][0]
        imageData[rows, cols] = 0