Manticore  Version 2.0alpha
Physics of Molecular Clouds
manticore.cc
Go to the documentation of this file.
1 
8 #include "Detector.h"
9 #include "Graybody.h"
10 #include "PACS.h"
11 #include "version.h"
12 
13 namespace mu = mutils;
14 
15 namespace manticore {
16 
17 void ccfCheck()
18 {
19  auto f = mu::Log::stream;
20  bool extend = false;
21  Dust dust(1.0, 1e10, 0.0);
22  Graybody gray(dust); // Blackbody.
23  PACS pacs70(70, extend), pacs100(100, extend), pacs160(160, extend);
24  pacs70.init();
25  pacs100.init();
26  pacs160.init();
27 
28  fputs("\n**** Blackbody color corrections ****\n", f);
29  fputs("Temp(K) 70u 100u 160u\n", f);
30  for (auto T: {1e4, 1e3, 1e2, 5e1, 1e1, 5e0}) {
31  fprintf(f, "%5gK %7.3f %7.3f %7.3f\n", T,
32  pacs70.ccf(gray, T), pacs100.ccf(gray, T), pacs160.ccf(gray, T));
33  }
34 
35  fputs("\n**** Graybody color corrections ****\n", f);
36  fputs("\(beta, T) 70u 100u 160u\n", f);
37  for (double beta=1.0; beta <= 2.0; beta++) {
38  dust.setModel(1.0, 1.0, beta);
39  for (auto T: {1e2, 1e1}) {
40  fprintf(f, "(%g, %3gK) = %.3f %.3f %.3f\n", beta, T,
41  pacs70.ccf(gray, T), pacs100.ccf(gray, T), pacs160.ccf(gray, T));
42  }
43  }
44 
45  double T = 15.0, Sigma = 1.0, sr = 3.62e-9;
46  dust.setModel(157.0, 1.0, 1.5);
47  fprintf(f, "\nExample flux = %.2e erg/cm^2/s, Fnu = %.2f Jy, 1/CCF = %.3f\n",
48  gray.F(T, Sigma, &pacs100, sr),
49  gray.Inu(pacs100.freqBand(), T, Sigma)*sr/1e-23,
50  1.0/pacs100.ccf(gray, T, Sigma));
51 
52  fputs("\n**** Derivative test ****\n", f);
53  fprintf(f, "dF/dT: %.4e calc, %.4e true\n",
54  (gray.F(T+1e-3, Sigma, &pacs100, sr)-
55  gray.F(T-1e-3, Sigma, &pacs100, sr))/2e-3,
56  gray.dF_dT(T, Sigma, &pacs100, sr));
57  fprintf(f, "dF/dS: %.4e calc, %.4e true\n",
58  (gray.F(T, Sigma+1e-3, &pacs100, sr)-
59  gray.F(T, Sigma-1e-3, &pacs100, sr))/2e-3,
60  gray.dF_dS(T, Sigma, &pacs100, sr));
61 }
62 
74 gsl_spline *initSpline(const tableType &table, bool ln)
75 {
76  std::vector<double> x, y;
77  for (auto &xy: table) {
78  x.push_back(xy.first), y.push_back(ln ? log(xy.second) : xy.second);
79  }
80  auto spline = gsl_spline_alloc(gsl_interp_cspline, table.size());
81  gsl_spline_init(spline, &x[0], &y[0], x.size());
82  return spline;
83 }
84 
87 {
88  const char *what;
89  std::string when;
90  if (*manticore::reldate) { what = "released", when = manticore::reldate; }
91  else { what = "built", when = std::string(__DATE__) + " " + __TIME__; }
92  fprintf(mu::Log::stream, "Manticore version %s, %s %s.\n\n",
93  manticore::version, what, when.c_str());
94 }
95 
97 int getBand(const CCfits::HDU &hdu)
98 {
99  double band;
100  return (int )hdu.keyWord("BAND").value(band);
101 }
102 
103 } // namespace manticore
104 
105 
106 int main(int argc, char *argv[])
107 try {
108  // Command line interface.
109  mu::CommandLine cli;
110  std::vector<mu::CommandLine::Option> opts{
111  {'2', "two-param", "", "", "", "",
112  "Fit two parameter dust emission model (default).\n"
113  "(Single-temperature cloud model.)"},
114 
115  {'3', "three-param", "", "", "", "",
116  "Fit three parameter dust emission model (default: two-param).\n"
117  "(Two-temperature cloud model with prescribed halo temperature.)"},
118 
119  {'4', "four-param", "", "", "", "",
120  "Fit four parameter dust emission model (default: two-param).\n"
121  "(Two-temperature cloud model, all parameters free.)"},
122 
123  {'A', "accuracy", "RELERR", "", "", "",
124  "Maximum relative error for least-squares fit (default: 1e-2)."},
125 
126  {'a', "abs-diff", "", "", "", "",
127  "Output absolute differences in delta maps (default: sigma-relative)."},
128 
129  {'B', "no-band-output", "", "", "", "",
130  "Do not append input band data to output FITS file."},
131 
132  {'C', "check", "", "", "", "",
133  "Generate comparative PACS color correction tables and exit."},
134 
135  {'c', "chi2-max", "CHI2", "", "", "",
136  "Maximum chi^2/DOF for meaningful 2-param result (default: 1.0)."},
137 
138  {'D', "dust-model", "NAME", "", "", "",
139  "Dust opacity model (default: OH5)."},
140 
141  {'e', "error-map", "FILE", "", "", "",
142  "Input FITS error map (BAND and TELESCOP keys must match parent image)."},
143 
144  {'E', "error-pct", "PCT", "", "", "",
145  "Percent flux error when error map unavailable (default: 3.0)."},
146 
147  {'F', "force", "", "", "", "",
148  "Force overwrite of existing files."},
149 
150  {'g', "gas-to-dust", "RATIO", "", "", "",
151  "Gas-to-dust ratio (default: 100.0)."},
152 
153  {'h', "help", "", "", "", "",
154  "Display command line help summary and exit."},
155 
156  {'l', "log-file", "FILE", "", "", "",
157  "Redirect log output to FILE (default is stderr)."},
158 
159  {'M', "model-map", "", "", "", "",
160  "Replace input data with model observation grid."},
161 
162  {'m', "max-iterations", "NMAX", "", "", "",
163  "Maximum least-squares iterations per pixel (default: 25)."},
164 
165  {'n', "num-bands", "NMIN", "", "", "",
166  "Minimum number of bands required for least-squares fit (default: 3)."},
167 
168  {'o', "output-file", "FILE", "", "", "",
169  "Output result to FITS file FILE (default: mtcore.fits)."},
170 
171  {'p', "point-source", "", "", "", "",
172  "Use point source detector response (default is extended sources)."},
173 
174  {'q', "quiet", "", "", "", "",
175  "Quiet mode; decrement logging level (opposite of -v).\n"
176  "(Specify multiple times for added effect.)"},
177 
178  {'s', "single-temp", "FILE", "", "", "",
179  "FITS output file from the single-temperature (2-param) fit."},
180 
181  {'T', "temp0", "T0", "", "", "",
182  "Initial guess for (halo) temperature in Kelvin (default: 16.5)."},
183 
184  {'t', "threads", "NTHREADS", "", "", "",
185  "Use NTHREADS threads for processing (default: 1)."},
186 
187  {'v', "verbose", "", "", "", "",
188  "Verbose mode; increment logging level (opposite of -q).\n"
189  "(Specify multiple times for added effect.)"},
190 
191  {'V', "version", "", "", "", "",
192  "Display program version and exit."},
193  };
194 
195  // Parse command line options.
196  cli.init(argc, argv, &opts);
197  manticore::dust::printModels(opts, 'D');
198 
199  // --quiet / --verbose
200  int verb = cli.getOption('v') - cli.getOption('q');
201  mu::Log::level += verb;
202  CCfits::FITS::setVerboseMode(verb > 0);
203 
204  // --help
205  if (cli.getOption('h')) {
206  bool quiet = (mu::Log::level <= mu::Log::WARN);
207  if (!quiet) { manticore::printVersion(); }
208  cli.usage(mu::Log::stream, opts, "BAND1.fits BAND2.fits BAND3.fits [...]",
209  quiet);
210  if (quiet) {
211  fputs("\nFor more details, use --verbose --help.\n", mu::Log::stream);
212  }
213  exit(EXIT_SUCCESS);
214  };
215 
216  // --version
217  if (cli.getOption('V')) {
219  exit(EXIT_SUCCESS);
220  }
221 
222  // --log-file
223  mu::Log::setStream(cli.getString('l', "!"));
224 
225  // --check
226  if (cli.getOption('C')) {
228  exit(EXIT_SUCCESS);
229  }
230 
231  manticore::process(cli);
232 
233  return EXIT_SUCCESS;
234 } catch (std::exception &ex) {
235  mu::printException(ex);
236  return EXIT_FAILURE;
237 }
void ccfCheck()
Definition: manticore.cc:17
void process(const mutils::CommandLine &cli)
Processes multi-wavelength maps into temperature/column density maps.
Definition: process.cc:82
static FILE * stream
Message log file stream.
Definition: Log.h:433
double dF_dT(double T, double Sigma, const Detector *detect=nullptr, double sr=1.0) const
Single-temperature graybody integrated flux T-derivative (erg/cm^2/s/K).
Definition: Graybody.h:185
unsigned getOption(const Option &option, Arguments *values=nullptr, unsigned nMax=-1) const
Retrieves all copies of a command line option.
Definition: CommandLine.cc:197
static constexpr int WARN
Warning condition.
Definition: Log.h:348
gsl_spline * initSpline(const tableType &table, bool ln)
Initializes cubic spline interpolator.
Definition: manticore.cc:74
Command line options and arguments.
Definition: CommandLine.h:47
std::string getString(char shortName, const std::string &defValue) const
Retrieves unique string option.
Definition: CommandLine.cc:392
void setModel(const std::string &model, double rho=100.0)
Set dust properties model (table-based).
Definition: Dust.cc:164
Package namespace.
Definition: Detector.cc:13
void printModels(std::vector< mu::CommandLine::Option > &opts, char name)
Add available dust model names to options summary.
Definition: Dust.cc:148
double dF_dS(double T, double Sigma, const Detector *detect=nullptr, double sr=1.0) const
Single-temperature graybody integrated flux Sigma-derivative (erg/s/g).
Definition: Graybody.h:194
virtual double ccf(const Graybody &gray, double T, double Sigma=1.0) const
Color correction factor.
Definition: Detector.cc:96
static int level
Message logging level for output to stream.
Definition: Log.h:430
static int setStream(const std::string &fname, bool append=true)
Sets the logging stream.
Definition: Log.h:380
void printVersion()
Prints version information to the log.
Definition: manticore.cc:86
constexpr const char *const version
Version string.
Definition: version.h:6
MathUtils package.
Definition: CommandLine.cc:10
PACS detector class.
Definition: PACS.h:17
virtual void init()
Initializes detector characteristics.
Definition: PACS.cc:1067
constexpr const char *const reldate
Release date (if any).
Definition: version.h:7
double F(double T, double Sigma, const Detector *detect=nullptr, double sr=1.0) const
Single-temperature graybody integrated flux (erg/cm^2/s).
Definition: Graybody.h:176
Graybody emission model.
Definition: Graybody.h:38
int getBand(const CCfits::HDU &hdu)
Returns nominal band center (microns) from an HDU.
Definition: manticore.cc:97
std::vector< std::pair< double, double > > tableType
Basic table data.
Definition: manticore.h:20
void init(int argc, char *argv[], const std::vector< Option > *opts)
Initializes new command line input.
Definition: CommandLine.cc:151
double Inu(double nu, double T, double Sigma) const
Simgle-temperature graybody specific intensity (erg/cm^2/s/Hz/sr).
Definition: Graybody.h:78
void usage(FILE *f, const std::vector< Option > &opts, const char *args="", bool quiet=false, bool basename=true) const
Summarizes command line usage (including options).
Definition: CommandLine.cc:411
int main(int argc, char *argv[])
Definition: manticore.cc:106
void printException(std::exception &ex)
Prints exception message.
Definition: Exception.h:194
Dust model.
Definition: Dust.h:28