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

@ -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);
@ -106,7 +108,7 @@ int main(int argc, char *argv[]) {
}
g = (bf / 2.)*(1. + sqrt(1 - 2.*s*s/(bf*bf)));
printf("s = %f, bf = %f, g = %f.\n",s,bf,g);
fflush(stdout);
adjs = (PARTADJ *)malloc(np*sizeof(PARTADJ));
@ -305,10 +307,10 @@ int main(int argc, char *argv[]) {
totalvol += (double)vols[i];
}
printf("Average volume = %g\n",totalvol/(float)nvp);
/* 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;
@ -16,11 +16,17 @@ int main(int argc, char *argv[]) {
int i,j,k,p,nout;
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,10 +110,14 @@ 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);
// exit(0);
// 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,25 +222,34 @@ 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);
printf("Outputting to%s, %s\n\n", adjfile, volfile);
adj = fopen(adjfile,"w");
if (adj == NULL) {
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

@ -36,6 +36,8 @@ int delaunadj (coordT *points, int nvp, int nvpbuf, int nvpall, PARTADJ **adjs)
int numdiv;
PARTADJ adjst;
int errorReported = 0;
adjst.adj = (int *)malloc(MAXVERVER*sizeof(int));
if (adjst.adj == NULL) {
@ -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]);