コード例 #1
0
def _primordial(grid=[]):
    """
    Builds a list of all BHs in bianry systems, in order to search for BHs in primordial binary systems
    """
    if grid == []:
        grid = _get_grid()
    IC = {}
    for sim_index, sim_type in enumerate(grid):
        sim_type_list = subprocess.Popen(
            'ls bev.82.short{0}*'.format(sim_type),
            shell=True,
            stdout=subprocess.PIPE)
        stdout, stderr = sim_type_list.communicate()
        stdout = stdout.split()
        stdout = list(set(stdout))
        data = {}
        IC[sim_type] = {}
        for sim in stdout:
            BHBH_set = set()
            bevData, meta = ip.bh_data('bev.82', [0, 1, 2, 3, 4],
                                       meta_data={},
                                       info=sim.split('short')[-1])
            for val in bevData:
                if (val[3] == 14):
                    BHBH_set.add(val[1])
                if (val[4] == 14):
                    BHBH_set.add(val[2])
            IC[sim_type][sim] = BHBH_set
    return IC
コード例 #2
0
def massDist(saveLocation='', inf='', to_return=False):
    """
    Plots the the mass distribution of black holes from the various simulation snapshots as color-coded CDFs
    'saveLocation' is the folder in which to save the plots
    'inf' is the the suffix for the relevant shortfiles (usually the simulation name, e.g. 'N10K_r10_Z01_1')
    'to_return' set to true if instead of ploting the data, return it instead
    """
    if not saveLocation == '':
        if not os.path.exists(saveLocation):
            os.makedirs(saveLocation)
    sevData, meta = ip.bh_data('sev.83', [0, 3], meta_data={}, info=inf)
    bevData, meta = ip.bh_data('bev.82', [0, 3, 4, 9, 10],
                               meta_data=meta,
                               info=inf)
    hiData, meta = ip.bh_data('hidat.87', [0, 4, 5, 6, 7, 8, 9],
                              meta_data=meta,
                              info=inf)
    mass = {}
    for val in sevData:
        if not val[0] in mass:
            mass[val[0]] = {'sBH': [], 'bBH': [], 'tBH': []}
        mass[val[0]]['sBH'].append(val[1])
    for val in bevData:
        if not val[0] in mass:
            mass[val[0]] = {'sBH': [], 'bBH': [], 'tBH': []}
        if val[1] == 14:
            mass[val[0]]['bBH'].append(val[3])
        if val[2] == 14:
            mass[val[0]]['bBH'].append(val[4])
    for val in hiData:
        if not val[0] in mass:
            mass[val[0]] = {'sBH': [], 'bBH': [], 'tBH': []}
        if val[1] == 14:
            mass[val[0]]['tBH'].append(val[4])
        if val[2] == 14:
            mass[val[0]]['tBH'].append(val[5])
        if val[3] == 14:
            mass[val[0]]['tBH'].append(val[6])
    if to_return:
        return (mass)
    all_keys = list(mass.keys())
    all_keys.sort()
    mass_keys = []
    for key in all_keys:
        non_zero = False
        for sub_key in mass[key]:
            if mass[key][sub_key] != []:
                non_zero = True
        if non_zero:
            mass_keys.append(key)
    plt.figure(1)
    colormap = plt.cm.coolwarm
    plt.gca().set_prop_cycle(
        cycler('color',
               [colormap(i) for i in np.linspace(0, 0.9, len(mass_keys))]))
    plt.figure(2)
    plt.gca().set_prop_cycle(
        cycler('color',
               [colormap(i) for i in np.linspace(0, 0.9, len(mass_keys))]))
    plt.figure(3)
    plt.hold(True)
    plt.gca().set_prop_cycle(
        cycler('color',
               [colormap(i) for i in np.linspace(0, 0.9, len(mass_keys))]))
    b_max_key = 0
    b_min_key = -1
    s_max_key = 0
    s_min_key = -1
    started = False
    for i, key in enumerate(mass_keys):
        tBH = mass[key]['sBH'] + mass[key]['bBH'] + mass[key]['tBH']
        tBH.sort()
        mass[key]['sBH'].sort()
        mass[key]['bBH'].sort()
        sBH_tot = _buildFraction(mass[key]['sBH'])
        bBH_tot = _buildFraction(mass[key]['bBH'])
        tBH_tot = _buildFraction(tBH)
        plt.figure(1)
        sBH_plot, = plt.step(([0] + mass[key]['sBH']), ([0] + sBH_tot),
                             where='post')
        plt.figure(2)
        bBH_plot, = plt.step(([0] + mass[key]['bBH']), ([0] + bBH_tot),
                             where='post')
        plt.figure(3)
        tBH_plot, = plt.step(([0] + tBH), ([0] + tBH_tot), where='post')
        if not started:
            tBH_pi = tBH_plot
        if (b_min_key == -1) and (mass[key]['bBH'] != []):
            b_min_key = key
            started = True
            bBH_pi = bBH_plot
        if (s_min_key == -1) and (mass[key]['sBH'] != []):
            s_min_key = key
            started = True
            sBH_pi = sBH_plot
        if started:
            if (b_min_key != -1) and (mass[key]['bBH'] != []):
                b_max_key = key
                bBH_pf = bBH_plot
                tBH_pf = tBH_plot
            if (s_min_key != -1) and (mass[key]['sBH'] != []):
                s_max_key = key
                sBH_pf = sBH_plot
                tBH_pf = tBH_plot
    plt.figure(4)
    Z = [[0, 0], [0, 0]]
    levels = range(int(s_min_key), int(s_max_key), 5)
    print('levels range: ', int(b_min_key), int(b_max_key))
    CS3 = plt.contourf(Z, levels, cmap=colormap)
    plt.clf()
    plt.figure(1)
    x1, x2, y1, y2 = plt.axis()
    plt.axis([x1, x2, 0, 1.1])
    plt.colorbar(CS3)
    plt.title('Single Black Hole Mass CDF')
    plt.xlabel('Black Hole Mass (M*)')
    plt.ylabel('Mass Fraction')
    plt.savefig((saveLocation + 'sBH_massFraction.png'))
    plt.figure(4)
    levels = range(int(b_min_key), int(b_max_key), 5)
    print('levels range: ', int(b_min_key), int(b_max_key))
    CS3 = plt.contourf(Z, levels, cmap=colormap)
    plt.clf()
    plt.figure(2)
    x1, x2, y1, y2 = plt.axis()
    plt.axis([x1, x2, 0, 1.1])
    plt.colorbar(CS3)
    plt.title('Binary Black Hole Mass CDF')
    plt.xlabel('Black Hole Mass (M*)')
    plt.ylabel('Mass Fraction')
    plt.savefig((saveLocation + 'bBH_massFraction.png'))
    plt.figure(4)
    levels = range(int(min(s_min_key, b_min_key)),
                   int(max(s_max_key, b_max_key)), 5)
    print('levels range: ', int(b_min_key), int(b_max_key))
    CS3 = plt.contourf(Z, levels, cmap=colormap)
    plt.clf()
    plt.figure(3)
    x1, x2, y1, y2 = plt.axis()
    plt.axis([x1, x2, 0, 1.1])
    plt.colorbar(CS3)
    plt.title('Total Black Hole Mass CDF')
    plt.xlabel('Black Hole Mass (M*)')
    plt.ylabel('Mass Fraction')
    plt.savefig((saveLocation + 'tBH_massFraction.png'))
    plt.close('all')
