Coverage for python/lsst/sims/maf/db/sdssDatabase.py : 29%

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
1from .database import Database
2import numpy as np
3import warnings
5__all__ = ['SdssDatabase']
7class SdssDatabase(Database):
8 """Connect to the stripe 82 database"""
9 def __init__(self, database=None, driver='sqlite', host=None, port=None,
10 dbTables={'clue.dbo.viewStripe82JoinAll':['viewStripe82JoinAll','id']},
11 defaultdbTables=None,
12 chunksize=1000000, **kwargs):
13 super(SdssDatabase,self).__init__(database=database, driver=driver, port=port, host=host,
14 dbTables=dbTables,defaultdbTables=defaultdbTables,
15 chunksize=chunksize,**kwargs )
19 def fetchMetricData(self, colnames, sqlconstraint, groupBy=None,
20 cleanNaNs=True, **kwargs):
21 """Get data for metric"""
22 table = self.tables['clue.dbo.viewStripe82JoinAll']
23 # MSSQL doesn't seem to like double quotes?
24 if sqlconstraint != sqlconstraint.replace('"', "'"):
25 warnings.warn('Warning: Replacing double quotes with single quotes in SQL where-clause. \
26 Double quotes are not defined in standard SQL.')
27 sqlconstraint = sqlconstraint.replace('"', "'")
28 data = table.query_columns_Array(chunk_size = self.chunksize,
29 constraint = sqlconstraint,
30 colnames = colnames,
31 groupByCol = groupBy)
32 # Toss columns with NaNs.
33 if cleanNaNs:
34 for col in colnames:
35 good = np.where(np.isnan(data[col]) == False)
36 data = data[good]
37 return data