33 #include "paramfile.h" 34 #include "fitshandle.h" 43 using clock = std::chrono::steady_clock;
44 clock::time_point starttime;
48 : starttime(clock::now()) {}
49 double operator()()
const 51 return std::chrono::duration<double>(clock::now() - starttime).count();
55 void write_fullfile(
const string &name,
int nside,
int nlmax,
double epsilon,
56 const vector<double> &wgt)
60 vector<fitscolumn> cols;
62 cols.push_back (fitscolumn (
"COMPRESSED PIXEL WEIGHTS",
"1",repcount,
64 out.insert_bintab(cols);
65 out.set_key (
"CREATOR",
string(
"compute_weights"),
66 "Software creating the FITS file");
67 out.set_key (
"NSIDE",nside,
"Resolution parameter for HEALPix");
68 out.set_key (
"MAX_LPOL",nlmax,
"Maximum l multipole");
69 double val=*max_element(wgt.begin(),wgt.end());
70 out.set_key(
"MAXVAL1",val,
"maximum value of pixel weights");
71 val=*min_element(wgt.begin(),wgt.end());
72 out.set_key(
"MINVAL1",val,
"minimum value of pixel weights");
73 out.set_key(
"EPSILON",epsilon,
"epsilon reached after minimization");
74 out.write_column(1,wgt);
77 int compute_weights_module (
int argc,
const char **argv)
79 module_startup (
"compute_weights", argc, argv);
80 paramfile params (getParamsFromCmdline(argc,argv));
82 planck_assert (params.param_present(
"outfile_ring")
83 || params.param_present(
"outfile_full"),
"no job requested");
84 int nside = params.find<
int>(
"nside");
85 int nlmax = params.find<
int>(
"nlmax");
88 cout <<
"Warning: specified nlmax is odd. Reducing by 1" << endl;
91 double epsilon = params.find<
double>(
"epsilon",1e-7);
92 int itmax = params.find<
int>(
"max_iter",10000);
94 if (params.param_present(
"outfile_ring"))
97 vector<double> wgt=
get_ringweights(nside,nlmax,epsilon,itmax,epsilon_out);
99 out.create (params.find<
string>(
"outfile_ring"));
100 vector<fitscolumn> cols;
102 cols.push_back (fitscolumn (
"TEMPERATURE WEIGHTS",
"1",repcount,
104 cols.push_back (fitscolumn (
"Q-POLARISATION WEIGHTS",
"1",repcount,
106 cols.push_back (fitscolumn (
"U-POLARISATION WEIGHTS",
"1",repcount,
108 out.insert_bintab(cols);
109 out.set_key (
"CREATOR",
string(
"compute_weights"),
110 "Software creating the FITS file");
111 out.set_key (
"NSIDE",nside,
"Resolution parameter for HEALPIX");
112 out.set_key (
"MAX_LPOL",nlmax,
"Maximum multipole l used in map synthesis");
113 double val=*max_element(wgt.begin(),wgt.end());
114 out.set_key(
"MAXVAL1",val,
"maximum value of T weights");
115 out.set_key(
"MAXVAL2",val,
"maximum value of Q weights");
116 out.set_key(
"MAXVAL3",val,
"maximum value of U weights");
117 val=*min_element(wgt.begin(),wgt.end());
118 out.set_key(
"MINVAL1",val,
"minimum value of T weights");
119 out.set_key(
"MINVAL2",val,
"minimum value of Q weights");
120 out.set_key(
"MINVAL3",val,
"minimum value of U weights");
121 out.set_key(
"EPSILON",epsilon_out,
"epsilon reached after minimization");
122 out.write_column(1,wgt);
123 out.write_column(2,wgt);
124 out.write_column(3,wgt);
126 if (params.param_present(
"outfile_full"))
128 FullWeightComputer comp(nside,nlmax);
129 auto name = params.find<
string>(
"outfile_full");
130 double lasteps=2, dumpeps=2;
134 while((comp.current_iter()<itmax) && (comp.current_epsilon()>epsilon))
137 double eps=comp.current_epsilon();
140 best = comp.current_alm();
143 if ((t()-t_old>120) && (dumpeps>lasteps))
145 cout <<
"\nwriting output file. eps=" << lasteps << endl;
146 write_fullfile(name, nside, nlmax, lasteps, comp.alm2wgt(best));
153 cout <<
"\nwriting output file. eps=" << lasteps << endl;
154 write_fullfile(name, nside, nlmax, lasteps, comp.alm2wgt(best));
vector< double > get_ringweights(int nside, int lmax, double epsilon, int itmax, double &epsilon_out)