diff --git a/Model_I/sim_axion.py b/Model_I/sim_axion.py index e778412..89c7517 100644 --- a/Model_I/sim_axion.py +++ b/Model_I/sim_axion.py @@ -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): @@ -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) diff --git a/Model_I/sim_cdm.py b/Model_I/sim_cdm.py index 2811275..dac1022 100644 --- a/Model_I/sim_cdm.py +++ b/Model_I/sim_cdm.py @@ -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): @@ -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) diff --git a/Model_I/sim_no_sub.py b/Model_I/sim_no_sub.py index 9d45151..4d329e1 100644 --- a/Model_I/sim_no_sub.py +++ b/Model_I/sim_no_sub.py @@ -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): @@ -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) diff --git a/Model_II/sim_axion.py b/Model_II/sim_axion.py index a3e5e28..57f3590 100644 --- a/Model_II/sim_axion.py +++ b/Model_II/sim_axion.py @@ -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): @@ -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) diff --git a/Model_II/sim_cdm.py b/Model_II/sim_cdm.py index ca9e4f3..34eda56 100644 --- a/Model_II/sim_cdm.py +++ b/Model_II/sim_cdm.py @@ -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): @@ -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) diff --git a/Model_II/sim_no_sub.py b/Model_II/sim_no_sub.py index 8c1cade..985587c 100644 --- a/Model_II/sim_no_sub.py +++ b/Model_II/sim_no_sub.py @@ -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): @@ -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) diff --git a/Model_III/sim_axion.py b/Model_III/sim_axion.py index 8c976a1..12dc75e 100644 --- a/Model_III/sim_axion.py +++ b/Model_III/sim_axion.py @@ -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): @@ -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) diff --git a/Model_III/sim_cdm.py b/Model_III/sim_cdm.py index edce33d..125e221 100644 --- a/Model_III/sim_cdm.py +++ b/Model_III/sim_cdm.py @@ -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): @@ -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) diff --git a/Model_III/sim_no_sub.py b/Model_III/sim_no_sub.py index 94dec4c..f2b12b9 100644 --- a/Model_III/sim_no_sub.py +++ b/Model_III/sim_no_sub.py @@ -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): @@ -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) diff --git a/Model_IV/sim_axion.py b/Model_IV/sim_axion.py index ead70eb..fbc09b7 100644 --- a/Model_IV/sim_axion.py +++ b/Model_IV/sim_axion.py @@ -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 @@ -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 @@ -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']) @@ -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) diff --git a/Model_IV/sim_cdm.py b/Model_IV/sim_cdm.py index 3d789db..8d951d9 100644 --- a/Model_IV/sim_cdm.py +++ b/Model_IV/sim_cdm.py @@ -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 @@ -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 @@ -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']) @@ -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) diff --git a/Model_IV/sim_no_sub.py b/Model_IV/sim_no_sub.py index 000df74..e24ae17 100644 --- a/Model_IV/sim_no_sub.py +++ b/Model_IV/sim_no_sub.py @@ -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 @@ -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']) @@ -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) """ diff --git a/deeplense/lens.py b/deeplense/lens.py index 9ea428b..44ca421 100644 --- a/deeplense/lens.py +++ b/deeplense/lens.py @@ -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