コード例 #1
0
def catsimSatellite(config, lon_centroid, lat_centroid, distance, stellar_mass, r_physical, 
                    m_maglim_1, m_maglim_2, m_ebv,
                    plot=False, title='test'):
    """
    Simulate a single satellite. This is currently only valid for band_1 = g and band_2 = r.
    r_physical is azimuthally averaged half-light radius, kpc
    """

    # Probably don't want to parse every time
    completeness = getCompleteness(config)
    log_photo_error = getPhotoError(config)

    s = ugali.analysis.source.Source()

    # Following McConnachie 2012, ellipticity = 1 - (b/a) , where a is semi-major axis and b is semi-minor axis
    
    r_h = np.degrees(np.arcsin(r_physical / distance)) # Azimuthally averaged half-light radius
    #ellipticity = 0.3 # Semi-arbitrary default for testing purposes
    # See http://iopscience.iop.org/article/10.3847/1538-4357/833/2/167/pdf
    # Based loosely on https://arxiv.org/abs/0805.2945
    ellipticity = np.random.uniform(0.1, 0.8)
    position_angle = np.random.uniform(0., 180.) # Random position angle (deg)
    a_h = r_h / np.sqrt(1. - ellipticity) # semi-major axis (deg)
    
        
    # Elliptical kernels take the "extension" as the semi-major axis
    ker = ugali.analysis.kernel.EllipticalPlummer(lon=lon_centroid, lat=lat_centroid, ellipticity=ellipticity, position_angle=position_angle)

    flag_too_extended = False
    if a_h >= 1.0:
        print 'Too extended: a_h = %.2f'%(a_h)
        a_h = 1.0
        flag_too_extended = True
    ker.setp('extension', value=a_h, bounds=[0.0,1.0])
    s.set_kernel(ker)
    
    age = np.random.choice([10., 12.0, 13.5])
    metal_z = np.random.choice([0.0001, 0.0002])
    distance_modulus = ugali.utils.projector.distanceToDistanceModulus(distance)
    iso = isochrone_factory('Bressan2012', survey=config['survey'], age=age, z=metal_z, distance_modulus=distance_modulus)
    s.set_isochrone(iso)
    # Simulate takes stellar mass as an argument, NOT richness
    mag_1, mag_2 = s.isochrone.simulate(stellar_mass) 

    lon, lat = s.kernel.sample_lonlat(len(mag_2))

    nside = healpy.npix2nside(len(m_maglim_1)) # Assuming that the two maglim maps have same resolution
    pix = ugali.utils.healpix.angToPix(nside, lon, lat)
    maglim_1 = m_maglim_1[pix]
    maglim_2 = m_maglim_2[pix]
    if config['survey'] == 'des':
        # DES Y3 Gold fiducial
        mag_extinction_1 = 3.186 * m_ebv[pix]
        mag_extinction_2 = 2.140 * m_ebv[pix]
    elif config['survey'] == 'ps1':
        # From Table 6 in Schlafly 2011 with Rv = 3.1
        # http://iopscience.iop.org/article/10.1088/0004-637X/737/2/103/pdf
        mag_extinction_1 = 3.172 * m_ebv[pix]
        mag_extinction_2 = 2.271 * m_ebv[pix]
    
    # Photometric uncertainties are larger in the presence of interstellar dust reddening
    mag_1_error = 0.01 + 10**(log_photo_error((mag_1 + mag_extinction_1) - maglim_1))
    mag_2_error = 0.01 + 10**(log_photo_error((mag_2 + mag_extinction_2) - maglim_2))

    # It would be better to convert to a flux uncertainty and then transform back to a magnitude
    #mag_1_meas = mag_1 + np.random.normal(scale=mag_1_error)
    #mag_2_meas = mag_2 + np.random.normal(scale=mag_2_error)
    flux_1_meas = magToFlux(mag_1) + np.random.normal(scale=getFluxError(mag_1, mag_1_error))
    mag_1_meas = np.where(flux_1_meas > 0., fluxToMag(flux_1_meas), 99.)
    flux_2_meas = magToFlux(mag_2) + np.random.normal(scale=getFluxError(mag_2, mag_2_error))
    mag_2_meas = np.where(flux_2_meas > 0., fluxToMag(flux_2_meas), 99.)

    # In the HSC SXDS ultra-deep field:
    # mean maglim_r_sof_gold_2.0 = 23.46
    # median maglim_r_sof_gold_2.0 = 23.47
    # m = healpy.read_map('/Users/keithbechtol/Documents/DES/projects/mw_substructure/des/y3a1/data/maps/y3a2_gold_1.0_cmv02-001_v1_nside4096_nest_r_depth.fits.gz')
    # np.mean(m[ugali.utils.healpix.angToDisc(4096, 34.55, -4.83, 0.75)])
    # np.median(m[ugali.utils.healpix.angToDisc(4096, 34.55, -4.83, 0.75)])

    # Includes penalty for interstellar extinction and also include variations in depth
    if config['survey'] == 'des':
        cut_detect = (np.random.uniform(size=len(mag_2)) < completeness(mag_2 + mag_extinction_2 + (23.46 - np.clip(maglim_2, 20., 26.))))
    elif config['survey'] == 'ps1':
        cut_detect = (np.random.uniform(size=len(mag_2)) < completeness(mag_2 + mag_extinction_2))

    n_g22 = np.sum(cut_detect & (mag_1 < 22.))
    n_g24 = np.sum(cut_detect & (mag_1 < 24.))
    print '  n_sim = %i, n_detect = %i, n_g24 = %i, n_g22 = %i'%(len(mag_1),np.sum(cut_detect),n_g24,n_g22)
    
    richness = stellar_mass / s.isochrone.stellarMass()
    #abs_mag = s.isochrone.absolute_magnitude()
    #abs_mag_martin = s.isochrone.absolute_magnitude_martin(richness=richness, n_trials=10)[0] # 100 trials seems to be sufficient for rough estimate
    #print 'abs_mag_martin = %.2f mag'%(abs_mag_martin)

    # The more clever thing to do would be to sum up the actual simulated stars
    if config['survey'] == 'des':
        v = mag_1 - 0.487*(mag_1 - mag_2) - 0.0249 # See https://github.com/DarkEnergySurvey/ugali/blob/master/ugali/isochrone/model.py
    elif config['survey'] == 'ps1':
        # https://arxiv.org/pdf/1706.06147.pdf
        # V - g = C_0 + C_1 * (g - r)
        C_0 = -0.017
        C_1 = -0.508
        v = mag_1 + C_0 + C_1 * (mag_1 - mag_2)
    flux = np.sum(10**(-v/2.5))
    abs_mag = -2.5*np.log10(flux) - distance_modulus

    #print abs_mag, abs_mag_martin

    #distance = ugali.utils.projector.distanceModulusToDistance(distance_modulus)
    #r_h = extension * np.sqrt(1. - ellipticity) # Azimuthally averaged half-light radius
    r_physical = distance * np.tan(np.radians(r_h)) # Azimuthally averaged half-light radius, kpc
    #print 'distance = %.3f kpc'%(distance)
    #print 'r_physical = %.3f kpc'%(r_physical)
    surface_brightness = ugali.analysis.results.surfaceBrightness(abs_mag, r_physical, distance) # Average within azimuthally averaged half-light radius
    #print 'surface_brightness = %.3f mag arcsec^-2'%(surface_brightness)
    
    if plot:
        import pylab
        pylab.ion()

        n_sigma_p = np.sum(cut_detect & (mag_1 < 23.))

        pylab.figure(figsize=(6., 6.))
        pylab.scatter(mag_1_meas[cut_detect] - mag_2_meas[cut_detect], mag_1_meas[cut_detect], edgecolor='none', c='black', s=5)
        pylab.xlim(-0.5, 1.)
        pylab.ylim(26., 16.)
        pylab.xlabel('g - r')
        pylab.ylabel('g')
        pylab.title('Number of stars with g < 23: %i'%(n_sigma_p))
        pylab.savefig('y3_sat_sim_cmd_%s.png'%(title), dpi=150.)
        
        print 'n_Sigma_p = %i'%(n_sigma_p)
        raw_input('WAIT')
        
    #if flag_too_extended:
    #    # This is a kludge to remove these satellites. fragile!!
    #    n_g24 = 1.e6

    return lon[cut_detect], lat[cut_detect], mag_1_meas[cut_detect], mag_2_meas[cut_detect], mag_1_error[cut_detect], mag_2_error[cut_detect], mag_extinction_1[cut_detect], mag_extinction_2[cut_detect], n_g22, n_g24, abs_mag, surface_brightness, ellipticity, position_angle, age, metal_z, flag_too_extended
