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

from .database import Database 

import numpy as np 

import warnings 

 

__all__ = ['SdssDatabase'] 

 

class SdssDatabase(Database): 

"""Connect to the stripe 82 database""" 

def __init__(self, database=None, driver='sqlite', host=None, port=None, 

dbTables={'clue.dbo.viewStripe82JoinAll':['viewStripe82JoinAll','id']}, 

defaultdbTables=None, 

chunksize=1000000, **kwargs): 

super(SdssDatabase,self).__init__(database=database, driver=driver, port=port, host=host, 

dbTables=dbTables,defaultdbTables=defaultdbTables, 

chunksize=chunksize,**kwargs ) 

 

 

 

def fetchMetricData(self, colnames, sqlconstraint, groupBy=None, 

cleanNaNs=True, **kwargs): 

"""Get data for metric""" 

table = self.tables['clue.dbo.viewStripe82JoinAll'] 

# MSSQL doesn't seem to like double quotes? 

if sqlconstraint != sqlconstraint.replace('"', "'"): 

warnings.warn('Warning: Replacing double quotes with single quotes in SQL where-clause. \ 

Double quotes are not defined in standard SQL.') 

sqlconstraint = sqlconstraint.replace('"', "'") 

data = table.query_columns_Array(chunk_size = self.chunksize, 

constraint = sqlconstraint, 

colnames = colnames, 

groupByCol = groupBy) 

# Toss columns with NaNs. 

if cleanNaNs: 

for col in colnames: 

good = np.where(np.isnan(data[col]) == False) 

data = data[good] 

return data