Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Gilman committed Jul 25, 2023
1 parent a91e094 commit 2207474
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
14 changes: 0 additions & 14 deletions pyHalo/Cosmology/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ def _volume_integrand_comoving(self, z, radius_arcsec):
dR = self.cosmo.astropy.hubble_distance.value * self.cosmo.astropy.efunc(z) ** -1
return area_comoving * dR

def _angle_to_arcsec_area(self, radius_arcsec, z):

theta = self._angle_to_arcsec_radius(radius_arcsec, z)

return np.pi * theta ** 2

def angle_to_comoving_area(self, radius_arcsec, z):
"""
computes the area corresponding to the angular radius of a plane at redshift z for a double cone with base at z_base
Expand Down Expand Up @@ -135,14 +129,6 @@ def angle_to_physical_area(self, radius_arcsec, z):

return area_comoving * a_z ** 2

def _angle_to_arcsec_radius(self, radius_arcsec, z):

r_co_mpc = self.angle_to_comovingradius(radius_arcsec, z)
r_co_kpc = r_co_mpc * 1000
asec_per_kpc = self.cosmo.astropy.arcsec_per_kpc_comoving(z).value

return r_co_kpc * asec_per_kpc

class Cone(object):

def __init__(self, cosmology, z_lens, z_source, opening_angle, angle_pad):
Expand Down
6 changes: 0 additions & 6 deletions pyHalo/preset_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,9 @@ def WDMGeneral(z_lens, z_source, log_mc, dlogT_dlogk, sigma_sub=0.025, log_mlow=
# SET THE SPATIAL DISTRIBUTION MODELS FOR SUBHALOS AND FIELD HALOS:
subhalo_spatial_distribution = ProjectedNFW
fieldhalo_spatial_distribution = LensConeUniform

kwargs_model_dlogT_dlogk = {'dlogT_dlogk': dlogT_dlogk}
mass_function_model_subhalos, kwargs_mfunc_subs = preset_mass_function_models('STUCKER_SHMF', kwargs_model_dlogT_dlogk)
mass_function_model_fieldhalos, kwargs_mfunc_field = preset_mass_function_models('STUCKER', kwargs_model_dlogT_dlogk)

# SET THE CONCENTRATION-MASS RELATION FOR SUBHALOS AND FIELD HALOS
concentration_model = 'FROM_FORMATION_HISTORY'
model_subhalos, kwargs_concentration_model_subhalos = preset_concentration_models(concentration_model,
Expand All @@ -757,11 +755,9 @@ def WDMGeneral(z_lens, z_source, log_mc, dlogT_dlogk, sigma_sub=0.025, log_mlow=
kwargs_concentration_model_fieldhalos['log_mc'] = log_mc
concentration_model_fieldhalos = model_fieldhalos(**kwargs_concentration_model_fieldhalos)
c_host = concentration_model_fieldhalos.nfw_concentration(10 ** log_m_host, z_lens)

# SET THE TRUNCATION RADIUS FOR SUBHALOS AND FIELD HALOS
kwargs_truncation_model_subhalos['lens_cosmo'] = pyhalo.lens_cosmo
kwargs_truncation_model_fieldhalos['lens_cosmo'] = pyhalo.lens_cosmo

model_subhalos, kwargs_trunc_subs = truncation_models(truncation_model_subhalos)
kwargs_trunc_subs.update(kwargs_truncation_model_subhalos)
if truncation_model_subhalos == 'TRUNCATION_GALACTICUS':
Expand All @@ -770,10 +766,8 @@ def WDMGeneral(z_lens, z_source, log_mc, dlogT_dlogk, sigma_sub=0.025, log_mlow=
model_fieldhalos, kwargs_trunc_field = truncation_models(truncation_model_fieldhalos)
kwargs_trunc_field.update(kwargs_truncation_model_fieldhalos)
truncation_model_fieldhalos = model_fieldhalos(**kwargs_trunc_field)

# NOW THAT THE CLASSES ARE SPECIFIED, WE SORT THE KEYWORD ARGUMENTS AND CLASSES INTO LISTS
population_model_list = ['SUBHALOS', 'LINE_OF_SIGHT', 'TWO_HALO']

mass_function_class_list = [mass_function_model_subhalos,
mass_function_model_fieldhalos,
mass_function_model_fieldhalos]
Expand Down
11 changes: 0 additions & 11 deletions pyHalo/realization_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,7 @@ def add_primordial_black_holes(self, pbh_mass_fraction, kwargs_pbh_mass_function
realization_smooth = Realization(masses, xcoords, ycoords, r3d, mdefs, redshifts, subhalo_flag,
self._realization.lens_cosmo, kwargs_halo_model=kwargs_halo_model,
mass_sheet_correction=False)

kwargs_pbh_mass_function['mass_fraction'] = mass_fraction_clumpy

for ii, (x_image_interp, y_image_interp, r_max) in enumerate(zip(x_image_interp_list, y_image_interp_list, r_max_arcsec)):
realization_with_clustering_temp = self.add_correlated_structure(DeltaFunction,
kwargs_pbh_mass_function,
Expand Down Expand Up @@ -421,7 +419,6 @@ def _get_fluctuation_halos(realization, fluctuation_amplitude, fluctuation_size,
fluctuation_size_variance_angle = fluctuation_size_variance / kpc_per_arcsec

if shape != 'aperture':

sigs = np.abs(np.random.normal(fluc_var_angle,fluctuation_size_variance_angle,n_flucs)) #random widths
kappa0 = np.random.normal(0, fluctuation_amplitude, n_flucs)
# kappa0 = amp / (2 * np.pi * sigma ** 2)
Expand All @@ -441,28 +438,20 @@ def _get_fluctuation_halos(realization, fluctuation_amplitude, fluctuation_size,
ys = aa*np.cos(angles)*np.sin(args['angle'])+bb*np.sin(angles)*np.cos(args['angle']) #random y positions

if shape == 'aperture':

amps, sigs, xs, ys = np.array([]), np.array([]), np.array([]), np.array([])

for i in range(0, len(n_flucs)): #loop through each image

sigs_i = np.random.normal(fluc_var_angle,fluctuation_size_variance_angle,n_flucs[i])
sigs_i = np.absolute(sigs_i)

kappa0 = np.random.normal(0, fluctuation_amplitude, n_flucs[i])
amps_i = kappa0 * 2*np.pi*sigs_i**2

angles_i = np.random.uniform(0, 2*np.pi, n_flucs[i]) # random angles
r = np.random.uniform(0, args['aperture'] ** 2, int(n_flucs[i]))
xs_i = r ** 0.5 * np.sin(angles_i) + args['x_images'][i]
ys_i = r ** 0.5 * np.cos(angles_i) + args['y_images'][i]
amps, sigs, xs, ys= np.append(amps, amps_i), np.append(sigs, sigs_i), np.append(xs, xs_i), np.append(ys, ys_i)

args_fluc=[{'amp': amps[i], 'sigma': sigs[i], 'center_x': xs[i], 'center_y': ys[i]} for i in range(len(amps))]
# kappa(r) = kappa * exp(-0.5 * r^2/sigma^2)
#sigma_crit = realization.lens_cosmo.sigmacrit # in units M_sun / arcsec^2
masses = np.absolute(amps)
#masses = [10 ** 8.0] * len(xs)
fluctuations = [Gaussian(masses[i], xs[i], ys[i], None, realization.lens_cosmo.z_lens,
True, realization.lens_cosmo, args_fluc[i],
truncation_class=None, concentration_class=None,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cosmology/test_cone_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ def test_total_volume(self):
volume_true = 1./3 * np.pi * radius_radians ** 2 * dz ** 2 * ds
npt.assert_almost_equal(volume_true, volume_pyhalo, 3)

def test_cone(self):

cone_arcsec = 4
radius_radians = cone_arcsec * 0.5 * self.cosmo.arcsec
geo = Geometry(self.cosmo, 0.5, 1.5, cone_arcsec, 'CONE', angle_pad=1.)
volume_pyhalo = 0
z = np.linspace(0.0, 1.5, 200)
for i in range(0, len(z)-1):
delta_z = z[i+1] - z[i]
volume_pyhalo += geo.volume_element_comoving(z[i], delta_z)

ds = self.cosmo.D_C_z(1.5)
volume_true = 1./3 * np.pi * radius_radians ** 2 * ds ** 3
npt.assert_almost_equal(volume_true, volume_pyhalo, 3)


if __name__ == '__main__':
pytest.main()

0 comments on commit 2207474

Please sign in to comment.