def test_equalize(filename, result_dir):
    input_img = Image.open(filename)
    output_img = equalize_hist(input_img)
    result_path = os.path.join(result_dir, 'equalize.png')
    output_img.save(result_path)
    print '[Saved] ' + result_path

    fig = plot_hist(output_img)
    plot_path = os.path.join(result_dir, 'hist-equalize.png')
    fig.savefig(plot_path)
    print '[Saved] ' + plot_path
def test_equalize(filename, result_dir):
    input_img = Image.open(filename)
    output_img = equalize_hist(input_img)
    result_path = os.path.join(result_dir, 'equalize.png')
    output_img.save(result_path)
    print '[Saved] ' + result_path

    fig = plot_hist(output_img)
    plot_path = os.path.join(result_dir, 'hist-equalize.png')
    fig.savefig(plot_path)
    print '[Saved] ' + plot_path
                       units='msun')
gas_halos = numpy.loadtxt(
    '/cosma5/data/durham/dc-murr1/simba_gas_neighbour_halos.txt')
gas_halos = gas_halos.astype(int)

frac_distance = distance / radius

mask = numpy.where(mass > 0)[0]
spread = spread[mask]
frac_distance = frac_distance[mask]
mass = mass[mask]
gas_halos = gas_halos[mask]
radius = radius[mask]

hist.plot_hist(mass, spread, r'Nearest halo mass [$M_{\odot}$]',
               'Spread metric / halo radius',
               '/cosma5/data/durham/dc-murr1/simba_gas_spread_mass.png')

where = numpy.where(gas_halos >= 0)[0]
spread = spread[where]
frac_distance = frac_distance[where]
mass = mass[where]
radius = radius[where]
'''
hist.plot_hist(
    mass,
    frac_spread,
    r'Nearest halo mass [$M_{\odot}$]',
    'Spread metric / halo radius',
    '/cosma5/data/durham/dc-murr1/simba_gas_neighbour_spread_mass.png'
)
import numpy
import unyt
import hist

spread = unyt.unyt_array(
    numpy.loadtxt('/cosma5/data/durham/dc-murr1/adiabatic_gas_spread.txt'),
    units='Mpc')
mass = unyt.unyt_array(numpy.loadtxt(
    '/cosma5/data/durham/dc-murr1/adi_gas_nearest_halo_mass.txt'),
                       units='msun')
neighbour_halos = numpy.loadtxt(
    '/cosma5/data/durham/dc-murr1/adi_gas_neighbour_halos.txt')

where = numpy.where(neighbour_halos >= 0)[0]
spread = spread[where]
mass = mass[where]

hist.plot_hist(
    mass, spread, r'Mass of nearest halo [$M_{\odot}$]', 'Spread Metric [Mpc]',
    '/cosma5/data/durham/dc-murr1/adi_gas_neighbour_spread_mass.png')
Exemple #5
0
    numpy.loadtxt('/cosma5/data/durham/dc-murr1/dm_nearest_halo_mass.txt'),
    units='msun')
dm_halos = numpy.loadtxt('/cosma5/data/durham/dc-murr1/dm_neighbour_halos.txt')
dm_halos = dm_halos.astype(int)

frac_distance = distance / radius

mask = numpy.where(frac_distance > 10**(-4))[0]
spread = spread[mask]
frac_distance = frac_distance[mask]
mass = mass[mask]
dm_halos = dm_halos[mask]
radius = radius[mask]

hist.plot_hist(frac_distance, spread, 'Distance to nearest halo / halo radius',
               'Spread metric / halo radius',
               '/cosma5/data/durham/dc-murr1/dm_spread_distance.png')

where = numpy.where(dm_halos >= 0)[0]
spread = spread[where]
frac_distance = frac_distance[where]
mass = mass[where]
radius = radius[where]
'''
hist.plot_hist(
    frac_distance,
    frac_spread,
    'Distance to nearest halo / halo radius',
    'Spread metric / halo radius',
    '/cosma5/data/durham/dc-murr1/dm_neighbour_spread_distance.png'
)
    units='msun')
dm_halos = numpy.loadtxt(
    '/cosma5/data/durham/dc-murr1/gas_neighbour_halos.txt')
dm_halos = dm_halos.astype(int)

frac_spread = spread / radius
frac_distance = distance / radius

mask = numpy.where(frac_distance > 10**(-4))[0]
frac_spread = frac_spread[mask]
frac_distance = frac_distance[mask]
mass = mass[mask]
dm_halos = dm_halos[mask]

hist.plot_hist(frac_distance, frac_spread,
               'Distance to nearest halo / halo radius',
               'Spread metric / halo radius',
               '/cosma5/data/durham/dc-murr1/gas_spread_distance.png')

where = numpy.where(dm_halos >= 0)[0]
frac_spread = frac_spread[where]
frac_distance = frac_distance[where]
mass = mass[where]