コード例 #3
0
def metaBinary(saveLocation='', All=True, BH=True, inf='', to_return=False):
    """
    Plots binary frequency over time
    'saveLocation' is the folder in which to save the plots
    'All' True to plot binary fraction for all objects
    'BH' True to plot binary fraction for black holes only
    'inf' is the the suffix for the relevant shortfiles (usually the simulation name, e.g. 'N10K_r10_Z01_1')
    'to_return' set to true if instead of ploting the data, return it instead
    """
    if not saveLocation == '':
        if not os.path.exists(saveLocation):
            os.makedirs(saveLocation)
    sevData, meta = ip.bh_data('sev.83', [0], meta_data={}, info=inf)
    bevData, meta = ip.bh_data('bev.82', [0, 3, 4], meta_data=meta, info=inf)
    if to_return:
        return (meta, sevData, bevData)
    if All:
        timeList = []
        AllRatio = []
        time_key_list = meta.keys()
        time_key_list.sort()
        for time in time_key_list:
            if ('singles' in meta[time]) and ('binaries' in meta[time]):
                timeList.append(time)
                ratio = float(meta[time]['binaries']) / (
                    meta[time]['binaries'] + meta[time]['singles'] + 0.001)
                AllRatio.append(ratio)
        plt.figure()
        plt.plot(timeList, AllRatio, '-')
        plt.title('Binary Frequency Over Time')
        plt.xlabel('Physical Time (MY)')
        plt.ylabel('Binary Frequency')
        plt.savefig((saveLocation + 'AllBinary.png'))
    if BH:
        count = {}
        for val in sevData:
            if not val[0] in count:
                count[val[0]] = {'singles': 0, 'binaries': 0}
            count[val[0]]['singles'] += 1
        for val in bevData:
            if not val[0] in count:
                count[val[0]] = {'singles': 0, 'binaries': 0}
            if val[1] == 14:
                count[val[0]]['binaries'] += 1
            if val[2] == 14:
                count[val[0]]['binaries'] += 1
        timeList = []
        BHRatio = []
        key_list = count.keys()
        key_list.sort()
        for time in key_list:
            timeList.append(time)
            ratio = float(count[time]['binaries']) / (
                count[time]['binaries'] + count[time]['singles'] + 0.001)
            BHRatio.append(ratio)
        plt.figure()
        plt.plot(timeList, BHRatio, '-')
        plt.title('Black Hole Binary Frequency Over Time')
        plt.xlabel('Physical Time (MY)')
        plt.ylabel('Black Hole Binary Frequency')
        plt.xscale('log')
        plt.savefig((saveLocation + 'BHBinary.png'))
    plt.close('all')
