Skip to content

Commit 07a517d

Browse files
committed
Finishing tutorial.
1 parent 0f9e1f6 commit 07a517d

File tree

1 file changed

+66
-48
lines changed

1 file changed

+66
-48
lines changed

tutorials/python/cluster_wl_simul.qmd

Lines changed: 66 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ from numcosmo_py.plotting.tools import add_ellipse_from_ellipticity
3535
3636
Ncm.cfg_init()
3737
38+
3839
Omega_b = 0.05
3940
Omega_c = 0.25
4041
Omega_k = 0.0
@@ -43,11 +44,11 @@ H0 = 70.0
4344
# Create a cosmology object
4445
cosmo = Nc.HICosmoDEXcdm.new()
4546
cosmo.omega_x2omega_k()
46-
cosmo.param_set_by_name("Omegab", Omega_b)
47-
cosmo.param_set_by_name("Omegac", Omega_c)
48-
cosmo.param_set_by_name("Omegak", Omega_k)
49-
cosmo.param_set_by_name("H0", H0)
50-
cosmo.param_set_by_name("w", -1.0)
47+
cosmo["Omegab"] = Omega_b
48+
cosmo["Omegac"] = Omega_c
49+
cosmo["Omegak"] = Omega_k
50+
cosmo["H0"] = H0
51+
cosmo["w"] = -1.0
5152
5253
dist = Nc.Distance.new(100.0)
5354
dist.prepare(cosmo)
@@ -80,7 +81,7 @@ The cluster's right ascension (RA) and declination (Dec) are set to $12.34^\circ
8081