hist.plot_hist(
    frac_distance, frac_spread, 'Distance to nearest halo / halo radius',
    'Spread metric / halo radius',
    '/cosma5/data/durham/dc-murr1/gas_neighbour_spread_distance.png')

one = numpy.where(
    numpy.logical_and(
        numpy.amin(mass) < mass, mass < numpy.percentile(mass, 25)))[0]
spread = unyt.unyt_array(
    numpy.loadtxt('/cosma5/data/durham/dc-murr1/gas_spread.txt'), units='Mpc')
bh_mass = unyt.unyt_array(
    numpy.loadtxt('/cosma5/data/durham/dc-murr1/gas_nearest_bh_mass.txt'),
    units='msun')
mass = unyt.unyt_array(
    numpy.loadtxt('/cosma5/data/durham/dc-murr1/gas_nearest_halo_mass.txt'),
    units='msun')
where_bh = numpy.where(bh_mass > 0)[0]
spread = spread[where_bh]
bh_mass = bh_mass[where_bh]
mass = mass[where_bh]

hist.plot_hist(bh_mass, spread,
               r"Mass of nearest halo's central BH [$M_{\odot}$]",
               'Spread metric [Mpc]',
               '/cosma5/data/durham/dc-murr1/gas_spread_bh.png')

dm_halos = numpy.loadtxt(
    '/cosma5/data/durham/dc-murr1/gas_neighbour_halos.txt')
dm_halos = dm_halos.astype(int)
dm_halos = dm_halos[where_bh]

where = numpy.where(dm_halos >= 0)[0]

spread = spread[where]
bh_mass = bh_mass[where]
mass = mass[where]

hist.plot_hist(bh_mass, spread,
               r"Mass of nearest halo's central BH [$M_{\odot}$]",
def test_plot(filename, result_dir):
    input_img = Image.open(filename)
    fig = plot_hist(input_img)
    result_path = os.path.join(result_dir, 'hist.png')
    fig.savefig(result_path)
    print '[Saved] ' + result_path
Exemple #9
0
    units='msun')
dm_halos = numpy.loadtxt('/cosma5/data/durham/dc-murr1/dm_neighbour_halos.txt')
dm_halos = dm_halos.astype(int)

spread = spread
frac_distance = distance / radius

mask = numpy.where(mass > 0)[0]
spread = spread[mask]
frac_distance = frac_distance[mask]
mass = mass[mask]
dm_halos = dm_halos[mask]
radius = radius[mask]

hist.plot_hist(mass, spread, r'Nearest halo mass [$M_{\odot}$]',
               'Spread metric / halo radius',
               '/cosma5/data/durham/dc-murr1/dm_spread_mass.png')

where = numpy.where(dm_halos >= 0)[0]
spread = spread[where]
frac_distance = frac_distance[where]
mass = mass[where]
radius = radius[where]

hist.plot_hist(mass, spread, r'Nearest halo mass [$M_{\odot}$]',
               'Spread metric / halo radius',
               '/cosma5/data/durham/dc-murr1/dm_neighbour_spread_mass.png')

