def submit_all(self, coords=None, queue=None, debug=False): """ Submit likelihood analyses on a set of coordinates. If coords is `None`, submit all coordinates in the footprint. Inputs: coords : Array of target locations in Galactic coordinates. queue : Overwrite submit queue. debug : Don't run. """ if coords is None: pixels = np.arange(hp.nside2npix(self.nside_likelihood)) else: coords = np.asarray(coords) if coords.ndim == 1: coords = np.array([coords]) if coords.shape[1] == 2: lon, lat = coords.T radius = np.zeros(len(lon)) elif coords.shape[1] == 3: lon, lat, radius = coords.T else: raise Exception("Unrecognized coords shape:" + str(coords.shape)) #ADW: targets is still in glon,glat if self.config['coords']['coordsys'].lower() == 'cel': lon, lat = gal2cel(lon, lat) vec = ang2vec(lon, lat) pixels = np.zeros(0, dtype=int) for v, r in zip(vec, radius): pix = query_disc(self.nside_likelihood, v, r, inclusive=True, fact=32) pixels = np.hstack([pixels, pix]) #pixels = np.unique(pixels) inside = ugali.utils.skymap.inFootprint(self.config, pixels) if inside.sum() != len(pixels): logger.warning("Ignoring pixels outside survey footprint:\n" + str(pixels[~inside])) if inside.sum() == 0: logger.warning("No pixels inside footprint.") return # Only write the configfile once outdir = mkdir(self.config['output']['likedir']) # Actually copy config instead of re-writing shutil.copy(self.config.filename, outdir) configfile = join(outdir, os.path.basename(self.config.filename)) pixels = pixels[inside] self.submit(pixels, queue=queue, debug=debug, configfile=configfile)
def _cache(self, name=None): pixel_area = hp.nside2pixarea(self.nside, degrees=True) vec = ang2vec(self.lon, self.lat) #self.pix = query_disc(self.nside,vec,self.extension) self.pix = ang2disc(self.nside, self.lon, self.lat, self.extension, inclusive=True) self._norm = 1. / (len(self.pix) * pixel_area)
def submit_all(self, coords=None, queue=None, debug=False): """ Submit likelihood analyses on a set of coordinates. If coords is `None`, submit all coordinates in the footprint. Inputs: coords : Array of target locations in Galactic coordinates. queue : Overwrite submit queue. debug : Don't run. """ if coords is None: pixels = numpy.arange(healpy.nside2npix(self.nside_likelihood)) else: coords = numpy.asarray(coords) if coords.ndim == 1: coords = numpy.array([coords]) if coords.shape[1] == 2: glon,glat = coords.T radius = numpy.zeros(len(glon)) elif coords.shape[1] == 3: glon,glat,radius = coords.T else: raise Exception("Unrecognized coords shape:"+str(coords.shape)) vec = ang2vec(glon,glat) pixels = numpy.zeros(0, dtype=int) for v,r in zip(vec,radius): pix = query_disc(self.nside_likelihood,v,r,inclusive=True,fact=32) pixels = numpy.hstack([pixels, pix]) #pixels = numpy.unique(pixels) inside = ugali.utils.skymap.inFootprint(self.config,pixels) if inside.sum() != len(pixels): logger.warning("Ignoring pixels outside survey footprint:\n"+str(pixels[~inside])) if inside.sum() == 0: logger.warning("No pixels inside footprint.") return # Only write the configfile once outdir = mkdir(self.config['output']['likedir']) configfile = '%s/config_queue.py'%(outdir) self.config.write(configfile) pixels = pixels[inside] self.submit(pixels,queue=queue,debug=debug,configfile=configfile)
def __init__(self, config, lon, lat): self.config = Config(config) self.lon = lon self.lat = lat self.projector = ugali.utils.projector.Projector(self.lon, self.lat) self.vec = vec = ang2vec(self.lon, self.lat) self.pix = ang2pix(self.config['coords']['nside_likelihood'], self.lon, self.lat) # Pixels from the entire ROI disk pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius']) self.pixels = PixelRegion(self.config['coords']['nside_pixel'], pix) # Pixels in the interior region pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius_interior']) self.pixels_interior = PixelRegion( self.config['coords']['nside_pixel'], pix) # Pixels in the outer annulus pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius_annulus']) pix = np.setdiff1d(self.pixels, pix) self.pixels_annulus = PixelRegion(self.config['coords']['nside_pixel'], pix) # Pixels within target healpix region pix = ugali.utils.skymap.subpixel( self.pix, self.config['coords']['nside_likelihood'], self.config['coords']['nside_pixel']) self.pixels_target = PixelRegion(self.config['coords']['nside_pixel'], pix) # Boolean arrays for selecting given pixels # (Careful, this works because pixels are pre-sorted by query_disc before in1d) self.pixel_interior_cut = np.in1d(self.pixels, self.pixels_interior) self.pixel_annulus_cut = np.in1d(self.pixels, self.pixels_annulus) # Some pixel properties self.area_pixel = hp.nside2pixarea( self.config.params['coords']['nside_pixel'], degrees=True) # deg^2 self.max_pixrad = np.degrees( hp.max_pixrad(self.config['coords']['nside_pixel'])) # deg # ADW: These are really bin edges, should be careful and consistent # It would be cleaner to separate the CMD from ROI self.bins_mag = np.linspace(self.config.params['mag']['min'], self.config.params['mag']['max'], self.config.params['mag']['n_bins'] + 1) self.bins_color = np.linspace( self.config.params['color']['min'], self.config.params['color']['max'], self.config.params['color']['n_bins'] + 1) self.centers_mag = ugali.utils.binning.centers(self.bins_mag) self.centers_color = ugali.utils.binning.centers(self.bins_color) self.delta_mag = self.bins_mag[1] - self.bins_mag[0] self.delta_color = self.bins_color[1] - self.bins_color[0]
def _cache(self, name=None): pixel_area = healpy.nside2pixarea(self.nside,degrees=True) vec = ang2vec(self.lon, self.lat) self.pix = query_disc(self.nside,vec,self.extension) self._norm = 1./(len(self.pix)*pixel_area)
def __init__(self, config, lon, lat): self.config = Config(config) self.lon = lon self.lat = lat self.projector = ugali.utils.projector.Projector(self.lon, self.lat) self.vec = vec = ang2vec(self.lon, self.lat) self.pix = ang2pix(self.config['coords']['nside_likelihood'], self.lon, self.lat) # Pixels from the entire ROI disk pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius']) self.pixels = PixelRegion(self.config['coords']['nside_pixel'], pix) # Pixels in the interior region pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius_interior']) self.pixels_interior = PixelRegion( self.config['coords']['nside_pixel'], pix) # Pixels in the outer annulus pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius_annulus']) pix = numpy.setdiff1d(self.pixels, pix) self.pixels_annulus = PixelRegion(self.config['coords']['nside_pixel'], pix) # Pixels within target healpix region pix = ugali.utils.skymap.subpixel( self.pix, self.config['coords']['nside_likelihood'], self.config['coords']['nside_pixel']) self.pixels_target = PixelRegion(self.config['coords']['nside_pixel'], pix) # Boolean arrays for selecting given pixels # (Careful, this works because pixels are pre-sorted by query_disc before in1d) self.pixel_interior_cut = numpy.in1d(self.pixels, self.pixels_interior) # ADW: Updated for more general ROI shapes #self.pixel_annulus_cut = ~self.pixel_interior_cut self.pixel_annulus_cut = numpy.in1d(self.pixels, self.pixels_annulus) # # These should be unnecessary now # self.centers_lon, self.centers_lat = self.pixels.lon, self.pixels.lat # self.centers_lon_interior,self.centers_lat_interior = self.pixels_interior.lon,self.pixels_interior.lat # self.centers_lon_target, self.centers_lat_target = self.pixels_target.lon, self.pixels_target.lat self.area_pixel = healpy.nside2pixarea( self.config.params['coords']['nside_pixel'], degrees=True) # deg^2 """ self.centers_x = self._centers(self.bins_x) self.centers_y = self._centers(self.bins_y) self.delta_x = self.config.params['coords']['pixel_size'] self.delta_y = self.config.params['coords']['pixel_size'] # Should actually try to take projection effects into account for better accuracy # MC integration perhaps? # Throw points in a cone around full ROI and see what fraction fall in self.area_pixel = self.config.params['coords']['pixel_size']**2 self.centers_lon, self.centers_lat = self.projector.imageToSphere(self.centers_x, self.centers_y) """ # ADW: These are really bin edges, should be careful and consistent self.bins_mag = numpy.linspace(self.config.params['mag']['min'], self.config.params['mag']['max'], self.config.params['mag']['n_bins'] + 1) self.bins_color = numpy.linspace( self.config.params['color']['min'], self.config.params['color']['max'], self.config.params['color']['n_bins'] + 1) self.centers_mag = ugali.utils.binning.centers(self.bins_mag) self.centers_color = ugali.utils.binning.centers(self.bins_color) self.delta_mag = self.bins_mag[1] - self.bins_mag[0] self.delta_color = self.bins_color[1] - self.bins_color[0] # Axis labels self.label_x = 'x (deg)' self.label_y = 'y (deg)' if self.config.params['catalog']['band_1_detection']: self.label_mag = '%s (mag)' % ( self.config.params['catalog']['mag_1_field']) else: self.label_mag = '%s (mag)' % ( self.config.params['catalog']['mag_2_field']) self.label_color = '%s - %s (mag)' % ( self.config.params['catalog']['mag_1_field'], self.config.params['catalog']['mag_2_field'])
def __init__(self, config, lon, lat): self.config = Config(config) self.lon = lon self.lat = lat self.projector = ugali.utils.projector.Projector(self.lon, self.lat) self.vec = vec = ang2vec(self.lon, self.lat) self.pix = ang2pix(self.config['coords']['nside_likelihood'],self.lon,self.lat) # Pixels from the entire ROI disk pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius']) self.pixels = PixelRegion(self.config['coords']['nside_pixel'],pix) # Pixels in the interior region pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius_interior']) self.pixels_interior = PixelRegion(self.config['coords']['nside_pixel'],pix) # Pixels in the outer annulus pix = query_disc(self.config['coords']['nside_pixel'], vec, self.config['coords']['roi_radius_annulus']) pix = numpy.setdiff1d(self.pixels, pix) self.pixels_annulus = PixelRegion(self.config['coords']['nside_pixel'],pix) # Pixels within target healpix region pix = ugali.utils.skymap.subpixel(self.pix,self.config['coords']['nside_likelihood'], self.config['coords']['nside_pixel']) self.pixels_target = PixelRegion(self.config['coords']['nside_pixel'],pix) # Boolean arrays for selecting given pixels # (Careful, this works because pixels are pre-sorted by query_disc before in1d) self.pixel_interior_cut = numpy.in1d(self.pixels, self.pixels_interior) # ADW: Updated for more general ROI shapes #self.pixel_annulus_cut = ~self.pixel_interior_cut self.pixel_annulus_cut = numpy.in1d(self.pixels, self.pixels_annulus) # # These should be unnecessary now # self.centers_lon, self.centers_lat = self.pixels.lon, self.pixels.lat # self.centers_lon_interior,self.centers_lat_interior = self.pixels_interior.lon,self.pixels_interior.lat # self.centers_lon_target, self.centers_lat_target = self.pixels_target.lon, self.pixels_target.lat self.area_pixel = healpy.nside2pixarea(self.config.params['coords']['nside_pixel'],degrees=True) # deg^2 """ self.centers_x = self._centers(self.bins_x) self.centers_y = self._centers(self.bins_y) self.delta_x = self.config.params['coords']['pixel_size'] self.delta_y = self.config.params['coords']['pixel_size'] # Should actually try to take projection effects into account for better accuracy # MC integration perhaps? # Throw points in a cone around full ROI and see what fraction fall in self.area_pixel = self.config.params['coords']['pixel_size']**2 self.centers_lon, self.centers_lat = self.projector.imageToSphere(self.centers_x, self.centers_y) """ # ADW: These are really bin edges, should be careful and consistent self.bins_mag = numpy.linspace(self.config.params['mag']['min'], self.config.params['mag']['max'], self.config.params['mag']['n_bins'] + 1) self.bins_color = numpy.linspace(self.config.params['color']['min'], self.config.params['color']['max'], self.config.params['color']['n_bins'] + 1) self.centers_mag = ugali.utils.binning.centers(self.bins_mag) self.centers_color = ugali.utils.binning.centers(self.bins_color) self.delta_mag = self.bins_mag[1] - self.bins_mag[0] self.delta_color = self.bins_color[1] - self.bins_color[0] # Axis labels self.label_x = 'x (deg)' self.label_y = 'y (deg)' if self.config.params['catalog']['band_1_detection']: self.label_mag = '%s (mag)'%(self.config.params['catalog']['mag_1_field']) else: self.label_mag = '%s (mag)'%(self.config.params['catalog']['mag_2_field']) self.label_color = '%s - %s (mag)'%(self.config.params['catalog']['mag_1_field'], self.config.params['catalog']['mag_2_field'])