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 

43 

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

45 """ """ 

46 

47 def __init__(self, **kwargs): 

48 self.keynames = ['newkey'] 

49 

50 def __eq__(self, othermap): 

51 return self.keynames == othermap.keynames 

52 

53 def __ne__(self, othermap): 

54 return self.keynames != othermap.keynames 

55 

56 def __lt__(self, othermap): 

57 return (self.keynames < othermap.keynames) 

58 

59 def __gt__(self, othermap): 

60 return (self.keynames > othermap.keynames) 

61 

62 def __le__(self, othermap): 

63 return (self.keynames <= othermap.keynames) 

64 

65 def __ge__(self, othermap): 

66 return (self.keynames >= othermap.keynames) 

67 

68 def run(self, slicePoints): 

69 """ 

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

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

72 """ 

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