Skip to content

Commit

Permalink
updated test to not use UW server. Modified variability to get bandpa…
Browse files Browse the repository at this point in the history
…ss name form ObservationMetaData object.
  • Loading branch information
SimonKrughoff committed May 27, 2014
1 parent 418ba96 commit ac038fa
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 62 deletions.
4 changes: 4 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# -*- python -*-
import os
from lsst.sconsUtils import scripts
scripts.BasicSConstruct("sims_photUtils")
base_env = Environment(ENV=os.environ)
for key in os.environ.iterkeys():
base_env = os.environ[key]
5 changes: 4 additions & 1 deletion python/lsst/sims/photUtils/Photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def loadBandPasses(self,bandPassList, bandPassRoot="total_"):
if self.bandPassKey != bandPassList:
self.bandPassKey=[]
self.bandPasses={}
path = os.getenv('LSST_THROUGHPUTS_DEFAULT')
#A hack to get around the fact that I can't get SCons to pass through env vars.
#path = os.getenv('LSST_THROUGHPUTS_DEFAULT_DIR')
path = os.path.join(os.getenv('THROUGHPUTS_DIR'),'baseline')

for i in range(len(bandPassList)):
self.bandPassKey.append(bandPassList[i])

Expand Down
12 changes: 6 additions & 6 deletions python/lsst/sims/photUtils/Variability.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import math
import os
import json as json
from lsst.sims.coordUtils import register_class, register_method
from lsst.sims.catalogs.measures.instance import register_class, register_method
from scipy.interpolate import InterpolatedUnivariateSpline
from scipy.interpolate import UnivariateSpline
from scipy.interpolate import interp1d
Expand Down Expand Up @@ -91,7 +91,7 @@ def get_stellar_variability(self):
zzout.append(zz[i])
yyout.append(yy[i])

if self.obs_metadata.metadata != None and self.obs_metadata.metadata['Opsim_filter']:
if self.obs_metadata.metadata != None and self.obs_metadata.bandpass:
magNormVarOut.append(magNorm[i])
else:
magNormVarOut.append(-999.0)
Expand Down Expand Up @@ -233,8 +233,8 @@ def get_galaxy_variability(self):
zAgnOut.append(zAgn[i])
yAgnOut.append(yAgn[i])

if self.obs_metadata.metadata != None and \
self.obs_metadata.metadata['Opsim_filter'] and \
if self.obs_metadata.metadata is not None and \
self.obs_metadata.bandpass and \
(not numpy.isnan(magNormAgn[i])):