コード例 #4
0
def metaGen(saveLocation='',
            RC=True,
            RSCALE=True,
            TotalN=True,
            NC=True,
            inf='',
            to_return=False):
    """
    Plots general cluster information over time
    'saveLocation' is the folder in which to save the plots
    'RC' True to plot core radius over time
    'RSCALE' True to plot half-mass radius over time
    'TotalN' True to plot total objects in the cluster over time
    'NC' True to plot objects in cluster core over time
    'inf' is the the suffix for the relevant shortfiles (usually the simulation name, e.g. 'N10K_r10_Z01_1')
    'to_return' set to true if instead of ploting the data, return it instead
    """
    if not saveLocation == '':
        if not os.path.exists(saveLocation):
            os.makedirs(saveLocation)
    sevData, meta = ip.bh_data('sev.83', [], meta_data={}, info=inf)
    bevData, meta = ip.bh_data('bev.82', [], meta_data=meta, info=inf)
    timeList = []
    RCList = []
    RSCALEList = []
    singleList = []
    binaryList = []
    TotalNList = []
    NCList = []
    time_key_list = meta.keys()
    time_key_list.sort()
    for time in time_key_list:
        if ('singles' in meta[time]) and ('binaries' in meta[time]):
            timeList.append(time)
            if RC:
                RCList.append(meta[time]['RC'])
            if RSCALE:
                RSCALEList.append(meta[time]['RSCALE'])
            if TotalN:
                singleList.append(meta[time]['singles'])
                binaryList.append(meta[time]['binaries'])
                TotalNList.append(
                    (meta[time]['singles'] + meta[time]['binaries']))
            if NC:
                NCList.append((meta[time]['NC']))
    if to_return:
        return (timeList, RCList, RSCALEList, singleList, binaryList,
                TotalNList)
    if RC:
        plt.figure()
        plt.plot(timeList, RCList, '-')
        plt.title('Core Radius Over Time')
        plt.xlabel('Physical Time (MY)')
        plt.ylabel('Core Radius (N-body Units)')
        plt.xscale('log')
        RCnumpy = np.array(map(float, RCList))
        RCavg = np.mean(RCnumpy)
        RCstd = np.std(RCnumpy)
        plt.ylim(0, min((RCavg + 3 * RCstd), plt.ylim()[1]))
        plt.savefig((saveLocation + 'RCTime.png'))
        plt.close('all')
    if RSCALE:
        plt.figure()
        plt.plot(timeList, RSCALEList, '-')
        plt.title('Half-mass Radius Over Time')
        plt.xlabel('Physical Time (MY)')
        plt.ylabel('Half-mass Radius (N-body Units)')
        plt.xscale('log')
        RSCALEnumpy = np.array(map(float, RSCALEList))
        RSavg = np.mean(RSCALEnumpy)
        RSstd = np.std(RSCALEnumpy)
        plt.ylim(0, min((RSavg + 3 * RSavg), plt.ylim()[1]))
        plt.savefig((saveLocation + 'RSCALETime.png'))
        plt.close('all')
    if TotalN:
        plt.figure()
        plt.plot(timeList, singleList, '-')
        plt.plot(timeList, binaryList, '-')
        plt.plot(timeList, TotalNList, '-')
        plt.title('Number of Stars in System Over Time')
        plt.xlabel('Physical Time (MY)')
        plt.ylabel('Star Count')
        plt.xscale('log')
        plt.legend(['Singles', 'Binaries', 'Total'], loc='best')
        plt.savefig((saveLocation + 'TotalNTime.png'))
        plt.close('all')
    if NC:
        plt.figure()
        plt.plot(timeList, NCList, '-')
        plt.title('Number of Stars in Core Over Time')
        plt.xlabel('Physical Time (MY)')
        plt.ylabel('Star Count in Core')
        plt.xscale('log')
        plt.savefig((saveLocation + 'CoreNTime.png'))
        plt.close('all')
    plt.close('all')
