Пример #1
0
    def detectability(self,**kwargs):
        """
        An a priori detectability proxy.
        """
        distance_modulus = kwargs.get('distance_modulus')
        distance = mod2dist(distance_modulus)
        stellar_mass = kwargs.get('stellar_mass')
        extension = kwargs.get('extension')

        # Normalized to 10^3 Msolar at mod=18
        norm = 10**3/mod2dist(18)**2
        detect = stellar_mass / distance**2
        detect /= norm
Пример #2
0
    def finalizeObjects(self, objects):
        objs = numpy.recarray(len(objects),
                              dtype=[('NAME','S24'),
                                     ('TS','f4'),
                                     ('GLON','f4'),
                                     ('GLAT','f4'),
                                     ('RA','f4'),
                                     ('DEC','f4'),
                                     ('MODULUS','f4'),
                                     ('DISTANCE','f4'),
                                     ('RICHNESS','f4'),
                                     ('MASS','f4'),
                                     ('NANNULUS','i4'),
                                     ('NINTERIOR','i4'),
                                     ])
        
        objs['TS'] = self.values[objects['IDX_MAX'],objects['ZIDX_MAX']]
        lon,lat = objects['X_MAX'],objects['Y_MAX']

        coordsys = self.config['coords']['coordsys']
        if coordsys.lower() == 'gal':
            print("GAL coordintes")
            objs['GLON'],objs['GLAT'] = lon,lat
            objs['RA'],objs['DEC'] = gal2cel(lon,lat)
        else:
            print("CEL coordintes")
            objs['RA'],objs['DEC'] = lon,lat
            objs['GLON'],objs['GLAT'] = cel2gal(lon,lat)

        modulus = objects['Z_MAX']
        objs['MODULUS'] = modulus
        objs['DISTANCE'] = mod2dist(modulus)

        nside = healpy.npix2nside(len(self.nannulus))
        pix = ang2pix(nside,lon,lat)

        richness = self.richness[objects['IDX_MAX'],objects['ZIDX_MAX']]
        objs['RICHNESS'] = richness
        objs['MASS'] = richness * self.stellar[pix]

        objs['NANNULUS']  = self.nannulus[pix].astype(int)
        objs['NINTERIOR'] = self.ninterior[pix].astype(int)

        # Default name formatting
        # http://cdsarc.u-strasbg.fr/ftp/pub/iau/
        # http://cds.u-strasbg.fr/vizier/Dic/iau-spec.htx
        fmt = "J%(hour)02i%(hmin)04.1f%(deg)+03i%(dmin)02i"
        for obj,_ra,_dec in zip(objs,objs['RA'],objs['DEC']):
            hms = dec2hms(_ra); dms = dec2dms(_dec)
            params = dict(hour=hms[0],hmin=hms[1]+hms[2]/60.,
                          deg=dms[0],dmin=dms[1]+dms[2]/60.)
            obj['NAME'] = fmt%params

        out = recfuncs.merge_arrays([objs,objects],usemask=False,
                                    asrecarray=True,flatten=True)

        return out
Пример #3
0
    def finalizeObjects(self, objects):
        objs = numpy.recarray(len(objects),
                              dtype=[('NAME','S24'),
                                     ('TS','f4'),
                                     ('GLON','f4'),
                                     ('GLAT','f4'),
                                     ('RA','f4'),
                                     ('DEC','f4'),
                                     ('MODULUS','f4'),
                                     ('DISTANCE','f4'),
                                     ('RICHNESS','f4'),
                                     ('MASS','f4'),
                                     ('NANNULUS','i4'),
                                     ('NINTERIOR','i4'),
                                     ])
        
        objs['TS'] = self.values[objects['IDX_MAX'],objects['ZIDX_MAX']]

        glon,glat = objects['X_MAX'],objects['Y_MAX']
        objs['GLON'],objs['GLAT'] = glon,glat
        
        ra,dec    = gal2cel(glon,glat)
        objs['RA'],objs['DEC'] = ra,dec

        modulus = objects['Z_MAX']
        objs['MODULUS'] = modulus
        objs['DISTANCE'] = mod2dist(modulus)

        #ninterior = ugali.utils.skymap.readSparseHealpixMap(self.roifile,'NINSIDE')
        #nannulus = ugali.utils.skymap.readSparseHealpixMap(self.roifile,'NANNULUS')
        #stellar = ugali.utils.skymap.readSparseHealpixMap(self.roifile,'STELLAR')

        nside = healpy.npix2nside(len(self.nannulus))
        pix = ang2pix(nside,glon,glat)

        richness = self.richness[objects['IDX_MAX'],objects['ZIDX_MAX']]
        objs['RICHNESS'] = richness
        objs['MASS'] = richness * self.stellar[pix]

        objs['NANNULUS']  = self.nannulus[pix].astype(int)
        objs['NINTERIOR'] = self.ninterior[pix].astype(int)

        # Default name formatting
        # http://cdsarc.u-strasbg.fr/ftp/pub/iau/
        # http://cds.u-strasbg.fr/vizier/Dic/iau-spec.htx
        fmt = "J%(hour)02i%(hmin)04.1f%(deg)+03i%(dmin)02i"
        for obj,_ra,_dec in zip(objs,ra,dec):
            hms = dec2hms(_ra); dms = dec2dms(_dec)
            params = dict(hour=hms[0],hmin=hms[1]+hms[2]/60.,
                          deg=dms[0],dmin=dms[1]+dms[2]/60.)
            obj['NAME'] = fmt%params

        out = recfuncs.merge_arrays([objs,objects],usemask=False,asrecarray=True,flatten=True)
        # This is safer than viewing as FITS_rec
        return pyfits.new_table(out).data
