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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Model_I/sim_axion.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_I/axion/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(5e3)


axion_masses = 10**np.random.uniform(-24,-22,num_sim)

for i in range(num_sim):
Expand All @@ -17,8 +19,8 @@
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)
File = np.array([lens.image_real, axion_masses[i]], dtype=object)
np.save(save_dir + 'axion_sim_' + str(random.getrandbits(128)), File)



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

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_I/cdm/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(5e3)

for i in range(num_sim):
Expand All @@ -15,7 +18,7 @@
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)
np.save(save_dir + 'cdm_sim_' + str(random.getrandbits(128)), File)



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

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_I/no_sub/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(5e3)

for i in range(num_sim):
Expand All @@ -15,7 +18,7 @@
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)
np.save(save_dir + 'no_sub_sim_' + str(random.getrandbits(128)), File)



Expand Down
10 changes: 6 additions & 4 deletions Model_II/sim_axion.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_II/axion/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(5e3)


axion_masses = 10**np.random.uniform(-24,-22,num_sim)

for i in range(num_sim):
Expand All @@ -18,8 +20,8 @@
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)
File = np.array([lens.image_real, axion_masses[i]], dtype=object)
np.save(save_dir + 'axion_sim_' + str(random.getrandbits(128)), File)



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

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_II/cdm/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(5e3)

for i in range(num_sim):
Expand All @@ -16,7 +19,7 @@
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)
np.save(save_dir + 'cdm_sim_' + str(random.getrandbits(128)), File)



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

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_II/no_sub/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(5e3)

for i in range(num_sim):
Expand All @@ -16,7 +19,7 @@
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)
np.save(save_dir + 'no_sub_sim_' + str(random.getrandbits(128)), File)



Expand Down
10 changes: 6 additions & 4 deletions Model_III/sim_axion.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import matplotlib.pyplot as plt
import numpy as np
import random
import os

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_III/axion/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(3e5)


axion_masses = 10**np.random.uniform(-24,-22,num_sim)

for i in range(num_sim):
Expand All @@ -18,8 +20,8 @@
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)
File = np.array([lens.image_real, axion_masses[i]], dtype=object)
np.save(save_dir + 'axion_sim_' + str(random.getrandbits(128)), File)



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

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_III/cdm/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(3e5)

for i in range(num_sim):
Expand All @@ -16,7 +19,7 @@
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)
np.save(save_dir + 'cdm_sim_' + str(random.getrandbits(128)), File)



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

from deeplense.lens import DeepLens

base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(base_dir, '../data/Model_III/no_sub/')
os.makedirs(save_dir, exist_ok=True)

# Number of sims
num_sim = int(3e5)

for i in range(num_sim):
Expand All @@ -16,7 +19,7 @@
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)
np.save(save_dir + 'no_sub_sim_' + str(random.getrandbits(128)), File)



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

base_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(base_dir, '../data')
train_dir = os.path.join(base_dir, 'train/axion/')
val_dir = os.path.join(base_dir, 'val/axion/')
os.makedirs(train_dir, exist_ok=True)
os.makedirs(val_dir, exist_ok=True)

# lenstronomy module import
import lenstronomy.Util.data_util as data_util
Expand All @@ -30,7 +38,7 @@
Euclid_i = Euclid(band='VIS', psf_type='GAUSSIAN', coadd_years=6)
kwargs_i_band = Euclid_i.kwargs_single_band()

from pyHalo.preset_models import ULDM
from pyHalo.PresetModels.uldm import ULDM
from pyHalo.Halos.lens_cosmo import LensCosmo
from pyHalo.single_realization import SingleHalo

