Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dae82a
commit 5a6b43b
Showing
7 changed files
with
250 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Galaxy cluster Sigma(R) reconstruction profiles, also known as 'Y' profiles. | ||
""" | ||
|
||
import cluster_toolkit | ||
from cluster_toolkit import _dcast | ||
import numpy as np | ||
|
||
def Sigma_REC_from_DeltaSigma(R, DeltaSigma): | ||
"""Reconstructed Sigma(R) profile, also known as 'Y' | ||
in the same units as DeltaSigma. | ||
Note: R and DeltaSigma must have the same shape, | ||
and have more than 1 element. The returned array | ||
has one fewer elements. | ||
Note: R must have constant logarithmic spacing. | ||
Args: | ||
R (array like): Projected radii. | ||
DeltaSigma (array like): Differential surface mass density. | ||
Returns: | ||
Reconstructed surface mass density. | ||
""" | ||
R = np.asarray(R) | ||
DeltaSigma = np.asarray(DeltaSigma) | ||
if R.shape != DeltaSigma.shape: | ||
raise Exception("R and DeltaSigma must have the same shape.") | ||
|
||
lnR = np.log(R) | ||
for i in range(len(lnR)-2): | ||
dlnR0 = lnR[i] - lnR[i+1] | ||
dlnR1 = lnR[i+1] - lnR[i+2] | ||
if not (np.fabs(dlnR0 - dlnR1) < 1e-6): | ||
raise Exception("R must have constant logarithmic spacing.") | ||
continue | ||
|
||
#Note the order here, we integrate DOWNWARD | ||
dlnR = lnR[0] - lnR[1] | ||
|
||
Sigma = np.zeros(len(R)-1) | ||
cluster_toolkit._lib.Sigma_REC_from_DeltaSigma(dlnR, _dcast(DeltaSigma), | ||
len(R), _dcast(Sigma)) | ||
return Sigma |
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,2 @@ | ||
int Sigma_REC_from_DeltaSigma(double dlnR, double*DeltaSigma, int N, | ||
double*Sigma); |
Large diffs are not rendered by default.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,54 @@ | ||
/** @file C_sigma_reconstruction.c | ||
* @brief Reconstructed Sigma(R) profiles from large scales. | ||
* | ||
* These experimental routines compute the "Y" | ||
* cluster profiles. This is also known as the | ||
* Sigma(R) reconstruction profiles. | ||
* | ||
* This file will undergo much cleanup in the near future. | ||
* | ||
* @author Tom McClintock (tmcclintock) | ||
* @bug No known bugs. | ||
*/ | ||
|
||
#include "C_sigma_reconstruction.h" | ||
|
||
#include <stdio.h> | ||
|
||
/** | ||
* \brief Reconstructed Sigma profiles (i.e. Y) | ||
* from a precomputed DeltaSigma profile. | ||
* | ||
* Note: output Sigma profile has one less element than | ||
* the input DeltaSigma, also we assume a regular grid | ||
* spacing in the ln(R). | ||
*/ | ||
int Sigma_REC_from_DeltaSigma(double dlnR, double*DeltaSigma, int N, | ||
double*Sigma){ | ||
/* | ||
The transformation is: | ||
Y = T*DeltaSigma = (2S - I)*DeltaSigma | ||
Where I is the identity matrix and S contains the Runge-kutta | ||
elements for a midpoint integration method (i.e. | ||
1/2s on the edges and 1s in the middle) | ||
*/ | ||
//Loop over Sigma elements; i.e. rows | ||
for(int i = 0; i < N-1; i++){ | ||
Sigma[i] = -DeltaSigma[i]; //Not sure if this is positive or negative | ||
|
||
//Loop over DeltaSigma elements; i.e. columns | ||
//for(int j = N-2-i; j < N; j++){ | ||
for(int j = i; j < N; j++){ | ||
Sigma[i] -= 2*dlnR*DeltaSigma[j]; | ||
//Downweight the first and last contributions (midpoint formula) | ||
//if ((j == N-2-i) || (j == N-1)){ | ||
if ((j == i) || (j == N-1)){ | ||
Sigma[i] += dlnR*DeltaSigma[j]; | ||
} | ||
//printf("%e\n",Sigma[i]); | ||
} | ||
} | ||
return 0; | ||
} |
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,5 @@ | ||
import pytest | ||
from cluster_toolkit import sigma_reconstruction as SR | ||
from os.path import dirname, join | ||
import numpy as np | ||
import numpy.testing as npt |