Manticore  Version 1.5.3
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  const double nuHz_1micron = 1e4*c_light;
22  Dust dust(1.0, 1e10, 0.0);
23  Graybody gray(dust, 1e-4); // Blackbody.
24  PACS pacs70(70, extend), pacs100(100, extend), pacs160(160, extend);
25  pacs70.init();
26  pacs100.init();
27  pacs160.init();
28 
29  fputs("\n**** Effective bandwidth (Hz) ****\n", f);
30  fputs(" 70u 100u 160u\n", f);
31  fprintf(f, "%8.2e %8.2e %8.2e\n",
32  pacs70.freqWidth(), pacs100.freqWidth(), pacs160.freqWidth());
33 
34  fputs("\n**** Blackbody color corrections ****\n", f);
35  fputs("Temp(K) 70u 100u 160u\n", f);
36  for (auto T: {1e4, 1e3, 1e2, 5e1, 1e1, 5e0}) {
37  fprintf(f, "%5gK %7.3f %7.3f %7.3f\n", T,
38  pacs70.ccf(gray, T), pacs100.ccf(gray, T), pacs160.ccf(gray, T));
39  }
40 
41  fputs("\n**** Graybody color corrections ****\n", f);
42  fputs("(beta, T) 70u 100u 160u\n", f);
43  for (double beta=1.0; beta <= 2.0; beta++) {
44  dust.setModel(nuHz_1micron/1.0, 1.0, beta);
45  for (auto T: {1e2, 1e1}) {
46  fprintf(f, "(%g, %3gK) = %.3f %.3f %.3f\n", beta, T,
47  pacs70.ccf(gray, T), pacs100.ccf(gray, T), pacs160.ccf(gray, T));
48  }
49  }
50 
51  double T = 15.0, Sigma = 1.0, sr = 3.62e-9;
52  dust.setModel(nuHz_1micron/157.0, 1.0, 1.5);
53  fprintf(f, "\nExample flux = %.2e erg/cm^2/s, Fnu = %.2f Jy, 1/CCF = %.3f\n",
54  gray.F(T, Sigma, &pacs100, sr),
55  gray.Inu(pacs100.freqBand(), T, Sigma)*sr/1e-23,
56  1.0/pacs100.ccf(gray, T, Sigma));
57 
58  fputs("\n**** Derivative test ****\n", f);
59  fprintf(f, "dF/dT: %.4e calc, %.4e true\n",
60  (gray.F(T+1e-3, Sigma, &pacs100, sr)-
61  gray.F(T-1e-3, Sigma, &pacs100, sr))/2e-3,
62  gray.dF_dT(T, Sigma, &pacs100, sr));
63  fprintf(f, "dF/dS: %.4e calc, %.4e true\n",
64  (gray.F(T, Sigma+1e-3, &pacs100, sr)-
65  gray.F(T, Sigma-1e-3, &pacs100, sr))/2e-3,
66  gray.dF_dS(T, Sigma, &pacs100, sr));
67 }
68 
81 gsl_spline *initSpline(const tableType &table, bool ln, unsigned stride)
82 {
84  for (unsigned i=0; i < table.size(); i += stride) {
85  auto &xy = table[i];
86  x.push_back(xy.first), y.push_back(ln ? log(xy.second) : xy.second);
87  }
88  auto spline = gsl_spline_alloc(gsl_interp_akima, x.size());
89  gsl_spline_init(spline, &x[0], &y[0], x.size());
90  return spline;
91 }
92 
95 {
96  const char *what;
97  std::string when;
98  if (*manticore::reldate) { what = "released", when = manticore::reldate; }
99  else { what = "built", when = std::string(__DATE__) + " " + __TIME__; }
100  fprintf(mu::Log::stream, "Manticore version %s, %s %s.\n\n",
101  manticore::version, what, when.c_str());
102 }
103 
105 int getBand(const CCfits::HDU &hdu)
106 {
107  double band;
108  return (int )hdu.keyWord("BAND").value(band);
109 }
110 
111 } // namespace manticore
112 
113 
114 int main(int argc, char *argv[])
115 try {
116  // Command line interface.
117  mu::CommandLine cli;
119  {'1', "one-param", "", "", "", "",
120  "Fit one parameter dust emission model (default: two-param).\n"
121  "(Fixed-temperature cloud model.)"},
122 
123  {'2', "two-param", "", "", "", "",
124  "Fit two parameter dust emission model (default).\n"
125  "(Single-temperature cloud model.)"},
126 
127  {'3', "three-param", "", "", "", "",
128  "Fit three parameter dust emission model (default: two-param).\n"
129  "(Two-temperature cloud model with prescribed halo temperature.)"},
130 
131  {'4', "four-param", "", "", "", "",
132  "Fit four parameter dust emission model (default: two-param).\n"
133  "(Two-temperature cloud model, all parameters free.)"},
134 
135  {'A', "accuracy", "RELERR", "", "", "",
136  "Maximum relative error for least-squares fit (default: 1e-3)."},
137 
138  {'a', "abs-diff", "", "", "", "",
139  "Output absolute differences in delta maps (default: sigma-relative)."},
140 
141  {'B', "no-band-output", "", "", "", "",
142  "Do not append input band data to output FITS file."},
143 
144  {'C', "cutout", "COLSxROWS@COL0,ROW0", "", "", "",
145  "Process only a COLSxROWS cutout at lower-left corner (COL0,ROW0)."},
146 
147  {'c', "chi2-max", "CHI2", "", "", "",
148  "Maximum chi^2/DOF for meaningful 2-param result (default: 1.0)."},
149 
150  {'D', "dust-model", "(MODEL | MODELhalo,MODELcore)", "", "", "",
151  "Dust opacity model(s) (default: DL3).\n"
152  "Use pow:nu0_GHz:kappa0:beta for power law kappa0*(nu/nu0)^beta."},
153 
154  {'e', "error-map", "FILE", "", "", "",
155  "Input FITS error map (BAND and TELESCOP keys must match parent image)."},
156 
157  {'E', "error-pct", "PCT", "", "", "",
158  "Percent flux error when error map unavailable (default: 3.0)."},
159 
160  {'F', "force", "", "", "", "",
161  "Force overwrite of existing files."},
162 
163  {'G', "grid-samp", "", "", "", "",
164  "Sample data on a fixed grid to estimate parameter variance.\n"
165  "(Total number of samples is 2^numBands.)"},
166 
167  {'g', "gas-to-dust", "(RATIO | RATIOhalo,RATIOcore)", "", "", "",
168  "Gas-to-dust ratio(s) (default: 100.0)."},
169 
170  {'h', "help", "", "", "", "",
171  "Display command line help summary and exit."},
172 
173  {'l', "log-file", "FILE", "", "", "",
174  "Redirect log output to FILE (default is stderr)."},
175 
176  {'M', "model-map", "", "", "", "",
177  "Replace input data with model observation grid."},
178 
179  {'m', "max-iterations", "NMAX", "", "", "",
180  "Maximum least-squares iterations per pixel (default: 50)."},
181 
182  {'N', "nh2-min", "NH2MIN", "", "", "",
183  "Minimum allowed (halo) N(H2) column density in cm^-2."},
184 
185  {'n', "num-bands", "NMIN", "", "", "",
186  "Minimum number of bands required for least-squares fit (default: 3)."},
187 
188  {'o', "output-file", "FILE", "", "", "",
189  "Output result to FITS file FILE (default: mtcore.fits)."},
190 
191  {'P', "pacs-check", "", "", "", "",
192  "Generate comparative PACS color correction tables and exit."},
193 
194  {'p', "point-source", "", "", "", "",
195  "Use point source detector response (default is extended sources)."},
196 
197  {'q', "quiet", "", "", "", "",
198  "Quiet mode; decrement logging level (opposite of -v).\n"
199  "(Specify multiple times for added effect.)"},
200 
201  {'R', "rand-samp", "N", "", "", "",
202  "Randomly sample data N times to estimate parameter variance.\n"
203  "(Without -G, -R or -S, the covariance matrix is used instead.)"},
204 
205  {'S', "sys-samp", "", "", "", "",
206  "Sample systematic data errors to estimate parameter variance.\n"
207  "(May be combined with -G or -R.)"},
208 
209  {'s', "single-temp", "FILE", "", "", "",
210  "FITS output file from the single-temperature (2-param) fit."},
211 
212  {'T', "temp0", "T0", "", "", "",
213  "Initial guess for (halo) temperature in Kelvin (default: 15.0)."},
214 
215  {'t', "threads", "NTHREADS", "", "", "",
216  "Use NTHREADS threads for processing (default: 1)."},
217 
218  {'v', "verbose", "", "", "", "",
219  "Verbose mode; increment logging level (opposite of -q).\n"
220  "(Specify multiple times for added effect.)"},
221 
222  {'V', "version", "", "", "", "",
223  "Display program version and exit."},
224  };
225 
226  // Parse command line options.
227  cli.init(argc, argv, &opts);
228  manticore::dust::printModels(opts, 'D');
229 
230  // --quiet / --verbose
231  int verb = cli.getOption('v') - cli.getOption('q');
232  mu::Log::level += verb;
233  CCfits::FITS::setVerboseMode(verb > 0);
234 
235  // --help
236  if (cli.getOption('h')) {
237  bool quiet = (mu::Log::level <= mu::Log::WARN);
238  if (!quiet) { manticore::printVersion(); }
239  cli.usage(mu::Log::stream, opts, "BAND1.fits BAND2.fits BAND3.fits [...]",
240  quiet);
241  if (quiet) {
242  fputs("\nFor more details, use --verbose --help.\n", mu::Log::stream);
243  }
244  exit(EXIT_SUCCESS);
245  };
246 
247  // --version
248  if (cli.getOption('V')) {
250  exit(EXIT_SUCCESS);
251  }
252 
253  // --log-file
254  mu::Log::setStream(cli.getString('l', "!"));
255 
256  // --check
257  if (cli.getOption('P')) {
259  exit(EXIT_SUCCESS);
260  }
261 
262  manticore::process(cli);
263 
264  return EXIT_SUCCESS;
265 } catch (std::exception &ex) {
266  mu::printException(ex);
267  return EXIT_FAILURE;
268 }
void ccfCheck()
Definition: manticore.cc:17
void process(const mutils::CommandLine &cli)
Processes multi-wavelength maps into temperature/column density maps.
Definition: process.cc:104
static FILE * stream
Message log file stream.
Definition: Log.h:433
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
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:670
virtual double freqWidth() const noexcept
Effective flux-conversion bandwidth (Hz).
Definition: Detector.h:75
Package namespace.
Definition: Detector.cc:15
T push_back(T... args)
void printModels(std::vector< mu::CommandLine::Option > &opts, char name)
Add available dust model names to options summary.
Definition: Dust.cc:654
virtual double ccf(const Graybody &gray, double T, double Sigma=1.0) const
Color correction factor.
Definition: Detector.cc:90
double F(double T, double Sigma, const Detector *detect, double sr=1.0) const
Single-temperature graybody integrated flux (erg/cm^2/s).
Definition: Graybody.h:198
constexpr double c_light
Speed of light (cm/s).
Definition: manticore.h:24
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:94
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
double dF_dT(double T, double Sigma, const Detector *detect, double sr=1.0) const
Single-temperature graybody integrated flux T-derivative (erg/cm^2/s/K).
Definition: Graybody.h:207
constexpr const char *const reldate
Release date (if any).
Definition: version.h:7
Graybody emission model.
Definition: Graybody.h:40
T size(T... args)
int getBand(const CCfits::HDU &hdu)
Returns nominal band center (microns) from an HDU.
Definition: manticore.cc:105
T c_str(T... args)
void init(int argc, char *argv[], const std::vector< Option > *opts)
Initializes new command line input.
Definition: CommandLine.cc:151
gsl_spline * initSpline(const tableType &table, bool ln, unsigned stride)
Initializes cubic spline interpolator.
Definition: manticore.cc:81
double Inu(double nu, double T, double Sigma) const
Single-temperature graybody specific intensity (erg/cm^2/s/Hz/sr).
Definition: Graybody.h:92
double dF_dS(double T, double Sigma, const Detector *detect, double sr=1.0) const
Single-temperature graybody integrated flux Sigma-derivative (erg/s/g).
Definition: Graybody.h:216
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:114
void printException(std::exception &ex)
Prints exception message.
Definition: Exception.h:194
Dust model.
Definition: Dust.h:28