magNormVarOut.append(self.sum_magnitudes(disk = magNormDisk[i], bulge = magNormBulge[i],
Expand Down Expand Up @@ -315,8 +315,8 @@ def applyVariability(self, varParams):
output = self._methodRegistry[method](self, params,expmjd)

if self.obs_metadata.metadata != None:
if self.obs_metadata.metadata['Opsim_filter']:
deltaMagNorm = output[self.obs_metadata.metadata['Opsim_filter'][0]]
if self.obs_metadata.bandpass:
deltaMagNorm = output[self.obs_metadata.bandpass]
else:
deltaMagNorm = None

Expand Down
5 changes: 5 additions & 0 deletions tests/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- python -*-
import os
from lsst.sconsUtils import scripts, env

scripts.BasicSConscript.tests()
133 changes: 79 additions & 54 deletions tests/testPhotometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,34 @@
import sys
import lsst.utils.tests as utilsTests

from lsst.sims.catalogs.measures.instance import InstanceCatalog
from lsst.sims.catalogs.measures.instance import InstanceCatalog, register_method, register_class
from lsst.sims.catalogs.generation.db import DBObject, ObservationMetaData
from lsst.sims.catalogs.generation.utils import myTestGals, myTestStars, \
makeStarTestDB, makeGalTestDB
#import lsst.sims.catUtils.baseCatalogModels
from lsst.sims.coordUtils.Astrometry import AstrometryGalaxies, AstrometryStars
from lsst.sims.photUtils.Photometry import PhotometryGalaxies, PhotometryStars
from lsst.sims.photUtils.EBV import EBVmixin

from lsst.sims.photUtils.Variability import Variability

# Create test databases
if os.path.exists('testDatabase.db'):
print "deleting database"
os.unlink('testDatabase.db')
makeStarTestDB(size=100000, seedVal=1)
makeGalTestDB(size=100000, seedVal=1)

@register_class
class MyVariability(Variability):
@register_method('testVar')
def applySineVar(self, varParams, expmjd):
period = varParams['period']
amplitude = varParams['amplitude']
phase = expmjd%period
magoff = amplitude*numpy.sin(2*numpy.pi*phase)
return {'u':magoff, 'g':magoff, 'r':magoff, 'i':magoff, 'z':magoff, 'y':magoff}

class testDefaults(object):

def get_proper_motion_ra(self):
Expand Down Expand Up @@ -52,16 +72,9 @@ def get_radial_velocity(self):

return out

class testCatalog(InstanceCatalog,AstrometryStars,Variability,testDefaults):
catalog_type = 'MISC'
default_columns=[('expmjd',5000.0,float)]
def db_required_columns(self):
return ['raJ2000'],['varParamStr']


class testStars(InstanceCatalog,AstrometryStars,EBVmixin,Variability,PhotometryStars,testDefaults):
class testStars(InstanceCatalog,AstrometryStars,EBVmixin,MyVariability,PhotometryStars,testDefaults):
catalog_type = 'test_stars'
column_outputs=['id','ra_corr','dec_corr','magNorm',\
column_outputs=['id','raObserved','decObserved','magNorm',\
'stellar_magNorm_var', \
'lsst_u','sigma_lsst_u','lsst_u_var','sigma_lsst_u_var',
'lsst_g','sigma_lsst_g','lsst_g_var','sigma_lsst_g_var',\
Expand All @@ -70,18 +83,12 @@ class testStars(InstanceCatalog,AstrometryStars,EBVmixin,Variability,PhotometryS
'lsst_z','sigma_lsst_z','lsst_z_var','sigma_lsst_z_var',\
'lsst_y','sigma_lsst_y','lsst_y_var','sigma_lsst_y_var',\
'EBV','varParamStr']
defSedName = 'sed_flat.txt'
default_columns = [('sedFilename', defSedName, (str, len(defSedName))) ,]

"""
class testStars(InstanceCatalog,Astrometry,EBVmixin,Variability,PhotometryStars,testDefaults):
catalog_type = 'test_stars'
column_outputs=['id','ra_corr','dec_corr','magNorm',\
'lsst_u','lsst_g','lsst_r','lsst_i','lsst_z','lsst_y',\
'EBV','varParamStr']
"""

class testGalaxies(InstanceCatalog,AstrometryGalaxies,EBVmixin,Variability,PhotometryGalaxies,testDefaults):
class testGalaxies(InstanceCatalog,AstrometryGalaxies,EBVmixin,MyVariability,PhotometryGalaxies,testDefaults):
catalog_type = 'test_galaxies'
column_outputs=['galid','ra_corr','dec_corr',\
column_outputs=['galid','raObserved','decObserved', 'redshift',\
'magNorm_Recalc_var', 'magNormAgn', 'magNormBulge', 'magNormDisk', \
'uRecalc', 'sigma_uRecalc', 'uRecalc_var','sigma_uRecalc_var',\
'gRecalc', 'sigma_gRecalc', 'gRecalc_var','sigma_gRecalc_var',\
Expand All @@ -101,49 +108,67 @@ class testGalaxies(InstanceCatalog,AstrometryGalaxies,EBVmixin,Variability,Photo
'iAgn', 'sigma_iAgn', 'iAgn_var', 'sigma_iAgn_var',\
'zAgn', 'sigma_zAgn', 'zAgn_var', 'sigma_zAgn_var',\
'yAgn', 'sigma_yAgn', 'yAgn_var', 'sigma_yAgn_var', 'varParamStr']
defSedName = "sed_flat.txt"
default_columns = [('sedFilename', defSedName, (str, len(defSedName))) ,
('sedFilenameAgn', defSedName, (str, len(defSedName))),
('sedFilenameBulge', defSedName, (str, len(defSedName))),
('sedFilenameDisk', defSedName, (str, len(defSedName))),
]

def get_internalAvDisk(self):
return numpy.ones(len(self._current_chunk))*0.1

def get_internalAvBulge(self):
return numpy.ones(len(self._current_chunk))*0.1

def get_galid(self):
return self.column_by_name('id')

class variabilityUnitTest(unittest.TestCase):

galaxy = DBObject.from_objid('galaxyBase')
rrly = DBObject.from_objid('rrly')
obsMD = DBObject.from_objid('opsim3_61')
obs_metadata = obsMD.getObservationMetaData(88544919, 0.1, makeCircBounds = True)

def testGalaxyVariability(self):

galcat = testCatalog(self.galaxy,obs_metadata = self.obs_metadata)
rows = self.galaxy.query_columns(['varParamStr'], constraint = 'VarParamStr is not NULL',chunk_size=20)
rows = rows.next()
for i in range(20):
#print "i ",i
mags=galcat.applyVariability(rows[i]['varParamStr'])
#print mags

def testRRlyVariability(self):
rrlycat = testCatalog(self.rrly,obs_metadata = self.obs_metadata)
rows = self.rrly.query_columns(['varParamStr'], constraint = 'VarParamStr is not NULL',chunk_size=20)
rows = rows.next()
for i in range(20):
mags=rrlycat.applyVariability(rows[i]['varParamStr'])
def setUp(self):
self.galaxy = myTestGals()
self.star = myTestStars()
self.obs_metadata = ObservationMetaData(mjd=52000.7, bandpassName='i', circ_bounds=dict(ra=200., dec=-30, radius=1.))

def tearDown(self):
del self.galaxy
del self.star
del self.obs_metadata

def testGalaxyVariability(self):

galcat = testGalaxies(self.galaxy, obs_metadata=self.obs_metadata)
results = self.galaxy.query_columns(['varParamStr'], constraint='VarParamStr is not NULL')
for result in results:
for row in result:
mags=galcat.applyVariability(row['varParamStr'])

def testStarVariability(self):
starcat = testStars(self.star, obs_metadata=self.obs_metadata)
results = self.star.query_columns(['varParamStr'], constraint='VarParamStr is not NULL')
for result in results:
for row in result:
mags=starcat.applyVariability(row['varParamStr'])

class photometryUnitTest(unittest.TestCase):

def setUp(self):
self.galaxy = myTestGals()
self.star = myTestStars()
self.obs_metadata = ObservationMetaData(mjd=52000.7, bandpassName='i', circ_bounds=dict(ra=200., dec=-30, radius=1.))

def tearDown(self):
del self.galaxy
del self.star
del self.obs_metadata

def testStars(self):
dbObj=DBObject.from_objid('rrly')
obs_metadata_pointed=ObservationMetaData(mjd=2013.23, circ_bounds=dict(ra=200., dec=-30, radius=1.))
obs_metadata_pointed.metadata = {}
obs_metadata_pointed.metadata['Opsim_filter'] = 'i'
test_cat=testStars(dbObj,obs_metadata=obs_metadata_pointed)
test_cat=testStars(self.star, obs_metadata=self.obs_metadata)
test_cat.write_catalog("testStarsOutput.txt")


def testGalaxies(self):
dbObj=DBObject.from_objid('galaxyBase')
obs_metadata_pointed=ObservationMetaData(mjd=50000.0, circ_bounds=dict(ra=0., dec=0., radius=0.01))
obs_metadata_pointed.metadata = {}
obs_metadata_pointed.metadata['Opsim_filter'] = 'i'
test_cat=testGalaxies(dbObj,obs_metadata=obs_metadata_pointed)
test_cat=testGalaxies(self.galaxy, obs_metadata=self.obs_metadata)
test_cat.write_catalog("testGalaxiesOutput.txt")

def suite():
Expand Down
2 changes: 1 addition & 1 deletion ups/sims_photUtils.table
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#setupRequired(sims_catalogs_measures)
setupRequired(sims_catalogs_measures)
setupRequired(sims_sed_library)
setupRequired(sims_dustmaps)
setupRequired(sims_coordUtils)
Expand Down

0 comments on commit ac038fa

Please sign in to comment.