Skip to content

Commit

Permalink
Use new opsim v4 db from sims_data
Browse files Browse the repository at this point in the history
  • Loading branch information
rhiannonlynne committed Oct 4, 2017
1 parent c82c60c commit c7e1b84
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
Binary file removed tests/opsimblitz1_1133_sqlite.db
Binary file not shown.
Binary file removed tests/pontus_1150.db
Binary file not shown.
7 changes: 4 additions & 3 deletions tests/testDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lsst.sims.maf.db as db
import lsst.utils.tests
from lsst.sims.utils.CodeUtilities import sims_clean_up

from lsst.utils import getPackageDir

class TestDb(unittest.TestCase):

Expand All @@ -15,8 +15,8 @@ def tearDownClass(cls):
sims_clean_up()

def setUp(self):
self.database = os.path.join(os.getenv('SIMS_MAF_DIR'),
'tests', 'pontus_1150.db')
self.database = os.path.join(getPackageDir('sims_data'),
'OpSimData', 'astro-lsst-01_2014.db')
self.driver = 'sqlite'

def tearDown(self):
Expand All @@ -32,6 +32,7 @@ def testBaseDatabase(self):
'SlewActivities', 'TargetExposures', 'ObsHistory',
'SlewFinalState', 'TargetHistory', 'ObsProposalHistory',
'SlewHistory', 'TargetProposalHistory', 'Proposal',
'ProposalField',
'SlewInitialState', 'UnscheduledDowntime']
self.assertEqual(set(basedb.tableNames),
set(expectedTables))
Expand Down
9 changes: 6 additions & 3 deletions tests/testMetricBundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import lsst.sims.maf.db as db
import glob
import os
import tempfile
import shutil
import lsst.utils.tests
from lsst.utils import getPackageDir
from lsst.sims.utils.CodeUtilities import sims_clean_up


Expand All @@ -22,7 +24,7 @@ def tearDownClass(cls):
sims_clean_up()

def setUp(self):
self.outDir = 'TMB'
self.outDir = tempfile.mkdtemp(prefix='TMB')

def testOut(self):
"""
Expand All @@ -38,9 +40,8 @@ def testOut(self):
map2 = maps.StellarDensityMap()

metricB = metricBundles.MetricBundle(metric, slicer, sql, stackerList=[stacker1, stacker2])
filepath = os.path.join(os.getenv('SIMS_MAF_DIR'), 'tests/')
database = os.path.join(getPackageDir('sims_data'), 'OpSimData', 'astro-lsst-01_2014.db')

database = os.path.join(filepath, 'pontus_1150.db')
opsdb = db.OpsimDatabaseV4(database=database)
resultsDb = db.ResultsDb(outDir=self.outDir)

Expand All @@ -49,6 +50,8 @@ def testOut(self):
bgroup.plotAll()
bgroup.writeAll()

opsdb.close()

outThumbs = glob.glob(os.path.join(self.outDir, 'thumb*'))
outNpz = glob.glob(os.path.join(self.outDir, '*.npz'))
outPdf = glob.glob(os.path.join(self.outDir, '*.pdf'))
Expand Down
9 changes: 5 additions & 4 deletions tests/testOpsimDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lsst.sims.maf.db as db
import lsst.sims.maf.utils.outputUtils as out
import lsst.utils.tests
from lsst.utils import getPackageDir
from lsst.sims.utils.CodeUtilities import sims_clean_up
from builtins import str

Expand All @@ -18,8 +19,8 @@ def tearDownClass(cls):
sims_clean_up()

def setUp(self):
self.database = os.path.join(os.getenv('SIMS_MAF_DIR'), 'tests',
'pontus_1150.db')
self.database = os.path.join(getPackageDir('sims_data'), 'OpSimData',
'astro-lsst-01_2014.db')
self.oo = db.OpsimDatabaseV4(database=self.database)

def tearDown(self):
Expand Down Expand Up @@ -61,13 +62,13 @@ def testOpsimDbFields(self):
def testOpsimDbRunLength(self):
"""Test query for length of opsim run."""
nrun = self.oo.fetchRunLength()
self.assertEqual(nrun, 1.)
self.assertEqual(nrun, 0.04)

def testOpsimDbSimName(self):
"""Test query for opsim name."""
simname = self.oo.fetchOpsimRunName()
self.assertTrue(isinstance(simname, str))
self.assertEqual(simname, 'pontus_1150')
self.assertEqual(simname, 'astro-lsst-01_2014')

def testOpsimDbConfig(self):
"""Test generation of config data. """
Expand Down
2 changes: 2 additions & 0 deletions ups/sims_maf.table
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ setupRequired(palpy)
setupRequired(healpy)
# For basic sims utilities
setupRequired(sims_utils)
# For opsim database for unit test
setupRequired(sims_data)
# For access to the db classes
setupRequired(sims_catalogs)
# For magnitude and SNR calculations
Expand Down

0 comments on commit c7e1b84

Please sign in to comment.