<jupyter_start><jupyter_text>Plot subhalos<jupyter_code>import sys, os
sys.path.append('../')

import logging
import numpy as np
import matplotlib.pyplot as plt
import astropy
%matplotlib inline
import pickle

from simulation.wrapper import augmented_data
from simulation.units import M_s
import paper_settings

logging.basicConfig(
    format='%(asctime)-5.5s %(name)-20.20s %(levelname)-7.7s %(message)s',
    datefmt='%H:%M',
    level=logging.INFO
)
paper_settings.setup()<jupyter_output><empty_output><jupyter_text>Settings<jupyter_code>n_cols = 4
n_rows = 2
###data_visualization


### x_train == lens image
x_train = np.load("../data/samples/x_train.npy")

### z_train == latent variable (e.g. redshift, M_halo...etc)
z_train = np.load("../data/samples/z_train.npy")

### theta == parameters of interest (f_sub, beta)
theta_alt_train = np.load("../data/samples/theta_alt_train.npy")

theta_train = np.load("../data/samples/theta_train.npy")


### 
log_r_xz_train = np.load("../data/samples/log_r_xz_train.npy")
t_xz_train= np.load("../data/samples/t_xz_train.npy")

print("data shape:", x_train[0].shape, theta_alt_train.shape, theta_train.shape, log_r_xz_train.shape, t_xz_train.shape)
#print()

for i in range(10):
    print("theta train", theta_train[i], "theta_alt_train", theta_alt_train[i], "z_train", z_train[i])
    print("log_r_xz_train", log_r_xz_train[i], "t_xz_train", t_xz_train[i])
    plt.imshow(x_train[i])
    plt.show()<jupyter_output>data shape: (64, 64) (10000, 2) (10000, 2) (10000,) (10000, 2)
theta train [ 0.0183317  -1.74972747] theta_alt_train [ 0.17710894 -2.01112602] z_train [ 2.75936022e+76  2.14239556e+35  5.56508302e-01  2.36840786e+02
 -6.02625720e-02 -1.55926643e-01  8.47578789e-01  2.10000000e+01
  1.50987736e-02  6.00000000e+00  5.35253914e-04  2.00000000e+00
  1.46549844e-03]
log_r_xz_train 1.2657570937785695198 t_xz_train [33.83013209 -1.3093534 ]<jupyter_text>Make data<jupyter_code>#imgs, sub_latents, global_latents = pickle.load( open( "simulations_data.pickle", "rb" ))
#imgs, sub_latents, global_latents = pickle.load( open( "data.pickle", "rb" ))
#theta, _, imgs, _, _, _,_, sub_latents, global_latents = augmented_data(
#    f_sub=0.05, beta=-1.9, n_images=n_cols*n_rows - 1, mine_gold=False,
#    draw_alignment=True, draw_host_mass=True, draw_host_redshift=True
#)
pickle.dump((imgs, sub_latents, global_latents), open( "simulations_data.pickle", "wb" ) )<jupyter_output><empty_output><jupyter_text>Plot subhalos<jupyter_code>fig, caxes = paper_settings.grid_width(
    n_cols, n_rows, n_caxes=2, large_margin=0.025, small_margin=0.025, sep=0.025, cbar_width=0.04
)

for i in range(n_cols*n_rows - 1):
    ax = plt.subplot(n_rows, n_cols, i+1)
    
    im = plt.imshow(
        np.log10(imgs[i]),
        vmin=2.3,
        vmax=3.15,
        cmap='gist_gray',
        extent=(-3.2,3.2,-3.2,3.2),
        origin="lower"
    )
    if i == 0:
        plt.plot([-2.9, -1.9], [-2.9, -2.9], c="white", lw=1.5, ls="-")
        plt.text(-2.4, -2.65, "$1''$", va="center", ha="center", color="white")
    
    sc0 = plt.scatter(
        sub_latents[i][:,1],
        sub_latents[i][:,2],
        s=10.,
        c=np.log10(sub_latents[i][:,0]/M_s),
        cmap=paper_settings.CMAP2,  # "plasma",
        vmin=6.8,
        vmax=9.0,
    )
    if i == 0:
        cbar1 = plt.colorbar(sc0, cax=caxes[0])
        cbar1.set_label(r'$\log_{10} \; (m_{200} / \mathrm{M}_{\odot})$')
        cbar1.set_ticks([7,7.5,8,8.5,9])
        caxes[0].plot([14.3], [8.92], 'o', markersize=5, c=paper_settings.COLOR_ALIGN, clip_on=False, zorder=100)
        
    sc1 = plt.scatter(
        [global_latents[i,4]],
        [global_latents[i,5]],
        s=200.,
        marker="+",
        c=[np.log10(global_latents[i,0]/M_s)],
        cmap=paper_settings.CMAP2,  # "Greens_r",
        vmin=12.0,
        vmax=14.0,
    )
    
    plt.xlim(-3.2,3.2)
    plt.ylim(-3.2,3.2)
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)
    
    if i == 0:
        cbar2 = plt.colorbar(sc1, cax=caxes[1])
        cbar2.set_label(r'$\log_{10} \; (M_{200} / \mathrm{M}_{\odot})$')
        cbar2.set_ticks([12.5, 13.,13.5,14])
        caxes[1].plot([19.5], [13.93], '+', markersize=10, c=paper_settings.COLOR_ALIGN, clip_on=False, zorder=100)

plt.savefig("../figures/simulations.pdf", dpi=300)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup