Exemplo n.º 1
0
 def create_stochastic_portion(self):
     """ Create the stochastic component of the galaxy images in each band"""
     catalog_extra = 1.1 # Draw about 1.1 times as many stars as we need to allow the model
     cluster = imf.make_cluster(self.stochastic_mass_fraction*self.mass*catalog_extra,
                        massfunc='kroupa',mmin=self.minmass_stochastic)
     nstars = len(cluster)/catalog_extra
     # Create an image with the number of stars drawn from an appropriately normalized
     # Poisson distribution
     self.create_poisson_model(nstars)
     print("Peak number of stars in a pixel: ",self.poisson_model.max())
     print("Pixel row,col of peak: ",np.unravel_index(self.poisson_model.argmax(),
           self.poisson_model.shape))
     # For each random stochastic draw of a mass in the cluster, 
     # find the nearest mass to it in the isochrone and make an array of these 
     # indices into the isochrone array
     #mass_indices = np.array([(np.abs(self.isochrone['initial_mass']-m)).argmin() for m in cluster])
     mass_indices = do_find_nearest(self.isochrone['initial_mass'],cluster)
     self.stochastic_image = {}
     for b in self.bands:
         self.stochastic_image[b]=self.galaxy_image[b]*0.
     xint,yint = self.x.flatten().astype(np.int32),self.y.flatten().astype(np.int32)
     nstars_added = 0
     pmflat = self.poisson_model.flatten()
     indices = np.nonzero(pmflat)[0]
     self.nonzero_pm_indices = indices
     npix_withstars = len(indices)
     for idx in indices:
         iso_indices = mass_indices[nstars_added:nstars_added+pmflat[idx]]
         nstars_added += pmflat[idx]
         for b in self.bands:
             np.put(self.stochastic_image[b],idx,self.isochrone[b][iso_indices].sum())
     print(f"{nstars_added} stars added to {npix_withstars} pixels")
Exemplo n.º 2
0
from imf import make_cluster
import pylab as pl

import imf

maxmass = [
    imf.make_cluster(500, verbose=False, silent=True).max()
    for ii in range(10000)
]
maxmass_sorted = [
    imf.make_cluster(500, stop_criterion='sorted', verbose=False,
                     silent=True).max() for ii in range(10000)
]
maxmass_before = [
    imf.make_cluster(500, stop_criterion='before', verbose=False,
                     silent=True).max() for ii in range(10000)
]
maxmass_after = [
    imf.make_cluster(500, stop_criterion='after', verbose=False,
                     silent=True).max() for ii in range(10000)
]

pl.clf()
pl.hist(maxmass, bins=50, alpha=0.5, label='nearest', histtype='step')
pl.hist(maxmass_sorted, bins=50, alpha=0.5, label='sorted', histtype='step')
pl.hist(maxmass_before, bins=50, alpha=0.5, label='before', histtype='step')
pl.hist(maxmass_after, bins=50, alpha=0.5, label='after', histtype='step')
pl.legend(loc='best')
Exemplo n.º 3
0
    import pylab as pl

    alpha = 2
    m0 = 5e2
    mmax = 5e5
    cluster_mass_xax = np.logspace(np.log10(m0),np.log10(mmax),1e4)
    def pr(m):
        return (m/m0)**-alpha
    probabilities = pr(cluster_mass_xax)
    cdf = probabilities.cumsum()
    cdf /= cdf.max() # normalize to sum (cdf)

    nclusters = 5000

    cluster_masses = np.array([np.interp(p, cdf, cluster_mass_xax) for p in np.random.rand(nclusters)])
    clusters = [make_cluster(m,mmax=m) for m in cluster_masses]

    luminosities = np.array([lum_of_cluster(c) for c in clusters])
    # no contrast
    # colors = [color_of_cluster(c) for c in clusters]

    def ctable(mass, mmin=0.08, mmax=120):
        return pl.cm.RdBu((mass-mmin)/(mmax-mmin))
        cr = np.log10(mmax)-np.log10(mmin)
        lm = np.log10(mass)-np.log10(mmin)
        return pl.cm.RdBu(lm/cr)
    colors = [color_of_cluster(c,ctable) for c in clusters]

    yax = [np.random.rand()*(np.log10(pr(m))-np.log10(pr(mmax))) + np.log10(pr(mmax)) for m in cluster_masses]

    pl.rc('font',size=30)
