Skip to content

Commit 5a6b43b

Browse files
committed
Implemented the Y(R) profiles.
1 parent 9dae82a commit 5a6b43b

File tree

7 files changed

+250
-1
lines changed

7 files changed

+250
-1
lines changed

cluster_toolkit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ def _dcast(x):
3434
if isinstance(x, list): x = np.asarray(x, dtype=np.float64, order='C')
3535
return _ffi.cast('double*', x.ctypes.data)
3636

37-
from . import averaging, bias, boostfactors, concentration, deltasigma, density, exclusion, massfunction, miscentering, peak_height, profile_derivatives, xi
37+
from . import averaging, bias, boostfactors, concentration, deltasigma, density, exclusion, massfunction, miscentering, peak_height, profile_derivatives, sigma_reconstruction, xi
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Galaxy cluster Sigma(R) reconstruction profiles, also known as 'Y' profiles.
2+
"""
3+
4+
import cluster_toolkit
5+
from cluster_toolkit import _dcast
6+
import numpy as np
7+
8+
def Sigma_REC_from_DeltaSigma(R, DeltaSigma):
9+
"""Reconstructed Sigma(R) profile, also known as 'Y'
10+
in the same units as DeltaSigma.
11+
12+
Note: R and DeltaSigma must have the same shape,
13+
and have more than 1 element. The returned array
14+
has one fewer elements.
15+
16+
Note: R must have constant logarithmic spacing.
17+
18+
Args:
19+
R (array like): Projected radii.
20+
DeltaSigma (array like): Differential surface mass density.
21+
22+
Returns:
23+
Reconstructed surface mass density.
24+
"""
25+
R = np.asarray(R)
26+
DeltaSigma = np.asarray(DeltaSigma)
27+
if R.shape != DeltaSigma.shape:
28+
raise Exception("R and DeltaSigma must have the same shape.")
29+
30+
lnR = np.log(R)
31+
for i in range(len(lnR)-2):
32+
dlnR0 = lnR[i] - lnR[i+1]
33+
dlnR1 = lnR[i+1] - lnR[i+2]
34+
if not (np.fabs(dlnR0 - dlnR1) < 1e-6):
35+
raise Exception("R must have constant logarithmic spacing.")
36+
continue
37+
38+
#Note the order here, we integrate DOWNWARD
39+
dlnR = lnR[0] - lnR[1]
40+
41+
Sigma = np.zeros(len(R)-1)
42+
cluster_toolkit._lib.Sigma_REC_from_DeltaSigma(dlnR, _dcast(DeltaSigma),
43+
len(R), _dcast(Sigma))
44+
return Sigma

include/C_sigma_reconstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int Sigma_REC_from_DeltaSigma(double dlnR, double*DeltaSigma, int N,
2+
double*Sigma);

notebooks/Sigma(R) Reconstruction.ipynb

Lines changed: 144 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/sigma_reconstructed.png

92.2 KB
Loading

src/C_sigma_reconstruction.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/** @file C_sigma_reconstruction.c
2+
* @brief Reconstructed Sigma(R) profiles from large scales.
3+
*
4+
* These experimental routines compute the "Y"
5+
* cluster profiles. This is also known as the
6+
* Sigma(R) reconstruction profiles.
7+
*
8+
* This file will undergo much cleanup in the near future.
9+
*
10+
* @author Tom McClintock (tmcclintock)
11+
* @bug No known bugs.
12+
*/
13+
14+
#include "C_sigma_reconstruction.h"
15+
16+
#include <stdio.h>
17+
18+
/**
19+
* \brief Reconstructed Sigma profiles (i.e. Y)
20+
* from a precomputed DeltaSigma profile.
21+
*
22+
* Note: output Sigma profile has one less element than
23+
* the input DeltaSigma, also we assume a regular grid
24+
* spacing in the ln(R).
25+
*/
26+
int Sigma_REC_from_DeltaSigma(double dlnR, double*DeltaSigma, int N,
27+
double*Sigma){
28+
/*
29+
The transformation is:
30+
31+
Y = T*DeltaSigma = (2S - I)*DeltaSigma
32+
33+
Where I is the identity matrix and S contains the Runge-kutta
34+
elements for a midpoint integration method (i.e.
35+
1/2s on the edges and 1s in the middle)
36+
*/
37+
//Loop over Sigma elements; i.e. rows
38+
for(int i = 0; i < N-1; i++){
39+
Sigma[i] = -DeltaSigma[i]; //Not sure if this is positive or negative
40+
41+
//Loop over DeltaSigma elements; i.e. columns
42+
//for(int j = N-2-i; j < N; j++){
43+
for(int j = i; j < N; j++){
44+
Sigma[i] -= 2*dlnR*DeltaSigma[j];
45+
//Downweight the first and last contributions (midpoint formula)
46+
//if ((j == N-2-i) || (j == N-1)){
47+
if ((j == i) || (j == N-1)){
48+
Sigma[i] += dlnR*DeltaSigma[j];
49+
}
50+
//printf("%e\n",Sigma[i]);
51+
}
52+
}
53+
return 0;
54+
}

tests/test_sigma_reconstruction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pytest
2+
from cluster_toolkit import sigma_reconstruction as SR
3+
from os.path import dirname, join
4+
import numpy as np
5+
import numpy.testing as npt

0 commit comments

Comments
 (0)