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 2016-2018 

2 

3""" 

4A FileHandler that generates a list of pixel positions and values from a 

5HEALPix skymap to be used in the old O2 MATLAB pipeline. 

6""" 

7 

8import logging 

9from llama.filehandler import FileHandler 

10from llama.files.lvc_skymap import LvcSkymapFits 

11 

12LOGGER = logging.getLogger(__name__) 

13 

14 

15class LvcSkymapTxt(FileHandler): 

16 """ 

17 A list of sky positions and probability densities in text form generated 

18 from the original Healpix-encoded skymap. The values form a 

19 space-delimited table, with each row corresponding to a pixel and the 

20 columns corresponding to theta, phi, and probability density (**Header is 

21 not included in text file**): 

22 

23 +-------------+------------+----------------------+ 

24 | theta [deg] | phi [deg] | probability density | 

25 +=============+============+======================+ 

26 | ... | ... | ... | 

27 +-------------+------------+----------------------+ 

28 """ 

29 

30 FILENAME = "lvc_skymap.txt" 

31 DEPENDENCIES = (LvcSkymapFits,) 

32 

33 def _generate(self): # pylint: disable=arguments-differ 

34 import healpy as hp 

35 fitsfile = self.DEPENDENCIES[0](self) 

36 # get pixel coordinates and pixel values 

37 pixel_values = hp.read_map(fitsfile.fullpath, verbose=False) 

38 npix = len(pixel_values) 

39 pixel_indices = range(npix) 

40 nside = hp.pixelfunc.npix2nside(npix) 

41 pixel_coords = hp.pixelfunc.pix2ang(nside, pixel_indices) 

42 # write pixels to outfile 

43 with open(self.fullpath, 'w') as outfile: 

44 for i in pixel_indices: 

45 outfile.write( 

46 str(pixel_coords[0][i]) + ' ' + 

47 str(pixel_coords[1][i]) + ' ' + 

48 str(pixel_values[i]) + '\n' 

49 )