Coverage for tests/testSSM_Diasources.py : 42%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Observation metadata modules # To access opsim sqlite database # photometric parameters (exptime lives here for dmag calculation) # SSM catalog modules # For camera.
lsst.utils.tests.init()
return (time.time() - time_prev, time.time())
print('\ntestObsCat failed to connect to fatboy') print('Sometimes that happens. Do not worry.')
# Build sso instance class 'skyVelocity', 'dist', 'dmagTrailing', 'dmagDetection', 'sedFilename', 'magFilter', 'magSNR', 'visibility', 'seeing', 'bandpass', 'visitExpTime', 'm5']
'velRa': np.degrees, 'velDec': np.degrees}
'velRa': np.degrees, 'velDec': np.degrees}
######
def tearDownClass(cls): sims_clean_up()
t = time.time() # Fake opsim data. database = os.path.join(getPackageDir('SIMS_DATA'), 'OpSimData/opsimblitz1_1133_sqlite.db') generator = ObservationMetaDataGenerator(database=database, driver='sqlite')
night = 20 query = 'select min(expMJD), max(expMJD) from summary where night=%d' % (night) res = generator.opsimdb.execute_arbitrary(query) expMJD_min = res[0][0] expMJD_max = res[0][1]
obsMetaDataResults = generator.getObservationMetaData(expMJD=(expMJD_min, expMJD_max), limit=3, boundLength=2.2)
dt, t = dtime(t) print('To query opsim database: %f seconds' % (dt))
write_header = True write_mode = 'w'
try: ssmObj = SolarSystemObj()
for obsMeta in obsMetaDataResults: # But moving objects databases are not currently complete for all years. # Push forward to night=747. # (note that we need the phosim dictionary as well)
newMJD = 59590.2 # this MJD is artificially chosen to be in the # time span of the new baseline simulated survey
obs = ObservationMetaData(mjd=newMJD, pointingRA=obsMeta.pointingRA, pointingDec=obsMeta.pointingDec, bandpassName=obsMeta.bandpass, rotSkyPos=obsMeta.rotSkyPos, m5=obsMeta.m5[obsMeta.bandpass], seeing=obsMeta.seeing[obsMeta.bandpass], boundLength=obsMeta.boundLength, boundType=obsMeta.boundType)
obs._OpsimMetaData = {'visitExpTime': 30}
mySsmDb = ssmCatCamera(ssmObj, obs_metadata = obs) photParams = PhotometricParameters(exptime = obs.OpsimMetaData['visitExpTime'], nexp=1, bandpass=obs.bandpass) mySsmDb.photParams = photParams
try: with lsst.utils.tests.getTempFilePath('.txt') as output_cat: mySsmDb.write_catalog(output_cat, write_header=write_header, write_mode=write_mode)
# verify that we did not write an empty catalog with open(output_cat, 'r') as input_file: lines = input_file.readlines() msg = 'MJD is %.3f' % obs.mjd.TAI self.assertGreater(len(lines), 1, msg=msg) except: # This is because the solar system object 'tables' # don't actually connect to tables on fatboy; they just # call methods stored on fatboy. Therefore, the connection # failure will not be noticed until this part of the test msg = sys.exc_info()[1].args[0] if 'DB-Lib error' in msg: reassure() continue else: raise
write_mode = 'a' write_header = False
dt, t = dtime(t) print('To query solar system objects: %f seconds (obs MJD time %f)' % (dt, obs.mjd.TAI))
except: trace = traceback.extract_tb(sys.exc_info()[2], limit=20) msg = sys.exc_info()[1].args[0] if 'Failed to connect' in msg or failedOnFatboy(trace): # if the exception was because of a failed connection # to fatboy, ignore it. reassure()
pass else: raise
lsst.utils.tests.init() unittest.main() |