Exemple #1
0
def pixelizeDensity(config, nside=None, force=False):
    if nside is None: 
        nside = config['coords']['nside_likelihood']
    coordsys = config['coords']['coordsys'].upper()
    filenames = config.getFilenames()
    infiles = filenames[~filenames['catalog'].mask]
    lon_field = config['catalog']['lon_field'].upper()
    lat_field = config['catalog']['lat_field'].upper()

    for ii,f in enumerate(infiles.data):
        infile = f['catalog']
        pix = f['pix']
        logger.info('(%i/%i) %s'%(ii+1, len(infiles), infile))

        outfile = config['data']['density']%pix
        if os.path.exists(outfile) and not force: 
            logger.info("Found %s; skipping..."%outfile)
            continue
            
        outdir = mkdir(os.path.dirname(outfile))
        pixels, density = stellarDensity(infile,nside,
                                         lon_field=lon_field,lat_field=lat_field)

        data = dict(PIXEL=pixels,DENSITY=density)
        healpix.write_partial_map(outfile,data,nside=nside,coord=coordsys[0])
Exemple #2
0
def pixelizeDensity(config, nside=None, force=False):
    if nside is None:
        nside = config['coords']['nside_likelihood']
    coordsys = config['coords']['coordsys'].upper()
    filenames = config.getFilenames()
    infiles = filenames[~filenames['catalog'].mask]
    lon_field = config['catalog']['lon_field'].upper()
    lat_field = config['catalog']['lat_field'].upper()

    for ii, f in enumerate(infiles.data):
        infile = f['catalog']
        pix = f['pix']
        logger.info('(%i/%i) %s' % (ii + 1, len(infiles), infile))

        outfile = config['data']['density'] % pix
        if os.path.exists(outfile) and not force:
            logger.info("Found %s; skipping..." % outfile)
            continue

        outdir = mkdir(os.path.dirname(outfile))
        pixels, density = stellarDensity(infile,
                                         nside,
                                         lon_field=lon_field,
                                         lat_field=lat_field)

        data = dict(PIXEL=pixels, DENSITY=density)
        healpix.write_partial_map(outfile,
                                  data,
                                  nside=nside,
                                  coord=coordsys[0])
Exemple #3
0
    def write(self, outfile):
        """
        Save the likelihood results as a sparse HEALPix map.
        """
        data = odict()
        data['PIXEL'] = self.roi.pixels_target
        # Full data output (too large for survey)
        if self.config['scan']['full_pdf']:
            data['LOG_LIKELIHOOD'] = self.log_likelihood_sparse_array.T
            data['RICHNESS'] = self.richness_sparse_array.T
            data['RICHNESS_LOWER'] = self.richness_lower_sparse_array.T
            data['RICHNESS_UPPER'] = self.richness_upper_sparse_array.T
            data['RICHNESS_LIMIT'] = self.richness_upper_limit_sparse_array.T
            #data['STELLAR_MASS']=self.stellar_mass_sparse_array.T
            data[
                'FRACTION_OBSERVABLE'] = self.fraction_observable_sparse_array.T
        else:
            data['LOG_LIKELIHOOD'] = self.log_likelihood_sparse_array.T
            data['RICHNESS'] = self.richness_sparse_array.T
            data[
                'FRACTION_OBSERVABLE'] = self.fraction_observable_sparse_array.T

        # Convert to 32bit float
        for k in data.keys()[1:]:
            data[k] = data[k].astype('f4', copy=False)

        # Stellar mass can be calculated from STELLAR * RICHNESS
        header = odict()
        header['STELLAR'] = round(self.stellar_mass_conversion, 8)
        header['LKDNSIDE'] = self.config['coords']['nside_likelihood']
        header['LKDPIX'] = ang2pix(self.config['coords']['nside_likelihood'],
                                   self.roi.lon, self.roi.lat)
        header['NROI'] = self.roi.inROI(self.loglike.catalog_roi.lon,
                                        self.loglike.catalog_roi.lat).sum()
        header['NANNULUS'] = self.roi.inAnnulus(
            self.loglike.catalog_roi.lon, self.loglike.catalog_roi.lat).sum()
        header['NINSIDE'] = self.roi.inInterior(
            self.loglike.catalog_roi.lon, self.loglike.catalog_roi.lat).sum()
        header['NTARGET'] = self.roi.inTarget(
            self.loglike.catalog_roi.lon, self.loglike.catalog_roi.lat).sum()

        # Flatten if there is only a single distance modulus
        # ADW: Is this really what we want to do?
        if len(self.distance_modulus_array) == 1:
            for key in data:
                data[key] = data[key].flatten()

        logger.info("Writing %s..." % outfile)
        write_partial_map(outfile,
                          data,
                          nside=self.config['coords']['nside_pixel'],
                          header=header,
                          clobber=True)

        fitsio.write(outfile,
                     dict(DISTANCE_MODULUS=self.distance_modulus_array.astype(
                         'f4', copy=False)),
                     extname='DISTANCE_MODULUS',
                     clobber=False)