コード例 #2
0
def analysis(ra, dec, mod, mc_source_id):
    """Analyze a candidate"""

    pix_nside_select = ugali.utils.healpix.angToPix(nside, ra, dec)
    ra_select, dec_select = ugali.utils.healpix.pixToAng(
        nside, pix_nside_select)
    pix_nside_neighbors = np.concatenate([[pix_nside_select],
                                          healpy.get_all_neighbours(
                                              nside, pix_nside_select)])

    # Construct data
    #data = simple.simple_utils.construct_modal_data(mode, pix_nside_neighbors)
    data = simple.simple_utils.construct_real_data(pix_nside_neighbors)
    if (mode == 0):
        print('mode = 0: running only on real data')
    elif (mode == 1):
        print('mode = 1: running on real data and simulated data')

        # inject objects for simulated object of mc_source_id
        sim_data = simple.simple_utils.construct_sim_data(
            pix_nside_neighbors, mc_source_id)
        data = simple.simple_utils.inject_sim(data, sim_data, mc_source_id)
    else:
        print('No mode specified; running only on real data')

    print('Loading data...')
    data = simple.simple_utils.construct_modal_data(mode, pix_nside_neighbors,
                                                    mc_source_id)
    quality_cut = simple.filters.quality_filter(survey, data)
    data = data[quality_cut]
    print('Found {} objects...').format(len(data))

    data = simple.filters.dered_mag(survey, data)

    # This should be generalized to also take the survey
    iso = isochrone_factory(name=isoname,
                            survey=isosurvey,
                            age=12,
                            z=0.0001,
                            distance_modulus=mod,
                            band_1=band_1.lower(),
                            band_2=band_2.lower())

    # g_radius estimate
    filter = simple.filters.star_filter(survey, data)

    iso_filter = simple.simple_utils.cut_isochrone_path(data[mag_dered_1],
                                                        data[mag_dered_2],
                                                        data[mag_err_1],
                                                        data[mag_err_2],
                                                        iso,
                                                        radius=0.1,
                                                        return_all=False)

    angsep = ugali.utils.projector.angsep(ra, dec, data[basis_1],
                                          data[basis_2])

    bins = np.linspace(0, 0.4, 21)  # deg
    centers = 0.5 * (bins[1:] + bins[0:-1])
    area = np.pi * (bins[1:]**2 - bins[0:-1]**2) * 60**2
    hist = np.histogram(angsep[(angsep < 0.4) & filter & iso_filter],
                        bins=bins)[0]  # counts

    f_interp = interpolate.interp1d(
        np.linspace(centers[0], centers[-1], len(hist)), hist / area, 'cubic')
    f_range = np.linspace(centers[0], centers[-1], 1000)
    f_val = f_interp(f_range)

    pairs = zip(f_range, f_val)

    peak = max(pairs[:len(pairs) / 4],
               key=lambda x: x[1])  # find peak within first quarter

    def peak_index(pairs, peak):
        for i in range(len(pairs)):
            if pairs[i] == peak:
                return i

    osc = int(
        0.04 / 0.4 *
        1000)  # +/- 0.04 (rounded down) deg oscillation about local extremum
    relmin = argrelextrema(f_val, np.less, order=osc)[0]

    try:
        if len(relmin) > 0:
            #half_point = f_range[relmin[0]]
            i = 0
            while ((f_range[relmin[i]] <= f_range[peak_index(pairs, peak)]) &
                   (i <= len(relmin) - 1)):
                i += 1
            half_point = f_range[relmin[i]]
        elif len(relmin) == 0:
            half_peak = (
                peak[1] + np.mean(f_val[len(f_val) / 4:])
            ) / 2.  # normalized to background (after first quarter)
            #half_peak = np.mean(f_val[len(f_val)/4:])
            half_pairs = []
            for i in pairs[peak_index(pairs, peak):len(pairs) /
                           2]:  # start after peak, stay within first quarter
                if i != peak:
                    half_pairs.append((i[0], abs(i[1] - half_peak)))
            half_point = min(half_pairs, key=lambda x: x[1])[0]  # deg
    except:
        half_point = 0.1  # fixed value to catch errors

    g_min = 0.5 / 60.  # deg
    g_max = 12. / 60.  # deg

    if half_point < g_min:
        g_radius = g_min
    elif half_point > g_max:
        g_radius = g_max
    else:
        g_radius = half_point  # deg

    angsep = ugali.utils.projector.angsep(ra, dec, data[basis_1],
                                          data[basis_2])
    nbhd = (angsep < g_radius)

    return (data, iso, g_radius, nbhd)
