Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00d3d1b

Browse files
vitentipennalima
andauthored
Implemented Integrated Sachs-Wolfe kernel. (#166)
* Implemented Integrated Sachs-Wolfe kernel. * Implemented the derivative of the growth function with respect to redshift. * Cleaning notebooks. * Uncrustify. * Fixing new object nc_xcor_limber_kernel_cmb_isw. * Encapsulating xcor objects. * New tests for xcor. * Made tests a package to allow relative imports. * Organized fixtures in a different file. * Using Stefan-Boltzmann constant. * Adding guard when eval inverse distance. * Fixed limits determination. * Setting more updated constants to CCL. * More high precision parameters. * New tests comparing with CCL. * Fix l dependent factor. * Fixed upper redshift for integration. * Removed time limit for some tests. * Fixed docstrings. * Fixing import. * Fixed power-spectrum derivative. * More tests for kernels. * Ignoring untestable lines. * Updated pylint python version to 3.10. * Added method to NcDistance to compute distance from z1 to z2 without cancellation. * New Cosmology python class to hold NumCosmo's cosmology and computation tools. * Renamed fixture files and reorganizing fixtures. * More fixtures. * Adding types and using Cosmology to hold NumCosmo outputs. * Improving weak-lensing kernel computation. * Tests with reorganized fixtures. * Computing the weak-lensing kernel in a efficient way. * Adding tests for weak-lensing kernel. * Adding tests for galaxy counts kernel. * Reorganized all fixture and tests. * Improved magnification bias computation. * Testing different bias interpolations. * Fixed bug in gsl spline serialization. * Testing comoving distance small difference. * Testing GSL set/get type features. * Testing galaxy kernel methods. * Testing CLASS powspec derivative. * Removed old untested alternative integration methods in xcor. --------- Co-authored-by: Mariana Penna Lima <[email protected]>
1 parent b43acc5 commit 00d3d1b

43 files changed

Lines changed: 3614 additions & 1767 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs=0
77

88
# Minimum Python version to use for version dependent checks. Will default to
99
# the version used to run pylint.
10-
py-version=3.9
10+
py-version=3.10
1111

1212
# Discover python modules and packages in the file system subtree.
1313
recursive=yes

numcosmo/data/nc_data_xcor.c

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,35 @@
7070
#include <gsl/gsl_multifit.h>
7171
#endif /* NUMCOSMO_GIR_SCAN */
7272

73+
struct _NcDataXcor
74+
{
75+
/*< private >*/
76+
NcmDataGaussCov parent_instance;
77+
78+
guint nobs;
79+
80+
NcXcorAB *xcab[NC_DATA_XCOR_MAX][NC_DATA_XCOR_MAX];
81+
82+
NcmObjArray *xcab_oa;
83+
/* guint xcab_oa_idx[NC_DATA_XCOR_MAX * NC_DATA_XCOR_MAX][2]; */
84+
/* guint xcab_oa_ctr; */
85+
86+
gint xcidx[NC_DATA_XCOR_MAX][NC_DATA_XCOR_MAX];
87+
guint xcidx_ctr;
88+
89+
/* gboolean X_init; */
90+
NcmMatrix *X1; /*[NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS]; */
91+
NcmMatrix *X2; /*[NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS]; / * X matrices (=mask dependent, cosmology independent part of the covariances <C_l^{a,b}C_l'^{c,d}>) * / */
92+
93+
NcmVector *pcl;
94+
NcmMatrix *pcov;
95+
96+
NcXcor *xc;
97+
98+
NcmModelCtrl *cosmo_ctrl;
99+
GPtrArray *xclk_ctrl;
100+
};
101+
73102
enum
74103
{
75104
PROP_0,
@@ -282,8 +311,7 @@ static void
282311
nc_data_xcor_finalize (GObject *object)
283312
{
284313
/* Chain up : end */
285-
G_OBJECT_CLASS (nc_data_xcor_parent_class)
286-
->finalize (object);
314+
G_OBJECT_CLASS (nc_data_xcor_parent_class)->finalize (object);
287315
}
288316

289317
static void _nc_data_xcor_prepare (NcmData *data, NcmMSet *mset);
@@ -355,57 +383,64 @@ _nc_data_xcor_fast_update (NcDataXcor *dxc, NcXcorLimberKernel *xcl, guint a, Nc
355383
{
356384
NcXcorLimberKernelGal *xclkg = NC_XCOR_LIMBER_KERNEL_GAL (xcl);
357385

358-
if (xclkg->fast_update)
386+
if (nc_xcor_limber_kernel_gal_get_fast_update (xclkg))
359387
{
360-
const gdouble biasratio = *(xclkg->bias) / xclkg->bias_old;
388+
gdouble bias, bias_old, noise_bias_old;
361389

362-
NcmVector *cl_th_0_aa = ncm_matrix_get_col (dxc->xcab[a][a]->cl_th, 0);
363-
NcmVector *cl_th_1_aa = ncm_matrix_get_col (dxc->xcab[a][a]->cl_th, 1);
390+
nc_xcor_limber_kernel_gal_get_bias (xclkg, &bias, &bias_old, &noise_bias_old);
391+
{
392+
const gdouble biasratio = bias / bias_old;
364393

365-
ncm_vector_add_constant (cl_th_0_aa, -1.0 * xclkg->noise_bias_old);
366-
ncm_vector_scale (cl_th_0_aa, gsl_pow_2 (biasratio));
367-
nc_xcor_limber_kernel_add_noise (xcl, cl_th_0_aa, cl_th_1_aa, 0);
394+
NcmVector *cl_th_0_aa = ncm_matrix_get_col (dxc->xcab[a][a]->cl_th, 0);
395+
NcmVector *cl_th_1_aa = ncm_matrix_get_col (dxc->xcab[a][a]->cl_th, 1);
368396

369-
ncm_vector_free (cl_th_0_aa);
370-
ncm_vector_free (cl_th_1_aa);
397+
ncm_vector_add_constant (cl_th_0_aa, -1.0 * noise_bias_old);
398+
ncm_vector_scale (cl_th_0_aa, gsl_pow_2 (biasratio));
399+
nc_xcor_limber_kernel_add_noise (xcl, cl_th_0_aa, cl_th_1_aa, 0);
371400

372-
const guint nobs = dxc->nobs;
373-
guint b;
401+
ncm_vector_free (cl_th_0_aa);
402+
ncm_vector_free (cl_th_1_aa);
374403

375-
if (nobs > 1)
376-
{
377-
for (b = 0; b < nobs; b++)
404+
const guint nobs = dxc->nobs;
405+
guint b;
406+
407+
if (nobs > 1)
378408
{
379-
if (a < b)
409+
for (b = 0; b < nobs; b++)
380410
{
381-
NcmVector *cl_th_0_ab = ncm_matrix_get_col (dxc->xcab[a][b]->cl_th, 0);
382-
NcmVector *cl_th_1_ab = ncm_matrix_get_col (dxc->xcab[a][b]->cl_th, 1);
411+
if (a < b)
412+
{
413+
NcmVector *cl_th_0_ab = ncm_matrix_get_col (dxc->xcab[a][b]->cl_th, 0);
414+
NcmVector *cl_th_1_ab = ncm_matrix_get_col (dxc->xcab[a][b]->cl_th, 1);
383415

384-
ncm_vector_scale (cl_th_0_ab, biasratio);
385-
ncm_vector_memcpy (cl_th_1_ab, cl_th_0_ab);
416+
ncm_vector_scale (cl_th_0_ab, biasratio);
417+
ncm_vector_memcpy (cl_th_1_ab, cl_th_0_ab);
386418

387-
ncm_vector_free (cl_th_0_ab);
388-
ncm_vector_free (cl_th_1_ab);
389-
}
390-
else if (b < a)
391-
{
392-
NcmVector *cl_th_0_ba = ncm_matrix_get_col (dxc->xcab[b][a]->cl_th, 0);
393-
NcmVector *cl_th_1_ba = ncm_matrix_get_col (dxc->xcab[b][a]->cl_th, 1);
419+
ncm_vector_free (cl_th_0_ab);
420+
ncm_vector_free (cl_th_1_ab);
421+
}
422+
else if (b < a)
423+
{
424+
NcmVector *cl_th_0_ba = ncm_matrix_get_col (dxc->xcab[b][a]->cl_th, 0);
425+
NcmVector *cl_th_1_ba = ncm_matrix_get_col (dxc->xcab[b][a]->cl_th, 1);
394426

395-
ncm_vector_scale (cl_th_0_ba, biasratio);
396-
ncm_vector_memcpy (cl_th_1_ba, cl_th_0_ba);
427+
ncm_vector_scale (cl_th_0_ba, biasratio);
428+
ncm_vector_memcpy (cl_th_1_ba, cl_th_0_ba);
397429

398-
ncm_vector_free (cl_th_0_ba);
399-
ncm_vector_free (cl_th_1_ba);
430+
ncm_vector_free (cl_th_0_ba);
431+
ncm_vector_free (cl_th_1_ba);
432+
}
400433
}
401434
}
402435
}
403436

404437
{
405438
NcmVector *orig_vec = ncm_model_orig_params_peek_vector (NCM_MODEL (xclkg));
406439

407-
xclkg->bias_old = *(xclkg->bias);
408-
xclkg->noise_bias_old = ncm_vector_get (orig_vec, NC_XCOR_LIMBER_KERNEL_GAL_NOISE_BIAS);
440+
nc_xcor_limber_kernel_gal_set_bias_old (xclkg,
441+
bias,
442+
ncm_vector_get (orig_vec, NC_XCOR_LIMBER_KERNEL_GAL_NOISE_BIAS)
443+
);
409444
}
410445

411446
return TRUE;

numcosmo/data/nc_data_xcor.h

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@
3838
G_BEGIN_DECLS
3939

4040
#define NC_TYPE_DATA_XCOR (nc_data_xcor_get_type ())
41-
#define NC_DATA_XCOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_DATA_XCOR, NcDataXcor))
42-
#define NC_DATA_XCOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NC_TYPE_DATA_XCOR, NcDataXcorClass))
43-
#define NC_IS_DATA_XCOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_DATA_XCOR))
44-
#define NC_IS_DATA_XCOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NC_TYPE_DATA_XCOR))
45-
#define NC_DATA_XCOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NC_TYPE_DATA_XCOR, NcDataXcorClass))
41+
42+
G_DECLARE_FINAL_TYPE (NcDataXcor, nc_data_xcor, NC, DATA_XCOR, NcmDataGaussCov)
4643

4744
#define NC_DATA_XCOR_MAX (5)
4845

@@ -62,48 +59,8 @@ G_BEGIN_DECLS
6259
/* */
6360
/* } NcDataXcorAB; */
6461

65-
typedef struct _NcDataXcorClass NcDataXcorClass;
66-
typedef struct _NcDataXcor NcDataXcor;
67-
68-
struct _NcDataXcor
69-
{
70-
/*< private >*/
71-
NcmDataGaussCov parent_instance;
72-
73-
guint nobs;
74-
75-
NcXcorAB *xcab[NC_DATA_XCOR_MAX][NC_DATA_XCOR_MAX];
76-
77-
NcmObjArray *xcab_oa;
78-
/* guint xcab_oa_idx[NC_DATA_XCOR_MAX * NC_DATA_XCOR_MAX][2]; */
79-
/* guint xcab_oa_ctr; */
80-
81-
gint xcidx[NC_DATA_XCOR_MAX][NC_DATA_XCOR_MAX];
82-
guint xcidx_ctr;
83-
84-
/* gboolean X_init; */
85-
NcmMatrix *X1; /*[NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS]; */
86-
NcmMatrix *X2; /*[NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS][NC_DATA_XCOR_MAX_NOBS]; / * X matrices (=mask dependent, cosmology independent part of the covariances <C_l^{a,b}C_l'^{c,d}>) * / */
87-
88-
NcmVector *pcl;
89-
NcmMatrix *pcov;
90-
91-
NcXcor *xc;
92-
93-
NcmModelCtrl *cosmo_ctrl;
94-
GPtrArray *xclk_ctrl;
95-
};
96-
97-
struct _NcDataXcorClass
98-
{
99-
/*< private >*/
100-
NcmDataGaussCovClass parent_class;
101-
};
102-
103-
GType nc_data_xcor_get_type (void) G_GNUC_CONST;
104-
10562
/* NcmData* nc_data_xcor_new (gboolean use_norma); */
106-
NcDataXcor *nc_data_xcor_new_full (const guint nobs, NcXcor *xc, gboolean use_norma); /*, const gchar* xcname[]); */
63+
NcDataXcor * nc_data_xcor_new_full (const guint nobs, NcXcor * xc, gboolean use_norma); /*, const gchar* xcname[]); */
10764
void nc_data_xcor_set_2 (NcDataXcor *dxc, guint a, guint b, guint ell_th_cut_off, guint ell_lik_min, guint ell_lik_max, const gchar *clobs_filename, const gchar *mixing_filename, const guint mixing_filelength);
10865
void nc_data_xcor_set_AB (NcDataXcor *dxc, NcXcorAB *xcab);
10966
void nc_data_xcor_set_3 (NcDataXcor *dxc);

numcosmo/lss/nc_growth_func.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@
7878
#include "math/ncm_spline_cubic_notaknot.h"
7979
#include "math/ncm_cfg.h"
8080

81-
82-
#ifndef NUMCOSMO_GIR_SCAN
83-
#endif /* NUMCOSMO_GIR_SCAN */
84-
8581
#ifndef NUMCOSMO_GIR_SCAN
8682
#include <cvode/cvode.h>
8783

numcosmo/math/ncm_c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ ncm_c_crit_number_density_n (void)
15721572
NCM_INLINE gdouble
15731573
ncm_c_blackbody_energy_density (void)
15741574
{
1575-
return 4.0 * (gsl_pow_2 (ncm_c_pi ()) * gsl_pow_4 (ncm_c_kb ()) / (60.0 * gsl_pow_3 (ncm_c_h () / (2.0 * ncm_c_pi ())) * gsl_pow_2 (ncm_c_c ()))) / ncm_c_c ();
1575+
return 4.0 * ncm_c_stefan_boltzmann () / ncm_c_c ();
15761576
}
15771577

15781578
NCM_INLINE gdouble

numcosmo/math/ncm_powspec.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ _ncm_powspec_get_property (GObject *object, guint prop_id, GValue *value, GParam
192192
}
193193
}
194194

195+
/* LCOV_EXCL_START */
195196
static void
196197
_ncm_powspec_prepare (NcmPowspec *powspec, NcmModel *model)
197198
{
@@ -206,6 +207,16 @@ _ncm_powspec_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const
206207
return 0.0;
207208
}
208209

210+
static gdouble
211+
_ncm_powspec_deriv_z (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k)
212+
{
213+
g_error ("_ncm_powspec_deriv_z: no default implementation, all children must implement it.");
214+
215+
return 0.0;
216+
}
217+
218+
/* LCOV_EXCL_STOP */
219+
209220
static void _ncm_powspec_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, NcmVector *k, NcmVector *Pk);
210221

211222
typedef struct __NcmPowspecSplineData
@@ -363,6 +374,7 @@ ncm_powspec_class_init (NcmPowspecClass *klass)
363374
klass->eval = &_ncm_powspec_eval;
364375
klass->eval_vec = &_ncm_powspec_eval_vec;
365376
klass->get_spline_2d = &_ncm_powspec_get_spline_2d;
377+
klass->deriv_z = &_ncm_powspec_deriv_z;
366378
}
367379

368380
static void
@@ -751,6 +763,23 @@ ncm_powspec_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, Ncm
751763
NCM_POWSPEC_GET_CLASS (powspec)->eval_vec (powspec, model, z, k, Pk);
752764
}
753765

766+
/**
767+
* ncm_powspec_deriv_z:
768+
* @powspec: a #NcmPowspec
769+
* @model: (allow-none): a #NcmModel
770+
* @z: time $z$
771+
* @k: mode $k$
772+
*
773+
* Evaluates the derivative of the power spectrum @powspec with respect to $z$ at $(z, k)$.
774+
*
775+
* Returns: $\partial P(z, k) / \partial z$.
776+
*/
777+
gdouble
778+
ncm_powspec_deriv_z (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k)
779+
{
780+
return NCM_POWSPEC_GET_CLASS (powspec)->deriv_z (powspec, model, z, k);
781+
}
782+
754783
/**
755784
* ncm_powspec_get_spline_2d:
756785
* @powspec: a #NcmPowspec

numcosmo/math/ncm_powspec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct _NcmPowspecClass
4747
void (*prepare) (NcmPowspec *powspec, NcmModel *model);
4848
gdouble (*eval) (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k);
4949
void (*eval_vec) (NcmPowspec *powspec, NcmModel *model, const gdouble z, NcmVector *k, NcmVector *Pk);
50+
gdouble (*deriv_z) (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k);
5051
void (*get_nknots) (NcmPowspec *powspec, guint *Nz, guint *Nk);
5152
NcmSpline2d *(*get_spline_2d) (NcmPowspec *powspec, NcmModel *model);
5253

@@ -84,6 +85,7 @@ void ncm_powspec_prepare (NcmPowspec *powspec, NcmModel *model);
8485
void ncm_powspec_prepare_if_needed (NcmPowspec *powspec, NcmModel *model);
8586
gdouble ncm_powspec_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k);
8687
void ncm_powspec_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, NcmVector *k, NcmVector *Pk);
88+
gdouble ncm_powspec_deriv_z (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k);
8789
NcmSpline2d *ncm_powspec_get_spline_2d (NcmPowspec *powspec, NcmModel *model);
8890
NcmModelCtrl *ncm_powspec_peek_model_ctrl (NcmPowspec *powspec);
8991

numcosmo/math/ncm_spline_gsl.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,21 +399,27 @@ ncm_spline_gsl_new_full_by_id (NcmSplineGslType type_id, NcmVector *xv, NcmVecto
399399
void
400400
ncm_spline_gsl_set_type (NcmSplineGsl *sg, const gsl_interp_type *type)
401401
{
402+
const GEnumValue *type_id = ncm_cfg_get_enum_by_id_name_nick (NCM_TYPE_SPLINE_GSL_TYPE, type->name);
403+
402404
if (sg->interp != NULL)
403405
{
404406
if (sg->type != type)
405407
{
406-
sg->type = type;
408+
sg->type = type;
409+
sg->type_id = type_id->value;
410+
g_free (sg->inst_name);
411+
sg->inst_name = g_strdup_printf ("NcmSplineGsl[%s]", type->name);
412+
407413
gsl_interp_free (sg->interp);
408414
sg->interp = NULL;
409415
_ncm_spline_gsl_reset (NCM_SPLINE (sg));
410416
}
411417
}
412418
else
413419
{
414-
sg->type = type;
420+
sg->type = type;
421+
sg->type_id = type_id->value;
415422
g_free (sg->inst_name);
416-
/* printf("NcmSplineGsl[%s]", type->name); */
417423
sg->inst_name = g_strdup_printf ("NcmSplineGsl[%s]", type->name);
418424
}
419425
}
@@ -429,8 +435,6 @@ ncm_spline_gsl_set_type (NcmSplineGsl *sg, const gsl_interp_type *type)
429435
void
430436
ncm_spline_gsl_set_type_by_id (NcmSplineGsl *sg, NcmSplineGslType type_id)
431437
{
432-
sg->type_id = type_id;
433-
434438
switch (type_id)
435439
{
436440
case NCM_SPLINE_GSL_LINEAR:
@@ -479,3 +483,31 @@ ncm_spline_gsl_set_type_by_name (NcmSplineGsl *sg, const gchar *type_name)
479483
ncm_spline_gsl_set_type_by_id (sg, type_id->value);
480484
}
481485

486+
/**
487+
* ncm_spline_gsl_get_type_id:
488+
* @sg: a #NcmSplineGsl
489+
*
490+
* This function returns the interpolation method id of @sg.
491+
*
492+
* Returns: the interpolation method id.
493+
*/
494+
NcmSplineGslType
495+
ncm_spline_gsl_get_type_id (NcmSplineGsl *sg)
496+
{
497+
return sg->type_id;
498+
}
499+
500+
/**
501+
* ncm_spline_gsl_get_gsl_type:
502+
* @sg: a #NcmSplineGsl
503+
*
504+
* This function returns the interpolation method of @sg.
505+
*
506+
* Returns: the gsl interpolation method.
507+
*/
508+
const gsl_interp_type *
509+
ncm_spline_gsl_get_gsl_type (NcmSplineGsl *sg)
510+
{
511+
return sg->type;
512+
}
513+

numcosmo/math/ncm_spline_gsl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ void ncm_spline_gsl_set_type (NcmSplineGsl *sg, const gsl_interp_type *type);
6767
void ncm_spline_gsl_set_type_by_id (NcmSplineGsl *sg, NcmSplineGslType type_id);
6868
void ncm_spline_gsl_set_type_by_name (NcmSplineGsl *sg, const gchar *type_name);
6969

70+
NcmSplineGslType ncm_spline_gsl_get_type_id (NcmSplineGsl *sg);
71+
const gsl_interp_type *ncm_spline_gsl_get_gsl_type (NcmSplineGsl *sg);
72+
7073
G_END_DECLS
7174

7275
#endif /* _NCM_SPLINE_GSL_H_ */

0 commit comments

Comments
 (0)