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# (c) Stefan Countryman 2019 

2 

3""" 

4Methods and ``FileHandler`` classes associated with fetching ZTF triggers. 

5""" 

6 

7import logging 

8from llama.utils import ( 

9 parameter_factory, 

10) 

11from llama.filehandler import JSONFile 

12from llama.files.healpix import HEALPixPSF 

13from llama.files.healpix.psf import PsfGaussian 

14from llama.files.skymap_info import SkymapInfo 

15from llama.files.lvc_skymap import LvcSkymapHdf5 

16from llama import detectors 

17 

18LOGGER = logging.getLogger(__name__) 

19 

20 

21def _ztf_psf(self): 

22 """A Psf object for this ZTF trigger that can be used to take products of 

23 this trigger's localization PSF with other skymap objects.""" 

24 return PsfGaussian(ra=self.ra, dec=self.dec, sigma=self.sigma) 

25 

26 

27ZtfTrigger = parameter_factory( 

28 "ZtfTrigger", 

29 """A class for holding ZTF trigger data in an easily accessible form.""", 

30 gps="""The time of the trigger in GPS seconds.""", 

31 ra="""The right ascension of the trigger in degrees (equatorial).""", 

32 dec="""The declination of the trigger in degrees (equatorial).""", 

33 sigma="""The 1 sigma gaussian region of the point spread function of this 

34 ZTF trigger in degrees. Should usually be very very small.""", 

35 psf=_ztf_psf, 

36) 

37 

38 

39def always_veto(eventdir): 

40 """Always veto this FileHandler so that it has to be manually added.""" 

41 return True 

42 

43 

44@HEALPixPSF.set_class_attributes 

45class ZtfTriggerList(JSONFile, HEALPixPSF): 

46 """ 

47 Takes a list of dictionaries describing neutrinos and saves it to a 

48 text file. Validates the neutrino data to make sure each neutrino contains 

49 (minimally) the following properties: 

50 

51 - gps 

52 - ra 

53 - dec 

54 

55 The sigma value is always expected to be negligible and is hence given as a 

56 small value (relative to GW skymap pixel sizes). 

57 """ 

58 

59 SIGMA = 0.1 

60 

61 class_vetoes = ( 

62 (always_veto, None), 

63 ) 

64 

65 FILENAME = "ztf_trigger_list.json" 

66 DEPENDENCIES = (SkymapInfo,) 

67 DETECTORS = (detectors.ZTF,) 

68 

69 def _generate(self): # pylint: disable=W0221 

70 """Take a list of neutrinos as an argument, validate, and save.""" 

71 raise NotImplementedError("Have to make this manually for now.") 

72 

73 @property 

74 def template_skymap_filehandler(self): 

75 return LvcSkymapHdf5 

76 

77 def source_locations(self): 

78 triggers = self.read_json() 

79 locations = list() 

80 # pylint: disable=C0103 

81 for trig in triggers: 

82 coords = (trig['ra'], trig['dec'], self.SIGMA) 

83 if all([isinstance(x, float) for x in coords]): 

84 locations.append(coords) 

85 else: 

86 LOGGER.warning('Excluding ZTF trigger with undefined coords: ' 

87 '%s', coords) 

88 return locations 

89 

90 @property 

91 def triggers(self): 

92 """Return a list containing a ``ZtfTrigger`` object for each trigger; 

93 more convenient to work with when writing formulae than dealing 

94 directly with the neutrino dictionaries.""" 

95 return [ZtfTrigger(**t) for t in self.read_json()] 

96 

97 @property 

98 def num_triggers(self): 

99 return len(self.read_json())