コード例 #3
0
ファイル: diagnostic_plots.py プロジェクト: eonadler/ugali
def analysis(targ_ra, targ_dec, mod):
    """Analyze a candidate"""

    #hdisc = healpix.ang2disc(nside, targ_ra, targ_dec, 1, inclusive=True)
    #files = []
    #for i in hdisc:
    #    if os.path.exists(datadir+'/cat_hpx_'+str(i).zfill(5)+'.fits'):
    #        files.append(datadir+'/cat_hpx_'+str(i).zfill(5)+'.fits')
    #
    ##data = utils.load_infiles(files, columns=['RA', 'DEC', 'WAVG_MAG_PSF_G', 'WAVG_MAG_PSF_R', 'EXTINCTION_G', 'EXTINCTION_R', 'WAVG_SPREAD_MODEL_R', 'SPREADERR_MODEL_R', 'WAVG_MAGERR_PSF_G', 'WAVG_MAGERR_PSF_R', 'MAGERR_PSF_G', 'MAGERR_PSF_R'])
    #data = utils.load_infiles(files, columns=COLUMNS)

    pix_nside_select = ugali.utils.healpix.angToPix(nside, targ_ra, targ_dec)
    ra_select, dec_select = ugali.utils.healpix.pixToAng(
        nside, pix_nside_select)
    pix_nside_neighbors = np.concatenate([[pix_nside_select],
                                          healpy.get_all_neighbours(
                                              nside, pix_nside_select)])
    data_array = []
    for pix_nside in pix_nside_neighbors:
        #infile = '%s/cat_hpx_%05i.fits'%(datadir, pix_nside)
        infile = '%s/y3a2_ngmix_cm_%05i.fits' % (datadir, pix_nside)
        #infile = '%s/*_%05i.fits'%(datadir, pix_nside) # TODO: get to work
        if not os.path.exists(infile):
            continue
        reader = pyfits.open(infile)
        data_array.append(reader[1].data)
        reader.close()
    print('Assembling data...')
    data = np.concatenate(data_array)
    print('Found {} objects...').format(len(data))
    print('Loading data...')

    ## De-redden magnitudes
    #try:
    #    data = mlab.rec_append_fields(data, ['WAVG_MAG_PSF_DRED_G', 'WAVG_MAG_PSF_DRED_R'], [data[mag_g_dred_flag], data[mag_r_dred_flag]])
    ##except:
    ##    data = mlab.rec_append_fields(data, ['WAVG_MAG_PSF_DRED_G', 'WAVG_MAG_PSF_DRED_R'], [data[mag_g_flag] - data[extinction_g_flag], data[mag_r_flag] - data[extinction_r_flag]])
    #except:
    #    data = mlab.rec_append_fields(data, ['WAVG_MAG_PSF_DRED_G', 'WAVG_MAG_PSF_DRED_R'], [data[mag_g_flag], data[mag_r_flag]])
    #
    #mag_g = data['WAVG_MAG_PSF_DRED_G']
    #mag_r = data['WAVG_MAG_PSF_DRED_R']
    mag_g = data[mag_g_dred_flag]
    mag_r = data[mag_r_dred_flag]

    iso = isochrone_factory('Bressan2012',
                            age=12,
                            z=0.0001,
                            distance_modulus=mod)

    # g_radius estimate
    filter_s = star_filter(data)

    mag_g = data[mag_g_dred_flag]
    mag_r = data[mag_r_dred_flag]

    iso_filter = (iso.separation(mag_g, mag_r) < 0.1)

    angsep = ugali.utils.projector.angsep(targ_ra, targ_dec, data['RA'],
                                          data['DEC'])

    bins = np.linspace(0, 0.4, 21)  # deg
    centers = 0.5 * (bins[1:] + bins[0:-1])
    area = np.pi * (bins[1:]**2 - bins[0:-1]**2) * 60**2
    hist = np.histogram(angsep[(angsep < 0.4) & filter_s & iso_filter],
                        bins=bins)[0]  # counts

    f_interp = interpolate.interp1d(
        np.linspace(centers[0], centers[-1], len(hist)), hist / area, 'cubic')
    f_range = np.linspace(centers[0], centers[-1], 1000)
    f_val = f_interp(f_range)

    pairs = list(zip(f_range, f_val))

    peak = max(pairs[:len(pairs) / 4],
               key=lambda x: x[1])  # find peak within first quarter

    def peak_index(pairs, peak):
        for i in range(len(pairs)):
            if pairs[i] == peak:
                return i

    osc = int(
        0.04 / 0.4 *
        1000)  # +/- 0.04 (rounded down) deg oscillation about local extremum
    relmin = argrelextrema(f_val, np.less, order=osc)[0]

    try:
        if len(relmin) > 0:
            #half_point = f_range[relmin[0]] # TODO rename
            i = 0
            while ((f_range[relmin[i]] <= f_range[peak_index(pairs, peak)]) &
                   (i <= len(relmin) - 1)):
                i += 1
            half_point = f_range[relmin[i]]
        elif len(relmin) == 0:
            half_peak = (
                peak[1] + np.mean(f_val[len(f_val) / 4:])
            ) / 2.  # normalized to background (after first quarter)
            #half_peak = np.mean(f_val[len(f_val)/4:])
            half_pairs = []
            for i in pairs[peak_index(pairs, peak):len(pairs) /
                           2]:  # start after peak, stay within first quarter
                if i != peak:
                    half_pairs.append((i[0], abs(i[1] - half_peak)))
            half_point = min(half_pairs, key=lambda x: x[1])[0]  # deg
    except:
        half_point = 0.1  # fixed value to catch errors

    g_min = 0.5 / 60.  # deg
    g_max = 12. / 60.  # deg

    if half_point < g_min:
        g_radius = g_min
    elif half_point > g_max:
        g_radius = g_max
    else:
        g_radius = half_point  # deg

    #c1 = SkyCoord(targ_ra, targ_dec, unit='deg') # frame is ICRS
    #nbhd = c1.separation(SkyCoord(data['RA'], data['DEC'], unit='deg')).deg < g_radius # selects objects inside the galactic radius
    angsep = ugali.utils.projector.angsep(targ_ra, targ_dec, data['RA'],
                                          data['DEC'])
    nbhd = (angsep < g_radius)

    return (data, iso, g_radius, nbhd)
