Hide keyboard shortcuts

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

import warnings 

import numpy 

from .BaseCatalogModels import BaseCatalogObj 

from lsst.sims.catalogs.db import ChunkIterator, CatalogDBObject 

from lsst.sims.utils import ObservationMetaData 

 

__all__ = ["SolarSystemObj", "CometObj", "NEOObj", "MBAObj", "MiscSolarSystemObj"] 

 

class SolarSystemObj(BaseCatalogObj): 

""" 

This is the base CatalogDBObject from which all other Solar System CatalogDBObjects 

derive. It will query all of the Solar System object tables on fatboy. 

 

Note: Solar System objects only exist for 50093.14 < mjd < 51923.0. If you query outside 

of that date range, you will get an empty catalog. 

""" 

objid = 'ssm' 

tableid = '' 

 

ssmtable = 'fSSMAllBase' 

# The variable ssmtable specifies which Table Valued Function to call on 

# fatboy. Valid values are: 

# fSSMCometBase -- to query comets 

# fSSMNEOBase -- to query Near Earth Objects 

# fSSMMBABase -- to query Main Belt Asteroids 

# fSSMnonMBABase -- to query objects that are none of the above 

# fSSMAllBase -- to query the union of all of the above 

 

objectTypeId = 40 

doRunTest = True 

testObservationMetaData = ObservationMetaData(boundType = 'circle', 

pointingRA = 0.0, pointingDec = 0.0, 

boundLength = 0.1, mjd=51200., bandpassName='r', m5=22.0) 

 

#Turn off default column mapping since we are querying a dynamic resource 

generateDefaultColumnMap = False 

 

#: Numpy can't cast a NoneType to an integer. This works with floats 

#: as None is cast to nan, but for integers this raises and exception. 

#: Typically it's not an issue as ints are usually ids of some sort, 

#: but in the case of the base galaxy catalog, it's possible for the 

#: varsimobjid to be None if the object does not contain an AGN. 

#: I'm over riding the _postprocess_results method to take care of this. 

#: I could also have refactored my database table so that no integer values 

#: contain NULL values. 

dbDefaultValues = {'varsimobjid':-1, 'myid':-1} 

 

#: The following maps column names to database schema. The tuples 

#: must be at least length 2. If column name is the same as the name 

#: in the DB the mapping element may be None. The rest of the tuple 

#: should be formatted like a numpy.dtype. If ommitted, the dtype 

#: is assumed to be float. 

columns = [('objid', 'ssmid', int), 

('raJ2000', 'ra*PI()/180.'), 

('decJ2000', 'decl*PI()/180.'), 

('sedFilename', 'sed_filename', str, 40), 

('dist', 'dist', numpy.float), 

('velRa', 'dradt*PI()/180.'), 

('velDec', 'ddecldt*PI()/180.'), 

('magNorm', 'magNorm', numpy.float), 

('umag', 'umag', numpy.float), 

('gmag', 'gmag', numpy.float), 

('rmag', 'rmag', numpy.float), 

('imag', 'imag', numpy.float), 

('zmag', 'zmag', numpy.float), 

('ymag', 'ymag', numpy.float)] 

 

def _get_column_query(self, colnames=None): 

raise NotImplementedError("We are calling a stored procedure so " 

"no need to loop over columns") 

 

def _get_table(self): 

#This needs to be overridden since __init__() calls the default impl. 

return None 

 

def getIdColKey(self): 

return 'objid' 

 

def query_columns(self, colnames=None, chunk_size=None, obs_metadata=None, constraint=None): 

"""Execute a query 

 

**Parameters** 

 

* colnames : list or None 

a list of valid column names, corresponding to entries in the 

`columns` class attribute. If not specified, all columns are 

queried. 

* chunksize : int (optional) 

if specified, then return an iterator object to query the database, 

each time returning the next `chunksize` elements. If not 

specified, all matching results will be returned. 

* obs_metadata : object (optional) 

object containing information on the observation including the region of the sky 

to query and time of the observation. 

* constraint : string (optional) 

if specified, the predicate is added to the query verbatim using AND 

 

**Returns** 

 

* result : structured array or iterator 

If chunksize is not specified, then result is a structured array of all 

items which match the specified query with columns named by the column 

names in the columns class attribute. If chunksize is specified, 

then result is an iterator over structured arrays of the given size. 

 

""" 

