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

1from lsst.sims.utils import ObservationMetaData 

2from lsst.sims.catalogs.db import CatalogDBObject 

3from lsst.sims.catalogs.definitions import InstanceCatalog 

4 

5__all__ = ["setupPhotometryCatalog"] 

6 

7def setupPhotometryCatalog(obs_metadata=None, dbConnection=None, catalogClass=None, 

8 photometryNameRoot='lsst', uncertainty=False): 

9 """ 

10 This method will read in an InstanceCatalog class (not an instantiation of that class; 

11 a class itself), and instantiation of ObservationMetaData and an instantiation of 

12 a CatalogDBObject class, instantiate the InstanceCatalog class according to the 

13 ObservationMetaData and CatalogDBObject and return the instantiated instanceCatalog. 

14 

15 Note that this class will tell the InstanceCatalog to only output photometric columns 

16 defined by the ObservationMetaData (i.e. if the ObservationMetaData.bandpass is 'u', 

17 then the instantiated InstanceCatalog will only write the u-based column of photometry. 

18 

19 @param [in] obs_metadata is an instantiation of an ObservationMetaData 

20 

21 @param [in] dbConnection is an instantiation of a CatalogDBObject daughter class 

22 

23 @param [in] catalogClass is a daughter class of InstanceCatalog (not an instantiation of 

24 that class; just the class itself) 

25 

26 @param [in] photometryNameRoot is a string indicating the naming convention of the 

27 photometry columns. This method will assume that columns are named 

28 

29 photometryNameRoot_bandpassName 

30 

31 Note: it is your responsibility to make sure that the catalogClass is able to calculate 

32 the columns specified this way (i.e. if photometryNameRoot is 'sdss', you should make 

33 sure that your catalogClass has getters for columns sdss_[u,g,r,i,z]) 

34 

35 @param [out] an instantiation of the provided InstanceCatalog daughter class that is 

36 consistent with the other inputs 

37 """ 

38 

39 if not isinstance(obs_metadata, ObservationMetaData): 

40 raise RuntimeError('obs_metadata needs to be an instantiation of ObservationMetaData') 

41 

42 if not isinstance(dbConnection, CatalogDBObject): 

43 raise RuntimeError('dbConnection needs to be an instantiation of a CatalogDBObject daughter class') 

44 

45 if not issubclass(catalogClass, InstanceCatalog): 

46 raise RuntimeError('catalogClass needs to be a daughter class of InstanceCatalog') 

47 

48 column_outputs = None #this will be how we specify the photometric columns for the 

49 #catalogClass 

50 

51 if obs_metadata.bandpass is not None: 

52 if hasattr(obs_metadata.bandpass, '__iter__'): 

53 for b in obs_metadata.bandpass: 

54 if column_outputs is None: 

55 column_outputs = [photometryNameRoot+'_'+b] 

56 else: 

57 column_outputs.append(photometryNameRoot+'_'+b) 

58 

59 if uncertainty: 

60 column_outputs.append('sigma_'+photometryNameRoot+'_'+b) 

61 else: 

62 column_outputs = [photometryNameRoot+'_'+obs_metadata.bandpass] 

63 if uncertainty: 

64 column_outputs.append('sigma_'+photometryNameRoot+'_'+obs_metadata.bandpass) 

65 

66 instantiation = catalogClass(dbConnection, obs_metadata=obs_metadata, column_outputs=column_outputs) 

67 return instantiation