def mergerfileinfo(snapkey, subfindID, size=2, trange=[-2.0, 2.0]): #merger_file = '/astro/snyder_lab2/Illustris/MorphologyAnalysis/imagedata_mergerinfo_SB25.hdf5' merger_file = '/astro/snyder_lab2/Illustris/MorphologyAnalysis/imagedata_mergerinfo_SB25_2017May08.hdf5' #update figure and exploratory quantities here #want to build training sets cleverly from these parameters with h5py.File(merger_file, 'r') as mcat: vals = mcat['mergerinfo'][snapkey][ 'latest_NumMinorMergersLastGyr'].value sfids = mcat['mergerinfo'][snapkey]['SubfindID'].value lsn = mcat['mergerinfo'][snapkey]['LatestTree_snapnum'].value last_merger = mcat['mergerinfo'][snapkey][ 'this_SnapNumLastMajorMerger'].value last_minmerger = mcat['mergerinfo'][snapkey][ 'this_SnapNumLastMinorMerger'].value next_merger = mcat['mergerinfo'][snapkey][ 'this_SnapNumNextMajorMerger'].value next_minmerger = mcat['mergerinfo'][snapkey][ 'this_SnapNumNextMinorMerger'].value sfi = np.where(sfids == subfindID)[0][0] val = vals[sfi] #also: get ALL keys for this subhalo return gsu.age_at_snap(lsn), gsu.age_at_snap( last_merger[sfi]), gsu.age_at_snap( last_minmerger[sfi]), gsu.age_at_snap( next_merger[sfi]), gsu.age_at_snap(next_minmerger[sfi]), val
def match_progdesc(snap, sfid, snapnums_int, latest_snap, latest_span=0.5,basepath='/astro/snyder_lab2/Illustris/Illustris-1'): this_snap_int = np.int32(snap[-3:]) snaps_int = snapnums_int #np.int64(np.asarray(snaplist)) sublink_id,tree_id,mstar,sfr = gsu.sublink_id_from_subhalo(basepath,this_snap_int,sfid) tree = gsu.load_full_tree(basepath,tree_id) mmpb_sublink_id,snaps,mass,mstar,r1,r2,mmpb_sfid,sfr,times = gsu.mmpb_from_tree(tree,sublink_id) time_now = gsu.age_at_snap(this_snap_int) #snap_latest,sfid_latest = get_merger_quantities(time_now,times,snaps,mmpb_sfid,mass,mstar,sfr,this_snap_int,sfid,time_span=latest_span) #print snaps, latest_snap lsi = np.where(snaps==latest_snap)[0] sfid_latest = mmpb_sfid[lsi] print time_now, latest_snap, sfid_latest, lsi matched_mmpb = np.zeros_like(snaps_int) matched_sfid = np.zeros_like(snaps_int) for i,snap in enumerate(snaps_int): tsi = np.where(snaps==snap)[0] if tsi.shape[0] == 1: matched_mmpb[i]=mmpb_sublink_id[tsi] matched_sfid[i]=mmpb_sfid[tsi] else: matched_mmpb[i] = -1 matched_sfid[i] = -1 return matched_mmpb, matched_sfid, sublink_id, latest_snap, sfid_latest
def match_progdesc(snap, sfid, snapnums_int, latest_snap, latest_span=0.5, basepath='/astro/snyder_lab2/Illustris/Illustris-1'): this_snap_int = np.int32(snap[-3:]) snaps_int = snapnums_int #np.int64(np.asarray(snaplist)) sublink_id, tree_id, mstar, sfr = gsu.sublink_id_from_subhalo( basepath, this_snap_int, sfid) tree = gsu.load_full_tree(basepath, tree_id) mmpb_sublink_id, snaps, mass, mstar, r1, r2, mmpb_sfid, sfr, times, mlpids, bhmdot, bhm = gsu.mmpb_from_tree( tree, sublink_id) time_now = gsu.age_at_snap(this_snap_int) #snap_latest,sfid_latest = get_merger_quantities(time_now,times,snaps,mmpb_sfid,mass,mstar,sfr,this_snap_int,sfid,time_span=latest_span) #print snaps, latest_snap #print(mlpids,snaps) lsi = np.where(snaps == latest_snap)[0] sfid_latest = mmpb_sfid[lsi] mlpid_latest = mlpids[lsi] i_now = np.where(snaps == this_snap_int)[0] mlpid_now = mlpids[i_now] mlpid_match = mlpid_latest == mlpid_now print(mlpid_latest, mlpid_now, mlpid_match) print(time_now, latest_snap, sfid_latest, lsi) matched_mmpb = np.zeros_like(snaps_int) matched_sfid = np.zeros_like(snaps_int) for i, snap in enumerate(snaps_int): tsi = np.where(snaps == snap)[0] if tsi.shape[0] == 1: matched_mmpb[i] = mmpb_sublink_id[tsi] matched_sfid[i] = mmpb_sfid[tsi] else: matched_mmpb[i] = -1 matched_sfid[i] = -1 return matched_mmpb, matched_sfid, sublink_id, latest_snap, sfid_latest, mlpid_match
subfind_id = morphcat[topkey][snapkey]['SubfindID'].value print(subfind_id.shape) sgrp = grp.create_group(snapkey) sgrp.create_dataset('SubfindID', data=np.int64(subfind_id)) this_snap_treesfid = np.zeros( (subfind_id.shape[0], len(snapnums_int)), dtype=np.int64) - 1 latest_snap_treesfid = np.zeros( (subfind_id.shape[0]), dtype=np.int64) - 1 mlpid_match_list = np.zeros((subfind_id.shape[0]), dtype=np.bool) print(this_snap_treesfid.shape) this_snap_int = np.int32(snapkey[-3:]) this_snap_time = gsu.age_at_snap(this_snap_int) latest_time = this_snap_time + merger_span lti = np.where(illcos.ages <= latest_time)[0] latest_i = lti[-1] latest_snap = illcos.snaps[latest_i] if latest_snap == 55: latest_snap = 56 latest_time = gsu.age_at_snap(latest_snap) print(latest_snap, latest_i, latest_time, this_snap_time, this_snap_int) for i, sfid in enumerate(subfind_id): existing_line = None if last_sfid_grid is not None: tbi = np.where(last_sfid_grid[:, s] == sfid)[0]
def masshistory(snapkey,subfindID,camnum=0,basepath='/astro/snyder_lab2/Illustris/Illustris-1',size=2,trange=[-1.5,1.5],alph=0.2,Q=8.0,sb='SB25',gyrbox=True,filters=['NC-F115W','NC-F150W','NC-F200W'],use_rfkey=True,npix=None,radeff=0.2,dx=0,dy=0,savefile=None): snapnum = snapkey[-3:] this_snap_int = np.int64(snapnum) sublink_id,tree_id,mstar,sfr = gsu.sublink_id_from_subhalo(basepath,this_snap_int,subfindID) tree = gsu.load_full_tree(basepath,tree_id) mmpb_sublink_id,snaps,mass,mstar,r1,r2,mmpb_sfid,sfr,times,mlpids,bhmdot,bhm = gsu.mmpb_from_tree(tree,sublink_id) time_now = gsu.age_at_snap(this_snap_int) time_latest,time_lastmajor,time_lastminor = mergerfileinfo(snapkey,subfindID) print(time_latest,time_lastmajor,time_lastminor) bhlum = radeff*((u.Msun/u.year)*bhmdot*((1.0e10)/ilh)/(0.978*1.0e9/ilh))*(astropy.constants.c**2) bhlum_lsun = bhlum.to('solLum') bhm_msun = bhm*(1.0e10)/ilh fig=pyplot.figure(figsize=(size*2,size)) pyplot.subplots_adjust(wspace=0.0,hspace=0.0) #mass history plot axi = fig.add_subplot(1,2,1) axi.semilogy(times-time_now,mstar) axi.semilogy(times[bhm_msun > 0]-time_now,bhm_msun[bhm_msun > 0]*2.0e2) axi.legend(['$M_* (t)$','$M_{bh} (t)/200$'],loc='upper left',fontsize=25) axi.plot([0.0,0.0],[1.0e8,1.0e12],marker=None,linestyle='dashed',color='black',linewidth=2.0) if gyrbox is True: axi.plot([time_latest-time_now,time_latest-time_now],[1.0e8,1.0e13],marker=None,linestyle='solid',color='gray',linewidth=1.0) axi.plot([time_latest-time_now-1.0,time_latest-time_now-1.0],[1.0e8,1.0e13],marker=None,linestyle='solid',color='gray',linewidth=1.0) axi.plot([time_lastmajor-time_now,time_lastmajor-time_now],[1.0e8,1.0e13],marker=None,linestyle='solid',color='Red',linewidth=4.0) axi.plot([time_lastminor-time_now,time_lastminor-time_now],[1.0e8,1.0e13],marker=None,linestyle='dotted',color='Red',linewidth=4.0) axi.set_xlim(trange[0],trange[1]) inrange=np.where(np.logical_and(times-time_now > trange[0], times-time_now <= trange[1]))[0] axi.set_ylim(np.min(mstar[inrange])/2.0,np.max(mstar[inrange])*2.0) ls = 25 axi.set_xlabel('$t-t_{obs} (Gyr)$',size=ls) #axi.set_ylabel('$M_* (t)$, $M_{bh} (t)/200$',size=ls) axi.tick_params(axis='both', which='major', labelsize=ls) #image(s?) axi = fig.add_subplot(1,2,2) camstr='{:02d}'.format(camnum) im_snap_keys, im_rf_fil_keys, im_npix = icmp.return_rf_variables() if use_rfkey is True: try: rfkey=im_rf_fil_keys[im_snap_keys==snapkey][0] npix=im_npix[im_snap_keys==snapkey][0] except: rfkey=None npix=400 else: rfkey=None if npix is None: npix=400 axi = showgalaxy.showgalaxy(axi,snapkey,subfindID,camstr,rfkey=rfkey,Npix=npix,alph=alph,Q=Q,sb=sb,filters=filters,dx=dx,dy=dy) if savefile is None: pyplot.show() else: fig.savefig(savefile,dpi=500) pyplot.close(fig) return 0
for s,snapkey in enumerate(snapkeys): print snapkey print morphcat[topkey][snapkey].keys() subfind_id = morphcat[topkey][snapkey]['SubfindID'].value print subfind_id.shape sgrp = grp.create_group(snapkey) sgrp.create_dataset('SubfindID',data=np.int64(subfind_id)) this_snap_treesfid = np.zeros((subfind_id.shape[0],len(snapnums_int)),dtype=np.int64 )-1 latest_snap_treesfid = np.zeros((subfind_id.shape[0]),dtype=np.int64 )-1 print this_snap_treesfid.shape this_snap_int = np.int32(snapkey[-3:]) this_snap_time = gsu.age_at_snap(this_snap_int) latest_time = this_snap_time + merger_span lti = np.where(illcos.ages <= latest_time)[0] latest_i = lti[-1] latest_snap = illcos.snaps[latest_i] if latest_snap==55: latest_snap=56 latest_time = gsu.age_at_snap(latest_snap) print latest_snap, latest_i, latest_time, this_snap_time, this_snap_int for i,sfid in enumerate(subfind_id): existing_line=None if last_sfid_grid is not None: tbi = np.where(last_sfid_grid[:,s]==sfid)[0]
def masshistory(snapkey, subfindID, camnum=0, basepath='/astro/snyder_lab2/Illustris/Illustris-1', size=2, trange=[-1.5, 1.5], gyrbox=True, radeff=0.2, savefile=None, do_bh=False, plot_rfs=False, do_mergers=True, annotation=None, label_redshift=False, bhtime=None, **kwargs): snapnum = snapkey[-3:] this_snap_int = np.int64(snapnum) sublink_id, tree_id, mstar, sfr = gsu.sublink_id_from_subhalo( basepath, this_snap_int, subfindID) tree = gsu.load_full_tree(basepath, tree_id) mmpb_sublink_id, snaps, mass, mstar, r1, r2, mmpb_sfid, sfr, times, mlpids, bhmdot, bhm = gsu.mmpb_from_tree( tree, sublink_id) time_now = gsu.age_at_snap(this_snap_int) time_latest, time_lastmajor, time_lastminor, time_nextmajor, time_nextminor, val = mergerfileinfo( snapkey, subfindID) print(time_lastmajor - time_now, time_lastminor - time_now, time_nextmajor - time_now, time_nextminor - time_now, time_latest, time_now, val) bhlum = radeff * ((u.Msun / u.year) * bhmdot * ((1.0e10) / ilh) / (0.978 * 1.0e9 / ilh)) * (astropy.constants.c**2) bhlum_lsun = bhlum.to('solLum') bhm_msun = bhm * (1.0e10) / ilh fig = pyplot.figure(figsize=(size * 2.05, size), dpi=50) pyplot.subplots_adjust(wspace=0.0, hspace=0.0, top=0.99, right=0.99, left=0.13, bottom=0.16) #mass history plot axi = fig.add_subplot(1, 2, 1) ml, = axi.plot(times - time_now, np.log10(mstar), color='black', lw=4.0) if do_bh is True: bh, = axi.plot(times[bhm_msun > 0] - time_now, np.log10(bhm_msun[bhm_msun > 0] * 2.0e2), color='DodgerBlue', lw=4.0) axi.plot([0.0, 0.0], [6, 15], marker=None, linestyle='solid', color='SlateGray', linewidth=2.0) ''' if gyrbox is True: axi.plot([time_latest-time_now,time_latest-time_now],[8,13],marker=None,linestyle='solid',color='gray',linewidth=1.0) axi.plot([time_latest-time_now-1.0,time_latest-time_now-1.0],[8,13],marker=None,linestyle='solid',color='gray',linewidth=1.0) ''' if do_mergers is True: majm1, = axi.plot([time_lastmajor - time_now], [np.interp(time_lastmajor, times, np.log10(mstar))], marker='o', markeredgecolor='None', markerfacecolor='Red', markersize=24, linestyle='None') majm2, = axi.plot([time_nextmajor - time_now], [np.interp(time_nextmajor, times, np.log10(mstar))], marker='o', markeredgecolor='None', markerfacecolor='Red', markersize=24, linestyle='None') minm1, = axi.plot([time_lastminor - time_now], [np.interp(time_lastminor, times, np.log10(mstar))], marker='o', markeredgecolor='Red', markerfacecolor='White', markersize=12, linestyle='None') minm2, = axi.plot([time_nextminor - time_now], [np.interp(time_nextminor, times, np.log10(mstar))], marker='o', markeredgecolor='Red', markerfacecolor='White', markersize=12, linestyle='None') if bhtime is not None: axi.plot([bhtime - time_now], [ np.interp(bhtime, times[bhm_msun > 0], np.log10(bhm_msun[bhm_msun > 0] * 2.0e2)) ], marker='o', markeredgecolor='None', markerfacecolor='DodgerBlue', markersize=24, linestyle='None') #majm1,=axi.plot([time_lastmajor-time_now,time_lastmajor-time_now],[8,13],marker=None,linestyle='solid',color='Red',linewidth=4.0) #minm1,=axi.plot([time_lastminor-time_now,time_lastminor-time_now],[8,13],marker=None,linestyle='dotted',color='Red',linewidth=4.0) #majm2,=axi.plot([time_nextmajor-time_now,time_nextmajor-time_now],[8,13],marker=None,linestyle='solid',color='Red',linewidth=4.0) #minm2,=axi.plot([time_nextminor-time_now,time_nextminor-time_now],[8,13],marker=None,linestyle='dotted',color='Red',linewidth=4.0) ''' if do_bh is True: axi.legend((ml,bh,majm,minm),['$log_{10} M_* (t)$','$log_{10} M_{bh} (t) x200$','last major','last minor'],loc='upper left',fontsize=18) else: axi.legend((ml,majm,minm),['$log_{10} M_* (t)$','last major','last minor'],loc='upper left',fontsize=18) ''' if do_mergers is True: axi.legend( (majm1, minm1), ['$M_{2}/M_{1} \geq 0.25$', '$0.25 \geq M_{2}/M_{1} \geq 0.1$'], loc='upper left', fontsize=18) axi.set_xlim(trange[0], trange[1]) inrange = np.where( np.logical_and(times - time_now > trange[0], times - time_now <= trange[1]))[0] if plot_rfs is True: ts_past500 = -0.5 ts_for500 = 0.0 ts_past250 = -0.25 ts_for250 = 0.0 ts_win500 = -0.25 te_past500 = 0.0 te_for500 = 0.5 te_past250 = 0.0 te_for250 = 0.25 te_win500 = 0.25 #past500 = patches.FancyBboxPatch((ts_past500,np.min(mstar[inrange])/1.9),te_past500-ts_past500,1.0e9,transform=axi.transData,boxstyle='round,pad=0.0,rounding_size=0.5') #axi.add_patch(past500) yb = np.log10(np.min(mstar[inrange]) / 1.9) yd = 0.1 #rftimehelper(axi,ts_past500,te_past500,yb,yd,'-500Myr') #rftimehelper(axi,ts_for500,te_for500,yb,yd,'+500Myr') #rftimehelper(axi,ts_past250,te_past250,yb+yd,yd,'-250Myr',fs=14) rftimehelper(axi, ts_for250, te_for250, yb + yd, yd, '+250Myr', fs=14) rftimehelper(axi, ts_win500, te_win500, yb + 2 * yd, yd, '+/-250Myr', fs=14) if do_bh is False: ylim_lo = np.log10(np.min(mstar[inrange]) / 2.0) ylim_hi = np.log10(np.max(mstar[inrange]) * 2.0) else: ylim_lo = np.log10( np.min(200.0 * bhm_msun[inrange][bhm_msun[inrange] > 0]) / 1.5) ylim_hi = np.log10(np.max(mstar[inrange]) * 8.0) ylim_lo = max([6.0, ylim_lo]) ylim_hi = min([ylim_hi, 13.0]) axi.set_ylim(ylim_lo, ylim_hi) if annotation is not None: axi.annotate(annotation, (0.0, ylim_hi - 0.05 * (ylim_hi - ylim_lo)), xycoords='data', fontsize=25, ha='center', va='top', bbox=dict(boxstyle='round', fc="white", ec="DodgerBlue", lw=2.0)) if do_mergers is True: shade = patches.Rectangle((-0.25, ylim_lo), 0.50, ylim_hi - ylim_lo, color='Silver', alpha=0.5, zorder=1) axi.add_patch(shade) ls = 25 axi.set_xlabel('$t-t_{obs} (Gyr)$', size=ls) if do_bh is False: axi.set_ylabel('$M_* (t)$', size=ls) else: multicolor_ylabel(axi, ('$M_*$ ', '$200\ M_{BH}$'), ('black', 'blue'), axis='y', size=ls + 5, weight='bold') #axi.set_ylabel('$M_*$,'+r' \textcolor{blue}{$200M_{BH}$}',size=ls) axi.tick_params(axis='both', which='major', labelsize=ls) axi.locator_params(nbins=4, prune='both') #image(s?) axi2 = fig.add_subplot(1, 2, 2) camstr = '{:02d}'.format(camnum) ''' im_snap_keys, im_rf_fil_keys, im_npix = icmp.return_rf_variables() if use_rfkey is True: try: rfkey=im_rf_fil_keys[im_snap_keys==snapkey][0] npix=im_npix[im_snap_keys==snapkey][0] except: rfkey=None npix=400 else: rfkey=None if npix is None: npix=400 ''' axi2, rgbt, pixas, headers_rgb = showgalaxy.showgalaxy( axi2, snapkey, subfindID, camstr, **kwargs) if label_redshift is True: axi2.annotate('z= {:5.2f}'.format( gsu.redshift_from_snapshot(int(snapkey[-3:]))), (0.5, 0.85), ha='center', xycoords='axes fraction', color='white', fontsize=ls) axi2.annotate('AB mag = {:4.2f}'.format(headers_rgb[0]['SUNAPMAG']), (0.5, 0.10), ha='center', xycoords='axes fraction', color='white', fontsize=ls) if savefile is not None: fig.savefig(savefile, dpi=50) else: pyplot.show() pyplot.close(fig) return 0