def test_UnresolvedCluster(): from popstar import synthetic as syn from popstar import atmospheres as atm from popstar import evolution from popstar.imf import imf from popstar.imf import multiplicity log_age = 6.7 AKs = 0.0 distance = 4000 metallicity=0 cluster_mass = 10**4. startTime = time.time() multi = multiplicity.MultiplicityUnresolved() imf_in = imf.Kroupa_2001(multiplicity=multi) evo = evolution.MergedBaraffePisaEkstromParsec() atm_func = atm.get_merged_atmosphere iso = syn.Isochrone(log_age, AKs, distance, metallicity=metallicity, evo_model=evo, atm_func=atm_func, mass_sampling=10) print('Made Isochrone: %d seconds' % (time.time() - startTime)) cluster = syn.UnresolvedCluster(iso, imf_in, cluster_mass) print('Constructed unresolved cluster: %d seconds' % (time.time() - startTime)) # Plot an integrated spectrum of the whole cluster. wave = cluster.wave_trim flux = cluster.spec_trim plt.clf() plt.plot(wave, flux, 'k.') return
def test_UnresolvedCluster(): from popstar import synthetic as syn from popstar import atmospheres as atm from popstar import evolution from popstar.imf import imf from popstar.imf import multiplicity log_age = 6.7 AKs = 0.0 distance = 4000 cluster_mass = 30. startTime = time.time() multi = multiplicity.MultiplicityUnresolved() imf_in = imf.Kroupa_2001(multiplicity=multi) evo = evolution.MergedBaraffePisaEkstromParsec() iso = syn.Isochrone(log_age, AKs, distance, evo, mass_sampling=10) print 'Made cluster: %d seconds' % (time.time() - startTime) cluster = syn.UnresolvedCluster(iso, imf_in, cluster_mass) print 'Constructed unresolved cluster: %d seconds' % (time.time() - startTime) # Plot an integrated spectrum of the whole cluster. wave = cluster.spec_trim.wave flux = cluster.spec_trim.flux plt.clf() plt.plot(wave, flux, 'k.') pdb.set_trace() return
def model_young_cluster_object(resolved=False): from popstar import synthetic as syn from popstar import atmospheres as atm from popstar import evolution from popstar.imf import imf from popstar.imf import multiplicity log_age = 6.5 AKs = 0.1 distance = 8000.0 cluster_mass = 10000. multi = multiplicity.MultiplicityUnresolved() imf_in = imf.Kroupa_2001(multiplicity=multi) evo = evolution.MergedPisaEkstromParsec() atm_func = atm.get_merged_atmosphere iso = syn.Isochrone(log_age, AKs, distance, evo, mass_sampling=10) if resolved: cluster = syn.ResolvedCluster(iso, imf_in, cluster_mass) else: cluster = syn.UnresolvedCluster(iso, imf_in, cluster_mass, wave_range=[19000, 24000]) # Plot the spectrum of the most massive star idx = cluster.mass_all.argmax() print('Most massive star is {0:f} M_sun.'.format(cluster.mass_all[idx])) #bigstar = cluster.spec_list_trim[idx] plt.figure(1) plt.clf() plt.plot(cluster.spec_list_trim[idx]._wavetable, cluster.spec_list_trim[idx]._fluxtable, 'k.') # Plot an integrated spectrum of the whole cluster. wave, flux = cluster.spec_list_trim[idx]._wavetable, cluster.spec_trim plt.figure(2) plt.clf() plt.plot(wave, flux, 'k.') return
def time_test_mass_match(): from popstar import synthetic as syn from popstar import atmospheres as atm from popstar import evolution from popstar.imf import imf from popstar.imf import multiplicity log_age = 6.7 AKs = 2.7 distance = 4000 cluster_mass = 5e3 imf_in = imf.Kroupa_2001(multiplicity=None) start_time = time.time() iso = syn.IsochronePhot(log_age, AKs, distance) iso_masses = iso.points['mass'] print('Generated iso masses in {0:.0f} s'.format(time.time() - start_time)) start_time = time.time() star_masses, isMulti, compMass, sysMass = imf_in.generate_cluster( cluster_mass) print('Generated cluster masses in {0:.0f} s'.format(time.time() - start_time)) def match_model_masses1(isoMasses, starMasses): indices = np.empty(len(starMasses), dtype=int) for ii in range(len(starMasses)): theMass = starMasses[ii] dm = np.abs(isoMasses - theMass) mdx = dm.argmin() # Model mass has to be within 10% of the desired mass if (dm[mdx] / theMass) > 0.1: indices[ii] = -1 else: indices[ii] = mdx return indices def match_model_masses2(isoMasses, starMasses): isoMasses_tmp = isoMasses.reshape((len(isoMasses), 1)) kdt = KDTree(isoMasses_tmp) starMasses_tmp = starMasses.reshape((len(starMasses), 1)) q_results = kdt.query(starMasses_tmp, k=1) indices = q_results[1] dm_frac = np.abs(starMasses - isoMasses[indices]) / starMasses idx = np.where(dm_frac > 0.1)[0] indices[idx] = -1 return indices print('Test #1 START') start_time = time.time() idx1 = match_model_masses1(iso_masses, star_masses) stop_time = time.time() print('Test #1 STOPPED after {0:.0f} seconds'.format(stop_time - start_time)) print('Test #2 START') start_time = time.time() idx2 = match_model_masses2(iso_masses, star_masses) stop_time = time.time() print('Test #2 STOPPED after {0:.0f} seconds'.format(stop_time - start_time)) return