Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
53 changes: 41 additions & 12 deletions Model_I/sim_axion.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,68 @@
import matplotlib.pyplot as plt
import numpy as np
import random

import os
from deeplense.lens import DeepLens


# Number of sims
# -------------------------------
# Configuration
# -------------------------------
num_sim = int(5e3)


axion_masses = 10**np.random.uniform(-24,-22,num_sim)
# Output directory
base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')
os.makedirs(base_path, exist_ok=True)

# Random axion masses
axion_masses = 10 ** np.random.uniform(-24, -22, num_sim)

# -------------------------------
# Simulation Loop
# -------------------------------
for i in range(num_sim):

lens = DeepLens(axion_mass=axion_masses[i])
lens.make_single_halo(1e12)
lens.make_vortex(3e10)
lens.make_source_light()
lens.simple_sim()
File = np.array([lens.image_real,axion_masses[i]])
np.save('/users/mtoomey/scratch/deeplense/Model_I_test/axion/axion_sim_' + str(random.getrandbits(128)),File)

sample = {
"image": lens.image_real,
"axion_mass": axion_masses[i]
}

np.save(os.path.join(base_path, f"sample_{i}.npy"), sample)

if i % 500 == 0:
print(f"[INFO] Saved {i}/{num_sim} samples")


# -------------------------------
# Optional Visualization (Debug)
# -------------------------------
if False:
plt.figure(figsize=(10,5))
plt.subplot(2,2,1)
plt.figure(figsize=(10, 5))

plt.subplot(2, 2, 1)
plt.imshow(lens.image_real)
plt.title("Image")
plt.colorbar()
plt.subplot(2,2,2)

plt.subplot(2, 2, 2)
plt.imshow(np.sqrt(lens.image_real))
plt.title("Sqrt(Image)")
plt.colorbar()
plt.subplot(2,2,3)

plt.subplot(2, 2, 3)
plt.imshow(lens.poisson)
plt.title("Poisson Noise")
plt.colorbar()
plt.subplot(2,2,4)

plt.subplot(2, 2, 4)
plt.imshow(lens.bkg)
plt.title("Background")
plt.colorbar()

plt.tight_layout()
plt.show()
6 changes: 5 additions & 1 deletion Model_I/sim_cdm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

Expand All @@ -15,8 +16,11 @@
lens.make_source_light()
lens.simple_sim()
File = lens.image_real
np.save('/users/mtoomey/scratch/deeplense/Model_I_test/cdm/cdm_sim_' + str(random.getrandbits(128)),File)
# This tells the computer: "Start where this script is, then find the data folder."
base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')

# This creates the folder if it doesn't exist yet
os.makedirs(base_path, exist_ok=True)


if False:
Expand Down
5 changes: 3 additions & 2 deletions Model_I/sim_no_sub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

Expand All @@ -15,8 +16,8 @@
lens.make_source_light()
lens.simple_sim()
File = lens.image_real
np.save('/users/mtoomey/scratch/deeplense/Model_I_test/no_sub/no_sub_sim_' + str(random.getrandbits(128)),File)

base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')
os.makedirs(base_path, exist_ok=True)


if False:
Expand Down
27 changes: 20 additions & 7 deletions Model_II/sim_axion.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens


# Number of sims
num_sim = int(5e3)
num_sim = int(5e3)

# Output directory
base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')
os.makedirs(base_path, exist_ok=True)

axion_masses = 10**np.random.uniform(-24,-22,num_sim)
# Random axion masses
axion_masses = 10 ** np.random.uniform(-24, -22, num_sim)

for i in range(num_sim):

lens = DeepLens(axion_mass=axion_masses[i])
lens.make_single_halo(1e12)
lens.make_vortex(3e10)
lens.set_instrument('Euclid')
lens.make_source_light_mag()
lens.simple_sim_2()
File = np.array([lens.image_real,axion_masses[i]])
np.save('/users/mtoomey/scratch/deeplense/Model_II_test/axion/axion_sim_' + str(random.getrandbits(128)),File)
lens.make_source_light()
lens.simple_sim()

sample = {
"image": lens.image_real,
"axion_mass": axion_masses[i]
}

np.save(os.path.join(base_path, f"sample_{i}.npy"), sample)

if i % 500 == 0:
print(f"[INFO] Saved {i}/{num_sim} samples")



Expand Down
6 changes: 5 additions & 1 deletion Model_II/sim_cdm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

Expand All @@ -16,7 +17,10 @@
lens.make_source_light_mag()
lens.simple_sim_2()
File = lens.image_real
np.save('/users/mtoomey/scratch/deeplense/Model_II_test/cdm/cdm_sim_' + str(random.getrandbits(128)),File)
base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')
os.makedirs(base_path, exist_ok=True)





Expand Down
5 changes: 4 additions & 1 deletion Model_II/sim_no_sub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

Expand All @@ -16,7 +17,9 @@
lens.make_source_light_mag()
lens.simple_sim_2()
File = lens.image_real
np.save('/users/mtoomey/scratch/deeplense/Model_II_test/no_sub/no_sub_sim_' + str(random.getrandbits(128)),File)
base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')
os.makedirs(base_path, exist_ok=True)




Expand Down
27 changes: 19 additions & 8 deletions Model_III/sim_axion.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import matplotlib.pyplot as plt
import numpy as np
import random

import os
from deeplense.lens import DeepLens


# Number of sims
num_sim = int(3e5)
num_sim = int(3e5)

# Output directory
base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')
os.makedirs(base_path, exist_ok=True)

axion_masses = 10**np.random.uniform(-24,-22,num_sim)
# Random axion masses
axion_masses = 10 ** np.random.uniform(-24, -22, num_sim)

