def ready4PL(Lmin, Lmax, Lpts_num, kmin, kmax, com_dist, zpts_num):
    # calculate the k corresponding to L (specified by user)
    Lpts = hk_tool_box.set_bin_log(Lmin, Lmax, Lpts_num,"logspace")
    # Lpts = numpy.linspace(Lmin, Lmax, Lpts_num)
    integ_k = numpy.zeros((zpts_num, Lpts_num))

    dLpts = Lpts[1:] - Lpts[:-1]

    for i in range(Lpts_num):
        # integrate PK for each fixed L
        # k = L/com_dist at Z
        integ_k[:, i] = (Lpts[i]+0.5) / com_dist

    # print("k h/Mpc ~[%.4f, %.4f]" % (integ_k.min(), integ_k.max()))

    # only in the interval, [kmin, kmax], will be calculated
    idx = integ_k < kmin
    integ_k[idx] = -1
    idx = integ_k > kmax
    integ_k[idx] = -1

    return Lpts, dLpts, integ_k
import time
import hk_FQlib
# import hk_c4py

warnings.filterwarnings('error')

# start
time_start = hk_tool_box.get_time_now()

# parameters

area_num = 4
# theta bin
theta_bin_num = 5
# theta_bin = hk_tool_box.set_bin_log(1, 128, theta_bin_num+1).astype(numpy.float32)
theta_bin = hk_tool_box.set_bin_log(5, 60,
                                    theta_bin_num + 1).astype(numpy.float32)

# bin number for ra & dec of each exposure
deg2arcmin = 60
deg2rad = numpy.pi / 180

grid_size = 15  #arcmin

# position in CFHTLens catalog
ra_idx = 0
dec_idx = 1

redshift_idx = 10

redshift_sep_thresh = 0.01
redshift_bin_num = 6
Beispiel #3
0
# Halo parameters
Mass = 3 * 10**13.5  # M_sun/h
conc = 6  # concentration
len_z = 0.3  # redshift
halo_position = galsim.PositionD(0, 0)  # arcsec
com_dist_len = cosmos.comoving_distance(len_z).value * h  # Mpc/h

nfw_model = galsim.NFWHalo(Mass, conc, len_z, halo_position, omega_m0,
                           omega_lam0)

# redshift threshold
src_z_threshold = len_z + 0.1

guess_num_p = 50
signal_guess = numpy.zeros((guess_num_p + guess_num_p, ))
signal_guess[:guess_num_p] = -hk_tool_box.set_bin_log(0.001, 500, guess_num_p)
signal_guess[guess_num_p:] = hk_tool_box.set_bin_log(0.001, 500, guess_num_p)
signal_guess = numpy.sort(signal_guess)

rng = numpy.random.RandomState(213 + rank * 124212)
# read the source data
sheared_path = data_path + "/data/segment_sheared_%s.hdf5" % data_type
non_sheared_path = data_path + "/data/segment_non_sheared_%s.hdf5" % data_type
# ra, dec Degree
src_z, src_ra, src_dec, src_radius, src_radian, mgt, mnu1, src_num = mix_data(
    rank, sheared_path, non_sheared_path, src_z_threshold, zerr_sig, rng)

total_num = (src_num / (1 - dilution_ratio)).astype(dtype=numpy.intc)

com_dist_src = cosmos.comoving_distance(src_z).value * h  # Mpc/h
Beispiel #4
0
Mass = 3*10 ** 13  # M_sun/h
conc = 6  # concentration
# len_z = 0.2  # redshift
halo_position = galsim.PositionD(0, 0)  # arcsec
com_dist_len = cosmos.comoving_distance(len_z).value * h  # Mpc/h
print("Lens plane at z = %.2f, %.5f Mpc/h" % (len_z, com_dist_len))

# lens profile
CF = hk_gglensing_tool.Cosmos_flat(omega_m0, 100*h)
CF.NFW_profile_galsim((0,0), Mass, conc, len_z)


separation_bin_num = 1
Rmin, Rmax = 0.05, 0.07 # Mpc/h

separation_bin = hk_tool_box.set_bin_log(Rmin, Rmax, separation_bin_num+1)

# read the parameters
h5f = h5py.File(param_path + "/%s"%stack_file, "r")
src_z = h5f["/z"][()]
# src_z_m = h5f["/z_m"][()]
src_ra = h5f["/ra"][()]
src_dec = h5f["/dec"][()]
src_g1 = h5f["/gamma1"][()]
src_g2 = h5f["/gamma2"][()]
h5f.close()