Expand Down Expand Up @@ -191,7 +199,7 @@ def simulate(image_galaxy,sigma_v,source_pos_xx,source_pos_yy,source_ang,zlens=0
######### Load real galaxies
################################################
# To get the images and labels from file
with h5py.File('../data/Galaxy10_DECals.h5', 'r') as F:
with h5py.File(os.path.join(data_dir, 'Galaxy10_DECals.h5'), 'r') as F:
images = np.array(F['images'])
typ = np.array(F['ans'])
z = np.array(F['redshift'])
Expand All @@ -216,7 +224,7 @@ 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)
np.save(os.path.join(val_dir, 'sim_'+ str(random.getrandbits(128))), (np.array(sim).clip(min=0)/np.max(sim)), allow_pickle=True)
else:
np.save('train/axion/sim_'+ str(random.getrandbits(128)),(np.array(sim).clip(min=0)/np.max(sim)),allow_pickle=True)
np.save(os.path.join(train_dir, 'sim_'+ str(random.getrandbits(128))), (np.array(sim).clip(min=0)/np.max(sim)), allow_pickle=True)

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

base_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(base_dir, '../data')
train_dir = os.path.join(base_dir, 'train/cdm/')
val_dir = os.path.join(base_dir, 'val/cdm/')
os.makedirs(train_dir, exist_ok=True)
os.makedirs(val_dir, exist_ok=True)

# lenstronomy module import
import lenstronomy.Util.data_util as data_util
Expand All @@ -30,7 +38,7 @@
Euclid_i = Euclid(band='VIS', psf_type='GAUSSIAN', coadd_years=6)
kwargs_i_band = Euclid_i.kwargs_single_band()

from pyHalo.preset_models import CDM
from pyHalo.PresetModels.cdm import CDM
from pyHalo.Halos.lens_cosmo import LensCosmo
from pyHalo.single_realization import SingleHalo

Expand Down Expand Up @@ -177,7 +185,7 @@ def simulate(image_galaxy,sigma_v,source_pos_xx,source_pos_yy,source_ang,zlens=0
######### Load real galaxies
################################################
# To get the images and labels from file
with h5py.File('../data/Galaxy10_DECals.h5', 'r') as F:
with h5py.File(os.path.join(data_dir, 'Galaxy10_DECals.h5'), 'r') as F:
images = np.array(F['images'])
typ = np.array(F['ans'])
z = np.array(F['redshift'])
Expand All @@ -202,7 +210,7 @@ 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)
np.save(os.path.join(val_dir, 'sim_'+ str(random.getrandbits(128))), (np.array(sim).clip(min=0)/np.max(sim)), allow_pickle=True)
else:
np.save('train/cdm/sim_'+ str(random.getrandbits(128)),(np.array(sim).clip(min=0)/np.max(sim)),allow_pickle=True)
np.save(os.path.join(train_dir, 'sim_'+ str(random.getrandbits(128))), (np.array(sim).clip(min=0)/np.max(sim)), allow_pickle=True)

14 changes: 11 additions & 3 deletions Model_IV/sim_no_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
import matplotlib.pyplot as plt
import h5py
import random
import os

base_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(base_dir, '../data')
train_dir = os.path.join(base_dir, 'train/no/')
val_dir = os.path.join(base_dir, 'val/no/')
os.makedirs(train_dir, exist_ok=True)
os.makedirs(val_dir, exist_ok=True)

# lenstronomy module import
import lenstronomy.Util.data_util as data_util
Expand Down Expand Up @@ -140,7 +148,7 @@ def simulate(image_galaxy,sigma_v,source_pos_xx,source_pos_yy,source_ang):
######### Load real galaxies
################################################
# To get the images and labels from file
with h5py.File('../data/Galaxy10_DECals.h5', 'r') as F:
with h5py.File(os.path.join(data_dir, 'Galaxy10_DECals.h5'), 'r') as F:
images = np.array(F['images'])
typ = np.array(F['ans'])
z = np.array(F['redshift'])
Expand All @@ -165,9 +173,9 @@ def simulate(image_galaxy,sigma_v,source_pos_xx,source_pos_yy,source_ang):
sim = simulate(img_zp1[arr[index]],sigma_v,source_pos_xx,source_pos_yy,source_ang)

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


"""
Expand Down
2 changes: 1 addition & 1 deletion deeplense/lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from astropy import units as u
from astropy.constants import G, c, M_sun

from pyHalo.preset_models import CDM
from pyHalo.PresetModels.cdm import CDM


from lenstronomy.LightModel.light_model import LightModel
Expand Down