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

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

from __future__ import print_function 

from builtins import object 

import inspect 

from future.utils import with_metaclass 

 

__all__ = ['MapsRegistry', 'BaseMap'] 

 

class MapsRegistry(type): 

""" 

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

""" 

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

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

if not hasattr(cls, 'registry'): 

cls.registry = {} 

modname = inspect.getmodule(cls).__name__ 

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

modname = '' 

else: 

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

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

else: 

modname = modname + '.' 

mapsname = modname + name 

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

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

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

cls.registry[mapsname] = cls 

 

def getClass(cls, mapsname): 

return cls.registry[mapsname] 

 

def help(cls, doc=False): 

for mapsname in sorted(cls.registry): 

if not doc: 

print(mapsname) 

if doc: 

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

print(cls.registry[mapsname].__doc__) 

maps = cls.registry[mapsname]() 

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

 

class BaseMap(with_metaclass(MapsRegistry, object)): 

""" """ 

 

def __init__(self,**kwargs): 

self.keyname = 'newkey' 

 

def run(self,slicePoints): 

""" 

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

adds additional metadata at each slicepoint and returns updated dict. 

""" 

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