def test4(): '''ASTRODATA-close TEST 4: SEF, Closing AD subdata will not affect hdulist ''' ad = AstroData(sci1) ad['SCI', 1].close() assert_not_equal(ad.hdulist, None, msg='original hdulist is None') ad.close()
def test3(): """ASTRODATA-remove TEST 3: Fail when given index out of range""" ad1 = AstroData(sci123) print "\n >>>>>>> AD <<<<<<<<" ad1.info() print "\n >>>>>>> AD remove <<<<<<<<" ad1.remove(3) print("ad1.remove(3)")
def test13(): """ASTRODATA-insert TEST 13: Fail when matching XNAM XVER found""" ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) ad1.info() adsci = ad4['SCI', 1] # Inserting sci 1 when sci 1 already exists ad1.insert(index=0, header=adsci.header, data=adsci.data)
def test13(): """ASTRODATA-append TEST 13: Fail sci1 to sci123 """ ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) print "\n >>>>>>> AD HOST <<<<<<<<" ad1.info() print "\n >>>>>>> AD APPEND <<<<<<<<" adsci = ad4['SCI', 1] print("adsci = ad4['SCI', 1]") ad1.append(header=adsci.header, data=adsci.data)
def test1(): '''ASTRODATA-single-extfuncs TEST 1: get_data() ''' print('\n\t* single ext fits testfile: %s' % sci1) ad = AstroData(sci1) print('\tad = AstroData(sci1)') data = ad.get_data() print('\tdata = ad.get_data()') print('\tid(data) = %s' % str(id(data))) print('\tid(ad.data) = %s' % str(id(ad.data))) eq_(id(data), id(ad.data), msg='objects are different')
def test3(): '''ASTRODATA-single-extfuncs TEST 3: get_header() (extension) ''' print('\n\t* single ext fits testfile: %s' % sci1) ad = AstroData(sci1) print('\tad = AstroData(sci1)') header = ad.get_header() print('\theader = ad.get_header)') print('\tid(header) = %s' % str(id(header))) print('\tid(ad[0].header) = %s' % str(id(ad[0].header))) eq_(id(header), id(ad[0].header), msg='objects are different')
def test2(): '''ASTRODATA-single-extfuncs TEST 2: set_data() ''' print('\n\t* single ext fits testfile: %s' % sci1) ad = AstroData(sci1) print('\tad = AstroData(sci1)') a = array([1,2,3]) print('\ta = array([1,2,3])') ad.set_data(a) print('\tad.set_data(a)') for i in range(len(ad)): eq_(ad.data[i], a[i], msg='array elements are different')
def test2(): """ ASTRODATA-deepcopy TEST 2: Orig attribute change does not affect copy (MEF) """ ad = AstroData(sci123) adDeepcopy = deepcopy(ad) savedFilename = ad._AstroData__origFilename ad._AstroData__origFilename = "newfilename.fits" eq_(adDeepcopy._AstroData__origFilename, savedFilename, msg="The attribute _AstroData__origFilename has been altered in deepcopy") ad.close() adDeepcopy.close()
def test1(): '''ASTRODATA-iter TEST 1: Compare for AD and for HDUList (MEF)''' ad = AstroData(sci123) aditerImageObjectIdList = [] hduImageObjectIdList = [] for a in ad: aditerImageObjectIdList.append(id(a.hdulist[1])) for phu in ad.hdulist[1:]: hduImageObjectIdList.append(id(phu)) ok_(aditerImageObjectIdList == hduImageObjectIdList, \ msg='Object ids are not the same') ad.close()
def test4(): """ ASTRODATA-deepcopy TEST 4: Orig attribute change does not affect copy (SEF) """ ad = AstroData(sci1) adDeepcopy = deepcopy(ad) savedFilename = ad._AstroData__origFilename ad.mode = "update" ad._AstroData__origFilename = "newfilename.fits" eq_(adDeepcopy.mode, "readonly", msg="Deepcopy Failure, mode is not readonly") ad.close() adDeepcopy.close()
def test1(): """ASTRODATA-deepcopy TEST 1: Pyfits HDUList id's are not equal (MEF)""" ad = AstroData(sci123) adDeepcopy = deepcopy(ad) adIdlist = [] adDeepcopyIdlist = [] for ext in ad: adIdlist.append(id(ext.hdulist[1])) for dext in adDeepcopy: adDeepcopyIdlist.append(id(dext.hdulist[1])) assert_not_equal(adIdlist, adDeepcopyIdlist, msg="hdulist ids are equal") ad.close() adDeepcopy.close()
def test7(): '''ASTRODATA-single-extfuncs TEST 7: MEF exceptions ''' print('\n\t* MEF testfile: %s' % sci123) hdulist = pyfits.open(sci123) print('\thdulist = pyfits.open(sci123)') ad = AstroData(hdulist) print('\tad = AstroData(hdulist) # 3 ext MEF hdulist') mes1 = 'This member or method can only be called for ' mes1 += 'Single HDU AstroData instances' try: data = ad.get_data() except Errors.SingleHDUMemberExcept,s: pass
def test3(): """ASTRODATA-inferred TEST 3: 'SCI' 1 if no XNAM found (SEF)""" testhdulist = pyfits.open(sci1) hlist = [] alist = [] for hdu in testhdulist[1:]: hlist.append(hdu.name) print("\n\n HDUList EXTNAME: %s" % hlist) ad = AstroData(testhdulist) alist.append((ad[0].extname(), ad[0].extver())) eq_(ad[0].extname(), "SCI", msg="extname is not sci") eq_(ad[0].extver(), 1, msg="extver is incorrect") print("\n AD (EXTNAME,EXTVER): %s" % alist) ad.close() testhdulist.close()
def test15(): """ASTRODATA-insert TEST 15: Build AD from scratch """ ad3 = AstroData(mdfscivardq1) print "\n >>>>>>> AD HOST <<<<<<<<" ad_new = AstroData() ad_new.info() print "\n >>>>>>> AD insert <<<<<<<<" ad_new.insert(index=0, moredata=ad3) ad3.info() print("ad_new.insert(index=0, moredata=ad3, auto_number=True)") print "\n >>>>>>> AD HOST (NEW) <<<<<<<<" ad_new.info() eq_(ad_new[3].extname(), "MDF") eq_(ad_new[2].extname(), "SCI") eq_(ad_new[1].extname(), "VAR") eq_(ad_new[0].extname(), "DQ") eq_(ad_new[2].extver(), 1) eq_(ad_new[1].extver(), 1) eq_(ad_new[0].extver(), 1)
def test1(): """ASTRODATA-inferred TEST 1: 'SCI',<VER> for all exts if no XNAMs found (MEF)""" testhdulist = pyfits.open(sci123) # make it so no XNAM found for hdu in testhdulist[1:]: hdu.name = "" hdu.header.rename_key("extname","xname" ) hlist = [] alist = [] for hdu in testhdulist[1:]: hlist.append(hdu.name) print("\n\n HDUList EXTNAME: %s" % hlist) ad = AstroData(testhdulist) for i in range(0,3): alist.append((ad[i].extname(), ad[i].extver())) eq_(ad[i].extname(), 'SCI', msg="extname is not sci") eq_(ad[i].extver(), i + 1, msg="extver is incorrect") print("\n AD (EXTNAME,EXTVER): %s" % alist) ad.close() testhdulist.close()
def test5(): '''ASTRODATA-mode TEST 5: Clobber changed readonly file''' outfile = 'testmode5.fits' if os.path.exists(outfile): os.remove(outfile) shutil.copy(sci123, outfile) ad = AstroData(outfile, mode='update') ad.hdulist[0].header['INSTRUME'] = 'GMOS-S' ad.write(clobber=True) ad.close() ad = AstroData(outfile) ok_(ad.hdulist[0].header['INSTRUME'] == 'GMOS-S', msg='Keyword is different') os.remove(outfile) ad.close()
def test2(): """ASTRODATA-remove TEST 2: Use 'XNAM', XVER""" ad1 = AstroData(sci123) print "\n >>>>>>> AD <<<<<<<<" ad1.info() print "\n >>>>>>> AD remove <<<<<<<<" ad1.remove(("SCI",1)) print("ad1.remove(('SCI',1))") print "\n >>>>>>> AD MODIFIED <<<<<<<<" ad1.info() eq_(ad1[0].extname(), "SCI") eq_(ad1[0].extver(), 2) eq_(ad1[1].extname(), "SCI")
def test1(): """ASTRODATA-remove TEST 1: Use index""" ad1 = AstroData(sci123) print "\n >>>>>>> AD <<<<<<<<" ad1.info() print "\n >>>>>>> AD remove <<<<<<<<" ad1.remove(1) print("ad1.remove(1)") print "\n >>>>>>> AD MODIFIED <<<<<<<<" ad1.info() eq_(ad1[0].extname(), "SCI") eq_(ad1[0].extver(), 2) eq_(ad1[1].extname(), "SCI") eq_(ad1[1].extver(), 3)
def test2(): '''ASTRODATA-mode TEST 2: Overwrite readonly AD using name change''' ad = AstroData(sci123) outfile = 'testmode2.fits' if os.path.exists(outfile): os.remove(outfile) ad.filename = outfile ad.write() assert_true(os.path.isfile(outfile), 'ad.write() FAIL') os.remove(outfile) ad.close()
def test8(): """ASTRODATA-append TEST 8: AUTO NUMBER, var2 to sci123""" ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) print "\n >>>>>>> AD HOST <<<<<<<<" ad1.info() print "\n >>>>>>> AD APPEND <<<<<<<<" adsci = ad4['VAR', 2] print("adsci = ad4['VAR', 2]") ad1.append(header=adsci.header, data=adsci.data, auto_number=True) print "ad1.append(header=adsci.header, data=adsci.data, auto_number=True)" print "\n >>>>>>> AD HOST (NEW) <<<<<<<<" ad1.info() eq_(ad1[3].extname(), "VAR") eq_(ad1[3].extver(), 4)
def test7(): """ASTRODATA-append TEST 7: AUTO NUMBER, sci1 to sci123""" ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) print "\n >>>>>>> AD HOST <<<<<<<<" ad1.info() print "\n >>>>>>> AD APPEND <<<<<<<<" adsci = ad4['SCI', 1] print("adsci = ad4['SCI', 1]") ad1.append(header=adsci.header, data=adsci.data, auto_number=True) print "ad1.append(header=adsci.header, data=adsci.data, auto_number=True)" print "\n >>>>>>> AD HOST (NEW) <<<<<<<<" ad1.info() eq_(ad1[3].hdulist[1].name, "SCI") eq_(ad1[3].extver(), 4)
def test17(): """ASTRODATA-insert TEST 17: AUTO NUMBER, MDF into MEF """ ad3 = AstroData(mdfscivardq1) ad1 = AstroData(sci123) print "\n >>>>>>> AD <<<<<<<<" ad1.info() print "\n >>>>>>> AD insert <<<<<<<<" ad1.insert(index=0, header=ad3[0].header, data=ad3[0].data) mystr = "ad1.insert(index=0, header=ad3[1].header, data=ad3[1].data," mystr += " auto_number=True)" print mystr print "\n >>>>>>> AD (MODIFIED) <<<<<<<<" ad1.info() eq_(ad1[0].extname(), "MDF") eq_(ad1[0].extver(), None)
def test8(): """ASTRODATA-insert TEST 8: Increment XVER if XNAME unknown """ ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) print "\n >>>>>>> AD <<<<<<<<" ad1.info() print "\n >>>>>>> AD insert <<<<<<<<" adsci = ad4['VAR', 2] print("adsci = ad4['VAR', 2]") ad1.insert(index=0, header=adsci.header, data=adsci.data, auto_number=True) print "ad1.insert(index=0,header=adsci.header, data=adsci.data, auto_number=True)" print "\n >>>>>>> AD MODIFIED <<<<<<<<" ad1.info() eq_(ad1[0].extname(), "VAR") eq_(ad1[0].extver(), 4)
def test9(): """ASTRODATA-append TEST 9: AUTO NUMBER, var3 to sci12""" ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) print "\n >>>>>>> AD HOST <<<<<<<<" ad1.hdulist.__delitem__(3) print("ad1.hdulist.__delitem__(3)") ad1.info() print "\n >>>>>>> AD APPEND <<<<<<<<" adsci = ad4['VAR', 3] print("adsci = ad4['VAR', 3]") print "ad1.append(header=adsci.header, data=adsci.data, auto_number=True)" ad1.append(header=adsci.header, data=adsci.data, auto_number=True) print "\n >>>>>>> AD HOST (NEW) <<<<<<<<" ad1.info() eq_(ad1[2].extname(), "VAR") eq_(ad1[2].extver(), 3)
def test7(): """ ASTRODATA-insert TEST 7: AUTO NUMBER, Incremnt XVER & latter indx if XNAME exists """ ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) print "\n >>>>>>> AD <<<<<<<<" ad1.info() print "\n >>>>>>> AD insert <<<<<<<<" adsci = ad4['SCI', 1] print("adsci = ad4['SCI', 1]") ad1.insert(index=1, header=adsci.header, data=adsci.data, auto_number=True) print "ad1.insert(index=1, header=adsci.header, data=adsci.data, auto_number=True)" print "\n >>>>>>> MODIFIED AD <<<<<<<<" ad1.info() eq_(ad1[1].hdulist[1].name, "SCI") eq_(ad1[1].extver(), 4)
def test16(): """ASTRODATA-insert TEST 16: AUTO NUMBER, MDF to empty AD """ ad3 = AstroData(mdfscivardq1) print "\n >>>>>>> AD <<<<<<<<" ad_new = AstroData(phu=ad3.phu) ad_new.info() print "\n >>>>>>> AD insert <<<<<<<<" ad_new.insert(index=0, header=ad3[0].header, data=ad3[0].data,\ auto_number=True) mystr = "ad_new.insert(index=0, header=ad4[1].header, data=ad4[1].data," mystr += " auto_number=True)" print mystr print "\n >>>>>>> AD MODIFIED <<<<<<<<" ad_new.info() eq_(ad_new[0].extname(), "MDF") eq_(ad_new[0].extver(), None)
def test16(): """ASTRODATA-append TEST 16: AUTO NUMBER MDF """ ad3 = AstroData(mdfscivardq1) print "\n >>>>>>> AD NEW <<<<<<<<" ad_new = AstroData(phu=ad3.phu) ad_new.info() print "\n >>>>>>> AD APPEND <<<<<<<<" ad_new.append(header=ad3[0].header, data=ad3[0].data,\ auto_number=True) mystr = "ad_new.append(header=ad4[1].header, data=ad4[1].data," mystr += " auto_number=True)" print mystr print "\n >>>>>>> AD NEW <<<<<<<<" ad_new.info() eq_(ad_new[0].extname(), "MDF") eq_(ad_new[0].extver(), None)
def test11(): """ ASTRODATA-insert TEST 11: AUTO NUMBER, XVER param allows duplicate XNAM XVER pairs """ ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) print "\n >>>>>>> AD <<<<<<<<" ad1.info() print "\n >>>>>>> AD insert <<<<<<<<" adsci = ad4['SCI', 1] print("adsci = ad4['SCI', 1]") ad1.insert(index=1, extver=2, header=adsci.header, data=adsci.data, \ auto_number=True) print("ad1.insert(index=1, extver=2, header=adsci.header, \ data=adsci.data, auto_number=True)") print "\n >>>>>>> AD MODIFIED <<<<<<<<" ad1.info() eq_(ad1[1].extname(), "SCI") eq_(ad1[1].extver(), 2)
def test9(): """ASTRODATA-insert TEST 9: AUTO NUMBER, XVER param inserts high XVER """ ad1 = AstroData(sci123) ad4 = AstroData(scivardq123) print "\n >>>>>>> AD <<<<<<<<" ad1.hdulist.__delitem__(3) print("ad1.hdulist.__delitem__(3)") ad1.info() print "\n >>>>>>> AD insert <<<<<<<<" adsci = ad4['VAR', 3] print("adsci = ad4['VAR', 3]") print("ad1.insert(index=2, header=adsci.header, data=adsci.data," "auto_number=True)") ad1.insert(index=2, header=adsci.header, data=adsci.data, \ auto_number=True, extver=5) print "\n >>>>>>> AD MODIFIED <<<<<<<<" ad1.info() eq_(ad1[2].extname(), "VAR") eq_(ad1[2].extver(), 5)
def test14(): """ASTRODATA-append TEST 14: AUTO NUMBER, given phu, construct sci123""" ad1 = AstroData(sci123) print "\n >>>>>>> AD NEW <<<<<<<<" ad_new = AstroData(phu=ad1.phu) ad_new.info() print "\n >>>>>>> AD APPEND <<<<<<<<" for i in range(1,4): adsci = ad1['SCI', i] print("adsci = ad1['SCI', %d]" % i) ad_new.append(header=adsci.header, data=adsci.data, auto_number=True) mystr = "ad_new.append(header=adsci.header, data=adsci.data," mystr += " auto_number=True)" print mystr print "\n >>>>>>> AD NEW <<<<<<<<" ad_new.info() eq_(ad_new[0].extname(), "SCI") eq_(ad_new[0].extver(), 1) eq_(ad_new[1].extname(), "SCI") eq_(ad_new[1].extver(), 2) eq_(ad_new[2].extname(), "SCI") eq_(ad_new[2].extver(), 3)