gt = numpy.sqrt(src_g1**2 + src_g2**2)
# # the measured ellipticity
src_num = src_g1.shape[0]
rng = numpy.random.RandomState(numpy.random.randint(1, 10000, 1))
def set_bin(data, bin_num, bound_scale, method="log", log_end=5):
    if method == "mean":
        temp_data = numpy.sort(data)
        bin_size = len(temp_data) / bin_num
        bins = [temp_data[int(i * bin_size)] for i in range(bin_num)]
        bins.append(temp_data[-1] * bound_scale)
        bins = numpy.array(bins)
    elif method == "sym-mean":
        temp_data = numpy.sort(numpy.abs(data))  # [:int(len(data[data>0])*0.99)]
        bin_size = len(temp_data) / bin_num * 2
        bins = numpy.array([temp_data[int(i * bin_size)] for i in range(1, int(bin_num / 2))])
        bins = numpy.sort(numpy.append(numpy.append(-bins, [0.]), bins))
        bound = numpy.max(numpy.abs(data)) * bound_scale
        bins = numpy.append(-bound, numpy.append(bins, bound))

    elif method == "mix_bin":
        mean_num, log_num = bin_num
        mean_num2, log_num2 = int(mean_num / 2), int(log_num / 2)

        hbins = numpy.zeros((mean_num2 + log_num2,))

        temp_data = numpy.sort(numpy.abs(data))  # [:int(len(data[data>0])*0.99)]

        bin_size = len(temp_data) / mean_num * 2
        mean_bins = numpy.array([temp_data[int(i * bin_size)] for i in range(1, mean_num2)])

        hbins[:mean_num2 - 1] = mean_bins

        hbins[mean_num2 - 1] = temp_data[-1]

        ed = numpy.log10(temp_data[-1])
        log_bin = 10 ** numpy.linspace(ed, ed + log_end, log_num2 + 1)
        hbins[mean_num2:] = log_bin[1:]

        inv = range(mean_num2 + log_num2 - 1, -1, -1)
        bins = numpy.zeros((mean_num + log_num + 1))
        bins[mean_num2 + log_num2 + 1:] = hbins
        bins[:mean_num2 + log_num2] = -hbins[inv]

    elif method == "log":
        data_min = data.min()
        bin_num2 = int(bin_num / 2)
        bins = numpy.zeros((bin_num + 1,))

        if data_min < 0:
            temp_data = numpy.sort(numpy.abs(data))
            data_min, data_max = temp_data[0], temp_data[-1]
            #             print(data_min, data_max)
            if data_min < 0.1:
                data_min = 0.1
            else:
                data_min = data_min * 0.95
            bin_num_ = bin_num2 - 1
            inverse = range(bin_num_, -1, -1)
            hbins = hk_tool_box.set_bin_log(data_min, data_max, bin_num2)

            #             hbins = numpy.exp(numpy.linspace(numpy.log(data_min), numpy.log(data_max), bin_num2))
            #             hbins = 10**numpy.linspace(numpy.log10(data_min), numpy.log10(data_max), bin_num2)

            bins[bin_num2 + 1:] = hbins
            bins[:bin_num2] = -hbins[inverse]

            bins[0] = bins[0] * bound_scale
            bins[-1] = bins[-1] * bound_scale
        else:
            data_max = data.max()
            bins = hk_tool_box.set_bin_log(data_min, data_max, bin_num+1)
            bins[0] = bins[0] * 0.95
            bins[-1] = bins[-1] * bound_scale
    else:
        m = max(numpy.abs(data.min()), numpy.abs(data.max()))
        bins = numpy.linspace(-m, m, bin_num + 1)
        bins[-1] = bins[-1] * bound_scale
        bins[0] = bins[0] * bound_scale
    return bins
Beispiel #6
0
# noisy
mgt_ny = (shear_est_ny[:, 0] * cos_2theta -
          shear_est_ny[:, 1] * sin_2theta) * coeff_1
mgx_ny = (shear_est_ny[:, 0] * sin_2theta +
          shear_est_ny[:, 1] * cos_2theta) * coeff_1
# mu_ny = shear_est_ny[:,3]*cos_4theta - shear_est_ny[:,4]*sin_4theta
# mn_ny = shear_est_ny[:,2]