Пример #4
0
    def finalizeObjects(self, objects):
        objs = np.recarray(len(objects),
                           dtype=[
                               ('NAME', 'S24'),
                               ('TS', 'f4'),
                               ('GLON', 'f4'),
                               ('GLAT', 'f4'),
                               ('RA', 'f4'),
                               ('DEC', 'f4'),
                               ('MODULUS', 'f4'),
                               ('DISTANCE', 'f4'),
                               ('RICHNESS', 'f4'),
                               ('MASS', 'f4'),
                               ('NANNULUS', 'i4'),
                               ('NINTERIOR', 'i4'),
                           ])

        objs['TS'] = self.values[objects['IDX_MAX'], objects['ZIDX_MAX']]
        lon, lat = objects['X_MAX'], objects['Y_MAX']

        coordsys = self.config['coords']['coordsys']
        if coordsys.lower() == 'gal':
            print("GAL coordintes")
            objs['GLON'], objs['GLAT'] = lon, lat
            objs['RA'], objs['DEC'] = gal2cel(lon, lat)
        else:
            print("CEL coordintes")
            objs['RA'], objs['DEC'] = lon, lat
            objs['GLON'], objs['GLAT'] = cel2gal(lon, lat)

        modulus = objects['Z_MAX']
        objs['MODULUS'] = modulus
        objs['DISTANCE'] = mod2dist(modulus)

        nside = healpy.npix2nside(len(self.nannulus))
        pix = ang2pix(nside, lon, lat)

        richness = self.richness[objects['IDX_MAX'], objects['ZIDX_MAX']]
        objs['RICHNESS'] = richness
        objs['MASS'] = richness * self.stellar[pix]

        objs['NANNULUS'] = self.nannulus[pix].astype(int)
        objs['NINTERIOR'] = self.ninterior[pix].astype(int)
        objs['NAME'] = ang2iau(objs['RA'], objs['DEC'], coord='cel')

        out = recfuncs.merge_arrays([objs, objects],
                                    usemask=False,
                                    asrecarray=True,
                                    flatten=True)

        return out