コード例 #5
0
def binaryStats(saveLocation='',
                ECC=True,
                PB=True,
                SEMI=True,
                hist=False,
                numBins=100,
                inf='',
                to_return=False):
    """
    Plots statistics of binary black hoels orbits from the various snapshots as color coded CDFs
    'saveLocation' is the folder in which to save the plots
    'ECC' True to plot eccentricity
    'PB' True to plot orbital period
    'SEMI' True to plot orbital semi-major axis
    'hist' True to plot an idividual histogram for each snapshot (WARNING: very slow)
    'numBins' to set the number of bins if 'hist' is True
    'inf' is the the suffix for the relevant shortfiles (usually the simulation name, e.g. 'N10K_r10_Z01_1')
    'to_return' set to true if instead of ploting the data, return it instead
    """
    if not saveLocation == '':
        if not os.path.exists(saveLocation):
            os.makedirs(saveLocation)
    columns = [0]
    indicies = [1, 1, 1]
    if ECC:
        columns = columns + [6]
        indicies[1] += 1
        indicies[2] += 1
    if PB:
        columns = columns + [7]
        indicies[2] += 1
    if SEMI:
        columns = columns + [8]
    bevData, meta = ip.bh_data('bev.82', columns, meta_data={}, info=inf)
    stats = {}
    for val in bevData:
        if not val[0] in stats:
            stats[val[0]] = {'ECC': [], 'PB': [], 'SEMI': []}
        if ECC:
            stats[val[0]]['ECC'].append(val[indicies[0]])
        if PB:
            stats[val[0]]['PB'].append(val[indicies[1]])
        if SEMI:
            stats[val[0]]['SEMI'].append(val[indicies[2]])
    if to_return:
        return (stats)
    all_keys = list(stats.keys())
    all_keys.sort()
    stats_keys = []
    for key in all_keys:
        non_zero = False
        for sub_key in stats[key]:
            if stats[key][sub_key] != []:
                non_zero = True
        if non_zero:
            stats_keys.append(key)
    plt.figure(1)
    colormap = plt.cm.coolwarm
    plt.gca().set_prop_cycle(
        cycler('color',
               [colormap(i) for i in np.linspace(0, 0.9, len(stats))]))
    plt.figure(2)
    plt.gca().set_prop_cycle(
        cycler('color',
               [colormap(i) for i in np.linspace(0, 0.9, len(stats))]))
    plt.figure(3)
    plt.hold(True)
    plt.gca().set_prop_cycle(
        cycler('color',
               [colormap(i) for i in np.linspace(0, 0.9, len(stats))]))
    for i, key in enumerate(stats_keys):
        temp_AU_list = []
        for item in stats[key]['SEMI']:
            AU = (10.0**item) * 0.00465047
            temp_AU_list.append(math.log10(AU))
        stats[key]['SEMI'] = temp_AU_list
        stats[key]['ECC'].sort()
        stats[key]['PB'].sort()
        stats[key]['SEMI'].sort()
        ECC_tot = _buildFraction(stats[key]['ECC'])
        PB_tot = _buildFraction(stats[key]['PB'])
        SEMI_tot = _buildFraction(stats[key]['SEMI'])
        if ECC:
            plt.figure(1)
            ECC_plot, = plt.step(([0] + stats[key]['ECC']), ([0] + ECC_tot),
                                 where='post')
        if PB:
            plt.figure(2)
            PB_plot, = plt.step(([0] + stats[key]['PB']), ([0] + PB_tot),
                                where='post')
        if SEMI:
            plt.figure(3)
            SEMI_plot, = plt.step(([0] + stats[key]['SEMI']), ([0] + SEMI_tot),
                                  where='post')
        if i == 0:
            if ECC:
                ECC_pi = ECC_plot
            if PB:
                PB_pi = PB_plot
            if SEMI:
                SEMI_pi = SEMI_plot
        if i == (len(stats_keys) - 1):
            if ECC:
                ECC_pf = ECC_plot
            if PB:
                PB_pf = PB_plot
            if SEMI:
                SEMI_pf = SEMI_plot
    min_key = stats_keys[0]
    max_key = stats_keys[-1]
    if ECC:
        plt.figure(5)
        Z = [[0, 0], [0, 0]]
        levels = range(int(min_key), int(max_key), 5)
        CS3 = plt.contourf(Z, levels, cmap=colormap)
        plt.clf()
        plt.figure(1)
        x1, x2, y1, y2 = plt.axis()
        plt.axis([x1, x2, 0, 1.1])
        plt.colorbar(CS3)
        plt.title('Binary Black Hole Eccentricity CDF')
        plt.xlabel('Eccentricity')
        plt.ylabel('Eccentricity Fraction')
        plt.savefig((saveLocation + 'ECC.png'))
    if PB:
        plt.figure(5)
        Z = [[0, 0], [0, 0]]
        levels = range(int(min_key), int(max_key), 5)
        CS3 = plt.contourf(Z, levels, cmap=colormap)
        plt.clf()
        plt.figure(2)
        x1, x2, y1, y2 = plt.axis()
        plt.axis([x1, x2, 0, 1.1])
        plt.colorbar(CS3)
        plt.title('Binary Black Hole Period CDF')
        plt.xlabel('Log_10( Period (days))')
        plt.ylabel('Period Fraction')
        plt.savefig((saveLocation + 'PB.png'))

        time = []
        max = []
        mean = []
        median = []
        mode = []
        min = []
        key_list = stats.keys()
        key_list.sort()
        for key in key_list:
            npList = np.asarray(stats[key]['PB'])
            modeList = scipy.stats.mode(npList).mode
            for i in range(len(modeList)):
                time.append(key)
                max.append(np.amax(npList))
                mean.append(np.mean(npList))
                median.append(np.median(npList))
                mode.append(modeList[i])
                min.append(np.amin(npList))
        plt.figure(4)
        plt.plot(time, max, '-')
        plt.plot(time, mean, '-')
        plt.plot(time, median, '-')
        plt.plot(time, mode, '-')
        plt.plot(time, min, '-')
        plt.legend(['Max', 'Mean', 'Median', 'Mode', 'Min'])
        plt.title('Black Hole Binary Statistics Over Time')
        plt.xlabel('Physical Time (MY)')
        plt.ylabel('Log_10( Period (days))')
        plt.savefig((saveLocation + 'bBH_PBStats.png'))
    if SEMI:
        plt.figure(5)
        Z = [[0, 0], [0, 0]]
        levels = range(int(min_key), int(max_key), 5)
        CS3 = plt.contourf(Z, levels, cmap=colormap)
        plt.clf()
        plt.figure(3)
        x1, x2, y1, y2 = plt.axis()
        plt.axis([x1, x2, 0, 1.1])
        plt.colorbar(CS3)
        plt.title('Binary Black Hole Semi-major Axis CDF')
        plt.xlabel('Log_10( Semi-major Axis (Au))')
        plt.ylabel('Semi-major Axis Fraction')
        plt.savefig((saveLocation + 'SEMI.png'))
    plt.close('all')
    if hist:
        if ECC:
            for time in stats:
                plt.figure()
                n, bins, patches = plt.hist(stats[time]['ECC'],
                                            numBins,
                                            normed=False,
                                            histtype='bar',
                                            rwidth=1)
                plt.title(
                    'Eccentricity Distribution of Black Hole Binaries: {0} MY'.
                    format(time))
                plt.xlabel('Eccentricity')
                plt.ylabel('N')
                plt.savefig((saveLocation + 'ECC.{0}MY.png'.format(time)))
                plt.close('all')
        if PB:
            for time in stats:
                plt.figure()
                n, bins, patches = plt.hist(stats[time]['PB'],
                                            numBins,
                                            normed=False,
                                            histtype='bar',
                                            rwidth=1)
                plt.title('Period Distribution of Black Hole Binaries: {0} MY'.
                          format(time))
                plt.xlabel('Log_10( Period (days))')
                plt.ylabel('N')
                plt.savefig((saveLocation + 'PB.{0}MY.png'.format(time)))
                plt.close('all')
        if SEMI:
            for time in stats:
                plt.figure()
                n, bins, patches = plt.hist(stats[time]['SEMI'],
                                            numBins,
                                            normed=False,
                                            histtype='bar',
                                            rwidth=1)
                plt.title(
                    'Semi-major Axis Distribution of Black Hole Binaries: {0} MY'
                    .format(time))
                plt.xlabel('Log_10( Semi-major Axis (Au))')
                plt.ylabel('N')
                plt.savefig((saveLocation + 'SEMI.{0}MY.png'.format(time)))
                plt.close('all')
    plt.close('all')