コード例 #4
0
ファイル: simulate_population.py プロジェクト: kadrlica/ugali
def catsimSatellite(config,
                    lon_centroid,
                    lat_centroid,
                    distance,
                    stellar_mass,
                    r_physical,
                    ellipticity,
                    position_angle,
                    age,
                    metal,
                    m_maglim_1,
                    m_maglim_2,
                    m_ebv,
                    plot=False,
                    title='test'):
    """ Simulate a single satellite. This is currently only valid for
    band_1 = g and band_2 = r.  r_physical is azimuthally averaged
    half-light radius, kpc

    Parameters
    ----------
    config : configuration
    lon_centroid : longitude centroid (deg)
    lat_centroid : latitude centroid (deg)
    distance : distance (kpc)
    stellar_mass : stellar mass (Msun)
    r_physical : azimuthally averaged physical half-light radius (kpc)
    ellipticity : ellipticity [0, 1]
    position_angle : position angle (deg)
    age : age (Gyr)
    metal : metallicity
    m_maglim_1 : mask of magnitude limit in band 2
    m_maglim_2 : mask of magnitude limit in band 2
    m_ebv : mask of E(B-V) values
    plot : Plot the output [False]
    
    Returns
    -------
    satellite : ordered dictionary of satellite star output
    """

    # Probably don't want to parse every time
    completeness = getCompleteness(config)
    log_photo_error = getPhotoError(config)

    s = ugali.analysis.source.Source()

    # Azimuthally averaged projected half-light radius (deg)
    r_h = np.degrees(np.arcsin(r_physical / distance))
    # Elliptical half-light radius along semi-major axis (deg)
    a_h = r_h / np.sqrt(1. - ellipticity)

    # Create the kernel without extension
    ker = ugali.analysis.kernel.EllipticalPlummer(
        lon=lon_centroid,
        lat=lat_centroid,
        ellipticity=ellipticity,
        position_angle=position_angle)
    # Apply a max extension cut
    flag_too_extended = False
    max_extension = 5.0  # deg
    if a_h >= max_extension:
        print 'Too extended: a_h = %.2f' % (a_h)
        a_h = max_extension
        flag_too_extended = True
    # Elliptical kernels take the "extension" as the semi-major axis
    extension = a_h  # Elliptical half-light radius
    ker.setp('extension', value=a_h, bounds=[0.0, max_extension])
    s.set_kernel(ker)

    # Create the isochrone
    distance_modulus = ugali.utils.projector.dist2mod(distance)
    iso = isochrone_factory('Bressan2012',
                            survey=config['survey'],
                            age=age,
                            z=metal,
                            distance_modulus=distance_modulus)
    s.set_isochrone(iso)
    # Simulate takes stellar mass as an argument, NOT richness
    mag_1, mag_2 = s.isochrone.simulate(stellar_mass)

    # Generate the positions of stars
    lon, lat = s.kernel.sample_lonlat(len(mag_2))

    nside = hp.npix2nside(len(
        m_maglim_1))  # Assuming that the two maglim maps have same resolution
    pix = ugali.utils.healpix.ang2pix(nside, lon, lat)
    maglim_1 = m_maglim_1[pix]
    maglim_2 = m_maglim_2[pix]
    if config['survey'] == 'des':
        # DES Y3 Gold fiducial
        mag_extinction_1 = 3.186 * m_ebv[pix]
        mag_extinction_2 = 2.140 * m_ebv[pix]
    elif config['survey'] == 'ps1':
        # From Table 6 in Schlafly 2011 with Rv = 3.1
        # http://iopscience.iop.org/article/10.1088/0004-637X/737/2/103/pdf
        mag_extinction_1 = 3.172 * m_ebv[pix]
        mag_extinction_2 = 2.271 * m_ebv[pix]
    elif config['survey'] == 'lsst':
        # From Table 6 in Schlafly 2011 with Rv = 3.1
        # http://iopscience.iop.org/article/10.1088/0004-637X/737/2/103/pdf
        mag_extinction_1 = 3.237 * m_ebv[pix]
        mag_extinction_2 = 2.273 * m_ebv[pix]

    # Photometric uncertainties are larger in the presence of interstellar dust reddening
    mag_1_error = 0.01 + 10**(log_photo_error((mag_1 + mag_extinction_1) -
                                              maglim_1))
    mag_2_error = 0.01 + 10**(log_photo_error((mag_2 + mag_extinction_2) -
                                              maglim_2))

    # It would be better to convert to a flux uncertainty and then transform back to a magnitude
    #mag_1_meas = mag_1 + np.random.normal(scale=mag_1_error)
    #mag_2_meas = mag_2 + np.random.normal(scale=mag_2_error)
    flux_1_meas = magToFlux(mag_1) + np.random.normal(
        scale=getFluxError(mag_1, mag_1_error))
    mag_1_meas = np.where(flux_1_meas > 0., fluxToMag(flux_1_meas), 99.)
    flux_2_meas = magToFlux(mag_2) + np.random.normal(
        scale=getFluxError(mag_2, mag_2_error))
    mag_2_meas = np.where(flux_2_meas > 0., fluxToMag(flux_2_meas), 99.)

    # In the HSC SXDS ultra-deep field:
    # mean maglim_r_sof_gold_2.0 = 23.46
    # median maglim_r_sof_gold_2.0 = 23.47
    # m = healpy.read_map('/Users/keithbechtol/Documents/DES/projects/mw_substructure/des/y3a1/data/maps/y3a2_gold_1.0_cmv02-001_v1_nside4096_nest_r_depth.fits.gz')
    # np.mean(m[ugali.utils.healpix.angToDisc(4096, 34.55, -4.83, 0.75)])
    # np.median(m[ugali.utils.healpix.angToDisc(4096, 34.55, -4.83, 0.75)])

    # Includes penalty for interstellar extinction and also include variations in depth
    if config['survey'] == 'des':
        cut_detect = (np.random.uniform(size=len(mag_2)) <
                      completeness(mag_2 + mag_extinction_2 +
                                   (23.46 - np.clip(maglim_2, 20., 26.))))
    elif config['survey'] == 'ps1':
        cut_detect = (np.random.uniform(size=len(mag_2)) <
                      completeness(mag_2 + mag_extinction_2))
    elif config['survey'] == 'lsst':
        cut_detect = (np.random.uniform(size=len(mag_2)) <
                      completeness(mag_2 + mag_extinction_2 +
                                   (25.0 - np.clip(maglim_2, 20., 26.)))
                      )  # Using the psuedo mag depth of 25 for now
    n_g22 = np.sum(cut_detect & (mag_1 < 22.))
    n_g24 = np.sum(cut_detect & (mag_1 < 24.))
    print('  n_sim = %i, n_detect = %i, n_g24 = %i, n_g22 = %i' %
          (len(mag_1), np.sum(cut_detect), n_g24, n_g22))

    richness = stellar_mass / s.isochrone.stellarMass()
    #abs_mag = s.isochrone.absolute_magnitude()
    #abs_mag_martin = s.isochrone.absolute_magnitude_martin(richness=richness, n_trials=10)[0] # 100 trials seems to be sufficient for rough estimate
    #print 'abs_mag_martin = %.2f mag'%(abs_mag_martin)

    # The more clever thing is to sum the simulated stars
    if config['survey'] == 'des':
        # See https://github.com/DarkEnergySurvey/ugali/blob/master/ugali/isochrone/model.py
        v = mag_1 - 0.487 * (mag_1 - mag_2) - 0.0249
    elif config['survey'] == 'ps1':
        # https://arxiv.org/pdf/1706.06147.pdf
        # V - g = C_0 + C_1 * (g - r)
        C_0 = -0.017
        C_1 = -0.508
        v = mag_1 + C_0 + C_1 * (mag_1 - mag_2)
    elif config['survey'] == 'lsst':
        # Numbers are just placeholders for now, need to figure out exact ones
        C_0 = -0.02
        C_1 = -0.50
        v = mag_1 + C_0 + C_1 * (mag_1 - mag_2)
    flux = np.sum(10**(-v / 2.5))
    abs_mag = -2.5 * np.log10(flux) - distance_modulus

    # Realized surface brightness within azimuthally averaged half-light radius
    surface_brightness = ugali.analysis.results.surfaceBrightness(
        abs_mag, r_physical, distance)

    if plot:
        import pylab
        pylab.ion()

        n_sigma_p = np.sum(cut_detect & (mag_1 < 23.))

        pylab.figure(figsize=(6., 6.))
        pylab.scatter(mag_1_meas[cut_detect] - mag_2_meas[cut_detect],
                      mag_1_meas[cut_detect],
                      edgecolor='none',
                      c='black',
                      s=5)
        pylab.xlim(-0.5, 1.)
        pylab.ylim(26., 16.)
        pylab.xlabel('g - r')
        pylab.ylabel('g')
        pylab.title('Number of stars with g < 23: %i' % (n_sigma_p))
        pylab.savefig('y3_sat_sim_cmd_%s.png' % ('test'), dpi=150.)

        print('n_Sigma_p = %i' % (n_sigma_p))
        raw_input('WAIT')

    satellite = odict(lon=lon[cut_detect],
                      lat=lat[cut_detect],
                      mag_1=mag_1_meas[cut_detect],
                      mag_2=mag_2_meas[cut_detect],
                      mag_1_error=mag_1_error[cut_detect],
                      mag_2_error=mag_2_error[cut_detect],
                      mag_extinction_1=mag_extinction_1[cut_detect],
                      mag_extinction_2=mag_extinction_2[cut_detect],
                      n_g22=n_g22,
                      n_g24=n_g24,
                      abs_mag=abs_mag,
                      surface_brightness=surface_brightness,
                      extension=extension,
                      flag_too_extended=flag_too_extended)

    return satellite
コード例 #5
0
ファイル: new_plot.py プロジェクト: sidneymau/simple
# quality selection
quality_cut = quality_filter(survey, data)
data = data[quality_cut]

data = dered_mag(survey, data)

color = data[mag_dered_1] - data[mag_dered_2]
mag = data[mag_dered_1]

stars = star_filter(survey, data)
galaxies = galaxy_filter(survey, data)

iso = isochrone_factory(name='Bressan2012',
                        survey='des',
                        age=12.0,
                        z=0.0001,
                        distance_modulus=mod,
                        band_1='g',
                        band_2='r')
#iso_sep = iso.separation(data[mag_1], data[mag_2])
iso_filter = cut_isochrone_path(data[mag_dered_1],
                                data[mag_dered_2],
                                data[mag_err_1],
                                data[mag_err_2],
                                iso,
                                radius=0.1,
                                return_all=False)

# projection of image
proj = ugali.utils.projector.Projector(ra, dec)
x, y = proj.sphereToImage(data['RA'], data['DEC'])