Пример #5
0
    def finalizeObjects(self, objects):
        objs = numpy.recarray(len(objects),
                              dtype=[
                                  ('NAME', 'S24'),
                                  ('TS', 'f4'),
                                  ('GLON', 'f4'),
                                  ('GLAT', 'f4'),
                                  ('RA', 'f4'),
                                  ('DEC', 'f4'),
                                  ('MODULUS', 'f4'),
                                  ('DISTANCE', 'f4'),
                                  ('RICHNESS', 'f4'),
                                  ('MASS', 'f4'),
                                  ('NANNULUS', 'i4'),
                                  ('NINTERIOR', 'i4'),
                              ])

        objs['TS'] = self.values[objects['IDX_MAX'], objects['ZIDX_MAX']]
        lon, lat = objects['X_MAX'], objects['Y_MAX']

        coordsys = self.config['coords']['coordsys']
        if coordsys.lower() == 'gal':
            print("GAL coordintes")
            objs['GLON'], objs['GLAT'] = lon, lat
            objs['RA'], objs['DEC'] = gal2cel(lon, lat)
        else:
            print("CEL coordintes")
            objs['RA'], objs['DEC'] = lon, lat
            objs['GLON'], objs['GLAT'] = cel2gal(lon, lat)

        modulus = objects['Z_MAX']
        objs['MODULUS'] = modulus
        objs['DISTANCE'] = mod2dist(modulus)

        nside = healpy.npix2nside(len(self.nannulus))
        pix = ang2pix(nside, lon, lat)

        richness = self.richness[objects['IDX_MAX'], objects['ZIDX_MAX']]
        objs['RICHNESS'] = richness
        objs['MASS'] = richness * self.stellar[pix]

        objs['NANNULUS'] = self.nannulus[pix].astype(int)
        objs['NINTERIOR'] = self.ninterior[pix].astype(int)

        # Default name formatting
        # http://cdsarc.u-strasbg.fr/ftp/pub/iau/
        # http://cds.u-strasbg.fr/vizier/Dic/iau-spec.htx
        fmt = "J%(hour)02i%(hmin)04.1f%(deg)+03i%(dmin)02i"
        for obj, _ra, _dec in zip(objs, objs['RA'], objs['DEC']):
            hms = dec2hms(_ra)
            dms = dec2dms(_dec)
            params = dict(hour=hms[0],
                          hmin=hms[1] + hms[2] / 60.,
                          deg=dms[0],
                          dmin=dms[1] + dms[2] / 60.)
            obj['NAME'] = fmt % params

        out = recfuncs.merge_arrays([objs, objects],
                                    usemask=False,
                                    asrecarray=True,
                                    flatten=True)

        return out
Пример #6
0
    def finalizeObjects(self, objects):
        objs = numpy.recarray(len(objects),
                              dtype=[
                                  ('NAME', 'S24'),
                                  ('TS', 'f4'),
                                  ('GLON', 'f4'),
                                  ('GLAT', 'f4'),
                                  ('RA', 'f4'),
                                  ('DEC', 'f4'),
                                  ('MODULUS', 'f4'),
                                  ('DISTANCE', 'f4'),
                                  ('RICHNESS', 'f4'),
                                  ('MASS', 'f4'),
                                  ('NANNULUS', 'i4'),
                                  ('NINTERIOR', 'i4'),
                              ])

        objs['TS'] = self.values[objects['IDX_MAX'], objects['ZIDX_MAX']]

        glon, glat = objects['X_MAX'], objects['Y_MAX']
        objs['GLON'], objs['GLAT'] = glon, glat

        ra, dec = gal2cel(glon, glat)
        objs['RA'], objs['DEC'] = ra, dec

        modulus = objects['Z_MAX']
        objs['MODULUS'] = modulus
        objs['DISTANCE'] = mod2dist(modulus)

        #ninterior = ugali.utils.skymap.readSparseHealpixMap(self.roifile,'NINSIDE')
        #nannulus = ugali.utils.skymap.readSparseHealpixMap(self.roifile,'NANNULUS')
        #stellar = ugali.utils.skymap.readSparseHealpixMap(self.roifile,'STELLAR')

        nside = healpy.npix2nside(len(self.nannulus))
        pix = ang2pix(nside, glon, glat)

        richness = self.richness[objects['IDX_MAX'], objects['ZIDX_MAX']]
        objs['RICHNESS'] = richness
        objs['MASS'] = richness * self.stellar[pix]

        objs['NANNULUS'] = self.nannulus[pix].astype(int)
        objs['NINTERIOR'] = self.ninterior[pix].astype(int)

        # Default name formatting
        # http://cdsarc.u-strasbg.fr/ftp/pub/iau/
        # http://cds.u-strasbg.fr/vizier/Dic/iau-spec.htx
        fmt = "J%(hour)02i%(hmin)04.1f%(deg)+03i%(dmin)02i"
        for obj, _ra, _dec in zip(objs, ra, dec):
            hms = dec2hms(_ra)
            dms = dec2dms(_dec)
            params = dict(hour=hms[0],
                          hmin=hms[1] + hms[2] / 60.,
                          deg=dms[0],
                          dmin=dms[1] + dms[2] / 60.)
            obj['NAME'] = fmt % params

        out = recfuncs.merge_arrays([objs, objects],
                                    usemask=False,
                                    asrecarray=True,
                                    flatten=True)
        # This is safer than viewing as FITS_rec
        return pyfits.new_table(out).data
