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 __future__ import print_function 

2from builtins import object 

3import inspect 

4from future.utils import with_metaclass 

5 

6__all__ = ['MapsRegistry', 'BaseMap'] 

7 

8class MapsRegistry(type): 

9 """ 

10 Meta class for Maps, to build a registry of maps classes. 

11 """ 

12 def __init__(cls, name, bases, dict): 

13 super(MapsRegistry, cls).__init__(name, bases, dict) 

14 if not hasattr(cls, 'registry'): 

15 cls.registry = {} 

16 modname = inspect.getmodule(cls).__name__ 

17 if modname.startswith('lsst.sims.maf.maps'): 17 ↛ 20line 17 didn't jump to line 20, because the condition on line 17 was never false

18 modname = '' 

19 else: 

20 if len(modname.split('.')) > 1: 

21 modname = '.'.join(modname.split('.')[:-1]) + '.' 

22 else: 

23 modname = modname + '.' 

24 mapsname = modname + name 

25 if mapsname in cls.registry: 25 ↛ 26line 25 didn't jump to line 26, because the condition on line 25 was never true

26 raise Exception('Redefining maps %s! (there are >1 maps with the same name)' %(mapsname)) 

27 if mapsname != 'BaseMaps': 27 ↛ exitline 27 didn't return from function '__init__', because the condition on line 27 was never false

28 cls.registry[mapsname] = cls 

29 

30 def getClass(cls, mapsname): 

31 return cls.registry[mapsname] 

32 

33 def help(cls, doc=False): 

34 for mapsname in sorted(cls.registry): 

35 if not doc: 

36 print(mapsname) 

37 if doc: 

38 print('---- ', mapsname, ' ----') 

39 print(cls.registry[mapsname].__doc__) 

40 maps = cls.registry[mapsname]() 

41 print(' added to SlicePoint: ', ','.join(maps.keynames)) 

42 

43class BaseMap(with_metaclass(MapsRegistry, object)): 

44 """ """ 

45 

46 def __init__(self,**kwargs): 

47 self.keyname = 'newkey' 

48 

49 def run(self,slicePoints): 

50 """ 

51 Given slicePoints (dict containing metadata about each slicePoint, including ra/dec), 

52 adds additional metadata at each slicepoint and returns updated dict. 

53 """ 

54 raise NotImplementedError('This must be defined in subclass')