mnu1_ny = (shear_est_ny[:, 2] + shear_est_ny[:, 3] * cos_4theta -
           shear_est_ny[:, 4] * sin_4theta) * coeff_2
mnu2_ny = (shear_est_ny[:, 2] - shear_est_ny[:, 3] * cos_4theta +
           shear_est_ny[:, 4] * sin_4theta) * coeff_2

radius_bin_num = numprocs
radius_bin = hk_tool_box.set_bin_log(0.2, 18, radius_bin_num + 1)
radius_bin_tag = [i for i in range(radius_bin_num)]
my_radius_bin_tag = hk_tool_box.alloc(radius_bin_tag, numprocs)[rank]

itemsize = MPI.DOUBLE.Get_size()

if rank == 0:
    # bytes for 10 double elements
    nbytes1 = len(pdf_bin_num) * 4 * radius_bin_num * itemsize
    nbytes2 = len(pdf_bin_num) * 4 * radius_bin_num * itemsize
    nbytes3 = 3 * radius_bin_num * itemsize
else:
    nbytes1 = 0
    nbytes2 = 0
    nbytes3 = 0
Beispiel #7
0
theta = h5f["/theta"][()]
# only \xi_+
xi = h5f["/xi_p"][()]
cov_inv = h5f["/inv_cov_xi_p"][()]
used_zbin = h5f["/used_zbin"][()]
h5f.close()

# arcmin to radian & degree
theta_radian = theta/60/180*numpy.pi
theta_degree = theta/60

data_num = theta_radian.shape[0]

theta_num_per_bin = 5

ell = hk_tool_box.set_bin_log(5, 15000, 200)

print("Data vector len: ", xi.shape)

################### initialize emcee #############################
numpy.random.seed(seed_ini)#+ rank*10)
para_lim = [[0.1, 3],[0.01, 1]]#,[0.01,0.2]]
nwalkers, ndim = thread, len(para_lim)
initial = numpy.zeros((nwalkers, ndim))

for i in range(ndim):
    a,b = para_lim[i]
    initial[:,i] = numpy.random.uniform(a,b,nwalkers)

print(nsteps, " steps")
with Pool(thread) as pool:
from astropy import units
import time
import hk_healpy_tool

warnings.filterwarnings('error')

# parameters
# cosmological parameters
omega_m0 = 0.315
H0 = 67.5
cosmos = FlatLambdaCDM(H0, omega_m0)

# separation bin, comoving or angular diameter distance in unit of Mpc/h
sep_bin_num = 25
bin_st, bin_ed = 0.02, 100
separation_bin = hk_tool_box.set_bin_log(bin_st, bin_ed,
                                         sep_bin_num + 1).astype(numpy.float32)

# bin number for ra & dec of each exposure
deg2arcmin = 60
deg2rad = numpy.pi / 180

# chi guess bin for PDF_SYM
delta_sigma_guess_num = 50
num_m = 25
num_p = delta_sigma_guess_num - num_m

delta_sigma_guess = numpy.zeros((delta_sigma_guess_num, ), dtype=numpy.float64)

delta_sigma_guess_bin_p = hk_tool_box.set_bin_log(0.01, 400,
                                                  num_p).astype(numpy.float64)
# delta_sigma_guess_bin_p = numpy.array([1000/1.3**i for i in range(num_p)])#
Beispiel #9
0
from sys import path,argv
path.append("/home/hklee/work/mylib")
from subprocess import Popen
import shutil
import hk_tool_box
import numpy


z = [[0.1, 2.0]]


dz = hk_tool_box.set_bin_log(0.001, 0.5, 31)
z_min, z_max = 0.15, 0.25

total_path = "/home/hklee/work/DECALS/DECALS_shear_catalog_v210729/gg_lensing"

# cmd = "mpirun -np 5 python prepare_cata.py prepare_foreground %.3f %.3f"%(z_min, z_max)
# a = Popen(cmd, shell=True)
# a.wait()


for iz in z:

    cmd = "mpirun -np 15 python prepare_cata.py prepare_background %.3f %.3f" % (iz[0], iz[1])
    a = Popen(cmd, shell=True)
    a.wait()

    cmd = "mpirun -np 1 python prepare_cata.py prepare_pdf"
    a = Popen(cmd, shell=True)
    a.wait()