コード例 #6
0
def blackHoleOverTime(saveLocation='', inf='', to_return=False):
    """
    Plots the various counts of black holes over time for a given simulation
    'saveLocation' is the folder in which to save the plots
    'inf' is the the suffix for the relevant shortfiles (usually the simulation name, e.g. 'N10K_r10_Z01_1')
    'to_return' set to true if instead of ploting the data, return it instead
    """
    if not saveLocation == '':
        if not os.path.exists(saveLocation):
            os.makedirs(saveLocation)
    sevData, meta = ip.bh_data('sev.83', [0, 2], meta_data={}, info=inf)
    bevData, meta = ip.bh_data('bev.82', [0, 3, 4], meta_data=meta, info=inf)
    hiData, meta = ip.bh_data('hidat.87', [0, 4, 5, 6],
                              meta_data=meta,
                              info=inf)
    escData, meta = ip.bh_data('esc.11', [0, 4], meta_data=meta, info=inf)
    count = {}
    for val in sevData:
        if not val[0] in count:
            count[val[0]] = {'sBH': 0, 'bBH': 0, 'tBH': 0, 'eBH': 0}
        if val[1] == 14:
            count[val[0]]['sBH'] += 1
    for val in bevData:
        if not val[0] in count:
            count[val[0]] = {'sBH': 0, 'bBH': 0, 'tBH': 0, 'eBH': 0}
        if val[1] == 14:
            count[val[0]]['bBH'] += 1
        if val[2] == 14:
            count[val[0]]['bBH'] += 1
    for val in hiData:
        if not val[0] in count:
            count[val[0]] = {'sBH': 0, 'bBH': 0, 'tBH': 0, 'eBH': 0}
        if val[1] == 14:
            count[val[0]]['tBH'] += 1
        if val[2] == 14:
            count[val[0]]['tBH'] += 1
        if val[3] == 14:
            count[val[0]]['tBH'] += 1
    for val in escData:
        if not val[0] in count:
            count[val[0]] = {'sBH': 0, 'bBH': 0, 'tBH': 0, 'eBH': 0}
        if val[1] == 14:
            count[val[0]]['eBH'] += 1
    time = []
    sBH = []
    bBH = []
    tBH = []
    eBH = []
    totBH = []
    key_list = count.keys()
    key_list.sort()
    for key in key_list:
        time.append(key)
        sBH.append(count[key]['sBH'])
        bBH.append(count[key]['bBH'])
        tBH.append(count[key]['tBH'])
        eBH.append(count[key]['eBH'])
        totBH.append(count[key]['sBH'] + count[key]['bBH'] +
                     count[key]['tBH'] + count[key]['eBH'])
    if to_return:
        return (time, sBH, bBH, tBH, eBH, totBH)
    plt.figure()
    plt.hold(True)
    plt.plot(time, sBH, '-')
    plt.plot(time, bBH, '-')
    plt.plot(time, tBH, '-')
    plt.plot(time, eBH, '-')
    plt.plot(time, totBH, '-')
    plt.title('Black Hole Count Over Time')
    plt.xlabel('Physical Time (MY)')
    plt.ylabel('N')
    plt.legend(
        ['Single BH', 'Binary BH', 'Triple BH', 'Escape BH', 'Total BH'],
        loc='best')
    plt.savefig((saveLocation + 'blackHoleCount.png'))
    plt.close('all')