Пример #7
0
 def distance(self):
     """ Convert to physical distance (kpc) """
     return mod2dist(self.distance_modulus)
Пример #8
0
    def get_results(self, **kwargs):
        kwargs.setdefault('alpha', self.alpha)
        kwargs.setdefault('burn', self.nburn * self.nwalkers)

        # Calculate best-fit parameters from MCMC chain
        logger.debug('Estimating parameters...')
        estimate = self.estimate_params(**kwargs)
        params = {k: v[0] for k, v in estimate.items()}
        results = dict(estimate)

        # Extra parameters from the MCMC chain
        logger.debug('Estimating auxiliary parameters...')
        try:
            results['ra'] = self.estimate('ra', **kwargs)
            results['dec'] = self.estimate('dec', **kwargs)
        except KeyError:
            logger.warn("Didn't find 'ra' or 'dec'")
            ra, dec = gal2cel(results['lon'][0], results['lat'][0])
            results['ra'] = ugali.utils.stats.interval(ra)
            results['dec'] = ugali.utils.stats.interval(dec)

        ra, dec = results['ra'][0], results['dec'][0]
        glon, glat = lon, lat = results['lon'][0], results['lat'][0]
        results.update(gal=[float(glon), float(glat)])
        results.update(cel=[float(ra), float(dec)])

        try:
            results['position_angle_cel'] = self.estimate(
                'position_angle_cel', **kwargs)
        except KeyError:
            results['position_angle_cel'] = ugali.utils.stats.interval(np.nan)

        # Update the loglike to the best-fit parameters from the chain
        logger.debug('Calculating TS...')
        ts = 2 * self.loglike.value(**params)
        results['ts'] = ugali.utils.stats.interval(ts, np.nan, np.nan)

        #lon,lat = estimate['lon'][0],estimate['lat'][0]
        #
        #results.update(gal=[float(lon),float(lat)])
        #ra,dec = gal2cel(lon,lat)
        #results.update(cel=[float(ra),float(dec)])
        #results['ra'] = ugali.utils.stats.interval(ra,np.nan,np.nan)
        #results['dec'] = ugali.utils.stats.interval(dec,np.nan,np.nan)

        # Celestial position angle
        # Break ambiguity in direction with '% 180.'
        pa, pa_err = results['position_angle']
        pa_cel = gal2cel_angle(lon, lat, pa) % 180.
        pa_cel_err = np.array(pa_err) - pa + pa_cel
        results['position_angle_cel'] = ugali.utils.stats.interval(
            pa_cel, pa_cel_err[0], pa_cel_err[1])

        mod, mod_err = estimate['distance_modulus']
        dist = mod2dist(mod)
        dist_lo, dist_hi = [mod2dist(mod_err[0]), mod2dist(mod_err[1])]
        results['distance'] = ugali.utils.stats.interval(
            dist, dist_lo, dist_hi)
        dist, dist_err = results['distance']

        ext, ext_err = estimate['extension']
        ext_sigma = np.nan_to_num(np.array(ext_err) - ext)
        results['extension_arcmin'] = ugali.utils.stats.interval(
            60 * ext, 60 * ext_err[0], 60 * ext_err[1])

        # Radially symmetric extension (correct for ellipticity).
        ell, ell_err = estimate['ellipticity']
        rext, rext_err = ext * np.sqrt(1 -
                                       ell), np.array(ext_err) * np.sqrt(1 -
                                                                         ell)
        rext_sigma = np.nan_to_num(np.array(rext_err) - rext)
        results['extension_radial'] = ugali.utils.stats.interval(
            rext, rext_err[0], rext_err[1])
        results['extension_radial_arcmin'] = ugali.utils.stats.interval(
            60 * rext, 60 * rext_err[0], 60 * rext_err[1])

        # Bayes factor for ellipticity
        results['ellipticity_bayes_factor'] = self.bayes_factor(
            'ellipticity', burn=kwargs['burn'])

        # Physical Size (should do this with the posteriors)
        # Radially symmetric
        dist_sigma = np.nan_to_num(np.array(dist_err) - dist)

        size = np.arctan(np.radians(ext)) * dist
        size_sigma = size * np.sqrt((ext_sigma / ext)**2 +
                                    (dist_sigma / dist)**2)
        size_err = [size - size_sigma[0], size + size_sigma[1]]
        results['physical_size'] = ugali.utils.stats.interval(
            size, size_err[0], size_err[1])

        rsize = np.arctan(np.radians(rext)) * dist
        rsize_sigma = rsize * np.sqrt((rext_sigma / rext)**2 +
                                      (dist_sigma / dist)**2)
        rsize_err = [rsize - rsize_sigma[0], rsize + rsize_sigma[1]]
        results['physical_size_radial'] = ugali.utils.stats.interval(
            rsize, rsize_err[0], rsize_err[1])

        # Richness
        rich, rich_err = estimate['richness']

        # Number of observed stars (sum of p-values)
        nobs = self.loglike.p.sum()
        nobs_lo, nobs_hi = nobs + np.sqrt(nobs) * np.array([-1, 1])
        results['nobs'] = ugali.utils.stats.interval(nobs, nobs_lo, nobs_hi)

        # Number of predicted stars (pixelization effects?)
        npred = self.loglike.f * rich
        npred_lo, npred_hi = rich_err[0] * self.loglike.f, rich_err[
            1] * self.loglike.f
        results['npred'] = ugali.utils.stats.interval(npred, npred_lo,
                                                      npred_hi)

        # Careful, depends on the isochrone...
        stellar_mass = self.source.stellar_mass()
        mass = rich * stellar_mass
        mass_lo, mass_hi = rich_err[0] * stellar_mass, rich_err[
            1] * stellar_mass
        results['mass'] = ugali.utils.stats.interval(mass, mass_lo, mass_hi)

        stellar_luminosity = self.source.stellar_luminosity()
        lum = rich * stellar_luminosity
        lum_lo, lum_hi = rich_err[0] * stellar_luminosity, rich_err[
            1] * stellar_luminosity
        results['luminosity'] = ugali.utils.stats.interval(lum, lum_lo, lum_hi)

        Mv = self.source.absolute_magnitude(rich)
        Mv_lo = self.source.absolute_magnitude(rich_err[0])
        Mv_hi = self.source.absolute_magnitude(rich_err[1])
        results['Mv'] = ugali.utils.stats.interval(Mv, Mv_lo, Mv_hi)

        # ADW: WARNING this is very fragile.
        # Also, this is not quite right, should cut on the CMD available space
        kwargs = dict(richness=rich,
                      mag_bright=16.,
                      mag_faint=23.,
                      n_trials=5000,
                      alpha=self.alpha,
                      seed=0)
        martin = self.config['results'].get('martin')
        if martin:
            logger.info("Calculating Martin magnitude...")
            if martin > 1: kwargs['n_trials'] = martin
            Mv_martin = self.source.isochrone.absolute_magnitude_martin(
                **kwargs)
            results['Mv_martin'] = Mv_martin
        else:
            logger.warning("Skipping Martin magnitude")
            results['Mv_martin'] = np.nan

        mu = surfaceBrightness(Mv, size, dist)
        results['surface_brightness'] = ugali.utils.stats.interval(
            mu, np.nan, np.nan)

        try:
            results['constellation'] = ugali.utils.projector.ang2const(
                lon, lat)[1]
        except:
            pass
        results['iau'] = ugali.utils.projector.ang2iau(lon, lat)

        coord = SkyCoord(ra * u.deg, dec * u.deg, distance=dist * u.kpc)
        results['ra_sex'] = str(coord.ra.to_string())
        results['dec_sex'] = str(coord.dec.to_string())

        # Calculate some separations from GC, LMC, SMC
        #NED coordinates with de Grisj distance
        LMC = SkyCoord(80.8939 * u.deg,
                       -69.7561 * u.deg,
                       distance=49.89 * u.kpc)
        #NED coordinates with de Grisj distance
        SMC = SkyCoord(13.1866 * u.deg,
                       -72.8286 * u.deg,
                       distance=61.94 * u.kpc)
        # GC from astropy?
        GC = SkyCoord(266.4168262 * u.deg,
                      -29.0077969 * u.deg,
                      distance=8.0 * u.kpc)

        results['d_gc'] = coord.separation_3d(GC).value
        results['d_lmc'] = coord.separation_3d(LMC).value
        results['d_smc'] = coord.separation_3d(SMC).value

        try:
            results['feh'] = float(self.source.isochrone.feh)
        except:
            results['feh'] = np.nan

        output = dict()
        output['params'] = params
        output['results'] = results
        return output
