def read_skymap_rotate(skymap_filename, theta=0, phi=0): '''Read the healpix skymap''' skymap, metadata = fits.read_sky_map(skymap_filename, nest=True) nside = hp.get_nside(skymap) npix = hp.nside2npix(nside) skymap = skymap[hp.ring2nest(nside, np.arange(npix))] if (not theta == 0) or (not phi == 0): skymap = rotate_map(skymap, np.deg2rad(theta), np.deg2rad(phi)) return skymap
def _read_O3(self, fname, convert_nested=True): skymap, metadata = fits.read_sky_map(fname, nest=None, distances=True) #Read the skymap self.event_name = get_ename(fname, verbose=self.verbose) if self.verbose: print('\nEvent: %s' % self.event_name) if (convert_nested) & ( metadata['nest'] ): #If one wants RING ordering (the one of O2 data afaik) just has to set "convert_nested" to True self.p_posterior = hp.reorder(skymap[0], n2r=True) self.mu = hp.reorder(skymap[1], n2r=True) self.sigma = hp.reorder(skymap[2], n2r=True) self.posteriorNorm = hp.reorder(skymap[3], n2r=True) else: self.p_posterior = skymap[0] self.mu = skymap[1] self.sigma = skymap[2] self.posteriorNorm = skymap[3] self.head = None
CWD = os.getcwd() gwtc1 = CWD + '/gwtc1-skymaps' #gwtc2 = CWD+'/all_skymaps' all_files = os.listdir(gwtc1) fnames = [] for file in all_files: if file.endswith('.fits'): fnames.append(file) #can remove the loop if you just want one file, in that case you give the filename instead of the loop # ras = [] # decs = [] for fname in fnames: print('processing ' + fname + '...') fits_file = gwtc1 + '/' + fname skymap, metadata = fits.read_sky_map(fits_file, nest=None) cls = 100 * postprocess.find_greedy_credible_levels(skymap) contour_levels = [50, 90, 99] #this was for Jamie trying to find the 'center' of the contours, ignore it # mx = np.max(skymap) # mean = np.mean(skymap) # std = np.std(skymap) # idx = np.where(skymap == mx) # print(mx, idx) # print('mean: {}'.format(mean)) # print('std: {}'.format(std)) # dec, ra= IndexToDeclRa(idx) # print('ra=',ra, 'dec=',dec)