-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from dangilman/gcs
Gcs
- Loading branch information
Showing
14 changed files
with
342 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from copy import deepcopy | ||
import numpy as np | ||
|
||
|
||
class Gaussian(object): | ||
""" | ||
This class generates masses from a delta function normalized with respect to a | ||
background density, a mass, and a volume | ||
""" | ||
name = 'GAUSSIAN' | ||
def __init__(self, n, mean, sigma, draw_poisson=True, *args, **kwargs): | ||
""" | ||
:param n: normalization, also equal to the number of objects | ||
:param mean: mass of objects to render | ||
:param sigma: rendering volume | ||
:param draw poisson: whether or not to draw from a poisson distribution | ||
""" | ||
self.mean = mean | ||
self.sigma = sigma | ||
self.n_mean = n | ||
self.first_moment = self.mean | ||
self.draw_poisson = draw_poisson | ||
|
||
def draw(self): | ||
|
||
""" | ||
:return: an array of masses | ||
""" | ||
|
||
if self.draw_poisson: | ||
n = int(np.random.poisson(self.n_mean)) | ||
else: | ||
n = int(np.round(self.n_mean)) | ||
|
||
if n > 0: | ||
log10_mass = np.random.normal(self.mean, self.sigma, n) | ||
m = 10 ** log10_mass | ||
return np.array(m) | ||
else: | ||
return np.array([]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import numpy.testing as npt | ||
from pyHalo.Halos.lens_cosmo import LensCosmo | ||
from lenstronomy.LensModel.Profiles.splcore import SPLCORE | ||
from pyHalo.Halos.HaloModels.powerlaw import GlobularCluster | ||
import pytest | ||
import numpy as np | ||
|
||
|
||
class TestSPLCORE(object): | ||
|
||
def setup_method(self): | ||
|
||
self.zhalo = 0.5 | ||
self.zsource = 2.0 | ||
self.lens_cosmo = LensCosmo(self.zhalo, self.zsource, None) | ||
self.splcore = SPLCORE() | ||
|
||
def test_lenstronomy_ID(self): | ||
|
||
mass = 10 ** 5 | ||
args = {'gamma': 2.5, | ||
'r_core_fraction': 0.05, | ||
'gc_size_lightyear': 100} | ||
profile = GlobularCluster(mass, 0.0, 0.0, self.zhalo, self.lens_cosmo, | ||
args, 1) | ||
lenstronomy_ID = profile.lenstronomy_ID | ||
npt.assert_string_equal(lenstronomy_ID[0], 'SPL_CORE') | ||
|
||
def test_lenstronomy_args(self): | ||
|
||
logM = 5.0 | ||
mass = 10 ** logM | ||
args = {'gamma': 2.5, | ||
'r_core_fraction': 0.05, | ||
'gc_size_lightyear': 100} | ||
profile = GlobularCluster(mass, 0.0, 0.0, self.zhalo, self.lens_cosmo, | ||
args, 1) | ||
lenstronomy_args, _ = profile.lenstronomy_params | ||
profile_lenstronomy = SPLCORE() | ||
profile_args = profile.profile_args | ||
gc_size = profile_args['gc_size'] | ||
rho0 = profile_args['rho0'] | ||
r_core = profile_args['r_core_arcsec'] | ||
gamma = profile_args['gamma'] | ||
mass = profile_lenstronomy.mass_3d(gc_size, rho0, r_core, gamma) | ||
sigma_crit_mpc = self.lens_cosmo.get_sigma_crit_lensing(profile.z, self.lens_cosmo.z_source) | ||
kpc_per_arcsec = self.lens_cosmo.cosmo.kpc_proper_per_asec(profile.z) | ||
sigma_crit_arcsec = sigma_crit_mpc * (0.001 * kpc_per_arcsec) ** 2 | ||
npt.assert_almost_equal(logM, np.log10(mass * sigma_crit_arcsec)) | ||
|
||
if __name__ == '__main__': | ||
pytest.main() |
Oops, something went wrong.