Пример #1
0
/* In setup, the options are obtained and passed to execute via the config object.*/
void * setup(c_datablock * options){
  DATABLOCK_STATUS status=0;
  sigma_r_config * config = malloc(sizeof(sigma_r_config));
  status |= c_datablock_get_double(options,OPTION_SECTION,"offset",&(config->offset));
  status |= c_datablock_get_double(options,OPTION_SECTION,"delta",&(config->delta));
  if(status){fprintf(stderr,"Error in setup.\n");exit(status);}
  return config;
}
/* In setup, the options are obtained and passed to execute via the config object.*/
void * setup(c_datablock * options){
  DATABLOCK_STATUS status=0;
  ave_delsig_config*config = malloc(sizeof(ave_delsig_config));
  status |= c_datablock_get_double(options,OPTION_SECTION,"bin_min",&(config->bin_min));
  status |= c_datablock_get_double(options,OPTION_SECTION,"bin_max",&(config->bin_max));
  status |= c_datablock_get_int(options,OPTION_SECTION,"num_bins",&(config->num_bins));
  if(status){fprintf(stderr,"Error in setup.\n");exit(status);}
  return config;
}
Пример #3
0
/* In execute, the options are taken in.
   Next, data is read from the block that was
   generated previously.
   Then, the calculation is kicked off.
   Then, the program writes to the block.*/
int execute(c_datablock * block, void * config_in){
  int i,j,l;//iteration variables
  DATABLOCK_STATUS status=0;
  int extents[]={0,0,0};//Used to read in >1D arrays. Note: the extents are zerod out in order to test array lengths
  int ndims;//Used to read in >1D arrays

  //Obtain the options from config.
  sigma_r_config * config = (sigma_r_config *)config_in;
  double offset = config->offset;
  double delta = config->delta;

  //Acquire the cluster mass and scale radius
  double M;
  double r_scale;
  status |= c_datablock_get_double(block,cosmo,"log10_cluster_mass",&M);
  status |= c_datablock_get_double(block,cosmo,"scale_radius",&r_scale);
  M = pow(10,M);

  //Acquire the radii and redshift to evaluate the correlation function at.
  double *r,*z;
  int numr;
  int numz;
  status |= c_datablock_get_double_array_1d(block,dist,"z",&z,&numz);
  status |= c_datablock_get_double_array_1d(block,setup_name,"radii",&r,&numr);

  //Acquire omega_m, the only cosmological parameter that comes into play here
  double omega_m, H0;
  status |= c_datablock_get_double(block,cosmo,"omega_m",&omega_m);
  status |= c_datablock_get_double(block,cosmo,"hubble",&H0);
  
  //Acquire the correlation function, xi, from the block
  status |= c_datablock_get_array_ndim(block,xi_hm,"xi_hm",&ndims);
  status |= c_datablock_get_double_array_shape(block,xi_hm,"xi_hm",ndims,extents);
  if(status){fprintf(stderr,"Error on reading in xi (2D) dimensions.\n");exit(status);}
  int numxi0 = extents[0],numxi1=extents[1];
  double xi[numxi0][numxi1];
  status |= c_datablock_get_double_array(block,xi_hm,"xi_hm",(double *)xi,ndims,extents);
  if(status){fprintf(stderr,"Error on reading in xi.\n");exit(status);}


  //Declare and allocate the resulting array for the surface density, \bar{Delta Sigma}(<R),
  //and \bar{Delta Sigma}(R)
  int ndimsd=2;
  int extentssd[]={numz,numr};
  double **sigma_r;

  sigma_r = (double **)malloc(numz*sizeof(double*));
  for(i=0;i<numz;i++)
    sigma_r[i] = (double *)malloc(numr*sizeof(double));
  
  //Do the surface density calculation
  //Note: we have to flatten the xi array
  status |= calc_sigma_r(M,r_scale,delta,z,numz,r,numr,(double *)xi,omega_m,H0,sigma_r,offset);

  //We have to flatten the sigma_r array in order to write to the block
  double sigma_r_out[numz][numr];
  for(i=0;i<numz;i++)
    for(j=0;j<numr;j++)
      sigma_r_out[i][j]=sigma_r[i][j];
  
  //Write sigma_r to the block
  char *name = "sigma_r";
  status |= c_datablock_put_double_array(block,name,name,(double *)sigma_r_out,ndimsd,extentssd);
  if(status){fprintf(stderr,"Error on writing out sigma_r to the block.\n");exit(status);}

  //Free the sigma_r array
  for(i=0;i<numz;i++)
    free(sigma_r[i]);
  free(sigma_r);

  return 0;//No likelihood from this module
}
Пример #4
0
int execute(c_datablock * block, void * config_in){
	DATABLOCK_STATUS status=0;
	covariance_config * config = (covariance_config*) config_in;
	int i,j,k;
	int NL;
	FILE *dat;
	char name[200];
	int corrtype=2;
	char sec[30];

	if (corrtype==1) sprintf(sec, "galaxy_shape_cl");
	if (corrtype==2) sprintf(sec, "galaxy_position_cl");

	// set covariance parameters

	double area, neff, sigma_e; //Survey area in deg^2, effective source density, shape dispersion
	int NZ;

	status |= c_datablock_get_int(block, config->survey, "nzbin", &NZ);
	status |= c_datablock_get_double(block, config->survey, "area", &area);
	status |= c_datablock_get_double(block, config->survey, "ngal", &neff);
	status |= c_datablock_get_double(block, config->survey, "shape_dispersion", &sigma_e);
	double ngal[NZ];
	double sig[NZ];

	for (int i ; i<NZ ; ++i){
		ngal[i] = neff/ ((double)NZ);
		sig[i] = sigma_e;
	}

	// allocate arrays
	double *ell;
	status |= c_datablock_get_double_array_1d(block, sec, "l_bins", &ell, &NL);
	double ***ps=bj_alloc_3D(4,NZ*NZ,NL);
	const int ND=NZ*(2*NZ+1);
	double ***cov=bj_alloc_3D(ND,ND,NL);	// [NZ*NZ][NZ*NZ][NL] suffices for individual WL or clustering covariances

	// Load power spectra from the datablock
	char bin[8];
	char section[30];
	double *cl;
	int tmp, sp;
	int lim = 0;
	
	for (j=0;j<NZ;j++) {
		if (corrtype == 1 || corrtype == 2) lim = j;
		if (corrtype == 1){ 
			sp = 0;
			sprintf(section, "galaxy_shape_cl");
		}
		if (corrtype == 2){ 
			sp = 3;
			sprintf(section, "galaxy_position_cl");
		}
		for (k=lim;k<NZ;k++) {
			status|=c_datablock_get_double_array_1d(block, section, bin, &cl, &tmp);
			for (i=0;i<NL;i++) {
				ps[sp][k+j*NZ][i] = cl[i];
				ps[sp][j+k*NZ][i]=ps[sp][k+j*NZ][i];	// symmetrise
			}
		}
	}

	// calculate covariance
	status=pscov(ell,ps,cov,area,ngal,sig,NZ,NL,2);

	printf("%i\n",status);

	// clean up
	bj_free_3D(ps,4,NZ*NZ,NL);
	bj_free_3D(cov,ND,ND,NL);
	free(ell);
	return 0;
}