one = numpy.where(
    numpy.logical_and(
        numpy.amin(frac_distance) < frac_distance,
Exemple #10
0
def load_prob_stats_and_calc_hist_thresh(stats_fn,
                                         num_ids,
                                         label1=None,
                                         num_images=-1,
                                         stats_fn2=None,
                                         num_ids2=None,
                                         label2=None,
                                         num_images2=-1,
                                         only_after_bin_val=None,
                                         show_hist=True,
                                         save_dir=None,
                                         label_list=None):
    print 'file1: ', stats_fn
    print 'file2: ', stats_fn2

    if save_dir is None:
        save_dir = './rlt_hist_output/'
    if not osp.exists(save_dir):
        os.makedirs(save_dir)

    if not label1:
        label1 = get_auto_label(stats_fn)

    prob_avg_vec, max_label_vec = load_prob_stats(stats_fn, num_ids)
    print 'prob_avg_vec.shape: ', prob_avg_vec.shape
    hist, bins = get_hist(prob_avg_vec)
    thresh = calc_otsu_threshold(hist, bins, only_after_bin_val)

    print 'Otsu_threshold for file1: ', thresh

    # out_prefix = osp.splitext(stats_fn)[0]
    # out_prefix = osp.join(save_dir, osp.basename(out_prefix))
    out_prefix = osp.join(save_dir, label1)

    hist_out_fn = out_prefix + '_thr%g.png' % thresh
    plot_hist(prob_avg_vec, bins, show_hist, hist_out_fn)

    thresh_out_fn = out_prefix + '_thr%g.txt' % thresh
    cnt_gteq_thresh = np.sum(prob_avg_vec >= thresh)
    cnt_lt_thresh = prob_avg_vec.size - cnt_gteq_thresh
    fp = open(thresh_out_fn, 'w')
    write_string = ('thresh: %g\ncnt(>=thresh):%d\ncnt(<thresh):%d' %
                    (thresh, cnt_gteq_thresh, cnt_lt_thresh))
    fp.write(write_string)
    fp.close()

    if stats_fn2:
        if not label2:
            label2 = get_auto_label(stats_fn2)

        prob_avg_vec2, max_label_vec2 = load_prob_stats(stats_fn2, num_ids2)
        print 'prob_avg_vec2.shape: ', prob_avg_vec2.shape
        hist, bins = get_hist(prob_avg_vec2)
        thresh2 = calc_otsu_threshold(hist, bins, only_after_bin_val)

        print 'Otsu_threshold for file2: ', thresh2

        # out_prefix2 = osp.splitext(stats_fn2)[0]
        # out_prefix2 = osp.join(save_dir, osp.basename(out_prefix2))
        out_prefix2 = osp.join(save_dir, label2)

        hist_out_fn2 = out_prefix2 + '_thr%g.png' % thresh2
        plot_hist(prob_avg_vec2, bins, show_hist, hist_out_fn2)

        thresh_out_fn = out_prefix2 + '_thr%g.txt' % thresh2
        cnt_gteq_thresh = np.sum(prob_avg_vec2 >= thresh2)
        cnt_lt_thresh = prob_avg_vec2.size - cnt_gteq_thresh
        fp = open(thresh_out_fn, 'w')
        write_string = ('thresh: %g\ncnt(>=thresh):%d\ncnt(<thresh):%d' %
                        (thresh2, cnt_gteq_thresh, cnt_lt_thresh))
        fp.write(write_string)
        fp.close()

        prob_avg_vec3 = np.hstack((prob_avg_vec, prob_avg_vec2))
        print 'prob_avg_vec.shape: ', prob_avg_vec3.shape
        hist, bins = get_hist(prob_avg_vec3)
        thresh3 = calc_otsu_threshold(hist, bins, only_after_bin_val)

        out_prefix3 = out_prefix + '_and_' + osp.basename(out_prefix2)

        hist_out_fn3 = out_prefix3 + '_thr%g.png' % thresh3
        plot_hist(prob_avg_vec3, None, show_hist, hist_out_fn3)

        print 'Otsu_threshold for file1 and file2: ', thresh3

        thresh_out_fn = out_prefix3 + '_thr%g.txt' % thresh3
        cnt_gteq_thresh = np.sum(prob_avg_vec3 >= thresh3)
        cnt_lt_thresh = prob_avg_vec3.size - cnt_gteq_thresh
        fp = open(thresh_out_fn, 'w')
        write_string = ('thresh: %g\ncnt(>=thresh):%d\ncnt(<thresh):%d' %
                        (thresh3, cnt_gteq_thresh, cnt_lt_thresh))
        fp.write(write_string)
        fp.close()
mask = numpy.where(mass > 0)[0]
spread = spread[mask]
mass = mass[mask]
dm_halos = dm_halos[mask]
radius = radius[mask]
density = density[mask]

where = numpy.where(dm_halos >= 0)[0]
spread = spread[where]
mass = mass[where]
radius = radius[where]
density = density[where]

hist.plot_hist(
    density, spread, 'Number of gas particles within 500kpc radius',
    'Spread metric [Mpc]',
    '/cosma5/data/durham/dc-murr1/adi_gas_neighbour_spread_density.png')

mass_cutoff = numpy.where(numpy.logical_and(mass > 10**8, mass < 10**10))[0]
spread_after = spread[mass_cutoff]
density_after = density[mass_cutoff]

spread_cutoff = numpy.where(
    numpy.logical_and(spread_after > 10**(-1), spread_after < 1))[0]
density_after = density_after[spread_cutoff]
spread_after = spread_after[spread_cutoff]

xbins = numpy.logspace(numpy.log10(numpy.amin(density)),
                       numpy.log10(numpy.amax(density)),
                       num=50)
ybins = numpy.logspace(numpy.log10(numpy.amin(spread)),
Exemple #12
0
import numpy
import unyt
import hist

spread = unyt.unyt_array(
    numpy.loadtxt('/cosma5/data/durham/dc-murr1/gas_spread.txt'), units='Mpc')
mass = unyt.unyt_array(
    numpy.loadtxt('/cosma5/data/durham/dc-murr1/gas_nearest_halo_mass.txt'),
    units='msun')
neighbour_halos = numpy.loadtxt(
    '/cosma5/data/durham/dc-murr1/gas_neighbour_halos.txt')

where = numpy.where(neighbour_halos >= 0)[0]
spread = spread[where]
mass = mass[where]

hist.plot_hist(mass, spread, r'Nearest halo mass [$M_{\odot}$]',
               'Spread metric [Mpc]',
               '/cosma5/data/durham/dc-murr1/gas_neighbour_spread_mass.png')
def test_plot(filename, result_dir):
    input_img = Image.open(filename)
    fig = plot_hist(input_img)
    result_path = os.path.join(result_dir, 'hist.png')
    fig.savefig(result_path)
    print '[Saved] ' + result_path