Exemplo n.º 4
0
        subplot.scatter(

            positions[...,0].value_in(nbody_system.length),

            positions[...,1].value_in(nbody_system.length),

            s = 1,

            edgecolors = 'red',

            facecolors = 'red'

        )



        subplot.set_xlim(-4.0,4.0)

        subplot.set_ylim(-4.0,4.0)

        subplot.set_aspect(1.)



        title = 'time = {0:.2f}'.format(time.value_in(nbody_system.time))



        subplot.set_title(title)#, fontsize=12)

        spines = []

        if index % plot_matrix_size == 0:

            spines.append('left')



        if index >= ((number_of_rows - 1)*plot_matrix_size):

            spines.append('bottom')





        adjust_spines(subplot, spines,np.arange(-4.0,4.1, 1.0))



        if index % plot_matrix_size == 0:

            subplot.set_ylabel('y')



        if index >= ((number_of_rows - 1)*plot_matrix_size):

            subplot.set_xlabel('x')

            

    plt.savefig('simple_cluster_powerlaw.png', clobber=True)





def write_init_file(m, pos, vel, fname):

    """

    Writes the initial masses, positions, and velocities of a cluster to a file.

    """

    f = open(fname, 'w')



    for i in np.arange(np.size(m)):

        f.write(str(m[i]) + '\t' + str(pos[i,0]) + '\t' + str(pos[i,1]) + '\t' + str(pos[i,2]) + '\t' + str(vel[i,0]) + '\t' + '\t' + str(vel[i,1]) + '\t' + str(vel[i,2]) + '\n')

Exemplo n.º 5
0
    mmax = 5e5
    cluster_mass_xax = np.logspace(np.log10(m0), np.log10(mmax), 1e4)

    def pr(m):
        return (m / m0)**-alpha

    probabilities = pr(cluster_mass_xax)
    cdf = probabilities.cumsum()
    cdf /= cdf.max()  # normalize to sum (cdf)

    nclusters = 5000

    cluster_masses = np.array([
        np.interp(p, cdf, cluster_mass_xax) for p in np.random.rand(nclusters)
    ])
    clusters = [make_cluster(m, mmax=m) for m in cluster_masses]

    luminosities = np.array([lum_of_cluster(c) for c in clusters])

    # no contrast
    # colors = [color_of_cluster(c) for c in clusters]


    def ctable(mass, mmin=0.08, mmax=120):
        return pl.cm.RdBu((mass - mmin) / (mmax - mmin))
        cr = np.log10(mmax) - np.log10(mmin)
        lm = np.log10(mass) - np.log10(mmin)
        return pl.cm.RdBu(lm / cr)

    colors = [color_of_cluster(c, ctable) for c in clusters]
Exemplo n.º 6
0
hdu3 = fits.PrimaryHDU(data=new_psf, header=psf_header)
hdu3.writeto('F200W_psf_regr.fits', overwrite=True)
'''

# Create empty image
imsize = [60.0, 60.0]  # arcsec
imnpix_y = round(imsize[0] / pixscale)
imnpix_x = round(imsize[1] / pixscale)
data = np.zeros((imnpix_y, imnpix_x), dtype=np.float64)

# Create sources:
# Binary example
#sources = create_sources.binary(br=0.5,Dec_offset=0.3,RA_offset=0.1,imsize=imsize,pixscale=pixscale)

# Cluster example
br_arr = imf.make_cluster(10000)  #Mass of cluster in Msun
nstars = br_arr.shape[0]
dec_arr = np.random.uniform(-29, 29, nstars)
ra_arr = np.random.uniform(-29, 29, nstars)
sources = create_sources.cluster(br=br_arr,Dec_offset=dec_arr,\
RA_offset=ra_arr,imsize=imsize,pixscale=pixscale)

# Example with a few sources
#sources = create_sources.multiple(br=[1.0,0.5,0.3,0.1],Dec_offset=[0.1,-0.2,0.3,-0.4],\
#RA_offset=[0.1,-0.3,0.35,0.5],imsize=imsize,pixscale=pixscale)

# Fill in point sources
for source in sources:
    data[sources[source]['Dec'],
         sources[source]['RA']] = sources[source]['Brightness']