コード例 #7
0
def grid_BHpartner(saveLocation='', grid=[], num_bins=0):
    """
    Gathers and plots a ratio of BHBH binaries to BH-other binaries over time for an entire grid.
    Bins the data for groups of simulations with the same initial conditions (e.g. 'N10K_r10_Z01_1' and 'N10K_r10_Z01_2', etc)
    saveLocation designates where to save the plots
    Grid allows the user to pass a list of simulations to include. Will run _get_grid() otherwise.
    num_bins specifies the number of bins to use for each set of initial conditions. Will place approx. 5 data points per bin otherwise
    Calls _get_grid(), ip.bh_data()
    """
    if grid == []:
        grid = _get_grid()
    legend = []
    for sim_index, sim_type in enumerate(grid):
        legend.append(sim_type)
        sim_type_list = subprocess.Popen(
            'ls bev.82.short{0}*'.format(sim_type),
            shell=True,
            stdout=subprocess.PIPE)
        stdout, stderr = sim_type_list.communicate()
        stdout = stdout.split()
        stdout = list(set(stdout))
        data = {}
        for sim in stdout:
            bevData, meta = ip.bh_data('bev.82', [0, 3, 4],
                                       meta_data={},
                                       info=sim.split('short')[-1])
            for val in bevData:
                if not val[0] in data:
                    data[val[0]] = [0, 0]
                if (val[1] == 14) and (val[2] == 14):
                    data[val[0]][0] = data[val[0]][0] + 1
                else:
                    data[val[0]][1] = data[val[0]][1] + 1
        if num_bins == 0:
            avg_sim_len = float(len(time_list)) / len(stdout)
            num_bins = int(avg_sim_len / 30)
        time_bins = []
        BHBH_bins = []
        BHO_bins = []
        keys = data.keys()
        keys.sort()
        for i in range(num_bins):
            time_bins.append([])
            BHBH_bins.append([])
            BHO_bins.append([])
        bin_min = min(keys)
        bin_cutoffs = [0] * num_bins
        dtime = float((max(keys)) - min(keys)) / num_bins
        for i in range(len(bin_cutoffs)):
            bin_cutoffs[i] = bin_min + ((i + 1) * dtime)
        for time in keys:
            for j, cutoff in enumerate(bin_cutoffs):
                if time < cutoff:
                    time_bins[j].append(time)
                    BHBH_bins[j].append(data[time][0])
                    BHO_bins[j].append(data[time][1])
                    break
        ratio_bins = []
        for i in range(len(time_bins)):
            time_bins[i] = bin_cutoffs[i] - (float(dtime) / 2)
            ratio_bins.append(
                float(sum(BHBH_bins[i])) /
                (sum(BHBH_bins[i]) + sum(BHO_bins[i]) + 0.000001))
        plt.plot(time_bins, ratio_bins)
    plt.title('BH Binary Partner Ratio')
    plt.ylabel('BHBH Binary Ratio')
    plt.xlabel('Physical Time (Myr)')
    plt.legend(legend, loc=0)
    plt.savefig((saveLocation + 'gridBHBHpartner.png'))
    plt.close('all')