for i in range(num_sim):

lens = DeepLens(axion_mass=axion_masses[i])
lens.make_single_halo(1e12)
lens.make_vortex(3e10)
lens.set_instrument('hst')
lens.make_source_light_mag()
lens.simple_sim_2()
File = np.array([lens.image_real,axion_masses[i]])
np.save('/users/mtoomey/scratch/deeplense/Model_III_test/axion/axion_sim_' + str(random.getrandbits(128)),File)
lens.make_source_light()
lens.simple_sim()

sample = {
"image": lens.image_real,
"axion_mass": axion_masses[i]
}

np.save(os.path.join(base_path, f"sample_{i}.npy"), sample)

if i % 500 == 0:
print(f"[INFO] Saved {i}/{num_sim} samples")


if False:
Expand Down
5 changes: 4 additions & 1 deletion Model_III/sim_cdm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

Expand All @@ -16,7 +17,9 @@
lens.make_source_light_mag()
lens.simple_sim_2()
File = lens.image_real
np.save('/users/mtoomey/scratch/deeplense/Model_III_test/cdm/cdm_sim_' + str(random.getrandbits(128)),File)
base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')
os.makedirs(base_path, exist_ok=True)




Expand Down
5 changes: 4 additions & 1 deletion Model_III/sim_no_sub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

Expand All @@ -16,7 +17,9 @@
lens.make_source_light_mag()
lens.simple_sim_2()
File = lens.image_real
np.save('/users/mtoomey/scratch/deeplense/Model_III_test/no_sub/no_sub_sim_' + str(random.getrandbits(128)),File)
base_path = os.path.join(os.getcwd(), 'data', 'Model_I', 'axion')
os.makedirs(base_path, exist_ok=True)




Expand Down
19 changes: 17 additions & 2 deletions Model_IV/sim_axion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import matplotlib.pyplot as plt
import h5py
import random
import os


script_dir = os.path.dirname(os.path.abspath(__file__))

data_root = os.path.join(script_dir, 'data_model_4')

# lenstronomy module import
import lenstronomy.Util.data_util as data_util
Expand All @@ -13,6 +19,7 @@
from lenstronomy.LightModel.Profiles.gaussian import GaussianEllipse
gauss = GaussianEllipse()

from pyHalo.realization_extensions.uldm import ULDM


# Define a specific cosmology
Expand Down Expand Up @@ -205,7 +212,13 @@ def simulate(image_galaxy,sigma_v,source_pos_xx,source_pos_yy,source_ang,zlens=0
# good galaxies, checked by eye
arr = [2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,54,55]
#################################################
# Create the folders if they don't exist
cdm_val_path = os.path.join(data_root, 'val', 'cdm')
cdm_train_path = os.path.join(data_root, 'train', 'cdm')
os.makedirs(cdm_val_path, exist_ok=True)
os.makedirs(cdm_train_path, exist_ok=True)

filename = f"sim_{random.getrandbits(128)}.npy"
number_of_sims = int(2.5e4)

for i in range(number_of_sims):
Expand All @@ -215,8 +228,10 @@ def simulate(image_galaxy,sigma_v,source_pos_xx,source_pos_yy,source_ang,zlens=0

sim = simulate(img_zp1[arr[index]],sigma_v,source_pos_xx,source_pos_yy,source_ang)


if i % 10 == 0:
np.save('val/axion/sim_'+ str(random.getrandbits(128)),(np.array(sim).clip(min=0)/np.max(sim)),allow_pickle=True)
save_path = os.path.join(cdm_val_path, filename)
else:
np.save('train/axion/sim_'+ str(random.getrandbits(128)),(np.array(sim).clip(min=0)/np.max(sim)),allow_pickle=True)
save_path = os.path.join(cdm_train_path, filename)

np.save(save_path, (np.array(sim).clip(min=0)/np.max(sim)), allow_pickle=True)
18 changes: 16 additions & 2 deletions Model_IV/sim_cdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import matplotlib.pyplot as plt
import h5py
import random
import os

script_dir = os.path.dirname(os.path.abspath(__file__))

data_root = os.path.join(script_dir, 'data_model_4')

# lenstronomy module import
import lenstronomy.Util.data_util as data_util
Expand Down Expand Up @@ -192,6 +197,13 @@ def simulate(image_galaxy,sigma_v,source_pos_xx,source_pos_yy,source_ang,zlens=0
arr = [2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,54,55]
#################################################

# Create the folders if they don't exist
cdm_val_path = os.path.join(data_root, 'val', 'cdm')
cdm_train_path = os.path.join(data_root, 'train', 'cdm')
os.makedirs(cdm_val_path, exist_ok=True)
os.makedirs(cdm_train_path, exist_ok=True)

filename = f"sim_{random.getrandbits(128)}.npy"
number_of_sims = int(2.5e4)

for i in range(number_of_sims):
Expand All @@ -201,8 +213,10 @@ def simulate(image_galaxy,sigma_v,source_pos_xx,source_pos_yy,source_ang,zlens=0

sim = simulate(img_zp1[arr[index]],sigma_v,source_pos_xx,source_pos_yy,source_ang)


if i % 10 == 0:
np.save('val/cdm/sim_'+ str(random.getrandbits(128)),(np.array(sim).clip(min=0)/np.max(sim)),allow_pickle=True)
save_path = os.path.join(cdm_val_path, filename)
else:
np.save('train/cdm/sim_'+ str(random.getrandbits(128)),(np.array(sim).clip(min=0)/np.max(sim)),allow_pickle=True)
save_path = os.path.join(cdm_train_path, filename)

np.save(save_path, (np.array(sim).clip(min=0)/np.max(sim)), allow_pickle=True)
Loading