Пример #9
0
    def get_results(self,**kwargs):
        kwargs.setdefault('alpha',self.alpha)
        kwargs.setdefault('burn',self.nburn*self.nwalkers)

        # Calculate best-fit parameters from MCMC chain
        logger.debug('Estimating parameters...')
        estimate = self.estimate_params(**kwargs)
        params = {k:v[0] for k,v in estimate.items()}
        results = dict(estimate)

        # Extra parameters from the MCMC chain
        logger.debug('Estimating auxiliary parameters...')
        try: 
            results['ra']  = self.estimate('ra',**kwargs)
            results['dec'] = self.estimate('dec',**kwargs)
        except KeyError:
            logger.warn("Didn't find 'ra' or 'dec'")
            ra,dec = gal2cel(results['lon'][0],results['lat'][0])
            results['ra'] = ugali.utils.stats.interval(ra)
            results['dec'] = ugali.utils.stats.interval(dec)

        ra,dec = results['ra'][0],results['dec'][0]
        glon,glat = lon,lat = results['lon'][0],results['lat'][0]
        results.update(gal=[float(glon),float(glat)])
        results.update(cel=[float(ra),float(dec)])

        try:
            results['position_angle_cel']  = self.estimate('position_angle_cel',**kwargs)
        except KeyError:
            results['position_angle_cel'] = ugali.utils.stats.interval(np.nan)

        # Update the loglike to the best-fit parameters from the chain
        logger.debug('Calculating TS...')
        ts = 2*self.loglike.value(**params)
        results['ts'] = ugali.utils.stats.interval(ts,np.nan,np.nan)
 
        #lon,lat = estimate['lon'][0],estimate['lat'][0]
        # 
        #results.update(gal=[float(lon),float(lat)])
        #ra,dec = gal2cel(lon,lat)
        #results.update(cel=[float(ra),float(dec)])
        #results['ra'] = ugali.utils.stats.interval(ra,np.nan,np.nan)
        #results['dec'] = ugali.utils.stats.interval(dec,np.nan,np.nan)
 
        # Celestial position angle
        # Break ambiguity in direction with '% 180.'
        pa,pa_err = results['position_angle']
        pa_cel = gal2cel_angle(lon,lat,pa) % 180.
        pa_cel_err = np.array(pa_err) - pa + pa_cel
        results['position_angle_cel'] = ugali.utils.stats.interval(pa_cel,pa_cel_err[0],pa_cel_err[1])
        
        mod,mod_err = estimate['distance_modulus']
        dist = mod2dist(mod)
        dist_lo,dist_hi = [mod2dist(mod_err[0]),mod2dist(mod_err[1])]
        results['distance'] = ugali.utils.stats.interval(dist,dist_lo,dist_hi)
        dist,dist_err = results['distance']
 
        ext,ext_err = estimate['extension']
        ext_sigma = np.nan_to_num(np.array(ext_err) - ext)
        results['extension_arcmin'] = ugali.utils.stats.interval(60*ext,60*ext_err[0],60*ext_err[1])
 
        # Radially symmetric extension (correct for ellipticity).
        ell,ell_err = estimate['ellipticity']
        rext,rext_err = ext*np.sqrt(1-ell),np.array(ext_err)*np.sqrt(1-ell)
        rext_sigma = np.nan_to_num(np.array(rext_err) - rext)
        results['extension_radial'] = ugali.utils.stats.interval(rext,rext_err[0],rext_err[1])
        results['extension_radial_arcmin'] = ugali.utils.stats.interval(60*rext,60*rext_err[0],60*rext_err[1])
 
        # Bayes factor for ellipticity
        results['ellipticity_bayes_factor'] = self.bayes_factor('ellipticity',burn=kwargs['burn'])
 
        # Physical Size (should do this with the posteriors)
        # Radially symmetric
        dist_sigma = np.nan_to_num(np.array(dist_err) - dist)

        size = np.arctan(np.radians(ext)) * dist
        size_sigma = size * np.sqrt((ext_sigma/ext)**2 + (dist_sigma/dist)**2)
        size_err = [size-size_sigma[0],size+size_sigma[1]]
        results['physical_size'] = ugali.utils.stats.interval(size,size_err[0],size_err[1])

        rsize = np.arctan(np.radians(rext)) * dist
        rsize_sigma = rsize * np.sqrt((rext_sigma/rext)**2 + (dist_sigma/dist)**2)
        rsize_err = [rsize-rsize_sigma[0],rsize+rsize_sigma[1]]
        results['physical_size_radial'] = ugali.utils.stats.interval(rsize,rsize_err[0],rsize_err[1])
 
        # Richness
        rich,rich_err = estimate['richness']
 
        # Number of observed stars (sum of p-values)
        nobs = self.loglike.p.sum()
        nobs_lo,nobs_hi = nobs + np.sqrt(nobs)*np.array([-1,1])
        results['nobs'] = ugali.utils.stats.interval(nobs,nobs_lo,nobs_hi)
 
        # Number of predicted stars (pixelization effects?)
        npred = self.loglike.f*rich
        npred_lo,npred_hi = rich_err[0]*self.loglike.f,rich_err[1]*self.loglike.f
        results['npred'] = ugali.utils.stats.interval(npred,npred_lo,npred_hi)
        
        # Careful, depends on the isochrone...
        stellar_mass = self.source.stellar_mass()
        mass = rich*stellar_mass
        mass_lo,mass_hi = rich_err[0]*stellar_mass,rich_err[1]*stellar_mass
        results['mass'] = ugali.utils.stats.interval(mass,mass_lo,mass_hi)
 
        stellar_luminosity = self.source.stellar_luminosity()
        lum = rich*stellar_luminosity
        lum_lo,lum_hi = rich_err[0]*stellar_luminosity,rich_err[1]*stellar_luminosity
        results['luminosity'] = ugali.utils.stats.interval(lum,lum_lo,lum_hi)

        # Absolute magnitude only calculated for DES isochrones with g,r 
        try:
            Mv = self.source.absolute_magnitude(rich)
            Mv_lo = self.source.absolute_magnitude(rich_err[0])
            Mv_hi = self.source.absolute_magnitude(rich_err[1])
            results['Mv'] = ugali.utils.stats.interval(Mv,Mv_lo,Mv_hi)
        except ValueError as e:
            logger.warning("Skipping absolute magnitude")
            logger.warn(str(e))
            results['Mv'] = np.nan

        # ADW: WARNING this is very fragile.
        # Also, this is not quite right, should cut on the CMD available space
        kwargs = dict(richness=rich,mag_bright=16., mag_faint=23.,
                      n_trials=5000,alpha=self.alpha, seed=0)
        martin = self.config['results'].get('martin')
        if martin:
            logger.info("Calculating Martin magnitude...")
            if martin > 1: kwargs['n_trials'] = martin
            Mv_martin = self.source.isochrone.absolute_magnitude_martin(**kwargs)
            results['Mv_martin'] = Mv_martin
        else:
            logger.warning("Skipping Martin magnitude")
            results['Mv_martin'] = np.nan
        
        mu = surfaceBrightness(Mv, size, dist)
        results['surface_brightness'] = ugali.utils.stats.interval(mu,np.nan,np.nan)
 
        try: 
            results['constellation'] = ang2const(lon,lat,self.coordsys)[1]
        except:
            pass
        results['iau'] = ugali.utils.projector.ang2iau(lon,lat)
 
        coord = SkyCoord(ra*u.deg,dec*u.deg,distance=dist*u.kpc)
        results['ra_sex'] = str(coord.ra.to_string())
        results['dec_sex'] = str(coord.dec.to_string())
 
        # Calculate some separations from GC, LMC, SMC
        #NED coordinates with de Grisj distance
        LMC = SkyCoord(80.8939*u.deg,-69.7561*u.deg,distance=49.89*u.kpc)
        #NED coordinates with de Grisj distance
        SMC = SkyCoord(13.1866*u.deg,-72.8286*u.deg,distance=61.94*u.kpc)
        # GC from astropy?
        GC = SkyCoord(266.4168262*u.deg,-29.0077969*u.deg,distance=8.0*u.kpc)
         
        results['d_gc'] = coord.separation_3d(GC).value
        results['d_lmc'] = coord.separation_3d(LMC).value
        results['d_smc'] = coord.separation_3d(SMC).value

        try:
            results['feh'] = float(self.source.isochrone.feh)
        except:
            results['feh'] = np.nan
        
        output = dict()
        output['params'] = params
        output['results'] = results
        return output
Пример #10
0
 def distance(self):
     """ Convert to physical distance (kpc) """
     return mod2dist(self.distance_modulus)