34 #include "paramfile.h" 36 #include "lsconstants.h" 38 #include "fitshandle.h" 40 #include "string_utils.h" 43 #include "planck_rng.h" 48 class PolarizationHolder
53 void getQU(
const pointing &p,
double &q,
double &u)
const 56 fix_arr<double,4> wgt;
59 for (tsize i=0;i<4;++i) {q+=Q[pix[i]]*wgt[i];u+=U[pix[i]]*wgt[i]; }
62 vec3 getQUDir(
const vec3 &loc)
const 67 if (abs(loc.x)+abs(loc.y) > 0.0)
68 east = vec3(-loc.y,loc.x,0).Norm();
69 vec3 north = crossprod(loc, east);
70 double angle = 0.5*safe_atan2(u,q);
71 return north*(-cos(angle)) + east*sin(angle);
75 double getQUMagnitude(
const pointing& p)
const 79 return sqrt(q*q + u*u);
84 void get_step(
const PolarizationHolder &ph, vec3 &loc, vec3 &dir,
double theta)
86 loc=(loc+dir*theta).Norm();
87 vec3 tdir=ph.getQUDir(loc);
88 dir = (dotprod(dir,tdir)<0) ? -tdir : tdir;
108 double theta, arr<vec3> &locs)
110 vec3 first_dir=ph.getQUDir(location);
111 vec3 dir = first_dir;
114 locs[locs.size()/2] = loc;
116 for(
int i = 1 + locs.size()/2; i<int(locs.size()); i++)
124 for(
int i = -1 + locs.size()/2; i>=0; i--)
134 for(tsize i=0; i<kernel.size(); i++)
136 double sinx = sin(pi*(i+1) / (kernel.size()+1));
137 kernel[i] = sinx*sinx;
142 void convolve(
const arr<double> &kernel,
const arr<double> &raw, arr<double> &convolution)
144 convolution.alloc(raw.size()-kernel.size()+1);
145 for(tsize i=0; i<convolution.size(); i++)
148 for (tsize j=0; j<kernel.size(); j++)
149 total += kernel[j] * raw[i+j];
150 convolution[i] = total;
157 int kernel_steps,
double step_radian)
159 arr<double> kernel(kernel_steps), convolution, rawtexture;
161 arr<vec3> curve(steps);
166 for(
int i=0; i<texture.
Npix(); i++)
172 rawtexture.alloc(curve.size());
173 for (tsize i2=0; i2<curve.size(); i2++)
175 convolve(kernel, rawtexture, convolution);
176 for (tsize j=0; j<convolution.size(); j++)
178 int k = texture.
vec2pix(curve[j+kernel.size()/2]);
179 texture[k] += convolution[j];
190 int steps,
int kernel_steps,
double step_radian,
double polmin,
double polmax)
192 PolarizationHolder ph;
198 for (
int i=0; i<mag.
Npix(); i++)
202 mag[i] = min(polmax,max(polmin,ph.getQUMagnitude(p)));
206 lic_function(hit, tex, ph, th, steps, kernel_steps, step_radian);
208 for (
int i=0; i<tex.
Npix(); ++i)
210 double tmin,tmax,mmin,mmax;
213 for (
int i=0; i<tex.
Npix(); ++i)
215 mag[i]*=(tex[i]-tmin);
216 tex[i]=1.0-(tex[i]-tmin)/(tmax-tmin);
219 for (
int i=0; i<mag.
Npix(); ++i)
220 mag[i]=1.0-(mag[i]-mmin)/(mmax-mmin);
223 int main(
int argc,
const char** argv)
225 module_startup (
"alice3", argc, argv);
226 paramfile params (getParamsFromCmdline(argc,argv));
234 int nside = params.find<
int>(
"nside");
235 int steps = params.find<
int>(
"steps",100);
236 double step_radian=arcmin2rad*params.find<
double>(
"step_arcmin",10.);
237 int kernel_steps = params.find<
int>(
"kernel_steps",50);
238 double polmin = params.find<
double>(
"polmin",-1e30),
239 polmax = params.find<
double>(
"polmax",1e30);
240 string out = params.find<
string>(
"out");
243 if (params.param_present(
"texture"))
247 planck_rng rng(params.find<
int>(
"rand_seed",42));
248 if (params.param_present(
"ell"))
250 int ell = params.find<
int>(
"ell");
251 if (ell<0) ell=2*nside;
254 cout <<
"Background texture using ell = " << ell << endl;
256 a(ell,0)=fcomplex(rng.rand_gauss(),0.);
257 for (
int m=0; m<=ell; m++)
258 { a(ell,m).real(rng.rand_gauss()); a(ell,m).imag(rng.rand_gauss()); }
263 for (
int i=0; i<th.Npix(); i++)
264 th[i] = rng.rand_uni() - 0.5;
269 tex(nside,
RING,SET_NSIDE),
270 mag(nside,
RING,SET_NSIDE);
273 PolarizationHolder ph;
277 for (
int i=0; i<mag.Npix(); i++)
282 lic_main(Q, U, th, hit, tex, mag, steps, kernel_steps, step_radian, polmin, polmax);
void minmax(T &Min, T &Max) const
vec3 pix2vec(I pix) const
I vec2pix(const vec3 &vec) const
void lic_main(const Healpix_Map< double > &Q, const Healpix_Map< double > &U, const Healpix_Map< double > &th, Healpix_Map< double > &hit, Healpix_Map< double > &tex, Healpix_Map< double > &mag, int steps, int kernel_steps, double step_radian, double polmin, double polmax)
void make_kernel(arr< double > &kernel)
int lic_function(Healpix_Map< double > &hitcount, Healpix_Map< double > &texture, const PolarizationHolder &ph, const Healpix_Map< double > &th, int steps, int kernel_steps, double step_radian)
void runge_kutta_2(const vec3 &location, const PolarizationHolder &ph, double theta, arr< vec3 > &locs)
void read_Healpix_map_from_fits(fitshandle &inp, Healpix_Map< T > &map, int colnum)
T interpolated_value(const pointing &ptg) const
void get_interpol(const pointing &ptg, fix_arr< I, 4 > &pix, fix_arr< double, 4 > &wgt) const
void write_Healpix_map_to_fits(fitshandle &out, const Healpix_Map< T > &map, PDT datatype)
void alm2map(const Alm< xcomplex< T > > &alm, Healpix_Map< T > &map, bool add_map)
void get_step(const PolarizationHolder &ph, vec3 &loc, vec3 &dir, double theta)
pointing pix2ang(I pix) const
void convolve(const arr< double > &kernel, const arr< double > &raw, arr< double > &convolution)
void runge_kutta_step(vec3 &loc, vec3 &dir, const PolarizationHolder &ph, double theta)