Skip to content

Commit d075c38

Browse files
authored
gh-107: add all public functions/classes under glass namespace (#221)
- All public or user-facing GLASS functionality now falls under the `glass` module name. - Use absolute imports instead of relative imports within the package (PEP8) Closes: #107 Changed: All the public functions and classes are now under the `glass` namespace
1 parent d7bd1e2 commit d075c38

17 files changed

+180
-137
lines changed

docs/user/how-glass-works.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Radial discretisation
2020
The discretisation in the radial (line of sight) direction is done in *GLASS*
2121
using the concept of a :term:`radial window`, which consists of a window
2222
function :math:`W` that assigns a weight :math:`W(z)` to each redshift
23-
:math:`z`. In the *GLASS* code, the :class:`~glass.shells.RadialWindow` named
23+
:math:`z`. In the *GLASS* code, the :class:`~glass.RadialWindow` named
2424
tuple is used to define radial windows.
2525

2626
A sequence :math:`W_1, W_2, \ldots` of such window functions defines the shells
27-
of the simulation. For example, the :func:`~glass.shells.tophat_windows`
27+
of the simulation. For example, the :func:`~glass.tophat_windows`
2828
function takes redshift boundaries and returns a sequence of top hat windows,
2929
which are flat and non-overlapping.
3030

@@ -169,7 +169,7 @@ shells:
169169
170170
In short, the requirements say that each shell has an effective redshift which
171171
partitions the window functions of all other shells. In *GLASS*, it is stored
172-
as the ``zeff`` attribute of :class:`~glass.shells.RadialWindow`. Functions
172+
as the ``zeff`` attribute of :class:`~glass.RadialWindow`. Functions
173173
that construct a list of windows for shells should ensure these requirements
174174
are met.
175175

examples/1-basic/density.ipynb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,8 @@
4242
"import camb\n",
4343
"from cosmology import Cosmology\n",
4444
"\n",
45-
"# GLASS imports: matter, random fields, random points, galaxies\n",
46-
"import glass.shells\n",
47-
"import glass.fields\n",
48-
"import glass.points\n",
49-
"import glass.galaxies\n",
45+
"# import GLASS for matter, random fields, random points, galaxies\n",
46+
"import glass\n",
5047
"\n",
5148
"\n",
5249
"# cosmology for the simulation\n",
@@ -66,10 +63,10 @@
6663
"cosmo = Cosmology.from_camb(pars)\n",
6764
"\n",
6865
"# shells of 200 Mpc in comoving distance spacing\n",
69-
"zb = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
66+
"zb = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
7067
"\n",
7168
"# linear radial window functions\n",
72-
"ws = glass.shells.linear_windows(zb)\n",
69+
"ws = glass.linear_windows(zb)\n",
7370
"\n",
7471
"# load the angular matter power spectra previously computed with CAMB\n",
7572
"cls = np.load(\"cls.npy\")"
@@ -97,10 +94,10 @@
9794
"outputs": [],
9895
"source": [
9996
"# compute Gaussian cls for lognormal fields for 3 correlated shells\n",
100-
"gls = glass.fields.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n",
97+
"gls = glass.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n",
10198
"\n",
10299
"# generator for lognormal matter fields\n",
103-
"matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)"
100+
"matter = glass.generate_lognormal(gls, nside, ncorr=3)"
104101
]
105102
},
106103
{
@@ -129,7 +126,7 @@
129126
"dndz = np.full_like(z, 0.01)\n",
130127
"\n",
131128
"# distribute the dN/dz over the linear window functions\n",
132-
"ngal = glass.shells.partition(z, dndz, ws)"
129+
"ngal = glass.partition(z, dndz, ws)"
133130
]
134131
},
135132
{
@@ -164,11 +161,9 @@
164161
"# simulate and add galaxies in each matter shell to cube\n",
165162
"for i, delta_i in enumerate(matter):\n",
166163
" # simulate positions from matter density\n",
167-
" for gal_lon, gal_lat, gal_count in glass.points.positions_from_delta(\n",
168-
" ngal[i], delta_i\n",
169-
" ):\n",
164+
" for gal_lon, gal_lat, gal_count in glass.positions_from_delta(ngal[i], delta_i):\n",
170165
" # sample redshifts uniformly in shell\n",
171-
" gal_z = glass.galaxies.redshifts(gal_count, ws[i])\n",
166+
" gal_z = glass.redshifts(gal_count, ws[i])\n",
172167
"\n",
173168
" # add counts to cube\n",
174169
" z1 = gal_z * np.cos(np.deg2rad(gal_lon)) * np.cos(np.deg2rad(gal_lat))\n",

examples/1-basic/lensing.ipynb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,8 @@
4646
"import camb\n",
4747
"from cosmology import Cosmology\n",
4848
"\n",
49-
"# GLASS imports\n",
50-
"import glass.shells\n",
51-
"import glass.fields\n",
52-
"import glass.lensing\n",
53-
"import glass.galaxies\n",
49+
"# import GLASS\n",
50+
"import glass\n",
5451
"\n",
5552
"\n",
5653
"# cosmology for the simulation\n",
@@ -70,10 +67,10 @@
7067
"cosmo = Cosmology.from_camb(pars)\n",
7168
"\n",
7269
"# shells of 200 Mpc in comoving distance spacing\n",
73-
"zb = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
70+
"zb = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
7471
"\n",
7572
"# linear radial window functions\n",
76-
"ws = glass.shells.linear_windows(zb)\n",
73+
"ws = glass.linear_windows(zb)\n",
7774
"\n",
7875
"# load the angular matter power spectra previously computed with CAMB\n",
7976
"cls = np.load(\"cls.npy\")"
@@ -102,10 +99,10 @@
10299
"source": [
103100
"# compute Gaussian cls for lognormal fields for 3 correlated shells\n",
104101
"# putting nside here means that the HEALPix pixel window function is applied\n",
105-
"gls = glass.fields.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n",
102+
"gls = glass.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n",
106103
"\n",
107104
"# generator for lognormal matter fields\n",
108-
"matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)"
105+
"matter = glass.generate_lognormal(gls, nside, ncorr=3)"
109106
]
110107
},
111108
{
@@ -130,7 +127,7 @@
130127
"outputs": [],
131128
"source": [
132129
"# this will compute the convergence field iteratively\n",
133-
"convergence = glass.lensing.MultiPlaneConvergence(cosmo)"
130+
"convergence = glass.MultiPlaneConvergence(cosmo)"
134131
]
135132
},
136133
{
@@ -160,7 +157,7 @@
160157
"dndz = np.exp(-((z - 0.5) ** 2) / (0.1) ** 2)\n",
161158
"\n",
162159
"# distribute dN/dz over the radial window functions\n",
163-
"ngal = glass.shells.partition(z, dndz, ws)"
160+
"ngal = glass.partition(z, dndz, ws)"
164161
]
165162
},
166163
{
@@ -200,7 +197,7 @@
200197
" kappa_i = convergence.kappa\n",
201198
"\n",
202199
" # compute shear field\n",
203-
" gamm1_i, gamm2_i = glass.lensing.shear_from_convergence(kappa_i)\n",
200+
" gamm1_i, gamm2_i = glass.shear_from_convergence(kappa_i)\n",
204201
"\n",
205202
" # add to mean fields using the galaxy number density as weight\n",
206203
" kappa_bar += ngal[i] * kappa_i\n",

examples/1-basic/matter.ipynb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
"import camb\n",
4343
"from cosmology import Cosmology\n",
4444
"\n",
45-
"# these are the GLASS imports: matter and random fields\n",
46-
"import glass.shells\n",
47-
"import glass.fields\n",
45+
"# import GLASS for matter and random fields\n",
46+
"import glass\n",
4847
"\n",
4948
"\n",
5049
"# cosmology for the simulation\n",
@@ -65,16 +64,16 @@
6564
"cosmo = Cosmology.from_camb(pars)\n",
6665
"\n",
6766
"# shells of 200 Mpc in comoving distance spacing\n",
68-
"zb = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
67+
"zb = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
6968
"\n",
7069
"# load precomputed angular matter power spectra\n",
7170
"cls = np.load(\"cls.npy\")\n",
7271
"\n",
7372
"# compute Gaussian cls for lognormal fields with 3 correlated shells\n",
74-
"gls = glass.fields.lognormal_gls(cls, ncorr=3, nside=nside)\n",
73+
"gls = glass.lognormal_gls(cls, ncorr=3, nside=nside)\n",
7574
"\n",
7675
"# this generator will yield the matter fields in each shell\n",
77-
"matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)"
76+
"matter = glass.generate_lognormal(gls, nside, ncorr=3)"
7877
]
7978
},
8079
{

examples/1-basic/photoz.ipynb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
"import numpy as np\n",
3939
"import matplotlib.pyplot as plt\n",
4040
"\n",
41-
"# GLASS imports: matter shells, galaxies, random points, and observational\n",
42-
"import glass.galaxies\n",
43-
"import glass.observations\n",
41+
"# import GLASS for matter shells, galaxies, random points, and observational\n",
42+
"import glass\n",
4443
"\n",
4544
"# how many arcmin2 over the entire sphere\n",
4645
"from glass.core.constants import ARCMIN2_SPHERE\n",
@@ -54,7 +53,7 @@
5453
"\n",
5554
"# parametric galaxy redshift distribution\n",
5655
"z = np.linspace(0, 3, 301)\n",
57-
"dndz = n_arcmin2 * glass.observations.smail_nz(z, 1.0, 2.2, 1.5)\n",
56+
"dndz = n_arcmin2 * glass.smail_nz(z, 1.0, 2.2, 1.5)\n",
5857
"\n",
5958
"# compute the over galaxy number density on the sphere\n",
6059
"ngal = np.trapz(dndz, z)"
@@ -87,10 +86,10 @@
8786
"n = np.random.poisson(ngal * ARCMIN2_SPHERE)\n",
8887
"\n",
8988
"# sample n true redshifts\n",
90-
"ztrue = glass.galaxies.redshifts_from_nz(n, z, dndz)\n",
89+
"ztrue = glass.redshifts_from_nz(n, z, dndz)\n",
9190
"\n",
9291
"# sample n photometric redshifts\n",
93-
"zphot = glass.galaxies.gaussian_phz(ztrue, phz_sigma_0)"
92+
"zphot = glass.gaussian_phz(ztrue, phz_sigma_0)"
9493
]
9594
},
9695
{
@@ -147,7 +146,7 @@
147146
"metadata": {},
148147
"source": [
149148
"Now define a number of photometric redshift bins. They are chosen by the\n",
150-
":func:`~glass.observations.equal_dens_zbins` function to produce the same\n",
149+
":func:`~glass.equal_dens_zbins` function to produce the same\n",
151150
"number of galaxies in each bin.\n",
152151
"\n"
153152
]
@@ -167,7 +166,7 @@
167166
"outputs": [],
168167
"source": [
169168
"nbins = 5\n",
170-
"zbins = glass.observations.equal_dens_zbins(z, dndz, nbins)"
169+
"zbins = glass.equal_dens_zbins(z, dndz, nbins)"
171170
]
172171
},
173172
{
@@ -176,7 +175,7 @@
176175
"source": [
177176
"After the photometric bins are defined, make histograms of the *true* redshift\n",
178177
"distribution $n(z)$ using the *photometric* redshifts for binning. Use\n",
179-
"the :func:`~glass.observations.tomo_nz_gausserr()` function to also plot the\n",
178+
"the :func:`~glass.tomo_nz_gausserr()` function to also plot the\n",
180179
"expected tomographic redshift distributions with the same model.\n",
181180
"\n"
182181
]
@@ -211,7 +210,7 @@
211210
}
212211
],
213212
"source": [
214-
"tomo_nz = glass.observations.tomo_nz_gausserr(z, dndz, phz_sigma_0, zbins)\n",
213+
"tomo_nz = glass.tomo_nz_gausserr(z, dndz, phz_sigma_0, zbins)\n",
215214
"tomo_nz *= ARCMIN2_SPHERE * (z[-1] - z[0]) / 40\n",
216215
"\n",
217216
"for (z1, z2), nz in zip(zbins, tomo_nz):\n",

examples/1-basic/shells.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"import camb\n",
4444
"from cosmology import Cosmology\n",
4545
"\n",
46-
"import glass.shells\n",
46+
"import glass\n",
4747
"import glass.ext.camb\n",
4848
"\n",
4949
"\n",
@@ -64,10 +64,10 @@
6464
"cosmo = Cosmology.from_camb(pars)\n",
6565
"\n",
6666
"# shells of 200 Mpc in comoving distance spacing\n",
67-
"zgrid = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
67+
"zgrid = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
6868
"\n",
6969
"# triangular radial windows, equivalent to linear interpolation of n(z)\n",
70-
"shells = glass.shells.linear_windows(zgrid)\n",
70+
"shells = glass.linear_windows(zgrid)\n",
7171
"\n",
7272
"# compute angular matter power spectra with CAMB\n",
7373
"cls = glass.ext.camb.matter_cls(pars, lmax, shells)"

examples/2-advanced/cosmic_shear.ipynb

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@
4141
"import camb\n",
4242
"from cosmology import Cosmology\n",
4343
"\n",
44-
"# GLASS modules: cosmology and everything in the glass namespace\n",
45-
"import glass.shells\n",
46-
"import glass.fields\n",
47-
"import glass.points\n",
48-
"import glass.shapes\n",
49-
"import glass.lensing\n",
50-
"import glass.galaxies\n",
44+
"import glass\n",
5145
"from glass.core.constants import ARCMIN2_SPHERE\n",
5246
"\n",
5347
"\n",
@@ -68,10 +62,10 @@
6862
"cosmo = Cosmology.from_camb(pars)\n",
6963
"\n",
7064
"# shells of 200 Mpc in comoving distance spacing\n",
71-
"zb = glass.shells.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
65+
"zb = glass.distance_grid(cosmo, 0.0, 1.0, dx=200.0)\n",
7266
"\n",
7367
"# linear window function for shells\n",
74-
"ws = glass.shells.linear_windows(zb)\n",
68+
"ws = glass.linear_windows(zb)\n",
7569
"\n",
7670
"# load the angular matter power spectra previously computed with CAMB\n",
7771
"cls = np.load(\"../1-basic/cls.npy\")"
@@ -100,10 +94,10 @@
10094
"source": [
10195
"# compute Gaussian cls for lognormal fields for 3 correlated shells\n",
10296
"# putting nside here means that the HEALPix pixel window function is applied\n",
103-
"gls = glass.fields.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n",
97+
"gls = glass.lognormal_gls(cls, nside=nside, lmax=lmax, ncorr=3)\n",
10498
"\n",
10599
"# generator for lognormal matter fields\n",
106-
"matter = glass.fields.generate_lognormal(gls, nside, ncorr=3)"
100+
"matter = glass.generate_lognormal(gls, nside, ncorr=3)"
107101
]
108102
},
109103
{
@@ -128,7 +122,7 @@
128122
"outputs": [],
129123
"source": [
130124
"# this will compute the convergence field iteratively\n",
131-
"convergence = glass.lensing.MultiPlaneConvergence(cosmo)"
125+
"convergence = glass.MultiPlaneConvergence(cosmo)"
132126
]
133127
},
134128
{
@@ -165,7 +159,7 @@
165159
"dndz *= n_arcmin2 / np.trapz(dndz, z)\n",
166160
"\n",
167161
"# distribute dN/dz over the radial window functions\n",
168-
"ngal = glass.shells.partition(z, dndz, ws)"
162+
"ngal = glass.partition(z, dndz, ws)"
169163
]
170164
},
171165
{
@@ -211,15 +205,15 @@
211205
" # compute the lensing maps for this shell\n",
212206
" convergence.add_window(delta_i, ws[i])\n",
213207
" kappa_i = convergence.kappa\n",
214-
" gamm1_i, gamm2_i = glass.lensing.shear_from_convergence(kappa_i)\n",
208+
" gamm1_i, gamm2_i = glass.shear_from_convergence(kappa_i)\n",
215209
"\n",
216210
" # generate galaxy positions uniformly over the sphere\n",
217-
" for gal_lon, gal_lat, gal_count in glass.points.uniform_positions(ngal[i]):\n",
211+
" for gal_lon, gal_lat, gal_count in glass.uniform_positions(ngal[i]):\n",
218212
" # generate galaxy ellipticities from the chosen distribution\n",
219-
" gal_eps = glass.shapes.ellipticity_intnorm(gal_count, sigma_e)\n",
213+
" gal_eps = glass.ellipticity_intnorm(gal_count, sigma_e)\n",
220214
"\n",
221215
" # apply the shear fields to the ellipticities\n",
222-
" gal_she = glass.galaxies.galaxy_shear(\n",
216+
" gal_she = glass.galaxy_shear(\n",
223217
" gal_lon, gal_lat, gal_eps, kappa_i, gamm1_i, gamm2_i\n",
224218
" )\n",
225219
"\n",

0 commit comments

Comments
 (0)