コード例 #8
0
def grid_minSEMI(saveLocation='',
                 num_bins=0,
                 grid=[],
                 return_min_inspiral=False,
                 inspiral_cutoff=0.001):
    """
    Gathers and plots the minimum semi-major axis of a binary system with at least one black hole over time for an entire grid.
    Caclulates the corresponding inspiral time using Peter's equation. Code found in inspiral.py
    Bins the data for groups of simulations with the same initial conditions (e.g. 'N10K_r10_Z01_1' and 'N10K_r10_Z01_2', etc)
    saveLocation designates where to save the plots
    Grid allows the user to pass a list of simulations to include. Will run _get_grid() otherwise.
    num_bins specifies the number of bins to use for each set of initial conditions. Will place approx. 5 data points per bin otherwise
    Calls _get_grid(), ip.bh_data(), inspiral.inspiral_time_peters()
    """
    plt.close('all')
    if grid == []:
        grid = _get_grid()
    legend = []
    semis = []
    eccens = []
    m1s = []
    m2s = []
    times = []
    plt.figure(1)
    plt.figure(2)
    color_list = ['b', 'g', 'r', 'c', 'm', 'y', 'k']
    BHBH_names = {}
    for sim_index, sim_type in enumerate(grid):
        legend.append(sim_type)
        sim_type_list = subprocess.Popen(
            'ls bev.82.short{0}*'.format(sim_type),
            shell=True,
            stdout=subprocess.PIPE)
        stdout, stderr = sim_type_list.communicate()
        stdout = stdout.split()
        stdout = list(set(stdout))
        data = {}
        for sim in stdout:
            BHBH_names[sim.split('short')[-1]] = []
            bevData, meta = ip.bh_data('bev.82', [0, 3, 4, 6, 8, 9, 10, 1, 2],
                                       meta_data={},
                                       info=sim.split('short')[-1])
            for val in bevData:
                if (val[1] == 14) and (val[2] == 14):
                    if not val[0] in data:
                        data[val[0]] = []
                    data[val[0]].append(
                        (val[4], val[3], val[5], val[6], val[7], val[8],
                         sim.split('short')[-1]))
        inspiral_time_list = []
        inspiral_list = []
        for key in data:
            inspirals = []
            for binary in data[key]:
                if binary[1] < 1.0:
                    print(binary)
                    it = inspiral.inspiral_time_peters(binary[0], binary[1],
                                                       binary[2], binary[3])
                    inspirals.append(it)
                    if it < inspiral_cutoff:
                        BHBH_names[binary[6]].append(int(binary[4]))
                        BHBH_names[binary[6]].append(int(binary[5]))
            if inspirals != []:
                print('inspiral found')
                inspiral_time_list.append(key)
                inspiral_list.append(min(inspirals))
        for sim in BHBH_names:
            BHBH_names[sim] = list(set(BHBH_names[sim]))
        plt.figure(1)
        plt.plot(inspiral_time_list, inspiral_list)
        plt.figure(2)
        for key in data:
            data[key] = min(data[key])
        if num_bins == 0:
            avg_sim_len = float(len(time_list)) / len(stdout)
            num_bins = int(avg_sim_len / 30)
        time_bins = []
        semi_bins = []
        ecc_bins = []
        m1_bins = []
        m2_bins = []
        keys = data.keys()
        keys.sort()
        for i in range(num_bins):
            time_bins.append([])
            semi_bins.append([])
            ecc_bins.append([])
            m1_bins.append([])
            m2_bins.append([])
        bin_min = min(keys)
        bin_cutoffs = [0] * num_bins
        dtime = float((max(keys)) - min(keys)) / num_bins
        for i in range(len(bin_cutoffs)):
            bin_cutoffs[i] = bin_min + ((i + 1) * dtime)
        for time in keys:
            for j, cutoff in enumerate(bin_cutoffs):
                if time < cutoff:
                    time_bins[j].append(time)
                    semi_bins[j].append(data[time][0])
                    ecc_bins[j].append(data[time][1])
                    m1_bins[j].append(data[time][2])
                    m2_bins[j].append(data[time][3])
                    break
        for i in range(len(time_bins)):
            time_bins[i] = bin_cutoffs[i] - (float(dtime) / 2)
            if semi_bins[i] == []:
                semi_bins[i] = semi_bins[i - 1]
                ecc_bins[i] = ecc_bins[i - 1]
                m1_bins[i] = m1_bins[i - 1]
                m2_bins[i] = m2_bins[i - 1]
            else:
                Rstar = min(semi_bins[i])
                min_index = semi_bins[i].index(Rstar)
                ecc_bins[i] = ecc_bins[i][min_index]
                m1_bins[i] = m1_bins[i][min_index]
                m2_bins[i] = m2_bins[i][min_index]
                AU = (10**Rstar) * 0.00465047
                semi_bins[i] = math.log10(AU)
        plt.plot(time_bins, semi_bins, color=color_list[sim_index])
        semis.append(semi_bins)
        eccens.append(ecc_bins)
        m1s.append(m1_bins)
        m2s.append(m2_bins)
        times.append(time_bins)
    ax1 = plt.gca()
    ax2 = ax1.twinx()
    ax2.set_yscale('log')
    inspiral_list = []
    for i in range(len(eccens)):
        inspiral_list.append([])
        for j in range(len(eccens[i])):
            inspiral_list[i].append(
                inspiral.inspiral_time_peters(semis[i][j], eccens[i][j],
                                              m1s[i][j], m2s[i][j]))
            if inspiral_list[i][j] < 1:
                print(i, j, semis[i][j], eccens[i][j], m1s[i][j], m2s[i][j],
                      inspiral_list[i][j])
        ax2.plot(times[i], inspiral_list[i], ':', color=color_list[i])
    plt.title('Min BHBH Binary Semi-major Axis')
    ax1.set_ylabel('Semi-major Axis (log_10( Semi (AU)))')
    ax2.set_ylabel('Corresponding Inspiral Time (Gyr)')
    plt.xlabel('Physical Time')
    plt.legend(legend, loc=0)
    plt.savefig((saveLocation + 'gridMinBHBHSemi.png'))
    plt.figure(1)
    plt.title('Min Inspiral Time')
    plt.ylabel('Inpiral Time (Gyr)')
    plt.xlabel('Physical Time (Myr)')
    plt.yscale('log')
    plt.legend(legend, loc=0)
    plt.savefig((saveLocation + 'gridInspiralTime.png'))
    plt.close('all')
    if return_min_inspiral:
        return (BHBH_names)