Skip to content

Commit

Permalink
Make TAUTAIL, the stopping criterion for optical depth profiles, conf…
Browse files Browse the repository at this point in the history
…igurable

TAUTAIL gives the minimum optical depth each particle can
contribute to a pixel (although the nearest pixel is always included).
Make this runtime configurable instead of a compile constant.
  • Loading branch information
sbird committed Sep 1, 2018
1 parent 6b85ec4 commit e08e5f5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cextract/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int main(int argc, char **argv)
populate_los_table(cofm, axis,NumLos, ext_table, box100);
/*Setup the interpolator*/
const double velfac = atime/h100*Hz/1e3;
ParticleInterp pint(NBINS, LAMBDA_LYA_H1, GAMMA_LYA_H1, FOSC_LYA, HMASS, box100, velfac, atime, cofm, axis,NumLos,1);
ParticleInterp pint(NBINS, LAMBDA_LYA_H1, GAMMA_LYA_H1, FOSC_LYA, HMASS, box100, velfac, atime, cofm, axis,NumLos,1, 1e-5);
if(!(output=fopen(outname.c_str(),"w")))
{
fprintf(stderr, "Error opening %s: %s\n",outname.c_str(), strerror(errno));
Expand Down
11 changes: 4 additions & 7 deletions fake_spectra/absorption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
/*Conversion factor between internal energy and mu and temperature in K */
#define TSCALE ((GAMMA-1.0) * PROTONMASS * ESCALE / BOLTZMANN)

//Threshold of tau below which we stop computing profiles
//Note that because this is for each particle, it should be fairly small.
#define TAUTAIL 1e-5

/* Find the integral of the particle density in this pixel by integrating an SPH kernel
* over the z direction.
* Arguments:
Expand Down Expand Up @@ -105,7 +101,8 @@ kern_frac_func get_kern_frac(const int kernel)

//Factor of 1e5 in bfac converts from cm/s to km/s
//Factor of 1e5 in voigt_fac converts from cm/s to km/s
LineAbsorption::LineAbsorption(const double lambda, const double gamma, const double fosc, const double amumass, const double velfac_i, const double boxsize, const double atime_i,const int kernel_i):
LineAbsorption::LineAbsorption(const double lambda, const double gamma, const double fosc, const double amumass, const double velfac_i, const double boxsize, const double atime_i,const int kernel_i, const double tautail):
tautail(tautail),
sigma_a( sqrt(3.0*M_PI*SIGMA_T/8.0) * lambda * fosc ),
bfac( sqrt(2.0*BOLTZMANN/(amumass*PROTONMASS))/1e5 ),
voigt_fac( gamma*lambda/(4.*M_PI)/1e5 ),
Expand Down Expand Up @@ -187,7 +184,7 @@ void LineAbsorption::add_tau_particle(double * tau, const int nbins, const doubl
j+=nbins;
tau[j]+=taulast;
//Absorption will only decrease as you go further from the particle.
if(taulast < TAUTAIL)
if(taulast < tautail)
break;
}
//Go from the particle backwards
Expand All @@ -201,7 +198,7 @@ void LineAbsorption::add_tau_particle(double * tau, const int nbins, const doubl
j+=nbins;
tau[j]+=taulast;
//Absorption will only decrease as you go further from the particle.
if(taulast < TAUTAIL)
if(taulast < tautail)
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion fake_spectra/absorption.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LineAbsorption
* gamma: transition rate in 1/s
* fosc: oscillation fraction
* */
LineAbsorption(const double lambda, const double gamma, const double fosc, const double amumass, const double velfac_i, const double boxsize, const double atime_i, const int kernel_i);
LineAbsorption(const double lambda, const double gamma, const double fosc, const double amumass, const double velfac_i, const double boxsize, const double atime_i, const int kernel_i, const double tautail);

/* Add the absorption from a particle to the spectrum in the array
* tau, or the density from the particle to the array colden,
Expand All @@ -52,6 +52,9 @@ class LineAbsorption
void add_tau_particle(double * tau, const int nbins, const double dr2, const float dens, const float ppos, const float pvel, const float temp, const float smooth);

private:
/* Threshold of tau below which we stop computing profiles.
* Note that because this is for each particle, it should be fairly small.*/
const double tautail;
/* Absorption cross-sections cm^2 */
const double sigma_a;
/* Constant factor to turn sqrt(temperature) in K into velocity in km/s*/
Expand Down
4 changes: 2 additions & 2 deletions fake_spectra/part_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
class ParticleInterp: public LineAbsorption
{
public:
ParticleInterp(const int nbins_i, const double lambda, const double gamma, const double fosc, const double amumass, const double boxsize, const double velfac, const double atime, const double cofm[], const int axis[], const int NumLos, const int kernel):
LineAbsorption(lambda, gamma, fosc, amumass, velfac, boxsize, atime, kernel),
ParticleInterp(const int nbins_i, const double lambda, const double gamma, const double fosc, const double amumass, const double boxsize, const double velfac, const double atime, const double cofm[], const int axis[], const int NumLos, const int kernel, const double tautail):
LineAbsorption(lambda, gamma, fosc, amumass, velfac, boxsize, atime, kernel, tautail),
nbins(nbins_i),nlos(NumLos),
sort_los_table(cofm, axis, NumLos, boxsize)
{
Expand Down
8 changes: 4 additions & 4 deletions fake_spectra/py_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ extern "C" PyObject * Py_Particle_Interpolation(PyObject *self, PyObject *args)
//Things which should be from input
int nbins, NumLos, compute_tau, kernel;
long long Npart;
double box100, velfac, lambda, gamma, fosc, amumass, atime;
double box100, velfac, lambda, gamma, fosc, amumass, atime, tautail;
npy_intp size[2];
//Input variables in np format
PyArrayObject *pos, *vel, *dens, *temp, *h;
PyArrayObject *cofm, *axis;

//Get our input
if(!PyArg_ParseTuple(args, "iiidddddddO!O!O!O!O!O!O!", &compute_tau, &nbins, &kernel, &box100, &velfac, &atime, &lambda, &gamma, &fosc, &amumass, &PyArray_Type, &pos, &PyArray_Type, &vel, &PyArray_Type, &dens, &PyArray_Type, &temp, &PyArray_Type, &h, &PyArray_Type, &axis, &PyArray_Type, &cofm) )
if(!PyArg_ParseTuple(args, "iiiddddddddO!O!O!O!O!O!O!", &compute_tau, &nbins, &kernel, &box100, &velfac, &atime, &lambda, &gamma, &fosc, &amumass, &tautail, &PyArray_Type, &pos, &PyArray_Type, &vel, &PyArray_Type, &dens, &PyArray_Type, &temp, &PyArray_Type, &h, &PyArray_Type, &axis, &PyArray_Type, &cofm) )
{
PyErr_SetString(PyExc_AttributeError, "Incorrect arguments: use compute_tau, nbins, boxsize, velfac, atime, lambda, gamma, fosc, species mass (amu), pos, vel, dens, temp, h, axis, cofm\n");
PyErr_SetString(PyExc_AttributeError, "Incorrect arguments: use compute_tau, nbins, boxsize, velfac, atime, lambda, gamma, fosc, species mass (amu), min. tau, pos, vel, dens, temp, h, axis, cofm\n");
return NULL;
}

Expand Down Expand Up @@ -167,7 +167,7 @@ extern "C" PyObject * Py_Particle_Interpolation(PyObject *self, PyObject *args)
PyErr_SetString(PyExc_MemoryError, "Getting contiguous copies of input arrays failed\n");
return NULL;
}
ParticleInterp pint(nbins, lambda, gamma, fosc, amumass, box100, velfac, atime, Cofm, Axis ,NumLos, kernel);
ParticleInterp pint(nbins, lambda, gamma, fosc, amumass, box100, velfac, atime, Cofm, Axis ,NumLos, kernel, tautail);

PyObject * for_return;
/* Allocate array space. This is (I hope) contiguous.
Expand Down
5 changes: 4 additions & 1 deletion fake_spectra/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def __init__(self,num, base,cofm, axis, res=1., cdir=None, savefile="spectra.hdf
self.cdir = cdir
#Minimum length of spectra within which to look at metal absorption (in km/s)
self.minwidth = 500.
#Stopping criterion for optical depth: if a particle is adding less
#than this to a pixel, stop the integration.
self.tautail = 1e-5
try:
if load_snapshot:
self.snapshot_set = absn.AbstractSnapshotFactory(num, base)
Expand Down Expand Up @@ -505,7 +508,7 @@ def _get_elem_den(self, elem, ion, den, temp, ind, ind2):
def _do_interpolation_work(self,pos, vel, elem_den, temp, hh, amumass, line, get_tau):
"""Run the interpolation on some pre-determined arrays, spat out by _read_particle_data"""
#Factor of 10^-8 converts line width (lambda_X) from Angstrom to cm
return _Particle_Interpolate(get_tau*1, self.nbins, self.snapshot_set.get_kernel(), self.box, self.velfac, self.atime, line.lambda_X*1e-8, line.gamma_X, line.fosc_X, amumass, pos, vel, elem_den, temp, hh, self.axis, self.cofm)
return _Particle_Interpolate(get_tau*1, self.nbins, self.snapshot_set.get_kernel(), self.box, self.velfac, self.atime, line.lambda_X*1e-8, line.gamma_X, line.fosc_X, amumass, self.tautail, pos, vel, elem_den, temp, hh, self.axis, self.cofm)

def particles_near_lines(self, pos, hh,axis=None, cofm=None):
"""Filter a particle list, returning an index list of those near sightlines"""
Expand Down

0 comments on commit e08e5f5

Please sign in to comment.