Exemple #4
0
    def write(self, outfile):
        """
        Save the likelihood results as a sparse HEALPix map.
        """
        data = odict()
        data['PIXEL']=self.roi.pixels_target
        # Full data output (too large for survey)
        if self.config['scan']['full_pdf']:
            data['LOG_LIKELIHOOD']=self.log_likelihood_sparse_array.T
            data['RICHNESS']=self.richness_sparse_array.T
            data['RICHNESS_LOWER']=self.richness_lower_sparse_array.T
            data['RICHNESS_UPPER']=self.richness_upper_sparse_array.T
            data['RICHNESS_LIMIT']=self.richness_upper_limit_sparse_array.T
            #data['STELLAR_MASS']=self.stellar_mass_sparse_array.T
            data['FRACTION_OBSERVABLE']=self.fraction_observable_sparse_array.T
        else:
            data['LOG_LIKELIHOOD']=self.log_likelihood_sparse_array.T
            data['RICHNESS']=self.richness_sparse_array.T
            data['FRACTION_OBSERVABLE']=self.fraction_observable_sparse_array.T

        # Convert to 32bit float
        for k in list(data.keys())[1:]:
            data[k] = data[k].astype('f4',copy=False)
            
        # Stellar mass can be calculated from STELLAR * RICHNESS
        header = odict()
        header['STELLAR']=round(self.stellar_mass_conversion,8)
        header['LKDNSIDE']=self.config['coords']['nside_likelihood']
        header['LKDPIX']=ang2pix(self.config['coords']['nside_likelihood'],
                                 self.roi.lon,self.roi.lat)
        header['NROI']=self.roi.inROI(self.loglike.catalog_roi.lon,
                                      self.loglike.catalog_roi.lat).sum()
        header['NANNULUS']=self.roi.inAnnulus(self.loglike.catalog_roi.lon,
                                              self.loglike.catalog_roi.lat).sum()
        header['NINSIDE']=self.roi.inInterior(self.loglike.catalog_roi.lon,
                                              self.loglike.catalog_roi.lat).sum()
        header['NTARGET']=self.roi.inTarget(self.loglike.catalog_roi.lon,
                                            self.loglike.catalog_roi.lat).sum()

        # Flatten if there is only a single distance modulus
        # ADW: Is this really what we want to do?
        if len(self.distance_modulus_array) == 1:
            for key in data:
                data[key] = data[key].flatten()

        logger.info("Writing %s..."%outfile)
        write_partial_map(outfile,data,
                          nside=self.config['coords']['nside_pixel'],
                          header=header,
                          clobber=True
                          )
        
        fitsio.write(outfile,
                     dict(DISTANCE_MODULUS=self.distance_modulus_array.astype('f4',copy=False)),
                     extname='DISTANCE_MODULUS',
                     clobber=False)
Exemple #5
0
    def writeLabels(self,filename=None):
        if filename is None: filename = self.labelfile

        # ADW: Is it necessary to convert labels?
        data_dict = {'PIXEL':self.pixels,
                     'LABEL':self.labels.astype(float,copy=False)}

        logger.info("Writing %s..."%filename)
        healpix.write_partial_map(filename,data_dict,self.nside)
        fitsio.write(filename,
                     {'DISTANCE_MODULUS':self.distances.astype('f4',copy=False)},
                     extname='DISTANCE_MODULUS',
                     clobber=False)
Exemple #6
0
    def writeLabels(self, filename=None):
        if filename is None: filename = self.labelfile

        # ADW: Is it necessary to convert labels?
        data_dict = {
            'PIXEL': self.pixels,
            'LABEL': self.labels.astype(float, copy=False)
        }

        logger.info("Writing %s..." % filename)
        healpix.write_partial_map(filename, data_dict, self.nside)
        fitsio.write(
            filename,
            {'DISTANCE_MODULUS': self.distances.astype('f4', copy=False)},
            extname='DISTANCE_MODULUS',
            clobber=False)
Exemple #7
0
    def writeLabels(self, filename=None):
        """Write the labeled array to a file.
        
        Parameters
        ----------
        filename : output filename (default: labelfile)

        Returns
        -------
        None
        """
        if filename is None: filename = self.labelfile

        data_dict = {'PIXEL': self.pixels, 'LABEL': self.labels}

        healpix.write_partial_map(filename, data_dict, self.nside)
        fitsio.write(
            filename,
            {'DISTANCE_MODULUS': self.distances.astype('f4', copy=False)},
            extname='DISTANCE_MODULUS',
            clobber=False)