if colnames is None: 

colnames = [k for k in self.columnMap.keys()] 

 

mappedcolnames = ["%s as %s"%(self.columnMap[x], x) for x in colnames] 

mappedcolnames = ",".join(mappedcolnames) 

 

if obs_metadata is not None and obs_metadata.bounds is not None: 

if obs_metadata.bounds.boundType == 'circle': 

regionStr = 'REGION CIRCLE J2000 %f %f %f'%(obs_metadata.bounds.RAdeg, 

obs_metadata.bounds.DECdeg, 

60.*obs_metadata.bounds.radiusdeg) 

elif obs_metadata.bounds.boundType == 'box': 

regionStr = 'REGION RECT J2000 %f %f %f %f'%(obs_metadata.bounds.RAminDeg, 

obs_metadata.bounds.DECminDeg, 

obs_metadata.bounds.RAmaxDeg, 

obs_metadata.bounds.DECmaxDeg) 

else: 

raise RuntimeError("SolarSystemObj does not know about boundType %s " 

% obs_metadata.bounds.boundType) 

else: 

regionStr = 'REGION CIRCLE J2000 180. 0. 10800.' 

warnings.warn("Searching over entire sky " 

"since no bounds specified. " 

"This could be a very bad idea " 

"if the database is large") 

 

query = "select %s from [LSSTCATSIM].[dbo].%s("%(mappedcolnames, self.ssmtable)+\ 

"%f, '%s')"%(obs_metadata.mjd.TAI, regionStr) 

 

if constraint is not None: 

query += "where %s"%(constraint) 

 

return ChunkIterator(self, query, chunk_size) 

 

 

class CometObj(SolarSystemObj): 

""" 

This CatalogDBObject class queries the table of comets on fatboy 

 

Note: Solar System objects only exist for 5093.14 < mjd < 51923.0. If you query outside 

of that date range, you will get an empty catalog. 

""" 

ssmtable = 'fSSMCometBase' 

 

# This object needs its own testObservationMetaData. The 

# testObservationMetaData defined in SolarSystemObj is too small. 

# It returns zero objects, which causes an error in testAllObjects.py 

testObservationMetaData = ObservationMetaData(boundType = 'circle', 

pointingRA = 0.0, pointingDec = 0.0, 

boundLength = 0.5, mjd=51200., bandpassName='r', m5=22.0) 

 

 

class NEOObj(SolarSystemObj): 

""" 

This CatalogDBObject class queries the table of Near Earth Objects on fatboy 

 

Note: Solar System objects only exist for 5093.14 < mjd < 51923.0. If you query outside 

of that date range, you will get an empty catalog. 

""" 

ssmtable = 'fSSMNEOBase' 

 

# This object needs its own testObservationMetaData. The 

# testObservationMetaData defined in SolarSystemObj is too small. 

# It returns zero objects, which causes an error in testAllObjects.py 

testObservationMetaData = ObservationMetaData(boundType = 'circle', 

pointingRA = 0.0, pointingDec = 0.0, 

boundLength = 0.5, mjd=51200., bandpassName='r', m5=22.0) 

 

 

 

class MBAObj(SolarSystemObj): 

""" 

This CatalogDBObject class queries the table of Main Belt Asteroids on fatboy 

 

Note: Solar System objects only exist for 5093.14 < mjd < 51923.0. If you query outside 

of that date range, you will get an empty catalog. 

""" 

ssmtable = 'fSSMMBABase' 

 

# since the MBA tables have been updated, we need to include a testObservationMetaData 

# that had an mjd>=59580.0, since that is the new time range for the simulated 

# LSST survey 

testObservationMetaData = ObservationMetaData(boundType = 'circle', 

pointingRA = 0.0, pointingDec = 0.0, 

boundLength = 0.5, mjd=59590., bandpassName='r', m5=22.0) 

 

 

class MiscSolarSystemObj(SolarSystemObj): 

""" 

This CatalogDBObject class queriess the table of Solar Systems objects on fatboy 

that are not comets, near Earth objects, or main belt asteroids 

 

Note: Solar System objects only exist for 5093.14 < mjd < 51923.0. If you query outside 

of that date range, you will get an empty catalog. 

""" 

ssmtable = 'fSSMnonMBABase'