Slight re-organization of C/C++ tools. Significant modifications to support observational data. Python and pipeline scripts added

This commit is contained in:
P.M. Sutter 2012-10-31 10:43:15 -05:00
parent 15496df4ff
commit 14abbc2018
42 changed files with 16252 additions and 557 deletions

View file

@ -14,6 +14,8 @@ struct ZobovVoid
float proba;
int numParticles, coreParticle;
float volume;
float barycenter[3];
float nearestBoundary;
};
struct ZobovRep

View file

@ -22,6 +22,7 @@ bool loadParticleInfo(ParticleInfo& info,
info.ranges[1][1] = f_info.get_att("range_y_max")->as_double(0);
info.ranges[2][0] = f_info.get_att("range_z_min")->as_double(0);
info.ranges[2][1] = f_info.get_att("range_z_max")->as_double(0);
info.mask_index = f_info.get_att("mask_index")->as_int(0); //PMS
for (int i = 0; i < 3; i++)
info.length[i] = info.ranges[i][1] - info.ranges[i][0];

View file

@ -15,6 +15,7 @@ struct ParticleInfo
ParticleVector particles;
float ranges[3][2];
float length[3];
int mask_index; // PMS
};
bool loadParticleInfo(ParticleInfo& info,

View file

@ -0,0 +1,531 @@
#include <healpix_map.h>
#include <healpix_map_fitsio.h>
#include <boost/format.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "generateFromCatalog_conf.h"
#include "contour_pixels.hpp"
#include <netcdfcpp.h>
#include <CosmoTool/fortran.hpp>
#include <gsl/gsl_interp.h>
#include <gsl/gsl_integration.h>
#define LIGHT_SPEED 299792.458
using namespace std;
using boost::format;
using namespace CosmoTool;
struct NYU_Data
{
int index;
int sector;
int region;
double ra, dec;
double cz;
double fgotten;
double phi_z;
};
struct Position
{
double xyz[3];
};
struct ParticleData
{
vector<int> id_gal;
vector<double> ra;
vector<double> dec;
vector<double> redshift;
int id_mask;
// PMS
int mask_index;
// END PMS
vector<Position> pos;
double box[3][2];
double Lmax;
};
typedef vector<NYU_Data> NYU_VData;
// this defines the expansion function that we will integrate
// Laveaux & Wandelt (2012) Eq. 24
struct my_expan_params { double Om; double w0; double wa; };
double expanFun (double z, void * p) {
struct my_expan_params * params = (struct my_expan_params *)p;
double Om = (params->Om);
double w0 = (params->w0);
double wa = (params->wa);
//const double h0 = 1.0;
const double h0 = 0.71;
double ez;
double wz = w0 + wa*z/(1+z);
ez = Om*pow(1+z,3) + (1.-Om);
//ez = Om*pow(1+z,3) + pow(h0,2) * (1.-Om)*pow(1+z,3+3*wz);
ez = sqrt(ez);
//ez = sqrt(ez)/h0;
ez = 1./ez;
return ez;
}
void loadData(const string& fname, NYU_VData & data)
{
ifstream f(fname.c_str());
while (!f.eof())
{
NYU_Data d;
f >> d.index >> d.sector >> d.region >> d.ra >> d.dec >> d.cz >> d.fgotten >> d.phi_z;
data.push_back(d);
}
}
void generateGalaxiesInCube(NYU_VData& data, ParticleData& output_data,
bool useLCDM)
{
double d2r = M_PI/180;
gsl_function expanF;
expanF.function = &expanFun;
struct my_expan_params expanParams;
double maxZ = 2.0, z, result, error, *dL, *redshifts;
int numZ = 1000, iZ;
size_t nEval;
expanParams.Om = 0.27;
expanParams.w0 = -1.0;
expanParams.wa = 0.0;
expanF.params = &expanParams;
dL = (double *) malloc(numZ * sizeof(double));
redshifts = (double *) malloc(numZ * sizeof(double));
for (iZ = 0; iZ < numZ; iZ++) {
z = iZ * maxZ/numZ;
//gsl_integration_qng(&expanF, 0.0, z, 1.e-6, 1.e-6, &result, &error, &nEval);
dL[iZ] = result;
redshifts[iZ] = z;
}
gsl_interp *interp = gsl_interp_alloc(gsl_interp_linear, numZ);
gsl_interp_init(interp, redshifts, dL, numZ);
gsl_interp_accel *acc = gsl_interp_accel_alloc();
output_data.pos.resize(data.size());
output_data.id_gal.resize(data.size());
output_data.ra.resize(data.size());
output_data.dec.resize(data.size());
output_data.redshift.resize(data.size());
for (int j = 0; j < 3; j++)
{
output_data.box[j][0] = -INFINITY;
output_data.box[j][1] = INFINITY;
}
for (int i = 0; i < data.size(); i++)
{
double ra = data[i].ra*d2r, dec = data[i].dec*d2r;
Position& p = output_data.pos[i];
if (useLCDM) {
//double pos = gsl_interp_eval(interp, redshifts, dL, data[i].cz, acc);
gsl_integration_qng(&expanF, 1.e-6, data[i].cz/LIGHT_SPEED,
1.e-6,
1.e-6, &result, &error, &nEval);
double Dc = result*LIGHT_SPEED;
cout << "HELLO " << data[i].cz << " " << Dc << endl;
p.xyz[0] = Dc*cos(ra)*cos(dec);
p.xyz[1] = Dc*sin(ra)*cos(dec);
p.xyz[2] = Dc*sin(dec);
} else {
p.xyz[0] = data[i].cz*cos(ra)*cos(dec);
p.xyz[1] = data[i].cz*sin(ra)*cos(dec);
p.xyz[2] = data[i].cz*sin(dec);
}
//printf("CREATE %e %e\n", data[i].cz, sqrt(p.xyz[0]*p.xyz[0] + p.xyz[1]*p.xyz[1] + p.xyz[2]*p.xyz[2]));
output_data.id_gal[i] = data[i].index;
output_data.ra[i] = ra;
output_data.dec[i] = dec;
output_data.redshift[i] = data[i].cz;
for (int j = 0; j < 3; j++)
{
if (p.xyz[j] > output_data.box[j][0])
output_data.box[j][0] = p.xyz[j];
if (p.xyz[j] < output_data.box[j][1])
output_data.box[j][1] = p.xyz[j];
}
//printf("INSERT GAL %d %e %e %e\n", output_data.id_gal[i], p.xyz[0], p.xyz[1], p.xyz[2]);
}
cout << format("Galaxy position generated: %d galaxies") % output_data.pos.size() << endl;
cout << format("box is %g < x < %g; %g < y < %g; %g < z < %g")
% (1e-2*output_data.box[0][1]) % (1e-2*output_data.box[0][0])
% (1e-2*output_data.box[1][1]) % (1e-2*output_data.box[1][0])
% (1e-2*output_data.box[2][1]) % (1e-2*output_data.box[2][0]) << endl;
gsl_interp_free(interp);
}
void generateSurfaceMask(generateFromCatalog_info& args ,
Healpix_Map<float>& mask,
vector<int>& pixel_list,
vector<int>& full_mask_list,
NYU_VData& data,
ParticleData& output_data)
{
// Find the first free index
int idx = -1;
int insertion = 0;
double volume = pixel_list.size()*1.0/mask.Npix()*4*M_PI;
int numToInsert;
for (int i = 0; i < output_data.id_gal.size(); i++)
{
if (idx < output_data.id_gal[i])
idx = output_data.id_gal[i]+1;
}
output_data.id_mask = idx;
// PMS
output_data.mask_index = output_data.id_gal.size();
// END PMS
cout << "Generate surface mask..." << endl;
double Rmax = -1;
for (int j = 0; j < 3; j++)
{
Rmax = max(Rmax, max(output_data.box[j][0], -output_data.box[j][1]));
}
output_data.Lmax = Rmax;
// PMS - write a small text file with galaxy position
FILE *fp;
fp = fopen("galaxies.txt", "w");
for (int i = 0; i < data.size(); i++) {
Position& p = output_data.pos[i];
fprintf(fp, "%e %e %e\n",
(p.xyz[0]),
(p.xyz[1]),
(p.xyz[2]));
}
fclose(fp);
// END PMS
cout << format("Rmax is %g, surface volume is %g") % (Rmax/100) % (volume/(4*M_PI)) << endl;
volume *= Rmax*Rmax*Rmax/3/1e6;
numToInsert = (int)floor(volume*args.density_fake_arg);
cout << format("3d volume to fill: %g (Mpc/h)^3") % volume << endl;
cout << format("Will insert %d particles") % numToInsert << endl;
fp = fopen("mock_galaxies.txt", "w");
double pct = 0;
for (int i = 0; i < numToInsert; i++) {
double new_pct = i*100./numToInsert;
if (new_pct-pct > 5.) {
pct = new_pct;
cout << format(" .. %3.0f %%") % pct << endl;
}
Position p;
bool stop_here;
do {
int p0 = (int)floor(drand48()*pixel_list.size());
vec3 v = mask.pix2vec(pixel_list[p0]);
double r = Rmax*pow(drand48(),1./3);
p.xyz[0] = v.x * r;
p.xyz[1] = v.y * r;
p.xyz[2] = v.z * r;
stop_here = true;
for (int j = 0; j < 3; j++) {
if (p.xyz[j] > output_data.box[j][0] ||
p.xyz[j] < output_data.box[j][1])
stop_here = false;
}
}
while (!stop_here);
// PMS : write mock galaxies to a small file for plotting
fprintf(fp, "%e %e %e\n",
(p.xyz[0]),
(p.xyz[1]),
(p.xyz[2]));
// END PMS
output_data.pos.push_back(p);
output_data.id_gal.push_back(idx);
output_data.ra.push_back(-1);
output_data.dec.push_back(-1);
output_data.redshift.push_back(-1);
//printf("INSERT MOCK %d %e %e %e\n", idx, p.xyz[0], p.xyz[1], p.xyz[2]);
insertion++;
}
fclose(fp);
// PMS
// TEST - insert mock galaxies along box edge
fp = fopen("mock_boundary.txt", "w");
double dx[3];
dx[0] = output_data.box[0][1] - output_data.box[0][0];
dx[1] = output_data.box[1][1] - output_data.box[1][0];
dx[2] = output_data.box[2][1] - output_data.box[2][0];
int nPart = 100;
// TEST
for (int iDir = 0; iDir < 0; iDir++) {
for (int iFace = 0; iFace < 0; iFace++) {
//for (int iDir = 0; iDir < 3; iDir++) {
//for (int iFace = 0; iFace < 2; iFace++) {
int iy = (iDir + 1) % 3;
int iz = (iDir + 2) % 3;
for (int i = 0; i < nPart; i++) {
for (int j = 0; j < nPart; j++) {
Position p;
p.xyz[iDir] = output_data.box[iDir][iFace];
p.xyz[iy] = i * dx[iy]/nPart + output_data.box[iy][0];
p.xyz[iz] = j * dx[iz]/nPart + output_data.box[iz][0];
output_data.pos.push_back(p);
output_data.id_gal.push_back(idx);
output_data.ra.push_back(-1);
output_data.dec.push_back(-1);
output_data.redshift.push_back(-1);
insertion++;
fprintf(fp, "%e %e %e\n",
(p.xyz[0]),
(p.xyz[1]),
(p.xyz[2]));
}
}
}
}
fclose(fp);
// END PMS
// PMS
// TEST - insert mock galaxies along spheres of survey redshift boundaries
fp = fopen("mock_sphere.txt", "w");
for (int p = 0; p < full_mask_list.size(); p++) {
vec3 v = mask.pix2vec(full_mask_list[p]);
Position p;
double r = args.zMin_arg * LIGHT_SPEED;
if (r > 0.) {
p.xyz[0] = v.x * r;
p.xyz[1] = v.y * r;
p.xyz[2] = v.z * r;
output_data.pos.push_back(p);
output_data.id_gal.push_back(idx);
output_data.ra.push_back(-1);
output_data.dec.push_back(-1);
output_data.redshift.push_back(-1);
insertion++;
fprintf(fp, "%e %e %e\n",
(p.xyz[0]),
(p.xyz[1]),
(p.xyz[2]));
}
r = args.zMax_arg * LIGHT_SPEED;
p.xyz[0] = v.x * r;
p.xyz[1] = v.y * r;
p.xyz[2] = v.z * r;
output_data.pos.push_back(p);
output_data.id_gal.push_back(idx);
output_data.ra.push_back(-1);
output_data.dec.push_back(-1);
output_data.redshift.push_back(-1);
insertion++;
fprintf(fp, "%e %e %e\n",
(p.xyz[0]),
(p.xyz[1]),
(p.xyz[2]));
}
fclose(fp);
// END PMS
cout << format("Done. Inserted %d particles.") % insertion << endl;
}
void saveData(ParticleData& pdata)
{
NcFile f("particles.nc", NcFile::Replace);
assert(f.is_valid());
NcDim *d = f.add_dim("space", 3);
NcDim *p = f.add_dim("Np", pdata.pos.size());
NcVar *v = f.add_var("particles", ncDouble, d, p);
double *x = new double[pdata.pos.size()];
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < pdata.pos.size(); i++)
x[i] = pdata.pos[i].xyz[j];
v->put_rec(d, x, j);
}
v = f.add_var("id_gal", ncInt, p);
v->put(&pdata.id_gal[0], pdata.id_gal.size());
delete[] x;
}
void saveForZobov(ParticleData& pdata, const string& fname, const string& paramname)
{
UnformattedWrite f(fname);
static const char axis[] = { 'X', 'Y', 'Z' };
double Lmax = pdata.Lmax;
f.beginCheckpoint();
f.writeInt32(pdata.pos.size());
f.endCheckpoint();
for (int j = 0; j < 3; j++)
{
cout << format("Writing %c components...") % axis[j] << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < pdata.pos.size(); i++)
{
f.writeReal32((pdata.pos[i].xyz[j]+Lmax)/(2*Lmax));
}
f.endCheckpoint();
}
NcFile fp(paramname.c_str(), NcFile::Replace);
fp.add_att("range_x_min", -Lmax/100.);
fp.add_att("range_x_max", Lmax/100.);
fp.add_att("range_y_min", -Lmax/100.);
fp.add_att("range_y_max", Lmax/100.);
fp.add_att("range_z_min", -Lmax/100.);
fp.add_att("range_z_max", Lmax/100.);
fp.add_att("mask_index", pdata.mask_index); // PMS
int nOutputPart = pdata.mask_index;
//int nOutputPart = pdata.pos.size();
NcDim *NumPart_dim = fp.add_dim("numpart_dim", nOutputPart);
NcVar *v = fp.add_var("particle_ids", ncInt, NumPart_dim);
NcVar *vra = fp.add_var("RA", ncInt, NumPart_dim);
NcVar *vdec = fp.add_var("DEC", ncInt, NumPart_dim);
NcVar *vredshift = fp.add_var("z", ncInt, NumPart_dim);
//NcVar *v2 = fp.add_var("expansion", ncDouble, NumPart_dim);
//double *expansion_fac = new double[pdata.pos.size()];
//for (int i = 0; i < pdata.pos.size(); i++)
// expansion_fac[i] = 1.0;
v->put(&pdata.id_gal[0], nOutputPart);
vra->put(&pdata.ra[0], nOutputPart);
vdec->put(&pdata.dec[0], nOutputPart);
vredshift->put(&pdata.redshift[0], nOutputPart);
//v2->put(expansion_fac, pdata.pos.size());
//delete[] expansion_fac;
}
int main(int argc, char **argv)
{
generateFromCatalog_info args_info;
generateFromCatalog_conf_params args_params;
generateFromCatalog_conf_init(&args_info);
generateFromCatalog_conf_params_init(&args_params);
args_params.check_required = 0;
if (generateFromCatalog_conf_ext (argc, argv, &args_info, &args_params))
return 1;
if (!args_info.configFile_given)
{
if (generateFromCatalog_conf_required (&args_info, GENERATEFROMCATALOG_CONF_PACKAGE))
return 1;
}
else
{
args_params.check_required = 1;
args_params.initialize = 0;
if (generateFromCatalog_conf_config_file (args_info.configFile_arg,
&args_info,
&args_params))
return 1;
}
generateFromCatalog_conf_print_version();
cout << "Loading NYU data..." << endl;
vector<NYU_Data> data;
Healpix_Map<float> o_mask;
vector<int> pixel_list;
vector<int> full_mask_list;
ParticleData output_data;
loadData(args_info.catalog_arg, data);
cout << "Loading mask..." << endl;
read_Healpix_map_from_fits(args_info.mask_arg, o_mask);
Healpix_Map<float> mask;
mask.SetNside(128, RING);
mask.Import(o_mask);
computeContourPixels(mask,pixel_list);
// We compute a cube holding all the galaxies + the survey surface mask
cout << "Placing galaxies..." << endl;
generateGalaxiesInCube(data, output_data, args_info.useLCDM_flag);
generateSurfaceMask(args_info, mask, pixel_list, full_mask_list,
data, output_data);
saveForZobov(output_data, args_info.output_arg, args_info.params_arg);
// saveData(output_data);
// PMS
FILE *fp = fopen("mask_index.txt", "w");
fprintf(fp, "%d", output_data.mask_index);
fclose(fp);
fp = fopen("sample_info.txt", "w");
fprintf(fp, "Lmax = %f\n", output_data.Lmax);
fprintf(fp, "mask_index = %d\n", output_data.mask_index);
fprintf(fp, "total_particles = %d\n", output_data.pos.size());
fclose(fp);
fp = fopen("total_particles.txt", "w");
fprintf(fp, "%d", output_data.pos.size());
fclose(fp);
printf("Done!\n");
// END PMS
return 0;
}

