Coverage for python/lsst/sims/catUtils/baseCatalogModels/SsmModels.py : 48%

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
1import warnings
2import numpy
3from .BaseCatalogModels import BaseCatalogObj
4from lsst.sims.catalogs.db import ChunkIterator, CatalogDBObject
5from lsst.sims.utils import ObservationMetaData
7__all__ = ["SolarSystemObj", "CometObj", "NEOObj", "MBAObj", "MiscSolarSystemObj"]
9class SolarSystemObj(BaseCatalogObj):
10 """
11 This is the base CatalogDBObject from which all other Solar System CatalogDBObjects
12 derive. It will query all of the Solar System object tables on fatboy.
14 Note: Solar System objects only exist for 50093.14 < mjd < 51923.0. If you query outside
15 of that date range, you will get an empty catalog.
16 """
17 objid = 'ssm'
18 tableid = ''
20 ssmtable = 'fSSMAllBase'
21 # The variable ssmtable specifies which Table Valued Function to call on
22 # fatboy. Valid values are:
23 # fSSMCometBase -- to query comets
24 # fSSMNEOBase -- to query Near Earth Objects
25 # fSSMMBABase -- to query Main Belt Asteroids
26 # fSSMnonMBABase -- to query objects that are none of the above
27 # fSSMAllBase -- to query the union of all of the above
29 objectTypeId = 40
30 doRunTest = True
31 testObservationMetaData = ObservationMetaData(boundType = 'circle',
32 pointingRA = 0.0, pointingDec = 0.0,
33 boundLength = 0.1, mjd=51200., bandpassName='r', m5=22.0)
35 #Turn off default column mapping since we are querying a dynamic resource
36 generateDefaultColumnMap = False
38 #: Numpy can't cast a NoneType to an integer. This works with floats
39 #: as None is cast to nan, but for integers this raises and exception.
40 #: Typically it's not an issue as ints are usually ids of some sort,
41 #: but in the case of the base galaxy catalog, it's possible for the
42 #: varsimobjid to be None if the object does not contain an AGN.
43 #: I'm over riding the _postprocess_results method to take care of this.
44 #: I could also have refactored my database table so that no integer values
45 #: contain NULL values.
46 dbDefaultValues = {'varsimobjid':-1, 'myid':-1}
48 #: The following maps column names to database schema. The tuples
49 #: must be at least length 2. If column name is the same as the name
50 #: in the DB the mapping element may be None. The rest of the tuple
51 #: should be formatted like a numpy.dtype. If ommitted, the dtype
52 #: is assumed to be float.
53 columns = [('objid', 'ssmid', int),
54 ('raJ2000', 'ra*PI()/180.'),
55 ('decJ2000', 'decl*PI()/180.'),
56 ('sedFilename', 'sed_filename', str, 40),
57 ('dist', 'dist', numpy.float),
58 ('velRa', 'dradt*PI()/180.'),
59 ('velDec', 'ddecldt*PI()/180.'),
60 ('magNorm', 'magNorm', numpy.float),
61 ('umag', 'umag', numpy.float),
62 ('gmag', 'gmag', numpy.float),
63 ('rmag', 'rmag', numpy.float),
64 ('imag', 'imag', numpy.float),
65 ('zmag', 'zmag', numpy.float),
66 ('ymag', 'ymag', numpy.float)]
68 def _get_column_query(self, colnames=None):
69 raise NotImplementedError("We are calling a stored procedure so "
70 "no need to loop over columns")
72 def _get_table(self):
73 #This needs to be overridden since __init__() calls the default impl.
74 return None
76 def getIdColKey(self):
77 return 'objid'
79 def query_columns(self, colnames=None, chunk_size=None, obs_metadata=None, constraint=None):
80 """Execute a query
82 **Parameters**
84 * colnames : list or None
85 a list of valid column names, corresponding to entries in the
86 `columns` class attribute. If not specified, all columns are
87 queried.
88 * chunksize : int (optional)
89 if specified, then return an iterator object to query the database,
90 each time returning the next `chunksize` elements. If not
91 specified, all matching results will be returned.
92 * obs_metadata : object (optional)
93 object containing information on the observation including the region of the sky
94 to query and time of the observation.
95 * constraint : string (optional)
96 if specified, the predicate is added to the query verbatim using AND
98 **Returns**
100 * result : structured array or iterator
101 If chunksize is not specified, then result is a structured array of all
102 items which match the specified query with columns named by the column
103 names in the columns class attribute. If chunksize is specified,
104 then result is an iterator over structured arrays of the given size.
106 """
107 if colnames is None:
108 colnames = [k for k in self.columnMap.keys()]
110 mappedcolnames = ["%s as %s"%(self.columnMap[x], x) for x in colnames]
111 mappedcolnames = ",".join(mappedcolnames)
113 if obs_metadata is not None and obs_metadata.bounds is not None:
114 if obs_metadata.bounds.boundType == 'circle':
115 regionStr = 'REGION CIRCLE J2000 %f %f %f'%(obs_metadata.bounds.RAdeg,
116 obs_metadata.bounds.DECdeg,
117 60.*obs_metadata.bounds.radiusdeg)
118 elif obs_metadata.bounds.boundType == 'box':
119 regionStr = 'REGION RECT J2000 %f %f %f %f'%(obs_metadata.bounds.RAminDeg,
120 obs_metadata.bounds.DECminDeg,
121 obs_metadata.bounds.RAmaxDeg,
122 obs_metadata.bounds.DECmaxDeg)
123 else:
124 raise RuntimeError("SolarSystemObj does not know about boundType %s "
125 % obs_metadata.bounds.boundType)
126 else:
127 regionStr = 'REGION CIRCLE J2000 180. 0. 10800.'
128 warnings.warn("Searching over entire sky "
129 "since no bounds specified. "
130 "This could be a very bad idea "
131 "if the database is large")
133 query = "select %s from [LSSTCATSIM].[dbo].%s("%(mappedcolnames, self.ssmtable)+\
134 "%f, '%s')"%(obs_metadata.mjd.TAI, regionStr)
136 if constraint is not None:
137 query += "where %s"%(constraint)
139 return ChunkIterator(self, query, chunk_size)
142class CometObj(SolarSystemObj):
143 """
144 This CatalogDBObject class queries the table of comets on fatboy
146 Note: Solar System objects only exist for 5093.14 < mjd < 51923.0. If you query outside
147 of that date range, you will get an empty catalog.
148 """
149 ssmtable = 'fSSMCometBase'
151 # This object needs its own testObservationMetaData. The
152 # testObservationMetaData defined in SolarSystemObj is too small.
153 # It returns zero objects, which causes an error in testAllObjects.py
154 testObservationMetaData = ObservationMetaData(boundType = 'circle',
155 pointingRA = 0.0, pointingDec = 0.0,
156 boundLength = 0.5, mjd=51200., bandpassName='r', m5=22.0)
159class NEOObj(SolarSystemObj):
160 """
161 This CatalogDBObject class queries the table of Near Earth Objects on fatboy
163 Note: Solar System objects only exist for 5093.14 < mjd < 51923.0. If you query outside
164 of that date range, you will get an empty catalog.
165 """
166 ssmtable = 'fSSMNEOBase'
168 # This object needs its own testObservationMetaData. The
169 # testObservationMetaData defined in SolarSystemObj is too small.
170 # It returns zero objects, which causes an error in testAllObjects.py
171 testObservationMetaData = ObservationMetaData(boundType = 'circle',
172 pointingRA = 0.0, pointingDec = 0.0,
173 boundLength = 0.5, mjd=51200., bandpassName='r', m5=22.0)
177class MBAObj(SolarSystemObj):
178 """
179 This CatalogDBObject class queries the table of Main Belt Asteroids on fatboy
181 Note: Solar System objects only exist for 5093.14 < mjd < 51923.0. If you query outside
182 of that date range, you will get an empty catalog.
183 """
184 ssmtable = 'fSSMMBABase'
186 # since the MBA tables have been updated, we need to include a testObservationMetaData
187 # that had an mjd>=59580.0, since that is the new time range for the simulated
188 # LSST survey
189 testObservationMetaData = ObservationMetaData(boundType = 'circle',
190 pointingRA = 0.0, pointingDec = 0.0,
191 boundLength = 0.5, mjd=59590., bandpassName='r', m5=22.0)
194class MiscSolarSystemObj(SolarSystemObj):
195 """
196 This CatalogDBObject class queriess the table of Solar Systems objects on fatboy
197 that are not comets, near Earth objects, or main belt asteroids
199 Note: Solar System objects only exist for 5093.14 < mjd < 51923.0. If you query outside
200 of that date range, you will get an empty catalog.
201 """
202 ssmtable = 'fSSMnonMBABase'