8182
```{python}
8283
83-
# Set parametners
84+
# Set parameters
8485
mass_delta = 200
8586
cluster_M = 2.0e16
8687
cluster_c = 4.0
@@ -94,12 +95,12 @@ density_profile = Nc.HaloDensityProfileNFW.new(
9495
surface_mass_density = Nc.WLSurfaceMassDensity.new(dist)
9596
halo_position = Nc.HaloPosition.new(dist)
9697
97-
density_profile.param_set_by_name("cDelta", cluster_c)
98-
density_profile.param_set_by_name("log10MDelta", np.log10(cluster_M))
98+
density_profile["cDelta"] = cluster_c
99+
density_profile["log10MDelta"] = np.log10(cluster_M)
99100
100-
halo_position.param_set_by_name("ra", cluster_ra)
101-
halo_position.param_set_by_name("dec", cluster_dec)
102-
halo_position.param_set_by_name("z", cluster_z)
101+
halo_position["ra"] = cluster_ra
102+
halo_position["dec"] = cluster_dec
103+
halo_position["z"] = cluster_z
103104
104105
surface_mass_density.prepare(cosmo)
105106
halo_position.prepare(cosmo)
@@ -127,7 +128,7 @@ The specific values are as follows:
127128
- Declination (Dec): $[-55.273^\circ, -54.973^\circ]$
128129
- **Galaxy shape distribution**:
129130
- **Intrinsic ellipticity dispersion**: $1.0 \times 10^{-8}$
130-
- **Ellipticity mesurement error**: $1.0 \times 10^{-8}$
131+
- **Ellipticity measurement error**: $1.0 \times 10^{-8}$
131132

132133
```{python}
133134
@@ -150,10 +151,7 @@ z_true = Nc.GalaxySDTrueRedshiftLSSTSRD.new(galaxy_true_z_min, galaxy_true_z_max
150151
z_dist = Nc.GalaxySDObsRedshiftGauss.new(z_true)
151152
s_dist = Nc.GalaxySDShapeGauss.new()
152153
153-
s_dist.param_set_by_name("e-rms", galaxy_shape_e_rms)
154-
s_dist.param_set_by_name("e-sigma", galaxy_shape_e_sigma)
155-
156-
s_dist.set_models(cosmo, halo_position)
154+
s_dist["e-rms"] = galaxy_shape_e_rms
157155
158156
pass
159157
```
@@ -167,14 +165,14 @@ We then set the minimum and maximum radii for the weak lensing analysis to focus
167165

168166
```{python}
169167
min_r, max_r = 0.3, 3.0
170-
cluster = Nc.DataClusterWL.new(s_dist, z_dist, p_dist)
168+
cluster = Nc.DataClusterWL.new()
171169
cluster.set_cut(min_r, max_r)
172170
```
173171
### Model-Set
174172

175173
We create an `Nc.MSet` object to encapsulate the models defined above.
176174
The `MSet` object serves as the main container for all models in a given analysis.
177-
We add the cosmological model, the cluster profile and positon models, the galaxy distribution models, and the weak lensing model to the model set.
175+
We add the cosmological model, the cluster profile and position models, the galaxy distribution models, and the weak lensing model to the model set.
178176

179177
This comprehensive model set allows us to manage and run simulations, ensuring that all components interact correctly to produce the desired weak lensing data.
180178

@@ -186,8 +184,8 @@ mset = Ncm.MSet.new_array(
186184
surface_mass_density,
187185
halo_position,
188186
s_dist,
189-
z_true,
190187
z_dist,
188+
p_dist,
191189
]
192190
)
193191
@@ -207,18 +205,32 @@ The mock data, consisting of $200$ galaxies around the cluster, is then generate
207205
```{python}
208206
seed = 1235
209207
n_galaxies = 200
208+
sigma_z = 0.03
210209
211210
rng = Ncm.RNG.seeded_new("mt19937", seed)
212211
213-
cluster.gen_obs(
214-
cosmo,
215-
density_profile,
216-
surface_mass_density,
217-
halo_position,
218-
n_galaxies,
219-
rng,
220-
Nc.GalaxyWLObsCoord.EUCLIDEAN,
212+
z_data = Nc.GalaxySDObsRedshiftData.new(z_dist)
213+
p_data = Nc.GalaxySDPositionData.new(p_dist, z_data)
214+
s_data = Nc.GalaxySDShapeData.new(s_dist, p_data)
215+
216+
obs = Nc.GalaxyWLObs.new(
217+
Nc.GalaxyWLObsCoord.EUCLIDEAN, n_galaxies, list(s_data.required_columns())
221218
)
219+
220+
for i in range(n_galaxies):
221+
z_dist.gen(mset, z_data, sigma_z, rng)
222+
p_dist.gen(mset, p_data, rng)
223+
s_dist.gen(
224+
mset,
225+
s_data,
226+
galaxy_shape_e_sigma,
227+
galaxy_shape_e_sigma,
228+
Nc.GalaxyWLObsCoord.EUCLIDEAN,
229+
rng,
230+
)
231+
s_data.write_row(obs, i)
232+
233+
cluster.set_obs(obs)
222234
```
223235

224236
The mock data can be retrieved from the `cluster` object and used for further analysis.
@@ -277,8 +289,8 @@ add_ellipse_from_ellipticity(
277289
ax,
278290
obs_df["ra"],
279291
obs_df["dec"],
280-
obs_df["e1_int"],
281-
obs_df["e2_int"],
292+
obs_df["epsilon_int_1"],
293+
obs_df["epsilon_int_2"],
282294
ellipse_scale=0.005,
283295
edgecolor="red",
284296
)
@@ -287,8 +299,8 @@ add_ellipse_from_ellipticity(
287299
ax,
288300
obs_df["ra"],
289301
obs_df["dec"],
290-
obs_df["e1"],
291-
obs_df["e2"],
302+
obs_df["epsilon_obs_1"],
303+
obs_df["epsilon_obs_2"],
292304
ellipse_scale=0.005,
293305
edgecolor="blue",
294306
)
@@ -321,25 +333,31 @@ This allows us to explore how changes in these properties affect the weak lensin
321333
322334
323335
def gen_galaxies(halo_ra: float, halo_dec: float, halo_mass: float) -> pd.DataFrame:
324-
halo_position.param_set_by_name("ra", halo_ra)
325-
halo_position.param_set_by_name("dec", halo_dec)
326-
density_profile.param_set_by_name("log10MDelta", np.log10(halo_mass))
336+
rng = Ncm.RNG.seeded_new("mt19937", 1235)
337+
halo_position["ra"] = halo_ra
338+
halo_position["dec"] = halo_dec
339+
density_profile["log10MDelta"] = np.log10(halo_mass)
327340
328341
surface_mass_density.prepare(cosmo)
329342
halo_position.prepare(cosmo)
330343
331-
rng = Ncm.RNG.seeded_new("mt19937", 1235)
332-
cluster.gen_obs(
333-
cosmo,
334-
density_profile,
335-
surface_mass_density,
336-
halo_position,
337-
n_galaxies,
338-
rng,
339-
Nc.GalaxyWLObsCoord.EUCLIDEAN,
344+
obs = Nc.GalaxyWLObs.new(
345+
Nc.GalaxyWLObsCoord.EUCLIDEAN, n_galaxies, list(s_data.required_columns())
340346
)
341347
342-
obs = cluster.peek_obs()
348+
for i in range(n_galaxies):
349+
z_dist.gen(mset, z_data, sigma_z, rng)
350+
p_dist.gen(mset, p_data, rng)
351+
s_dist.gen(
352+
mset,
353+
s_data,
354+
galaxy_shape_e_sigma,
355+
galaxy_shape_e_sigma,
356+
Nc.GalaxyWLObsCoord.EUCLIDEAN,
357+
rng,
358+
)
359+
s_data.write_row(obs, i)
360+
343361
columns = obs.peek_columns()
344362
345363
obs_dict = {}
@@ -393,8 +411,8 @@ for i, ra_shift in enumerate(ra_shifts):
393411
ax,
394412
obs_df["ra"],
395413
obs_df["dec"],
396-
obs_df["e1"],
397-
obs_df["e2"],
414+
obs_df["epsilon_obs_1"],
415+
obs_df["epsilon_obs_2"],
398416
ellipse_scale=0.005,
399417
edgecolor="blue",
400418
)
@@ -452,8 +470,8 @@ for i, mass_shift in enumerate(mass_shifts):
452470
ax,
453471
obs_df["ra"],
454472
obs_df["dec"],
455-
obs_df["e1"],
456-
obs_df["e2"],
473+
obs_df["epsilon_obs_1"],
474+
obs_df["epsilon_obs_2"],
457475
ellipse_scale=0.005,
458476
edgecolor="blue",
459477
)

0 commit comments

Comments
 (0)