View file

@ -7,8 +7,11 @@ option "catalog" - "Input NYU-VAGC catalog" string required
option "mask" - "Healpix mask of unobserved data (in Equatorial coordinates)" string required
option "density_fake" - "Number density of boundary fake tracers (1 h^3/ Mpc^3)" double optional default="1"
option "zMin" - "Minimum redshift of data" double required
option "zMax" - "Maximum redshift of data" double required
option "output" - "Filename of particle datafile" string required
option "params" - "Output parameters of the datacube" string required
option "box_thickness" - "Thickness of the limiting mask" double optional default="1"
option "box_density" - "Fake Galaxy density on the box" double optional default="1"
option "useLCDM" - "Convert to real space using LCDM cosmology" flag off

View file

@ -18,65 +18,9 @@ using namespace CosmoTool;
#define LIGHT_SPEED 299792.458
static double gadgetUnit=1e-3;
SimuData *doLoadRamses(const char *basename, int baseid, int velAxis, bool goRedshift)
{
SimuData *d, *outd;
d = loadRamsesSimu(basename, baseid, -1, true, 0);
outd = new SimuData;
outd->NumPart = d->TotalNumPart;
outd->BoxSize = d->BoxSize;
outd->TotalNumPart = outd->NumPart;
outd->Hubble = d->Hubble;
outd->Omega_Lambda = d->Omega_Lambda;
outd->Omega_M = d->Omega_M;
outd->time = d->time;
for (int k = 0; k < 3; k++)
outd->Pos[k] = new float[outd->NumPart];
outd->Vel[2] = new float[outd->NumPart];
delete d;
int curCpu = 0;
cout << "loading cpu 0 " << endl;
while (d = loadRamsesSimu(basename, baseid, curCpu, true, NEED_POSITION|NEED_VELOCITY|NEED_GADGET_ID))
{
for (int k = 0; k < 3; k++)
for (int i = 0; i < d->NumPart; i++)
{
assert(d->Id[i] >= 1);
assert(d->Id[i] <= outd->TotalNumPart);
outd->Pos[k][d->Id[i]-1] = d->Pos[k][i];
outd->Vel[2][d->Id[i]-1] = d->Vel[velAxis][i];
}
if (goRedshift)
for (int i = 0; i < d->NumPart; i++)
outd->Pos[velAxis][d->Id[i]-1] += d->Vel[velAxis][i]/100.;
delete d;
curCpu++;
cout << "loading cpu " << curCpu << endl;
}
return outd;
}
SimuData *myLoadGadget(const char *fname, int id, int flags)
{
SimuData *sim = loadGadgetMulti(fname, id, flags);
sim->BoxSize *= gadgetUnit*1000;
for (int j = 0; j < 3; j++)
{
if (sim->Pos[j] != 0) {
for (long i = 0; i < sim->NumPart; i++)
sim->Pos[j][i] *= gadgetUnit*1000;
}
}
return sim;
return loadGadgetMulti(fname, id, flags);
}
SimuData *doLoadSimulation(const char *gadgetname, int velAxis, bool goRedshift, SimuData *(*loadFunction)(const char *fname, int id, int flags))
@ -150,6 +94,53 @@ SimuData *doLoadSimulation(const char *gadgetname, int velAxis, bool goRedshift,
}
SimuData *doLoadMultidark(const char *multidarkname)
{
SimuData *outd;
FILE *fp;
int actualNumPart;
outd = new SimuData;
cout << "opening multidark file " << multidarkname << endl;
fp = fopen(multidarkname, "r");
if (fp == NULL) {
cout << "could not open file!" << endl;
return 0;
}
fscanf(fp, "%f\n", &outd->BoxSize);
fscanf(fp, "%f\n", &outd->Omega_M);
fscanf(fp, "%f\n", &outd->Hubble);
fscanf(fp, "%f\n", &outd->time);
fscanf(fp, "%d\n", &outd->NumPart);
outd->time = 1./(1.+outd->time); // convert to scale factor
outd->TotalNumPart = outd->NumPart;
outd->Omega_Lambda = 1.0 - outd->Omega_M;
for (int k = 0; k < 3; k++)
outd->Pos[k] = new float[outd->NumPart];
outd->Vel[2] = new float[outd->NumPart];
cout << "loading multidark particles" << endl;
actualNumPart = 0;
for (int i = 0; i < outd->NumPart; i++) {
fscanf(fp, "%f %f %f %f\n", &outd->Pos[0][i], &outd->Pos[1][i],
&outd->Pos[2][i], &outd->Vel[2][i]);
if (outd->Pos[0][i] == -99 && outd->Pos[1][i] == -99 &&
outd->Pos[2][i] == -99 && outd->Vel[2][i] == -99) {
break;
} else {
actualNumPart++;
}
}
fclose(fp);
outd->NumPart = actualNumPart;
outd->TotalNumPart = actualNumPart;
return outd;
}
static double cubic(double a)
{
@ -166,7 +157,7 @@ struct TotalExpansion
}
};
Interpolate make_cosmological_redshift(double OM, double OL, double z0, double z1, int N = 1000)
Interpolate make_cosmological_redshift(double OM, double OL, double z0, double z1, int N = 5000)
{
TotalExpansion e_computer;
double D_tilde, Q, Qprime;
@ -190,7 +181,7 @@ Interpolate make_cosmological_redshift(double OM, double OL, double z0, double z
return buildFromVector(pairs);
}
void metricTransform(SimuData *data, int axis, bool reshift, bool pecvel, double*& expfact, bool cosmo_flag)
void metricTransform(SimuData *data, int axis, bool reshift, bool pecvel, double*& expfact)
{
int x0, x1, x2;
@ -208,25 +199,21 @@ void metricTransform(SimuData *data, int axis, bool reshift, bool pecvel, double
abort();
}
double z0 = 1/data->time - 1;
Interpolate z_vs_D = make_cosmological_redshift(data->Omega_M, data->Omega_Lambda, 0., z0+2*data->BoxSize*100/LIGHT_SPEED); // Redshift 2*z0 should be sufficient ?
Interpolate z_vs_D = make_cosmological_redshift(data->Omega_M, data->Omega_Lambda, 0., z0+8*data->BoxSize*100/LIGHT_SPEED); // Redshift 2*z0 should be sufficient ?
double z_base = reshift ? z0 : 0;
TotalExpansion e_computer;
double baseComovingDistance;
float vmax = 0;
expfact = new double[data->NumPart];
cout << "Using base redshift z=" << z0 << endl;
cout << "Using base redshift z=" << z0 << " " << z0+8*data->BoxSize*100/LIGHT_SPEED << endl;
e_computer.Omega_M = data->Omega_M;
e_computer.Omega_L = data->Omega_Lambda;
baseComovingDistance = LIGHT_SPEED/100.* gslIntegrate(e_computer, 0, z0, 1e-3);
cout << "Comoving distance = " << baseComovingDistance << " Mpc/h" << endl;
cout << "Add peculiar velocities ? -> " << (pecvel ? " yes " : " no ") << endl;
for (uint32_t i = 0; i < data->NumPart; i++)
{
float& x = data->Pos[x0][i];
@ -242,25 +229,21 @@ void metricTransform(SimuData *data, int axis, bool reshift, bool pecvel, double
// Distorted redshift
if (reduced_red == 0)
z = 0;
else if (cosmo_flag)
else {
z = (z_vs_D.compute(reduced_red)-z_base)*LIGHT_SPEED/100.;
else
z = reduced_red*LIGHT_SPEED/100.0;
}
expfact[i] = z / z_old;
// Add peculiar velocity
if (pecvel) {
vmax = std::max(v,vmax);
if (pecvel)
z += v/100;
}
}
catch(const InvalidRangeException& e) {
cout << "Trying to interpolate out of the tabulated range." << endl;
cout << "The offending value is z=" << reduced_red << endl;
abort();
}
}
cout << "vmax=" << vmax << endl;
}
void generateOutput(SimuData *data, int axis,
@ -315,63 +298,6 @@ void generateOutput(SimuData *data, int axis,
f.endCheckpoint();
}
void makeBoxFromParameter(SimuData *simu, double *efac, SimuData* &boxed, generateMock_info& args_info)
{
NcFile f(args_info.inputParameter_arg);
NcVar *v;
int *particle_id;
double *expansion_fac;
boxed = new SimuData;
boxed->Hubble = simu->Hubble;
boxed->Omega_M = simu->Omega_M;
boxed->Omega_Lambda = simu->Omega_Lambda;
boxed->time = simu->time;
boxed->BoxSize = simu->BoxSize;
NcVar *v_id = f.get_var("particle_ids");
long *edges1;
double ranges[3][2];
double mul[3];
edges1 = v_id->edges();
assert(v_id->num_dims()==1);
boxed->NumPart = edges1[0];
delete[] edges1;
particle_id = new int[boxed->NumPart];
v_id->get(particle_id, boxed->NumPart);
ranges[0][0] = f.get_att("range_x_min")->as_double(0);
ranges[0][1] = f.get_att("range_x_max")->as_double(0);
ranges[1][0] = f.get_att("range_y_min")->as_double(0);
ranges[1][1] = f.get_att("range_y_max")->as_double(0);
ranges[2][0] = f.get_att("range_z_min")->as_double(0);
ranges[2][1] = f.get_att("range_z_max")->as_double(0);
for (int j = 0; j < 3; j++)
{
boxed->Pos[j] = new float[boxed->NumPart];
boxed->Vel[j] = 0;
mul[j] = 1.0/(ranges[j][1] - ranges[j][0]);
}
uint32_t k = 0;
for (uint32_t i = 0; i < boxed->NumPart; i++)
{
int id = particle_id[i];
for (int j = 0; j < 3; j++)
{
boxed->Pos[j][i] = (simu->Pos[j][id]-ranges[j][0])*mul[j];
}
}
delete[] particle_id;
}
void makeBox(SimuData *simu, double *efac, SimuData *&boxed, generateMock_info& args_info)
{
float subsample = args_info.subsample_given ? args_info.subsample_arg : 1.0;
@ -409,15 +335,20 @@ void makeBox(SimuData *simu, double *efac, SimuData *&boxed, generateMock_info&
minmax[0][j] = min(simu->Pos[j][i], minmax[0][j]);
minmax[1][j] = max(simu->Pos[j][i], minmax[1][j]);
}
random_acceptance[i] = acceptance && (drand48() <= subsample);
if (random_acceptance[i])
goodParticles++;
}
cout << "Subsample fraction: " << subsample << endl;
cout << "Min range = " << ranges[0][0] << " " << ranges[1][0] << " " << ranges[2][0] << endl;
cout << "Max range = " << ranges[0][1] << " " << ranges[1][1] << " " << ranges[2][1] << endl;
cout << "Min position = " << minmax[0][0] << " " << minmax[0][1] << " " << minmax[0][2] << endl;
cout << "Max position = " << minmax[1][0] << " " << minmax[1][1] << " " << minmax[1][2] << endl;
cout << "Number of accepted particles: " << goodParticles << endl;
for (int j = 0; j < 3; j++)
{
boxed->Pos[j] = new float[goodParticles];
@ -425,6 +356,7 @@ void makeBox(SimuData *simu, double *efac, SimuData *&boxed, generateMock_info&
mul[j] = 1.0/(ranges[j][1] - ranges[j][0]);
}
cout << "Rescaling factors = " << mul[0] << " " << mul[1] << " " << mul[2] << endl;
boxed->NumPart = goodParticles;
particle_id = new int[goodParticles];
@ -501,14 +433,13 @@ int main(int argc, char **argv)
generateMock_conf_print_version();
gadgetUnit=args_info.gadgetUnit_arg;
if (args_info.ramsesBase_given || args_info.ramsesId_given)
{
if (args_info.ramsesBase_given && args_info.ramsesId_given)
simu = doLoadRamses(args_info.ramsesBase_arg,
args_info.ramsesId_arg,
args_info.axis_arg, false);
if (args_info.ramsesBase_given && args_info.ramsesId_given) {
//simu = doLoadRamses(args_info.ramsesBase_arg,
// args_info.ramsesId_arg,
// args_info.axis_arg, false);
}
else
{
cerr << "Both ramsesBase and ramsesId are required to be able to load snapshots" << endl;
@ -521,7 +452,7 @@ int main(int argc, char **argv)
return 1;
}
}
else if (args_info.gadget_given || args_info.flash_given)
else if (args_info.gadget_given || args_info.flash_given || args_info.multidark_given)
{
if (args_info.gadget_given && args_info.flash_given)
{
@ -529,10 +460,17 @@ int main(int argc, char **argv)
return 1;
}
if (args_info.gadget_given)
if (args_info.multidark_given) {
simu = doLoadMultidark(args_info.multidark_arg);
}
if (args_info.gadget_given) {
simu = doLoadSimulation(args_info.gadget_arg, args_info.axis_arg, false, myLoadGadget);
else
}
if (args_info.flash_given) {
simu = doLoadSimulation(args_info.flash_arg, args_info.axis_arg, false, loadFlashMulti);
}
if (simu == 0)
{
cerr << "Error while loading " << endl;
@ -551,18 +489,20 @@ int main(int argc, char **argv)
double *expfact;
metricTransform(simu, args_info.axis_arg, args_info.preReShift_flag, args_info.peculiarVelocities_flag, expfact, args_info.cosmo_flag);
if (args_info.cosmo_flag){
metricTransform(simu, args_info.axis_arg, args_info.preReShift_flag, args_info.peculiarVelocities_flag, expfact);
} else {
expfact = new double[simu->NumPart];
for (int j = 0; j < simu->NumPart; j++) expfact[j] = 1.0;
}
if (args_info.inputParameter_given)
makeBoxFromParameter(simu, expfact, simuOut, args_info);
else
makeBox(simu, expfact, simuOut, args_info);
delete simu;
generateOutput(simuOut, args_info.axis_arg, args_info.output_arg);
delete simuOut;
printf("Done!\n");
return 0;
}

View file

@ -9,6 +9,7 @@ option "ramsesId" - "Ramses snapshot id" int optional
option "gadget" - "Base name of gadget snapshot (without parallel writing extension)" string optional
option "flash" - "Base name for FLASH snapshot" string optional
option "multidark" - "Base name for multidark snapshot" string optional
option "axis" - "Redshift axis (X=0, Y=1, Z=2)" int optional default="2"
@ -28,6 +29,3 @@ option "peculiarVelocities" - "Added peculiar velocities distortion" flag off
option "cosmo" - "Apply cosmological redshift" flag on
option "subsample" - "Subsample the input simulation by the specified amount" double optional
option "inputParameter" - "Input geometry (optional, warning!)" string optional
option "gadgetUnit" - "Unit of length in gadget file in Mpc/h" double optional default="0.001"

View file

@ -0,0 +1,550 @@
// Reads in the void catalog and removes any void that could potentially
// be affected by a mock particle. It does this by computing the longest
// particle distance within each void and comparing it to the distance
// of the nearest mock particle. If the void could potentially by rotated
// to include this particle, we throw out the void.
// This is placed here instead of using the edgeAvoidance option in
// stackVoidsZero so that we can optionally filter the entire
// catalog at once before the stacking phase. This is useful
// for producing a "clean" void catalog for other purposes.
#include "gsl/gsl_math.h"
#include "string.h"
#include "ctype.h"
#include "stdlib.h"
#include <math.h>
#include <stdio.h>
#include <netcdfcpp.h>
#include "pruneVoids_conf.h"
#define LIGHT_SPEED 299792.458
#define MPC2Z 100./LIGHT_SPEED
#define Z2MPC LIGHT_SPEED/100.
typedef struct partStruct {
float x, y, z, vol;
} PART;
typedef struct zoneStruct {
int numPart;
int *partIDs;
} ZONE2PART;
typedef struct voidZoneStruct {
int numZones;
int *zoneIDs;
} VOID2ZONE;
typedef struct voidStruct {
float vol, coreDens, zoneVol, densCon, voidProb, radius;
int voidID, numPart, numZones, coreParticle, zoneNumPart;
float maxRadius, nearestMock, centralDen, redshift;
float center[3], barycenter[3];
int accepted;
} VOID;
int main(int argc, char **argv) {
// initialize arguments
pruneVoids_info args_info;
pruneVoids_conf_params args_params;
pruneVoids_conf_init(&args_info);
pruneVoids_conf_params_init(&args_params);
args_params.check_required = 0;
if (pruneVoids_conf_ext (argc, argv, &args_info, &args_params))
return 1;
if (!args_info.configFile_given) {
if (pruneVoids_conf_required (&args_info,
PRUNEVOIDS_CONF_PACKAGE))
return 1;
} else {
args_params.check_required = 1;
args_params.initialize = 0;
if (pruneVoids_conf_config_file (args_info.configFile_arg,
&args_info,
&args_params))
return 1;
}
int i, p, p2, numPartTot, numZonesTot, dummy, iVoid, iZ;
int numVoids, mockIndex, numKept;
double tolerance;
FILE *fp, *fpBarycenter, *fpDistances, *fpSkyPositions, *fpInfo;
PART *part, *voidPart;
ZONE2PART *zones2Parts;
VOID2ZONE *void2Zones;
VOID *voids;
float *temp, junk, voidVol;
int junkInt, voidID, numPart, numZones, zoneID, partID, maxNumPart;
int coreParticle, zoneNumPart;
float coreDens, zoneVol, densCon, voidProb, dist[3], dist2, minDist, maxDist;
float centralRad, centralDen;
double nearestEdge, redshift;
char line[500], junkStr[10];
int mask_index;
double ranges[2][3], boxLen[3], mul;
double volNorm, radius;
int clock1, clock2;
numVoids = args_info.numVoids_arg;
mockIndex = args_info.mockIndex_arg;
tolerance = args_info.tolerance_arg;
clock1 = clock();
printf("Pruning parameters: %f %f %f\n", args_info.zMin_arg,
args_info.zMax_arg,
args_info.rMin_arg);
// load box size
printf("\n Getting info...\n");
NcFile f_info(args_info.extraInfo_arg);
ranges[0][0] = f_info.get_att("range_x_min")->as_double(0);
ranges[0][1] = f_info.get_att("range_x_max")->as_double(0);
ranges[1][0] = f_info.get_att("range_y_min")->as_double(0);
ranges[1][1] = f_info.get_att("range_y_max")->as_double(0);
ranges[2][0] = f_info.get_att("range_z_min")->as_double(0);
ranges[2][1] = f_info.get_att("range_z_max")->as_double(0);
boxLen[0] = ranges[0][1] - ranges[0][0];
boxLen[1] = ranges[1][1] - ranges[1][0];
boxLen[2] = ranges[2][1] - ranges[2][0];
// read in all particle positions
printf("\n Loading particles...\n");
fp = fopen(args_info.partFile_arg, "r");
fread(&dummy, 1, 4, fp);
fread(&numPartTot, 1, 4, fp);
fread(&dummy, 1, 4, fp);
part = (PART *) malloc(numPartTot * sizeof(PART));
temp = (float *) malloc(numPartTot * sizeof(float));
volNorm = numPartTot/(boxLen[0]*boxLen[1]*boxLen[2]);
printf("VOL NORM = %f\n", volNorm);
printf("CENTRAL DEN = %f\n", args_info.maxCentralDen_arg);
fread(&dummy, 1, 4, fp);
fread(temp, numPartTot, 4, fp);
mul = ranges[0][1] - ranges[0][0];
for (p = 0; p < numPartTot; p++)
part[p].x = mul*temp[p];
fread(&dummy, 1, 4, fp);
fread(&dummy, 1, 4, fp);
fread(temp, numPartTot, 4, fp);
mul = ranges[1][1] - ranges[1][0];
for (p = 0; p < numPartTot; p++)
part[p].y = mul*temp[p];
fread(&dummy, 1, 4, fp);
fread(&dummy, 1, 4, fp);
fread(temp, numPartTot, 4, fp);
mul = ranges[2][1] - ranges[2][0];
for (p = 0; p < numPartTot; p++)
part[p].z = mul*temp[p];
if (!args_info.isObservation_flag) {
for (p = 0; p < numPartTot; p++) {
part[p].x += ranges[0][0];
part[p].y += ranges[1][0];
part[p].z += ranges[2][0];
}
}
fclose(fp);
printf(" Read %d particles...\n", numPartTot);
if (mockIndex == -1) mockIndex = numPartTot;
// read in desired voids
printf(" Loading voids...\n");
fp = fopen(args_info.voidDesc_arg ,"r");
fgets(line, sizeof(line), fp);
sscanf(line, "%d %s %d %s", &junkInt, junkStr, &junkInt, junkStr);
fgets(line, sizeof(line), fp);
voids = (VOID *) malloc(numVoids * sizeof(VOID));
i = 0;
while (fgets(line, sizeof(line), fp) != NULL) {
sscanf(line, "%d %d %d %f %f %d %d %f %d %f %f\n", &iVoid, &voidID,
&coreParticle, &coreDens, &zoneVol, &zoneNumPart, &numZones,
&voidVol, &numPart, &densCon, &voidProb);
i++;
voids[i-1].coreParticle = coreParticle;
voids[i-1].zoneNumPart = zoneNumPart;
voids[i-1].coreDens = coreDens;
voids[i-1].zoneVol = zoneVol;
voids[i-1].voidID = voidID;
voids[i-1].vol = voidVol;
voids[i-1].numPart = numPart;
voids[i-1].numZones = numZones;
voids[i-1].densCon = densCon;
voids[i-1].voidProb = voidProb;
voids[i-1].radius = pow(voidVol/volNorm*3./4./M_PI, 1./3.);
voids[i-1].accepted = 1;
}
fclose(fp);
// load up the zone membership for each void
printf(" Loading void-zone membership info...\n");
fp = fopen(args_info.void2Zone_arg, "r");
fread(&numZonesTot, 1, 4, fp);
void2Zones = (VOID2ZONE *) malloc(numZonesTot * sizeof(VOID2ZONE));
for (iZ = 0; iZ < numZonesTot; iZ++) {
fread(&numZones, 1, 4, fp);
void2Zones[iZ].numZones = numZones;
void2Zones[iZ].zoneIDs = (int *) malloc(numZones * sizeof(int));
for (p = 0; p < numZones; p++) {
fread(&void2Zones[iZ].zoneIDs[p], 1, 4, fp);
}
}
fclose(fp);
// now the particles-zone
printf(" Loading particle-zone membership info...\n");
fp = fopen(args_info.zone2Part_arg, "r");
fread(&dummy, 1, 4, fp);
fread(&numZonesTot, 1, 4, fp);
zones2Parts = (ZONE2PART *) malloc(numZonesTot * sizeof(ZONE2PART));
for (iZ = 0; iZ < numZonesTot; iZ++) {
fread(&numPart, 1, 4, fp);
zones2Parts[iZ].numPart = numPart;
zones2Parts[iZ].partIDs = (int *) malloc(numPart * sizeof(int));
for (p = 0; p < numPart; p++) {
fread(&zones2Parts[iZ].partIDs[p], 1, 4, fp);
}
}
// and finally volumes
printf(" Loading particle volumes...\n");
fp = fopen(args_info.partVol_arg, "r");
fread(&mask_index, 1, 4, fp);
if (mask_index != mockIndex) {
printf("NON-MATCHING MOCK INDICES!? %d %d\n", mask_index, mockIndex);
exit(-1);
}
for (p = 0; p < mask_index; p++) {
fread(&temp[0], 1, 4, fp);
part[p].vol = temp[0];
}
fclose(fp);
free(temp);
// check boundaries
printf(" Computing void properties...\n");
maxNumPart = 0;
for (iVoid = 0; iVoid < numVoids; iVoid++) {
if (voids[iVoid].numPart > maxNumPart) maxNumPart = voids[iVoid].numPart;
}
voidPart = (PART *) malloc(maxNumPart * sizeof(PART));
for (iVoid = 0; iVoid < numVoids; iVoid++) {
voidID = voids[iVoid].voidID;
//printf(" DOING %d (of %d) %d %d\n", iVoid, numVoids, voidID,
// voids[iVoid].numPart);
voids[iVoid].center[0] = part[voids[iVoid].coreParticle].x;
voids[iVoid].center[1] = part[voids[iVoid].coreParticle].y;
voids[iVoid].center[2] = part[voids[iVoid].coreParticle].z;
// first load up particles into a buffer
i = 0;
for (iZ = 0; iZ < void2Zones[voidID].numZones; iZ++) {
zoneID = void2Zones[voidID].zoneIDs[iZ];
for (p = 0; p < zones2Parts[zoneID].numPart; p++) {
partID = zones2Parts[zoneID].partIDs[p];
if (partID > mask_index ||
(part[partID].vol < 1.e-27 && part[partID].vol > 0.)) {
printf("BAD PART!? %d %d %e", partID, mask_index, part[partID].vol);
exit(-1);
}
voidPart[i].x = part[partID].x;
voidPart[i].y = part[partID].y;
voidPart[i].z = part[partID].z;
voidPart[i].vol = part[partID].vol;
i++;
}
}
// compute barycenters
double weight = 0.;
voids[iVoid].barycenter[0] = 0.;
voids[iVoid].barycenter[1] = 0.;
voids[iVoid].barycenter[2] = 0.;
// TODO handle periodic boundaries?
for (p = 0; p < voids[iVoid].numPart; p++) {
dist[0] = voidPart[p].x - voids[iVoid].center[0];
dist[1] = voidPart[p].y - voids[iVoid].center[1];
dist[2] = voidPart[p].z - voids[iVoid].center[2];
//if (!args_info.isObservation_flag) {
// dist[0] = fmin(dist[0], abs(boxLen[0]-dist[0]));
// dist[1] = fmin(dist[1], abs(boxLen[1]-dist[1]));
// dist[2] = fmin(dist[2], abs(boxLen[2]-dist[2]));
//}
voids[iVoid].barycenter[0] += voidPart[p].vol*(dist[0]);
voids[iVoid].barycenter[1] += voidPart[p].vol*(dist[1]);
voids[iVoid].barycenter[2] += voidPart[p].vol*(dist[2]);
weight += voidPart[p].vol;
}
voids[iVoid].barycenter[0] /= weight;
voids[iVoid].barycenter[1] /= weight;
voids[iVoid].barycenter[2] /= weight;
voids[iVoid].barycenter[0] += voids[iVoid].center[0];
voids[iVoid].barycenter[1] += voids[iVoid].center[1];
voids[iVoid].barycenter[2] += voids[iVoid].center[2];
// compute central density
centralRad = voids[iVoid].radius/args_info.centralRadFrac_arg;
centralRad *= centralRad;
centralDen = 0.;
for (p = 0; p < voids[iVoid].numPart; p++) {
dist[0] = voidPart[p].x - voids[iVoid].barycenter[0];
dist[1] = voidPart[p].y - voids[iVoid].barycenter[1];
dist[2] = voidPart[p].z - voids[iVoid].barycenter[2];
//if (!args_info.isObservation_flag) {
// dist[0] = fmin(dist[0], abs(boxLen[0]-dist[0]));
// dist[1] = fmin(dist[1], abs(boxLen[1]-dist[1]));
// dist[2] = fmin(dist[2], abs(boxLen[2]-dist[2]));
//}
dist2 = pow(dist[0],2) + pow(dist[1],2) + pow(dist[2],2);
if (dist2 < centralRad) centralDen += 1;
}
voids[iVoid].centralDen = centralDen / (4./3. * M_PI * pow(centralRad, 3./2.));
// compute maximum extent
if (args_info.isObservation_flag) {
maxDist = 0.;
for (p = 0; p < voids[iVoid].numPart; p++) {
for (p2 = p; p2 < voids[iVoid].numPart; p2++) {
dist[0] = voidPart[p].x - voidPart[p2].x;
dist[1] = voidPart[p].y - voidPart[p2].y;
dist[2] = voidPart[p].z - voidPart[p2].z;
dist2 = pow(dist[0],2) + pow(dist[1],2) + pow(dist[2],2);
if (dist2 > maxDist) maxDist = dist2;
}
}
voids[iVoid].maxRadius = sqrt(maxDist)/2.;
} else {
maxDist = 0.;
for (p = 0; p < voids[iVoid].numPart; p++) {
dist[0] = voidPart[p].x - voids[iVoid].barycenter[0];
dist[0] = voidPart[p].y - voids[iVoid].barycenter[1];
dist[0] = voidPart[p].z - voids[iVoid].barycenter[2];
dist2 = pow(dist[0],2) + pow(dist[1],2) + pow(dist[2],2);
if (dist2 > maxDist) maxDist = dist2;
}
voids[iVoid].maxRadius = sqrt(maxDist);
}
if (args_info.isObservation_flag) {
// compute distance from center to nearest mock
minDist = 1.e99;
for (p = mockIndex; p < numPartTot; p++) {
dist[0] = voids[iVoid].barycenter[0] - part[p].x;
dist[1] = voids[iVoid].barycenter[1] - part[p].y;
dist[2] = voids[iVoid].barycenter[2] - part[p].z;
dist2 = pow(dist[0],2) + pow(dist[1],2) + pow(dist[2],2);
if (dist2 < minDist) minDist = dist2;
}
voids[iVoid].nearestMock = sqrt(minDist);
} else {
voids[iVoid].nearestMock = 1.e99;
}
if (args_info.isObservation_flag) {
voids[iVoid].redshift =
sqrt(pow(voids[iVoid].barycenter[0] - boxLen[0]/2.,2) +
pow(voids[iVoid].barycenter[1] - boxLen[1]/2.,2) +
pow(voids[iVoid].barycenter[2] - boxLen[2]/2.,2));
voids[iVoid].redshift = voids[iVoid].redshift;
redshift = voids[iVoid].redshift;
nearestEdge = fmin(fabs(redshift-args_info.zMin_arg*LIGHT_SPEED),
fabs(redshift-args_info.zMax_arg*LIGHT_SPEED));
} else {
voids[iVoid].redshift = voids[iVoid].barycenter[2]/LIGHT_SPEED*100.;
nearestEdge = fmin(
fabs(voids[iVoid].barycenter[0] - ranges[0][0]),
fabs(voids[iVoid].barycenter[0] - ranges[0][1]));
nearestEdge = fmin(nearestEdge,
fabs(voids[iVoid].barycenter[1] - ranges[1][0]));
nearestEdge = fmin(nearestEdge,
fabs(voids[iVoid].barycenter[1] - ranges[1][1]));
nearestEdge = fmin(nearestEdge,
fabs(voids[iVoid].barycenter[2] - ranges[2][0]));
nearestEdge = fmin(nearestEdge,
fabs(voids[iVoid].barycenter[2] - ranges[2][1]));
}
if (nearestEdge < voids[iVoid].nearestMock) {
voids[iVoid].nearestMock = nearestEdge;
}
} // iVoid
printf(" Picking winners and losers...\n");
numKept = numVoids;
for (iVoid = 0; iVoid < numVoids; iVoid++) {
if (strcmp(args_info.dataPortion_arg, "edge") == 0 &&
tolerance*voids[iVoid].maxRadius < voids[iVoid].nearestMock) {
numKept--;
voids[iVoid].accepted = 0;
}
if (strcmp(args_info.dataPortion_arg, "central") == 0 &&
tolerance*voids[iVoid].maxRadius > voids[iVoid].nearestMock) {
numKept--;
voids[iVoid].accepted = 0;
}
if (voids[iVoid].centralDen > args_info.maxCentralDen_arg) {
numKept--;
voids[iVoid].accepted = -1;
}
if (voids[iVoid].radius < args_info.rMin_arg) {
numKept--;
voids[iVoid].accepted = 0;
}
}
printf(" Number kept: %d (out of %d)\n", numKept, numVoids);
printf(" Output...\n");
fp = fopen(args_info.output_arg, "w");
fpBarycenter = fopen(args_info.outCenters_arg, "w");
fpInfo = fopen(args_info.outInfo_arg, "w");
fpDistances = fopen(args_info.outDistances_arg, "w");
fpSkyPositions = fopen(args_info.outSkyPositions_arg, "w");
fprintf(fp, "%d particles, %d voids.\n", mockIndex, numKept);
fprintf(fp, "see column in master void file\n");
fprintf(fpInfo, "# center x,y,z (Mpc/h), volume (normalized), radius (Mpc/h), redshift, volume (Mpc/h^3), void ID\n");
fprintf(fpSkyPositions, "# RA, dec, redshift, radius (Mpc/h), void ID\n");
for (iVoid = 0; iVoid < numVoids; iVoid++) {
if (voids[iVoid].accepted != 1) continue;
fprintf(fp, "%d %d %d %f %f %d %d %f %d %f %f\n",
i,
voids[iVoid].voidID,
voids[iVoid].coreParticle,
voids[iVoid].coreDens,
voids[iVoid].zoneVol,
voids[iVoid].zoneNumPart,
voids[iVoid].numZones,
voids[iVoid].vol,
voids[iVoid].numPart,
voids[iVoid].densCon,
voids[iVoid].voidProb);
fprintf(fpBarycenter, "%d %e %e %e\n",
voids[iVoid].voidID,
voids[iVoid].barycenter[0],
voids[iVoid].barycenter[1],
voids[iVoid].barycenter[2]);
fprintf(fpDistances, "%d %e\n",
voids[iVoid].voidID,
voids[iVoid].nearestMock);
double outCenter[3];
outCenter[0] = voids[iVoid].barycenter[0];
outCenter[1] = voids[iVoid].barycenter[1];
outCenter[2] = voids[iVoid].barycenter[2];
if (args_info.isObservation_flag) {
outCenter[0] = (voids[iVoid].barycenter[0]-boxLen[0]/2.)*100.;
outCenter[1] = (voids[iVoid].barycenter[1]-boxLen[1]/2.)*100.;
outCenter[2] = (voids[iVoid].barycenter[2]-boxLen[2]/2.)*100.;
}
fprintf(fpInfo, "%.2f %.2f %.2f %.2f %.2f %.5f %.2f %d\n",
outCenter[0],
outCenter[1],
outCenter[2],
voids[iVoid].vol,
voids[iVoid].radius,
voids[iVoid].redshift,
4./3.*M_PI*pow(voids[iVoid].radius, 3),
voids[iVoid].voidID
);
fprintf(fpSkyPositions, "%.2f %.2f %.5f %.2f %d\n",
atan((voids[iVoid].barycenter[1]-boxLen[1]/2.)/(voids[iVoid].barycenter[0]-boxLen[0]/2.)) * 180/M_PI + 180,
asin((voids[iVoid].barycenter[2]-boxLen[2]/2.)/voids[iVoid].redshift) * 180/M_PI,
voids[iVoid].redshift,
voids[iVoid].radius,
voids[iVoid].voidID);
}
fclose(fp);
fclose(fpInfo);
fclose(fpBarycenter);
fclose(fpDistances);
// print the centers catalog again but without central density cuts
fpInfo = fopen(args_info.outNoCutInfo_arg, "w");
fprintf(fpInfo, "# center x,y,z (km/s), volume (normalized), radius (Mpc/h), redshift, volume (Mpc/h^3), void ID\n");
for (iVoid = 0; iVoid < numVoids; iVoid++) {
if (voids[iVoid].accepted == 0) continue;
double outCenter[3];
outCenter[0] = voids[iVoid].barycenter[0];
outCenter[1] = voids[iVoid].barycenter[1];
outCenter[2] = voids[iVoid].barycenter[2];
if (args_info.isObservation_flag) {
outCenter[0] = (voids[iVoid].barycenter[0]-boxLen[0]/2.)*100.;
outCenter[1] = (voids[iVoid].barycenter[1]-boxLen[1]/2.)*100.;
outCenter[2] = (voids[iVoid].barycenter[2]-boxLen[2]/2.)*100.;
}
fprintf(fpInfo, "%.2f %.2f %.2f %.2f %.2f %.5f %.2f %d\n",
outCenter[0],
outCenter[1],
outCenter[2],
voids[iVoid].vol,
voids[iVoid].radius,
voids[iVoid].redshift,
4./3.*M_PI*pow(voids[iVoid].radius, 3),
voids[iVoid].voidID);
}
fclose(fpInfo);
clock2 = clock();
printf(" Time: %f sec (for %d voids)\n", (1.*clock2-clock1)/CLOCKS_PER_SEC, numVoids);
clock1 = clock();
printf("Done!\n");
return 0;
} // end main

View file

@ -0,0 +1,47 @@
package "removeEdgeVoids"
version "alpha"
option "configFile" - "Configuration filename" string optional
option "partFile" - "Particle file from generateFromCatalog" string required
option "extraInfo" - "Extra particle file from generateFromCatalog" string required
option "voidDesc" - "Void list from ZOBOV" string required
option "void2Zone" - "Zone file from ZOBOV" string required
option "partVol" - "Particle volume file from ZOBOV" string required
option "zone2Part" - "Particle file from ZOBOV" string required
option "mockIndex" - "Beginning index of mock particles" int required
option "numVoids" - "Number of voids" int required
option "isObservation" - "We are working with observational data" flag off
option "zMin" - "Minimum redshift of sample" double optional default="0.0"
option "zMax" - "Maximum redshift of sample" double optional default="10.0"
option "rMin" - "Minimum allowable void radius" double optional default="0.0"
option "output" - "Output void file" string required
option "outDistances" - "output of distances from centers to nearest mock particle" string required
option "outCenters" - "output barycenters of voids" string required
option "outInfo" - "output info of voids" string required
option "outNoCutInfo" - "output info of voids" string required
option "outSkyPositions" - "output sky positions of voids" string required
option "dataPortion" - "all, central, or edge" string required
option "tolerance" - "Fraction of void width to consider edge" double optional default="1.0"
option "centralRadFrac" - "Fraction of void radii to consider central region" double optional default="4"
option "maxCentralDen" - "Maximum central density to accept as a void" double optional default="0.2"

113
pipeline/generateCatalog.py Executable file
View file

@ -0,0 +1,113 @@
#!/usr/bin/env python
# does full void analysis. Also generates 2d/1d stacked plots and hubble diagram
from void_python_tools.backend import *
from void_python_tools.plotting import *
import imp
# ------------------------------------------------------------------------------
def my_import(name):
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod
if (len(sys.argv) == 0):
print "Usage: ./anylyzeVoids.py parameter_file.py"
exit(-1)
if (len(sys.argv) > 1):
filename = sys.argv[1]
print " Loading parameters from", filename
if not os.access(filename, os.F_OK):
print " Cannot find parameter file!"
exit(-1)
#parms = __import__(filename[:-3], globals(), locals(), ['*'])
parms = imp.load_source("name", filename)
globals().update(vars(parms))
else:
print " Using default parameters"
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
if not os.access(logDir, os.F_OK):
os.makedirs(logDir)
if not os.access(figDir, os.F_OK):
os.makedirs(figDir)
if not continueRun:
print " Cleaning out log files..."
if startCatalogStage <= 1 and glob.glob(logDir+"/generate*") != []:
os.system("rm %s/generate*" % logDir)
if startCatalogStage <= 2 and glob.glob(logDir+"/zobov*") != []:
os.system("rm %s/zobov*" % logDir)
if startCatalogStage <= 3 and glob.glob(logDir+"/prune*") != []:
os.system("rm %s/prune*" % logDir)
for sample in dataSampleList:
sampleName = sample.fullName
print " Working with data set", sampleName, "..."
zobovDir = workDir+"/sample_"+sampleName+"/"
sample.zobovDir = zobovDir
if not os.access(zobovDir, os.F_OK):
os.makedirs(zobovDir)
# ---------------------------------------------------------------------------
if (startCatalogStage <= 1) and (endCatalogStage >= 1) and not sample.isCombo:
print " Extracting tracers from catalog...",
sys.stdout.flush()
logFile = logDir+"/generate_"+sampleName+".out"
if sample.dataType == "observation":
GENERATE_PATH = CTOOLS_PATH+"/mock/generateFromCatalog"
else:
GENERATE_PATH = CTOOLS_PATH+"/mock/generateMock"
launchGenerate(sample, GENERATE_PATH, workDir=workDir,
inputDataDir=inputDataDir, zobovDir=zobovDir,
figDir=figDir, logFile=logFile, useLCDM=useLCDM,
continueRun=continueRun)
# --------------------------------------------------------------------------
if (startCatalogStage <= 2) and (endCatalogStage >= 2) and not sample.isCombo:
print " Extracting voids with ZOBOV...",
sys.stdout.flush()
launchZobov(sample, ZOBOV_PATH, zobovDir=zobovDir, logDir=logDir,
continueRun=continueRun)
# -------------------------------------------------------------------------
if (startCatalogStage <= 3) and (endCatalogStage >= 3) and not sample.isCombo:
for thisDataPortion in dataPortions:
print " Taking data portion:", thisDataPortion, "...",
sys.stdout.flush()
logFile = logDir+"/pruneVoids_"+sampleName+"_"+\
thisDataPortion+".out"
PRUNE_PATH = CTOOLS_PATH+"/stacking/pruneVoids"
launchPrune(sample, PRUNE_PATH, thisDataPortion=thisDataPortion,
logFile=logFile, zobovDir=zobovDir, continueRun=continueRun)
# -------------------------------------------------------------------------
if (startCatalogStage <= 4) and (endCatalogStage >= 4):
print " Plotting...",
sys.stdout.flush()
for thisDataPortion in dataPortions:
plotNumberCounts(workDir, dataSampleList, figDir, showPlot=True, dataPortion=thisDataPortion, setName=setName)
print "\n Done!"

466
pipeline/prepareCatalogs.py Executable file
View file

@ -0,0 +1,466 @@
#!/usr/bin/env python
# prepares input catalogs based on multidark simulations
# (borrows heavily from generateMock, but doesn't hold much in memory)
# also creates necessary analyzeVoids input files
import numpy as np
import os
import sys
from Scientific.IO.NetCDF import NetCDFFile
import void_python_tools as vp
import argparse
catalogDir = os.getenv("HOME")+"/workspace/Voids/catalogs/multidark/"
scriptDir = os.getenv("PWD")+"/multidark/"
hodPath = os.getenv("HOME")+"/projects/Voids/hod/HOD.x"
outputDir = os.getenv("HOME")+"/workspace/Voids/multidark/"
figDir = os.getenv("PWD")+"/../figs/multidark/"
logDir = os.getenv("PWD")+"/../logs/multidark/"
dataFormat = "multidark"
dataType = "simulation"
useLightCone = True
redshifts = (("0.0", "0.53", "1.0"))
redshiftFileBase = "mdr1_particles_z"
numSlices = 4
numSubvolumes = 1
prefix = "md_"
subSamples = ((0.1, 0.05, 0.01, 0.002, 0.001, 0.0004, 0.0002))
numPart = 1024*1024*1024 # number of particles in base catalog
lbox = 1000
omegaM = 0.27
hubble = 0.70
# -----------------------------------------------------------------------------
LIGHT_SPEED = 299792.458
parser = argparse.ArgumentParser(description='options')
parser.add_argument('--scripts', dest='script', action='store_const',
const=True, default=False,
help='write scripts')
parser.add_argument('--subsamples', dest='subsample', action='store_const',
const=True, default=False,
help='write subsamples')
parser.add_argument('--halos', dest='halos', action='store_const',
const=True, default=False,
help='write halos')
parser.add_argument('--hod', dest='hod', action='store_const',
const=True, default=False,
help='write hos')
parser.add_argument('--all', dest='all', action='store_const',
const=True, default=False,
help='write everything')
args = parser.parse_args()
#------------------------------------------------------------------------------
def getSampleName(prefix, base, redshift, useVel, iSlice=-1, iVol=-1):
useVelString = ""
if useVel: useVelString = "_pv"
sampleName = prefix + base + useVelString + "_z" + redshift
if iSlice != -1:
sampleName += "_s" + str(iSlice)
if iVol != -1:
sampleName += "_d" + iVol
return sampleName
#------------------------------------------------------------------------------
# for given dataset parameters, outputs a script for use with analyzeVoids
def writeScript(prefix, base, scriptDir, catalogDir, redshifts, numSubvolumes,
numSlices, useVel, lbox, minRadius, omegaM, subsample=1.0,
suffix=".dat"):
setName = prefix + base
dataFileNameBase = setName #+ ".dat"
if useVel: setName += "_pv"
scriptFileName = scriptDir + "/" + "md_" + base
if useVel: scriptFileName += "_pv"
scriptFileName += ".py"
scriptFile = open(scriptFileName, 'w')
scriptFile.write("""#!/usr/bin/env/python
import os
from void_python_tools.backend.classes import *
continueRun = False
startCatalogStage = 1
endCatalogStage = 3
startAPStage = 1
endAPStage = 6
ZOBOV_PATH = os.getenv("PWD")+"/../zobov/"
CTOOLS_PATH = os.getenv("PWD")+"/../c_tools/"
freshStack = True
errorBars = "CALCULATED"
numIncoherentRuns = 100
ranSeed = 101010
useLCDM = False
bias = 1.16
dataPortions = ["central"]
dataSampleList = []
""")
dataInfo = """
catalogName = "{sampleName}"
workDir = "{outputDir}/{sampleName}/"
inputDataDir = "{catalogDir}"
figDir = "{figDir}/{sampleName}/"
logDir = "{logDir}/{sampleName}/"
"""
scriptFile.write(dataInfo.format(sampleName=setName, figDir=figDir,
logDir=logDir, outputDir=outputDir,
catalogDir=catalogDir,
inputDataDir=catalogDir))
sampleInfo = """
newSample = Sample(dataFile = "{dataFile}",
dataFormat = "{dataFormat}",
fullName = "{sampleName}",
nickName = "{sampleName}",
dataType = "simulation",
zBoundary = ({zMin}, {zMax}),
zRange = ({zMin}, {zMax}),
zBoundaryMpc = ({zMinMpc}, {zMaxMpc}),
omegaM = {omegaM},
minVoidRadius = {minRadius},
includeInHubble = True,
partOfCombo = False,
isCombo = False,
boxLen = {boxLen},
usePecVel = {usePecVel},
numSubvolumes = {numSubvolumes},
mySubvolume = "{mySubvolume}",
numSubDivisions = 4,
useLightCone = {useLightCone},
subsample = {subsample})
dataSampleList.append(newSample)
newSample.addStack({zMin}, {zMax}, {minRadius} , {minRadius}+2, True, False)
newSample.addStack({zMin}, {zMax}, {minRadius} , {minRadius}+4, True, False)
newSample.addStack({zMin}, {zMax}, {minRadius}+2, {minRadius}+6, True, False)
newSample.addStack({zMin}, {zMax}, {minRadius}+6, {minRadius}+10, True, False)
newSample.addStack({zMin}, {zMax}, {minRadius}+10, {minRadius}+18, True, False)
newSample.addStack({zMin}, {zMax}, {minRadius}+18, {minRadius}+24, True, False)
"""
for redshift in redshifts:
zBox = float(redshift)
Om = float(omegaM)
zBoxMpc = LIGHT_SPEED/100.*vp.angularDiameter(zBox, Om=Om)
boxMaxMpc = zBoxMpc + lbox
# converter from redshift to comoving distance
zVsDY = np.linspace(0., zBox+8*lbox*100./LIGHT_SPEED, 10000)
zVsDX = np.zeros(len(zVsDY))
for i in xrange(len(zVsDY)):
zVsDX[i] = vp.angularDiameter(zVsDY[i], Om=Om)
if useLightCone:
boxWidthZ = np.interp(vp.angularDiameter(zBox,Om=Om)+100. / \
LIGHT_SPEED*lbox, zVsDX, zVsDY)-zBox
dzSafe = 0.03
else:
boxWidthZ = lbox*100./LIGHT_SPEED
dzSafe = 0.0
for iSlice in xrange(numSlices):
# trim off the first and last 10,000 km/s
sliceMin = zBox + dzSafe + iSlice*(boxWidthZ-dzSafe)/numSlices
sliceMax = zBox + dzSafe + (iSlice+1)*(boxWidthZ-dzSafe)/numSlices
sliceMinMpc = sliceMin*LIGHT_SPEED/100.
sliceMaxMpc = sliceMax*LIGHT_SPEED/100.
sliceMin = "%0.2f" % sliceMin
sliceMax = "%0.2f" % sliceMax
sliceMinMpc = "%0.1f" % sliceMinMpc
sliceMaxMpc = "%0.1f" % sliceMaxMpc
dataFileName = dataFileNameBase + "_z" + redshift + suffix
for iX in xrange(numSubvolumes):
for iY in xrange(numSubvolumes):
mySubvolume = "%d%d" % (iX, iY)
sampleName = getSampleName(prefix, base, redshift, useVel,
iSlice=iSlice, iVol=mySubvolume)
scriptFile.write(sampleInfo.format(dataFile=dataFileName,
dataFormat=dataFormat,
sampleName=sampleName,
zMin=sliceMin,
zMax=sliceMax,
zMinMpc=sliceMinMpc,
zMaxMpc=sliceMaxMpc,
omegaM=Om,
boxLen=lbox,
usePecVel=useVel,
minRadius=minRadius,
numSubvolumes=numSubvolumes,
mySubvolume=mySubvolume,
useLightCone=useLightCone,
subsample=subsample))
scriptFile.close()
return
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
if not os.access(scriptDir, os.F_OK): os.mkdir(scriptDir)
#------------------------------------------------------------------------------
# first the directly downsampled runs
# Note: ss0.002 ~ SDSS DR7 dim2
# ss0.0004 ~ SDSS DR9 mid
baseResolution = numPart/lbox/lbox/lbox # particles/Mpc^3
for thisSubSample in subSamples:
keepFraction = float(thisSubSample) / baseResolution
maxKeep = keepFraction * numPart
minRadius = int(np.ceil(lbox/maxKeep**(1./3)))
if args.script or args.all:
print " Doing subsample", thisSubSample, " scripts"
if dataFormat == "multidark":
writeScript(prefix,
"ss"+str(thisSubSample), scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, False, lbox, minRadius, omegaM,
subsample=1.0)
writeScript(prefix, "ss"+str(thisSubSample), scriptDir, catalogDir,
redshifts, numSubvolumes, numSlices, True, lbox, minRadius,
omegaM, subsample=1.0)
elif dataFormat == "gadget":
writeScript("", redshiftFileBase, scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, True, lbox, minRadius, omegaM,
subsample=thisSubSample, suffix="")
if args.subsample or args.all:
print " Doing subsample", thisSubSample
for redshift in redshifts:
print " redshift", redshift
dataFile = catalogDir+"/"+redshiftFileBase+redshift
inFile = open(dataFile, 'r')
sampleName = getSampleName("ss"+str(thisSubSample), redshift, False)
outFile = open(catalogDir+"/"+sampleName+".dat", 'w')
outFile.write("%f\n" %(lbox))
outFile.write("%s" %(omegaM))
outFile.write("%s" %(hubble))
outFile.write("%s\n" %(redshift))
outFile.write("%d\n" %(maxKeep))
numKept = 0
for line in inFile:
if np.random.uniform() > keepFraction: continue
numKept += 1
if numKept > maxKeep: break
line = line.split(',')
x = float(line[0])
y = float(line[1])
z = float(line[2])
vz = float(line[3])
outFile.write("%e %e %e %e\n" %(x,y,z,vz))
outFile.write("-99 -99 -99 -99\n")
print "KEEPING:", numKept, "...predicted:", maxKeep
inFile.close()
outFile.close()
# -----------------------------------------------------------------------------
# now halos
if args.script or args.all:
print " Doing halo scripts"
dataFile = catalogDir+"/mdr1_halos_z"+redshifts[0]
inFile = open(dataFile, 'r')
numPart = 0
for line in inFile: numPart += 1
inFile.close()
minRadius = int(np.ceil(lbox/numPart**(1./3.)))
if dataFormat == "multidark":
writeScript(prefix, "halos", scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, False, lbox, minRadius, omegaM)
writeScript(prefix, "halos", scriptDir, catalogDir, redshifts, numSubvolumes,
numSlices, True, lbox, minRadius, omegaM)
if args.halos or args.all:
print " Doing halos"
for redshift in redshifts:
print " z = ", redshift
dataFile = catalogDir+"/mdr1_halos_z"+redshift
inFile = open(dataFile, 'r')
numPart = 0
for line in inFile: numPart += 1
inFile.close()
sampleName = getSampleName("halos", redshift, False)
outFile = open(catalogDir+"/"+sampleName+".dat", 'w')
outFile.write("%f\n" %(lbox))
outFile.write("%s" %(omegaM))
outFile.write("%s" %(hubble))
outFile.write("%s\n" %(redshift))
outFile.write("%d\n" %(numPart))
inFile = open(dataFile, 'r')
numKept = 0
for line in inFile:
numKept += 1
line = line.split(',')
x = float(line[0])
y = float(line[1])
z = float(line[2])
vz = float(line[5])
# write to output file
outFile.write("%e %e %e %e\n" %(x,y,z,vz))
inFile.close()
outFile.close()
# -----------------------------------------------------------------------------
# now the SDSS HOD
parFileText = """
% cosmology
OMEGA_M {omegaM}
HUBBLE {hubble}
OMEGA_B 0.0469
SIGMA_8 0.82
SPECTRAL_INDX 0.95
ITRANS 5
REDSHIFT {redshift}
% halo definition
%DELTA_HALO 200
DELTA_HALO 740.74 % 200/Om_m
M_max 1.00E+16
% fit function types
pdfs 11
pdfc 2
EXCLUSION 4
% hod parameters
M_min {Mmin}
GALAXY_DENSITY 0.0111134 % computed automatically if M_min set, use for sanity
M1 {M1}
sigma_logM {sigma_logM}
alpha {alpha}
M_cut {Mcut}
% simulation info
real_space_xi 1
HOD 1
populate_sim 1
HaloFile {haloFile}
RESOLUTION {numPartPerSide}
BOX_SIZE {boxSize}
% output
root_filename hod
"""
if args.script or args.all:
print " Doing DR7 HOD scripts"
if dataFormat == "multidark":
writeScript(prefix,
"hod_dr72dim2", scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, False, lbox, 5, omegaM)
writeScript(prefix,
"hod_dr72dim2", scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, True, lbox, 5, omegaM)
if args.hod or args.all:
print " Doing DR7 HOD"
for redshift in redshifts:
print " z = ", redshift
parFileName = "./hod.par"
parFile = open(parFileName, 'w')
haloFile = catalogDir+"/mdr1_halos_z"+redshift
parFile.write(parFileText.format(omegaM=omegaM,
hubble=hubble,
redshift=redshift,
Mmin=1.99526e12,
M1=3.80189e13,
sigma_logM=0.21,
alpha=1.12,
Mcut=6.91831e11,
haloFile=haloFile,
numPartPerSide=numPart**(1/3.),
boxSize=lbox))
parFile.close()
os.system(hodPath+" "+parFileName+">& /dev/null")
sampleName = getSampleName("hod_dr72dim2", redshift, False)
outFileName = catalogDir+"/"+sampleName+".dat"
os.system("mv hod.mock" + " " + outFileName)
os.system("rm ./hod.*")
# -----------------------------------------------------------------------------
# now the BOSS HOD
if args.script or args.all:
print " Doing DR9 HOD scripts"
if dataFormat == "multidark":
writeScript(prefix,
"hod_dr9mid", scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, False, lbox, 5, omegaM)
writeScript(prefix,
"hod_dr9mid", scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, True, lbox, 5, omegaM)
if args.hod or args.all:
print " Doing DR9 HOD"
for redshift in redshifts:
print " z = ", redshift
parFileName = "./hod.par"
parFile = open(parFileName, 'w')
haloFile = catalogDir+"/mdr1_halos_z"+redshift
parFile.write(parFileText.format(omegaM=omegaM,
hubble=hubble,
redshift=redshift,
Mmin=1.23e13,
M1=1.e14,
sigma_logM=0.596,
alpha=1.0127,
Mcut=1.19399e13,
haloFile=haloFile,
numPartPerSide=numPart**(1/3.),
boxSize=lbox))
parFile.close()
os.system(hodPath+" "+parFileName+">& /dev/null")
sampleName = getSampleName("hod_dr9mid", redshift, False)
outFileName = catalogDir+"/"+sampleName+".dat"
os.system("mv hod.mock" + " " + outFileName)
os.system("rm ./hod.*")

213
pipeline/prepareGadgetCatalog.py Executable file
View file

@ -0,0 +1,213 @@
#!/usr/bin/env python
# prepares input catalogs based on multidark simulations
# (borrows heavily from generateMock, but doesn't hold much in memory)
# also creates necessary analyzeVoids input files
import numpy as np
import os
import sys
from Scientific.IO.NetCDF import NetCDFFile
import void_python_tools as vp
import argparse
catalogDir = os.getenv("HOME")+"/workspace/Voids/catalogs/multidark/"
hodPath = os.getenv("HOME")+"/projects/Voids/hod/HOD.x"
voidOutputDir = os.getenv("HOME")+"/workspace/Voids/multidark/"
scriptDir = os.getenv("HOME")+"/projects/Voids/scripts/multidark/"
figDir = os.getenv("HOME")+"/projects/Voids/figs/multidark/"
logDir = os.getenv("HOME")+"/projects/Voids/logs/multidark/"
dataType = "simulation"
dataFormat = "gadget"
useLightCone = False # place particles on a light cone?
redshiftFileBase = "mdr1_particles_z" # common filename of particle files
redshifts = (("0.0", "0.53", "1.0")) # list of redshift particle files
numSlices = 4 # how many slices along the z-axis?
numSubvolumes = 1 # how many subdivisions along the x- and y-axes?
prefix = "testrun_" # prefix to give all outputs
subSamples = [ 0.01 ] # list of desired subsamples
numPart = 1024*1024*1024 # number of particles in base catalog
lbox = 1000 # Mpc/h
omegaM = 0.27
hubble = 0.70
# -----------------------------------------------------------------------------
LIGHT_SPEED = 299792.458
#------------------------------------------------------------------------------
def getSampleName(setName, redshift, useVel, iSlice=-1, iVol=-1):
sampleName = setName
if useVel: setName += "_pv"
if iSlice != -1: sampleName += "_s" + str(iSlice)
if iVol != -1: sampleName += "_d" + iVol
return sampleName
#------------------------------------------------------------------------------
# for given dataset parameters, outputs a script for use with analyzeVoids
def writeScript(setName, dataFileNameBase,
scriptDir, catalogDir, redshifts, numSubvolumes,
numSlices, useVel, lbox, minRadius, omegaM, subsample=1.0,
suffix=".dat"):
if useVel: setName += "_pv"
scriptFileName = scriptDir + "/" + setName + ".py"
scriptFile = open(scriptFileName, 'w')
scriptFile.write("""#!/usr/bin/env/python
import os
from void_python_tools.backend.classes import *
continueRun = False
startCatalogStage = 1
endCatalogStage = 3
startAPStage = 1
endAPStage = 6
ZOBOV_PATH = os.getenv("PWD")+"/../zobov/"
CTOOLS_PATH = os.getenv("PWD")+"/../c_tools/"
freshStack = True
errorBars = "CALCULATED"
numIncoherentRuns = 100
ranSeed = 101010
useLCDM = False
bias = 1.16
dataPortions = ["central"]
dataSampleList = []
""")
dataInfo = """
setName = "{setName}"
workDir = "{voidOutputDir}/{setName}/"
inputDataDir = "{inputDataDir}"
figDir = "{figDir}/{setName}/"
logDir = "{logDir}/{setName}/"
"""
scriptFile.write(dataInfo.format(setName=setName, figDir=figDir,
logDir=logDir, voidOutputDir=voidOutputDir,
inputDataDir=catalogDir))
sampleInfo = """
newSample = Sample(dataFile = "{dataFile}",
dataFormat = "{dataFormat}",
fullName = "{sampleName}",
nickName = "{sampleName}",
dataType = "simulation",
zBoundary = ({zMin}, {zMax}),
zRange = ({zMin}, {zMax}),
zBoundaryMpc = ({zMinMpc}, {zMaxMpc}),
omegaM = {omegaM},
minVoidRadius = {minRadius},
includeInHubble = True,
partOfCombo = False,
isCombo = False,
boxLen = {boxLen},
usePecVel = {usePecVel},
numSubvolumes = {numSubvolumes},
mySubvolume = "{mySubvolume}",
numSubDivisions = 4,
useLightCone = {useLightCone},
subsample = {subsample})
dataSampleList.append(newSample)
"""
for redshift in redshifts:
zBox = float(redshift)
Om = float(omegaM)
zBoxMpc = LIGHT_SPEED/100.*vp.angularDiameter(zBox, Om=Om)
boxMaxMpc = zBoxMpc + lbox
# converter from redshift to comoving distance
zVsDY = np.linspace(0., zBox+8*lbox*100./LIGHT_SPEED, 10000)
zVsDX = np.zeros(len(zVsDY))
for i in xrange(len(zVsDY)):
zVsDX[i] = vp.angularDiameter(zVsDY[i], Om=Om)
if useLightCone:
boxWidthZ = np.interp(vp.angularDiameter(zBox,Om=Om)+100. / \
LIGHT_SPEED*lbox, zVsDX, zVsDY)-zBox
dzSafe = 0.03
else:
boxWidthZ = lbox*100./LIGHT_SPEED
dzSafe = 0.0
for iSlice in xrange(numSlices):
sliceMin = zBox + dzSafe + iSlice*(boxWidthZ-dzSafe)/numSlices
sliceMax = zBox + dzSafe + (iSlice+1)*(boxWidthZ-dzSafe)/numSlices
sliceMinMpc = sliceMin*LIGHT_SPEED/100.
sliceMaxMpc = sliceMax*LIGHT_SPEED/100.
sliceMin = "%0.2f" % sliceMin
sliceMax = "%0.2f" % sliceMax
sliceMinMpc = "%0.1f" % sliceMinMpc
sliceMaxMpc = "%0.1f" % sliceMaxMpc
dataFileName = dataFileNameBase + redshift + suffix
for iX in xrange(numSubvolumes):
for iY in xrange(numSubvolumes):
mySubvolume = "%d%d" % (iX, iY)
sampleName = getSampleName(setName, redshift, useVel,
iSlice=iSlice, iVol=mySubvolume)
scriptFile.write(sampleInfo.format(dataFile=dataFileName,
dataFormat=dataFormat,
sampleName=sampleName,
zMin=sliceMin,
zMax=sliceMax,
zMinMpc=sliceMinMpc,
zMaxMpc=sliceMaxMpc,
omegaM=Om,
boxLen=lbox,
usePecVel=useVel,
minRadius=minRadius,
numSubvolumes=numSubvolumes,
mySubvolume=mySubvolume,
useLightCone=useLightCone,
subsample=subsample))
scriptFile.close()
return
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
if not os.access(scriptDir, os.F_OK): os.mkdir(scriptDir)
#------------------------------------------------------------------------------
# first the directly downsampled runs
# Note: ss0.002 ~ SDSS DR7 dim2
# ss0.0004 ~ SDSS DR9 mid
baseResolution = numPart/lbox/lbox/lbox # particles/Mpc^3
for thisSubSample in subSamples:
keepFraction = float(thisSubSample) / baseResolution
maxKeep = keepFraction * numPart
minRadius = int(np.ceil(lbox/maxKeep**(1./3)))
print " Doing subsample", thisSubSample, " scripts"
setName = prefix+"ss"+str(thisSubSample)
writeScript(setName, redshiftFileBase, scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, True, lbox, minRadius, omegaM,
subsample=thisSubSample, suffix="")
writeScript(setName, redshiftFileBase, scriptDir, catalogDir, redshifts,
numSubvolumes, numSlices, False, lbox, minRadius, omegaM,
subsample=thisSubSample, suffix="")

View file

@ -1,365 +0,0 @@
#include <healpix_map.h>
#include <healpix_map_fitsio.h>
#include <boost/format.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "generateFromCatalog_conf.h"
#include "contour_pixels.hpp"
#include <netcdfcpp.h>
#include <CosmoTool/fortran.hpp>
using namespace std;
using boost::format;
using namespace CosmoTool;
struct NYU_Data
{
int index;
int sector;
int region;
double ra, dec;
double cz;
double fgotten;
double phi_z;
};
struct Position
{
double xyz[3];
};
struct ParticleData
{
vector<int> id_gal;
int id_mask;
vector<Position> pos;
double box[3][2];
double Lmax;
};
typedef vector<NYU_Data> NYU_VData;
void loadData(const string& fname, NYU_VData & data)
{
ifstream f(fname.c_str());
while (!f.eof())
{
NYU_Data d;
f >> d.index >> d.sector >> d.region >> d.ra >> d.dec >> d.cz >> d.fgotten >> d.phi_z;
data.push_back(d);
}
}
void generateGalaxiesInCube(NYU_VData& data, ParticleData& output_data)
{
double d2r = M_PI/180;
output_data.pos.resize(data.size());
output_data.id_gal.resize(data.size());
for (int j = 0; j < 3; j++)
{
output_data.box[j][0] = -INFINITY;
output_data.box[j][1] = INFINITY;
}
for (int i = 0; i < data.size(); i++)
{
double ra = data[i].ra*d2r, dec = data[i].dec*d2r;
Position& p = output_data.pos[i];
p.xyz[0] = data[i].cz*cos(ra)*cos(dec);
p.xyz[1] = data[i].cz*sin(ra)*cos(dec);
p.xyz[2] = data[i].cz*sin(dec);
output_data.id_gal[i] = data[i].index;
for (int j = 0; j < 3; j++)
{
if (p.xyz[j] > output_data.box[j][0])
output_data.box[j][0] = p.xyz[j];
if (p.xyz[j] < output_data.box[j][1])
output_data.box[j][1] = p.xyz[j];
}
}
cout << format("Galaxy position generated: %d galaxies") % output_data.pos.size() << endl;
cout << format("box is %g < x < %g; %g < y < %g; %g < z < %g")
% (1e-2*output_data.box[0][1]) % (1e-2*output_data.box[0][0])
% (1e-2*output_data.box[1][1]) % (1e-2*output_data.box[1][0])
% (1e-2*output_data.box[2][1]) % (1e-2*output_data.box[2][0]) << endl;
}
static double cube(double x)
{
return x*x*x;
}
void generateBoxMask(generateFromCatalog_info& args ,
Healpix_Map<float>& mask,
vector<int>& pixel_list,
NYU_VData& data,
ParticleData& output_data)
{
int idx = -1;
int insertion = 0;
double volume = pixel_list.size()*1.0/mask.Npix()*4*M_PI;
int numToInsert;
idx = output_data.id_mask;
cout << "Generate box mask..." << endl;
double Rmax = output_data.Lmax, t = args.box_thickness_arg;
output_data.Lmax += args.box_thickness_arg;
volume *= Rmax*Rmax/1e6 * args.box_thickness_arg;
numToInsert = (int)floor(volume*args.box_density_arg);
for (int i = 0; i < numToInsert; i++)
{
Position p;
bool stop_here;
do
{
int p0 = (int)floor(drand48()*pixel_list.size());
vec3 v = mask.pix2vec(pixel_list[p0]);
double r = Rmax*pow(drand48()*(cube(1+t/Rmax)-1) + 1,1./3);
p.xyz[0] = v.x * r;
p.xyz[1] = v.y * r;
p.xyz[2] = v.z * r;
stop_here = true;
for (int j = 0; j < 3; j++)
{
if (p.xyz[j] > output_data.box[j][0] ||
p.xyz[j] < output_data.box[j][1])
stop_here = false;
}
}
while (!stop_here);
output_data.pos.push_back(p);
output_data.id_gal.push_back(idx);
insertion++;
}
}
void generateSurfaceMask(generateFromCatalog_info& args ,
Healpix_Map<float>& mask,
vector<int>& pixel_list,
NYU_VData& data,
ParticleData& output_data)
{
// Find the first free index
int idx = -1;
int insertion = 0;
double volume = pixel_list.size()*1.0/mask.Npix()*4*M_PI;
int numToInsert;
for (int i = 0; i < output_data.id_gal.size(); i++)
{
if (idx < output_data.id_gal[i])
idx = output_data.id_gal[i]+1;
}
output_data.id_mask = idx;
cout << "Generate surface mask..." << endl;
double Rmax = -1;
for (int j = 0; j < 3; j++)
{
Rmax = max(Rmax, max(output_data.box[j][0], -output_data.box[j][1]));
}
output_data.Lmax = Rmax;
cout << format("Rmax is %g, surface volume is %g") % (Rmax/100) % (volume/(4*M_PI)) << endl;
volume *= Rmax*Rmax*Rmax/3/1e6;
numToInsert = (int)floor(volume*args.density_fake_arg);
cout << format("3d volume to fill: %g (Mpc/h)^3") % volume << endl;
cout << format("Will insert %d particles") % numToInsert << endl;
double pct = 0;
for (int i = 0; i < numToInsert; i++)
{
double new_pct = i*100./numToInsert;
if (new_pct-pct > 5.)
{
pct = new_pct;
cout << format(" .. %3.0f %%") % pct << endl;
}
Position p;
bool stop_here;
do
{
int p0 = (int)floor(drand48()*pixel_list.size());
vec3 v = mask.pix2vec(pixel_list[p0]);
double r = Rmax*pow(drand48(),1./3);
p.xyz[0] = v.x * r;
p.xyz[1] = v.y * r;
p.xyz[2] = v.z * r;
stop_here = true;
for (int j = 0; j < 3; j++)
{
if (p.xyz[j] > output_data.box[j][0] ||
p.xyz[j] < output_data.box[j][1])
stop_here = false;
}
}
while (!stop_here);
output_data.pos.push_back(p);
output_data.id_gal.push_back(idx);
insertion++;
}
cout << format("Done. Inserted %d particles.") % insertion << endl;
}
void saveData(ParticleData& pdata)
{
NcFile f("particles.nc", NcFile::Replace);
assert(f.is_valid());
NcDim *d = f.add_dim("space", 3);
NcDim *p = f.add_dim("Np", pdata.pos.size());
NcVar *v = f.add_var("particles", ncDouble, d, p);
double *x = new double[pdata.pos.size()];
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < pdata.pos.size(); i++)
x[i] = pdata.pos[i].xyz[j];
v->put_rec(d, x, j);
}
v = f.add_var("id_gal", ncInt, p);
v->put(&pdata.id_gal[0], pdata.id_gal.size());
delete[] x;
}
void saveForZobov(ParticleData& pdata, const string& fname, const string& paramname)
{
UnformattedWrite f(fname);
static const char axis[] = { 'X', 'Y', 'Z' };
double Lmax = pdata.Lmax;
f.beginCheckpoint();
f.writeInt32(pdata.pos.size());
f.endCheckpoint();
for (int j = 0; j < 3; j++)
{
cout << format("Writing %c components...") % axis[j] << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < pdata.pos.size(); i++)
{
f.writeReal32((pdata.pos[i].xyz[j]+Lmax)/(2*Lmax));
}
f.endCheckpoint();
}
NcFile fp(paramname.c_str(), NcFile::Replace);
fp.add_att("range_x_min", -Lmax);
fp.add_att("range_x_max", Lmax);
fp.add_att("range_y_min", -Lmax);
fp.add_att("range_y_max", Lmax);
fp.add_att("range_z_min", -Lmax);
fp.add_att("range_z_max", Lmax);
NcDim *NumPart_dim = fp.add_dim("numpart_dim", pdata.pos.size());
NcVar *v = fp.add_var("particle_ids", ncInt, NumPart_dim);
NcVar *v2 = fp.add_var("expansion", ncDouble, NumPart_dim);
double *expansion_fac = new double[pdata.pos.size()];
for (int i = 0; i < pdata.pos.size(); i++)
expansion_fac[i] = 1.0;
v->put(&pdata.id_gal[0], pdata.id_gal.size());
v2->put(expansion_fac, pdata.pos.size());
delete[] expansion_fac;
}
int main(int argc, char **argv)
{
generateFromCatalog_info args_info;
generateFromCatalog_conf_params args_params;
generateFromCatalog_conf_init(&args_info);
generateFromCatalog_conf_params_init(&args_params);
args_params.check_required = 0;
if (generateFromCatalog_conf_ext (argc, argv, &args_info, &args_params))
return 1;
if (!args_info.configFile_given)
{
if (generateFromCatalog_conf_required (&args_info, GENERATEFROMCATALOG_CONF_PACKAGE))
return 1;
}
else
{
args_params.check_required = 1;
args_params.initialize = 0;
if (generateFromCatalog_conf_config_file (args_info.configFile_arg,
&args_info,
&args_params))
return 1;
}
generateFromCatalog_conf_print_version();
cout << "Loading NYU data..." << endl;
vector<NYU_Data> data;
Healpix_Map<float> o_mask;
vector<int> pixel_list;
ParticleData output_data;
loadData(args_info.catalog_arg, data);
cout << "Loading mask..." << endl;
read_Healpix_map_from_fits(args_info.mask_arg, o_mask);
Healpix_Map<float> mask;
mask.SetNside(128, RING);
mask.Import(o_mask);
computeContourPixels(mask,pixel_list);
// We compute a cube holding all the galaxies + the survey surface mask
generateGalaxiesInCube(data, output_data);
generateSurfaceMask(args_info, mask, pixel_list, data, output_data);
computeFilledPixels(mask,pixel_list);
generateBoxMask(args_info, mask, pixel_list, data, output_data);
saveForZobov(output_data, args_info.output_arg, args_info.params_arg);
// saveData(output_data);
return 0;
}

10
python_tools/PKG-INFO Normal file
View file

@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: voidProject
Version: 1.0
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN

14
python_tools/setup.py Normal file
View file

@ -0,0 +1,14 @@
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy as np
setup(
name='void_python_tools',
version='1.0',
cmdclass = {'build_ext': build_ext},
include_dirs = [np.get_include()],
packages=['void_python_tools','void_python_tools.backend','void_python_tools.apTools','void_python_tools.apTools.profiles','void_python_tools.apTools.chi2', 'void_python_tools.plotting'],
#ext_modules = [Extension("void_python_tools.chi2.velocityProfileFitNative", ["void_python_tools/chi2/velocityProfileFitNative.pyx"], libraries=["gsl", "gslcblas"]), Extension("void_python_tools.chi2.likelihoo", ["void_python_tools/chi2/likelihood.pyx"], libraries=["gsl", "gslcblas"])]
ext_modules = [Extension("void_python_tools.apTools.chi2.velocityProfileFitNative", ["void_python_tools/apTools/chi2/velocityProfileFitNative.pyx"], libraries=["gsl", "gslcblas"])]
)

View file

@ -0,0 +1,3 @@
from void_python_tools.backend import *
from void_python_tools.apTools import *
from void_python_tools.plotting import *

Binary file not shown.

View file

@ -0,0 +1,2 @@
from chi2 import *
from profiles import *

View file

@ -0,0 +1,3 @@
from velocityProfileFitNative import *
from likelihood import *
from cosmologyTools import *

View file

@ -0,0 +1,94 @@
# a suite of functions to compute expansion rates, angular diameter
# distances, and expected void stretching
import numpy as np
import scipy.integrate as integrate
__all__=['expansion', 'angularDiameter', 'expectedStretch', 'aveStretch', 'aveExpansion', 'aveStretchCone', 'aveWeightedStretch']
# returns 1/E(z) for the given cosmology
def expansion(z, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
wz = w0 + wa*z/(1+z)
ez = Om * (1+z)**3 + (Ot-Om)# * (1+z)**(3.+3*wz)
ez = 1./np.sqrt(ez)
return ez
# returns D_A(z) for the given cosmology
def angularDiameter(z, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
da = integrate.quad(expansion, 0.0, z, args=(Om, Ot, w0, wa))[0]
return da
# returns expected void stretch for the given cosmology
def expectedStretch(z, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
ez = 1./expansion(z, Om=Om, Ot=Ot, w0=w0, wa=wa)
da = angularDiameter(z, Om=Om, Ot=Ot, w0=w0, wa=wa)
return ez*da/z
# returns average expected void stretch for a given redshift range
def aveStretch(zStart, zEnd, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
if zStart == 0.0: zStart = 1.e-6
ave = integrate.quad(expectedStretch, zStart, zEnd, args=(Om, Ot, w0, wa))[0]
ave /= (zEnd-zStart)
return ave
# -----------------------------------------------------------------------------
# returns average expected void stretch for a given redshift range
# assuming a cone
def aveStretchCone(zStart, zEnd, skyFrac = 0.19, Om = 0.27, Ot = 1.0,
w0 = -1.0, wa = 0.0):
if zStart == 0.0: zStart = 1.e-6
h1 = zStart
h2 = zEnd
r1 = skyFrac * 4* np.pi * zStart**2
r2 = skyFrac * 4 * np.pi * zEnd**2
# surface area of a slice within a cone
def coneSlice(x, h, r):
return np.pi * (r/h*x)**2
def coneFunc(z, h, r, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
return coneSlice(z, h, r) * expectedStretch(z, Om, Ot, w0, wa)
aveHigh = integrate.quad(coneFunc, 0.0, zEnd, args=(h2, r2, Om, Ot, w0, wa), full_output=1)[0]
aveLow = integrate.quad(coneFunc, 0.0, zStart, args=(h1, r1, Om, Ot, w0, wa), full_output=1)[0]
volumeHigh = integrate.quad(coneSlice, 0.0, zEnd, args=(h2, r2))[0]
volumeLow = integrate.quad(coneSlice, 0.0, zStart, args=(h1, r1))[0]
return (aveHigh-aveLow)/(volumeHigh-volumeLow)
# -----------------------------------------------------------------------------
# returns average expected void stretch for a given redshift range
# weighted by an actual void distribution
def aveWeightedStretch(zStart, zEnd, skyFrac = 0.19, Om = 0.27, Ot = 1.0,
w0 = -1.0, wa = 0.0, dist=None, bins=None):
if zStart == 0.0: zStart = 1.e-6
def weightedSlice(x):
return np.interp(x, bins[:-1], dist)
def weightedFunc(z, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
return expectedStretch(z, Om, Ot, w0, wa) *\
weightedSlice(z)
ave = integrate.quad(weightedFunc, zStart, zEnd, args=(Om, Ot, w0, wa),
full_output=1)[0]
volume = integrate.quad(weightedSlice, zStart, zEnd, full_output=1)[0]
return ave/volume
# -----------------------------------------------------------------------------
# returns average expected expansion for a given redshift range
def aveExpansion(zStart, zEnd, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
if zStart == 0.0: zStart = 1.e-6
ave = integrate.quad(expansion, zStart, zEnd, args=(Om, Ot, w0, wa))[0]
ave = (zEnd-zStart)/ave
return ave

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,6 @@
from build import *
from draw import *
from fit import *
from mcmc import *
from generateExpFigure import *
from getSurveyProps import *

View file

@ -0,0 +1,53 @@
import numpy as np
import healpy as healpy
import scipy.integrate
__all__=['getSurveyProps']
# returns the volume and galaxy density for a given redshit slice
def getSurveyProps(maskFile, zmin, zmax, selFunMin, selFunMax, portion, selectionFuncFile=None):
mask = healpy.read_map(maskFile)
area = (1.*np.size(np.where(mask > 0)) / np.size(mask)) * 4.*np.pi
zmin = zmin * 3000
zmax = zmax * 3000
volume = area * (zmax**3 - zmin**3) / 3
if selectionFuncFile != None:
selfunc = np.genfromtxt(selectionFuncFile)
selfunc = np.array(selfunc)
selfunc[:,0] = selfunc[:,0]/100.
selfuncUnity = selfunc
selfuncUnity[:,1] = 1.0
selfuncMin = selfunc[0,0]
selfuncMax = selfunc[-1,0]
selfuncDx = selfunc[1,0] - selfunc[0,0]
selfuncN = np.size(selfunc[:,0])
selFunMin *= 3000
selFunMax *= 3000
selFunMin = max(selFunMin, selfuncMin)
selFunMax = min(selFunMax, selfuncMax)
def f(z): return selfunc[np.ceil((z-selfuncMin)/selfuncDx), 1]*z**2
def fTotal(z): return selfuncUnity[np.ceil((z-selfuncMin)/selfuncDx), 1]*z**2
zrange = np.linspace(selFunMin, selFunMax)
nbar = scipy.integrate.quad(f, selFunMin, selFunMax)
nbar = nbar[0]
ntotal = scipy.integrate.quad(fTotal, 0.0, max(selfuncUnity[:,0]))
#ntotal = scipy.integrate.quad(f, 0.0, max(selfunc[:,0]))
ntotal = ntotal[0]
nbar = ntotal / area / nbar
else:
nbar = 1.0
#print "PROPERTIES: ", volume, nbar
return (volume, nbar)

View file

@ -0,0 +1,2 @@
from classes import *
from launchers import *

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,169 @@
# classes and routines used to support scripts
import os
LIGHT_SPEED = 299792.458
class Stack:
zMin = 0.0
zMax = 0.1
rMin = 5
rMax = 15
zMinPlot = 0.0
zMaxPlot = 0.1
includeInHubble = True
partOfCombo = False
needProfile = True
rescaleMode = "rmax" # options: "rmax" to scale to largest void in stack
# "rv" normalize each void
def __init__(self, zMin, zMax, rMin, rMax, includeInHubble, partOfCombo,
zMinPlot=None, needProfile=True, rescaleMode="rmax"):
self.zMin = zMin
self.zMax = zMax
self.rMin = rMin
self.rMax = rMax
self.zMaxPlot = zMax
self.includeInHubble = includeInHubble
self.partOfCombo = partOfCombo
self.needProfile = needProfile
self.rescaleMode = rescaleMode
if zMinPlot == None:
self.zMinPlot = self.zMin
else:
self.zMinPlot = zMinPlot
class Sample:
dataType = "observation"
dataFormat = "sdss"
dataFile = "lss.dr72dim.dat"
fullName = "lss.dr72dim.dat"
nickName = "dim"
zobovDir = ""
maskFile = "rast_window_512.fits"
selFunFile = "czselfunc.all.dr72dim.dat"
skyFraction = 0.19
zBoundary = (0.0, 0.1)
zBoundaryMpc = (0., 300)
zRange = (0.0, 0.1)
omegaM = 0.27
minVoidRadius = 5
fakeDensity = 0.01
profileBinSize = 2 # Mpc
volumeLimited = True
includeInHubble = True
partOfCombo = False
isCombo = False
comboList = []
# applies to simulations only
boxLen = 1024 # Mpc/h
usePecVel = False
subsample = 1.0
useLightCone = True
numSubDivisions = 1
numSubvolumes = 1
mySubvolume = 1
stacks = []
def __init__(self, dataFile="", fullName="",
nickName="", maskFile="", selFunFile="",
zBoundary=(), zRange=(), zBoundaryMpc=(),
minVoidRadius=0, fakeDensity=0.01, volumeLimited=True,
includeInHubble=True, partOfCombo=False, isCombo=False,
comboList=(), profileBinSize=2.0, skyFraction=0.19,
dataType="observation", numSubDivisions=2,
boxLen=1024, usePecVel=False, omegaM=0.27,
numSubvolumes=1, mySubvolume=1, dataFormat="sdss",
subsample="1.0", useLightCone=True):
self.dataFile = dataFile
self.fullName = fullName
self.nickName = nickName
self.maskFile = maskFile
self.selFunFile = selFunFile
self.zBoundary = zBoundary
self.zBoundaryMpc = zBoundaryMpc
self.zRange = zRange
self.minVoidRadius = minVoidRadius
self.fakeDensity = fakeDensity
self.volumeLimited = volumeLimited
self.includeInHubble = includeInHubble
self.partOfCombo = partOfCombo
self.isCombo = isCombo
self.comboList = comboList
self.zobovDir = None
self.profileBinSize = profileBinSize
self.skyFraction = skyFraction
self.dataType = dataType
self.numSubDivisions = numSubDivisions
self.boxLen = boxLen
self.usePecVel = usePecVel
self.omegaM = omegaM
self.numSubvolumes = numSubvolumes
self.mySubvolume = mySubvolume
self.dataFormat = dataFormat
self.subsample = subsample
self.useLightCone = useLightCone
self.stacks = []
def addStack(self, zMin, zMax, rMin, rMax,
includeInHubble, partOfCombo,zMinPlot=None,
needProfile=True, rescaleMode="rmax"):
self.stacks.append(Stack(zMin, zMax, rMin, rMax,
includeInHubble, partOfCombo,
zMinPlot=zMinPlot, needProfile=needProfile,
rescaleMode=rescaleMode))
def getHubbleStacks(self):
stacksForHubble = []
for stack in self.stacks:
if stack.includeInHubble:
stacksForHubble.append(stack)
return stacksForHubble
def getUniqueRBins(self):
uniqueRStacks = []
for stack in self.stacks:
if not stack.includeInHubble:
continue
alreadyHere = False
for stackCheck in uniqueRStacks:
if stack.rMin == stackCheck.rMin and stack.rMax == stackCheck.rMax:
alreadyHere = True
break
if not alreadyHere:
uniqueRStacks.append(stack)
return uniqueRStacks
def getUniqueZBins(self):
uniqueZStacks = []
for stack in self.stacks:
if not stack.includeInHubble:
continue
alreadyHere = False
for stackCheck in uniqueZStacks:
if stack.zMin == stackCheck.zMin and stack.zMax == stackCheck.zMax:
alreadyHere = True
break
if not alreadyHere:
uniqueZStacks.append(stack)
return uniqueZStacks
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
def jobSuccessful(logFile, doneString):
jobDone = False
checkLine = ""
if os.access(logFile, os.F_OK):
filelines = file(logFile, "r").readlines()
if len(filelines) >= 1:
checkLine = filelines[-1]
jobDone = (checkLine == doneString)
return jobDone
def getStackSuffix(zMin, zMax, rMin, rMax, dataPortion):
return "z"+str(zMin)+"-"+str(zMax)+"_"+str(rMin)+"-"+str(rMax)+\
"Mpc"+"_"+dataPortion

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
from plotTools import *
from plotDefs import *

View file

@ -0,0 +1,13 @@
colorList = ['r', 'b', 'g', 'y', 'c', 'm', 'y',
'brown', 'grey',
'darkred', 'orange', 'pink', 'darkblue',
'lightblue', 'chocolate',
'indigo', 'lightseagreen', 'maroon', 'olive',
'royalblue', 'palevioletred', 'seagreen', 'tomato',
'aquamarine', 'darkslateblue',
'khaki', 'lawngreen', 'mediumorchid',
'orangered', 'thistle'
'yellowgreen']
linewidth = 4
fontsize = 12

View file

@ -0,0 +1,69 @@
__all__=['plotNumberCounts']
from void_python_tools.backend.classes import *
from plotDefs import *
import numpy as np
import os
import pylab as plt
# -----------------------------------------------------------------------------
def plotNumberCounts(workDir=None, sampleList=None, figDir=None, plotNameBase="numbercount",
showPlot=False, dataPortion=None, setName=None):
plt.clf()
plt.xlabel("Comoving Distance (Mpc/h)")
plt.ylabel("Number of Voids")
plotTitle = setName
plotName = plotNameBase
xMin = 1.e00
xMax = 0
for (iSample,sample) in enumerate(sampleList):
sampleName = sample.fullName
lineTitle = sampleName
filename = workDir+"/sample_"+sampleName+"/centers_"+dataPortion+"_"+\
sampleName+".out"
if not os.access(filename, os.F_OK):
print "File not found: ", filename
continue
data = np.loadtxt(filename, comments="#")
if data.ndim == 1:
print " Too few!"
continue
zMin = sample.zRange[0]
zMax = sample.zRange[1]
range = (zMin, zMax)
nbins = np.ceil((zMax-zMin)/0.1)
thisMax = np.max(data[:,5])
thisMin = np.min(data[:,5])
if thisMax > xMax: xMax = thisMax
if thisMin < xMin: xMin = thisMin
plt.hist(data[:,5], bins=nbins,
label=lineTitle, color=colorList[iSample],
histtype = "step", range=range,
linewidth=linewidth)
#plt.legend(title = "Samples", loc = "upper right")
plt.title(plotTitle)
plt.xlim(xMin, xMax)
#plt.xlim(xMin, xMax*1.4) # make room for legend
plt.savefig(figDir+"/fig_"+plotName+".pdf", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".eps", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".png", bbox_inches="tight")
if showPlot:
os.system("display %s" % figDir+"/fig_"+plotName+".png")

View file

@ -5,7 +5,7 @@
#include <math.h>
#define BIGFLT 1e30 /* Biggest possible floating-point number */
#define NLINKS 100 /* Number of possible links with the same rho_sl */
#define NLINKS 1000 /* Number of possible links with the same rho_sl */
#define FF fflush(stdout)
typedef struct Particle {
@ -61,16 +61,19 @@ int main(int argc,char **argv) {
double *sorter, e1,maxdenscontrast;
int *iord;
int mockIndex;
e1 = exp(1.)-1.;
if (argc != 7) {
if (argc != 8) {
printf("Wrong number of arguments.\n");
printf("arg1: adjacency file\n");
printf("arg2: volume file\n");
printf("arg3: output file containing particles in each zone\n");
printf("arg4: output file containing zones in each void\n");
printf("arg5: output text file\n");
printf("arg6: Density threshold (0 for no threshold)\n\n");
printf("arg6: Density threshold (0 for no threshold)\n");
printf("arg7: Beginning index of mock galaxies\n\n");
exit(0);
}
adjfile = argv[1];
@ -82,6 +85,11 @@ int main(int argc,char **argv) {
printf("Bad density threshold.\n");
exit(0);
}
if (sscanf(argv[7],"%f",&mockIndex) == 0) {
printf("Bad mock galaxy index.\n");
exit(0);
}
printf("TOLERANCE: %f\n", voltol);
if (voltol <= 0.) {
printf("Proceeding without a density threshold.\n");
voltol = 1e30;
@ -140,7 +148,10 @@ int main(int argc,char **argv) {
// fread(&np,1, sizeof(int),adj);
for (i=0;i<np;i++) {
// fread(&nin,1,sizeof(int),adj); /* actually nadj */
if (p[i].ncnt != p[i].nadj) {
// PMS
if (p[i].ncnt != p[i].nadj && i < mockIndex) {
//if (p[i].ncnt != p[i].nadj) {
// END PMS
p[i].nadj = p[i].ncnt;
printf("We didn't get all of %d's adj's; %d != %d.\n",i,nin,p[i].nadj);
/*exit(0);*/
@ -163,7 +174,10 @@ int main(int argc,char **argv) {
FF;
for (i=0;i<np;i++) {
fread(&p[i].dens,1,sizeof(float),vol);
if ((p[i].dens < 1e-30) || (p[i].dens > 1e30)) {
// PMS
if ((p[i].dens < 1e-30) || (p[i].dens > 1e30) && i < mockIndex) {
//if ((p[i].dens < 1e-30) || (p[i].dens > 1e30)) {
// END PMS
printf("Whacked-out volume found, of particle %d: %f\n",i,p[i].dens);
p[i].dens = 1.;
}
@ -343,6 +357,9 @@ int main(int argc,char **argv) {
fwrite(&np,1,4,zon);
fwrite(&nzones,1,4,zon);
for (h=0; h<nzones; h++) {
// PMS
//printf("%d %d %d", &(z[h].np), m[h], z[h].np);
// END PMS
fwrite(&(z[h].np),1,4,zon);
fwrite(m[h],z[h].np,4,zon);
free(m[h]);
@ -540,11 +557,15 @@ int main(int argc,char **argv) {
for (h=0; h<nzones; h++) {
i = iord[h];
prob = exp(-5.12*(z[i].denscontrast-1.) - 0.8*pow(z[i].denscontrast-1.,2.8));
// PMS
if (z[i].np == 1) continue;
// END PMS
fprintf(txt,"%d %d %d %e %e %d %d %e %d %f %6.2e\n",
h+1, i, z[i].core, p[z[i].core].dens, z[i].vol, z[i].np, z[i].nhl, z[i].voljoin, z[i].npjoin, z[i].denscontrast, prob);
} /* h+1 to start from 1, not zero */
fclose(txt);
printf("Done!\n");FF;
return(0);
}

View file

@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
coordT deladjs[3*MAXVERVER], points[3*MAXVERVER];
pointT intpoints[3*MAXVERVER];
FILE *pos, *out;
char *posfile, outfile[80], *suffix;
char *posfile, outfile[200], *suffix, *outDir;
PARTADJ *adjs;
float *vols;
float predict, xmin,xmax,ymin,ymax,zmin,zmax;
@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
int b[3];
double totalvol;
if (argc != 9) {
if (argc != 10) {
printf("Wrong number of arguments.\n");
printf("arg1: position file\n");
printf("arg2: border size\n");
@ -41,6 +41,7 @@ int main(int argc, char *argv[]) {
printf("arg4: suffix\n");
printf("arg5: number of divisions\n");
printf("arg6-8: b[0-2]\n\n");
printf("arg9: output directory\n");
exit(0);
}
posfile = argv[1];
@ -76,6 +77,7 @@ int main(int argc, char *argv[]) {
printf("That's no b index; try again.\n");
exit(0);
}
outDir = argv[9];
/* Boxsize should be the range in r, yielding a range 0-1 */
np = posread(posfile,&r,1./boxsize);
@ -308,7 +310,7 @@ int main(int argc, char *argv[]) {
/* Now the output!
First number of particles */
sprintf(outfile,"part.%s.%02d.%02d.%02d",suffix,b[0],b[1],b[2]);
sprintf(outfile,"%s/part.%s.%02d.%02d.%02d",outDir,suffix,b[0],b[1],b[2]);
printf("Output to %s\n\n",outfile);
out = fopen(outfile,"w");

View file

@ -11,7 +11,7 @@ int main(int argc, char *argv[]) {
int i, np;
float **rfloat, rtemp[3];
FILE *pos, *scr;
char *posfile, scrfile[80], systemstr[90], *suffix;
char *posfile, scrfile[200], systemstr[90], *suffix, *outDir, *vobozPath;
float xmin,xmax,ymin,ymax,zmin,zmax;
int isitinbuf;
@ -23,14 +23,20 @@ int main(int argc, char *argv[]) {
float border, boxsize;
float c[3];
int b[3];
int numThreads;
int mockIndex;
if (argc != 6) {
if (argc != 10) {
printf("Wrong number of arguments.\n");
printf("arg1: position file\n");
printf("arg2: buffer size (default 0.1)\n");
printf("arg3: box size\n");
printf("arg4: number of divisions (default 2)\n");
printf("arg5: suffix describing this run\n\n");
printf("arg5: suffix describing this run\n");
printf("arg6: number of parallel threads\n");
printf("arg7: location of voboz executables\n");
printf("arg8: output directory\n");
printf("arg9: index of mock galaxies\n\n");
exit(0);
}
posfile = argv[1];
@ -55,6 +61,18 @@ int main(int argc, char *argv[]) {
}
suffix = argv[5];
vobozPath = argv[6];
if (sscanf(vobozPath,"%d",&numThreads) != 1) {
printf("That's no number of threads; try again.\n");
exit(0);
}
vobozPath = argv[7];
outDir = argv[8];
if (sscanf(argv[9],"%d",&mockIndex) != 1) {
printf("That's no mock galaxy index; try again.\n");
exit(0);
}
/* Read the position file */
np = posread(posfile,&rfloat,1./boxsize);
@ -141,15 +159,19 @@ int main(int argc, char *argv[]) {
for (b[0]=0;b[0]<numdiv; b[0]++) {
for (b[1] = 0; b[1] < numdiv; b[1]++) {
for (b[2] = 0; b[2] < numdiv; b[2]++) {
fprintf(scr,"./voz1b1 %s %f %f,%f,%f %s %d %d %d %d &\n",
posfile,border,boxsize,boxsize,boxsize,suffix,numdiv,b[0],b[1],b[2]);
// TEST
fprintf(scr,"%s/voz1b1 %s %f %f,%f,%f %s %d %d %d %d %s&\n",
vobozPath,
posfile,border,boxsize,boxsize,boxsize,suffix,numdiv,b[0],b[1],b[2],
outDir);
// END TEST
p++;
if ((p == NUMCPU)) { fprintf(scr, "wait\n"); p = 0; }
if ((p == numThreads)) { fprintf(scr, "wait\n"); p = 0; }
}
}
}
fprintf(scr,"wait\n");
fprintf(scr,"./voztie %d %s\n",numdiv,suffix);
fprintf(scr,"%s/voztie %d %s %s %d\n", vobozPath, numdiv,suffix, outDir, mockIndex);
fclose(scr);
sprintf(systemstr,"chmod u+x %s",scrfile);

View file

@ -6,7 +6,7 @@
int main(int argc, char *argv[]) {
FILE *part, *adj, *vol;
char partfile[80], *suffix, adjfile[80], volfile[80];
char partfile[200], *suffix, adjfile[200], volfile[200], *outDir;
float *vols, volstemp;
PARTADJ *adjs;
@ -17,10 +17,16 @@ int main(int argc, char *argv[]) {
int nvp,npnotdone,nvpmax, nvpsum, *orig;
double avgnadj, avgvol;
if (argc != 3) {
// PMS
int mockIndex;
// END PMS
if (argc != 5) {
printf("Wrong number of arguments.\n");
printf("arg1: number of divisions (default 2)\n");
printf("arg2: suffix describing this run\n\n");
printf("arg2: suffix describing this run\n");
printf("arg3: file directory\n");
printf("arg4: Beginning index of mock particles\n\n");
exit(0);
}
if (sscanf(argv[1],"%d",&numdiv) != 1) {
@ -32,13 +38,18 @@ int main(int argc, char *argv[]) {
numdiv = 2;
}
suffix = argv[2];
outDir = argv[3];
if (sscanf(argv[4],"%d",&mockIndex) != 1) {
printf("That's no mock galaxy index; try again.\n");
exit(0);
}
np = -1; nvpmax = -1; nvpsum = 0;
for (i = 0; i < numdiv; i++) {
for (j = 0; j < numdiv; j++) {
for (k = 0; k < numdiv; k++) {
sprintf(partfile,"part.%s.%02d.%02d.%02d",suffix,i,j,k);
sprintf(partfile,"%s/part.%s.%02d.%02d.%02d",outDir,suffix,i,j,k);
part = fopen(partfile,"r");
if (part == NULL) {
printf("Unable to open file %s.\n\n",partfile);
@ -46,6 +57,7 @@ int main(int argc, char *argv[]) {
}
fread(&np2,1,sizeof(int),part);
fread(&nvp,1,sizeof(int),part);
nvpsum += nvp;
if (np == -1)
np = np2;
else
@ -58,9 +70,14 @@ int main(int argc, char *argv[]) {
}
}
}
printf("We have %d particles to tie together.\n",np); fflush(stdout);
printf("The maximum number of particles in a file is %d.\n",nvpmax);
// PMS
if (mockIndex == -1) mockIndex = np;
// END PMS
adjs = (PARTADJ *)malloc(np*sizeof(PARTADJ));
if (adjs == NULL) printf("Couldn't allocate adjs.\n");
vols = (float *)malloc(np*sizeof(float));
@ -77,7 +94,7 @@ int main(int argc, char *argv[]) {
for (i = 0; i < numdiv; i++) {
for (j = 0; j < numdiv; j++) {
for (k = 0; k < numdiv; k++) {
sprintf(partfile,"part.%s.%02d.%02d.%02d",suffix,i,j,k);
sprintf(partfile,"%s/part.%s.%02d.%02d.%02d",outDir,suffix,i,j,k);
part = fopen(partfile,"r");
if (part == NULL) {
printf("Unable to open file %s.\n\n",partfile);
@ -93,9 +110,13 @@ int main(int argc, char *argv[]) {
for (p=0;p<nvp;p++) {
fread(&volstemp,1,sizeof(float),part);
if (vols[orig[p]] > -1.)
if (fabs(vols[orig[p]]-volstemp)/volstemp > 1.5e-3) {
// printf("Inconsistent volumes for p. %d: (%10g,%10g)!\n",
// orig[p],vols[orig[p]],volstemp);
// PMS
if (fabs(vols[orig[p]]-volstemp)/volstemp > 1.5e-3 && orig[p] < mockIndex) {
//if (fabs(vols[orig[p]]-volstemp)/volstemp > 1.5e-3) {
// END PMS
printf("Inconsistent volumes for p. %d: (%10g,%10g)!\n",
orig[p],vols[orig[p]],volstemp);
// TEST
//exit(0);
}
vols[orig[p]] = volstemp;
@ -121,8 +142,71 @@ int main(int argc, char *argv[]) {
}
}
printf("\n");
// PMS : remove mock galaxies and anything adjacent to a mock galaxy
printf("\nRemoving mock galaxies...\n");
// completely unlink mock particles
for (i = mockIndex; i < np; i++) {
vols[i] = 1.e-29;
adjs[i].nadj = 0;
}
int numRemoved = 0;
// unlink particles adjacent to mock galaxies
for (i = 0; i < mockIndex; i++) {
for (j = 0; j < adjs[i].nadj; j++) {
if (adjs[i].adj[j] > mockIndex) {
//printf("KILLING %d\n", i);
vols[i] = 1.e-29;
adjs[i].nadj = 0;
numRemoved++;
break;
}
}
}
// update all other adjacencies
for (i = 0; i < mockIndex; i++) {
int numAdjSaved = 0;
for (j = 0; j < adjs[i].nadj; j++) {
//if ( vols[adjs[i].adj[j]] != -99) {
if ( adjs[adjs[i].adj[j]].nadj != 0) {
adjs[i].adj[numAdjSaved] = adjs[i].adj[j];
numAdjSaved++;
}
}
adjs[i].nadj = numAdjSaved;
}
/*
for (i = 0; i < mockIndex; i++) {
printf("ADJ: %d %d : ", i, adjs[i].nadj);
for (j = 0; j < adjs[i].nadj; j++) {
printf(" %d", adjs[i].adj[j]);
}
printf("\n");
}
*/
printf("Removed %d mock galaxies and %d adjacent galaxies.\n", np-mockIndex,
numRemoved);
printf("There are %d galaxies remaining.\n", mockIndex-numRemoved);
// END PMS
npnotdone = 0; avgnadj = 0.; avgvol = 0.;
for (p=0;p<np;p++) {
// PMS
if (vols[p] == 1.e-29) continue;
// END PMS
if (vols[p] == -1.) npnotdone++;
avgnadj += (double)(adjs[p].nadj);
avgvol += (double)(vols[p]);
@ -138,8 +222,8 @@ int main(int argc, char *argv[]) {
/* Now the output! */
sprintf(adjfile,"adj%s.dat",suffix);
sprintf(volfile,"vol%s.dat",suffix);
sprintf(adjfile,"%s/adj%s.dat",outDir,suffix);
sprintf(volfile,"%s/vol%s.dat",outDir,suffix);
printf("Outputting to%s, %s\n\n", adjfile, volfile);
@ -148,15 +232,24 @@ int main(int argc, char *argv[]) {
printf("Unable to open %s\n",adjfile);
exit(0);
}
fwrite(&np,1, sizeof(int),adj);
// PMS
fwrite(&mockIndex,1, sizeof(int),adj);
//fwrite(&np,1, sizeof(int),adj);
// END OMS
/* Adjacencies: first the numbers of adjacencies,
and the number we're actually going to write per particle */
for (i=0;i<np;i++)
// PMS
for (i=0;i<mockIndex;i++)
//for (i=0;i<np;i++)
// END PMS
fwrite(&adjs[i].nadj,1,sizeof(int),adj);
/* Now the lists of adjacencies (without double counting) */
for (i=0;i<np;i++)
if (adjs[i].nadj > 0) {
// PMS
for (i=0;i<mockIndex;i++) {
//for (i=0;i<np;i++) {
//if (adjs[i].nadj > 0) {
// END PMS
nout = 0;
for (j=0;j<adjs[i].nadj; j++) if (adjs[i].adj[j] > i) nout++;
fwrite(&nout,1,sizeof(int),adj);
@ -173,8 +266,12 @@ int main(int argc, char *argv[]) {
printf("Unable to open %s\n",volfile);
exit(0);
}
fwrite(&np,1, sizeof(int),vol);
fwrite(vols,sizeof(float),np,vol);
// PMS
fwrite(&mockIndex,1, sizeof(int),vol);
fwrite(vols,sizeof(float),mockIndex,vol);
//fwrite(&np,1, sizeof(int),vol);
//fwrite(vols,sizeof(float),np,vol);
// END PMS
fclose(vol);

View file

@ -37,6 +37,8 @@ int delaunadj (coordT *points, int nvp, int nvpbuf, int nvpall, PARTADJ **adjs)
PARTADJ adjst;
int errorReported = 0;
adjst.adj = (int *)malloc(MAXVERVER*sizeof(int));
if (adjst.adj == NULL) {
printf("Unable to allocate adjst.adj\n");
@ -100,9 +102,11 @@ int delaunadj (coordT *points, int nvp, int nvpbuf, int nvpall, PARTADJ **adjs)
if (adjst.nadj >= 4) {
qsort((void *)adjst.adj, adjst.nadj, sizeof(int), &compar);
count = 1;
for (i=1; i<adjst.nadj; i++)
if (adjst.adj[i] != adjst.adj[i-1]) {
if (adjst.adj[i] >= nvpbuf) {
if (adjst.adj[i] >= nvpbuf && !errorReported) {
errorReported = 1;
printf("Guard point encountered. Increase border and/or nguard.\n");
printf("P:(%f,%f,%f), G: (%f,%f,%f)\n",points[3*ver],points[3*ver+1],points[3*ver+2],
points[3*adjst.adj[i]],points[3*adjst.adj[i]+1],points[3*adjst.adj[i]+2]);