Manticore  Version 1.0
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 
96 } // namespace manticore
97 
98 
99 int main(int argc, char *argv[])
100 try {
101  // Command line interface.
102  mu::CommandLine cli;
103  std::vector<mu::CommandLine::Option> opts{
104  {'A', "accuracy", "RELERR", "", "", "",
105  "Maximum relative error for least-squares fit (default: 1e-2)."},
106 
107  {'B', "no-band-output", "", "", "", "",
108  "Do not append input band data to output FITS file."},
109 
110  {'c', "check", "", "", "", "",
111  "Generate comparative PACS color correction tables and exit."},
112 
113  {'d', "dust-model", "NAME", "", "", "",
114  "Dust opacity model (default: OH5)."},
115 
116  {'e', "error-map", "FILE", "", "", "",
117  "Input FITS error map (BAND and TELESCOP keys must match parent image)."},
118 
119  {'E', "error-pct", "PCT", "", "", "",
120  "Percent flux error when error map unavailable (default: 3.0)."},
121 
122  {'F', "force", "", "", "", "",
123  "Force overwrite of existing files."},
124 
125  {'g', "gas-to-dust", "RATIO", "", "", "",
126  "Gas-to-dust ratio (default: 100.0)."},
127 
128  {'h', "help", "", "", "", "",
129  "Display command line help summary and exit."},
130 
131  {'l', "log-file", "FILE", "", "", "",
132  "Redirect log output to FILE (default is stderr)."},
133 
134  {'M', "max-iterations", "NMAX", "", "", "",
135  "Maximum least-squares iterations per pixel (default: 25)."},
136 
137  {'n', "num-bands", "NMIN", "", "", "",
138  "Minimum number of bands required for least-squares fit (default: 3)."},
139 
140  {'o', "output-file", "FILE", "", "", "",
141  "Output result to FITS file FILE (default: mtcore.fits)."},
142 
143  {'p', "point-source", "", "", "", "",
144  "Use point source detector response (default is extended sources)."},
145 
146  {'q', "quiet", "", "", "", "",
147  "Quiet mode; decrement logging level (opposite of -v).\n"
148  "(Specify multiple times for added effect.)"},
149 
150  {'t', "threads", "NTHREADS", "", "", "",
151  "Use NTHREADS threads for processing (default: 1)."},
152 
153  {'v', "verbose", "", "", "", "",
154  "Verbose mode; increment logging level (opposite of -q).\n"
155  "(Specify multiple times for added effect.)"},
156 
157  {'V', "version", "", "", "", "",
158  "Display program version and exit."},
159  };
160 
161  // Parse command line options.
162  cli.init(argc, argv, &opts);
163  manticore::dust::printModels(opts, 'd');
164 
165  // --quiet / --verbose
166  int verb = cli.getOption('v') - cli.getOption('q');
167  mu::Log::level += verb;
168  CCfits::FITS::setVerboseMode(verb > 0);
169 
170  // --help
171  if (cli.getOption('h')) {
172  bool quiet = (mu::Log::level <= mu::Log::WARN);
173  if (!quiet) { manticore::printVersion(); }
174  cli.usage(mu::Log::stream, opts, "BAND1.fits BAND2.fits BAND3.fits [...]",
175  quiet);
176  if (quiet) {
177  fputs("\nFor more details, use --verbose --help.\n", mu::Log::stream);
178  }
179  exit(EXIT_SUCCESS);
180  };
181 
182  // --version
183  if (cli.getOption('V')) {
185  exit(EXIT_SUCCESS);
186  }
187 
188  // --log-file
189  mu::Log::setStream(cli.getString('l', "!"));
190 
191  // --check
192  if (cli.getOption('c')) {
194  exit(EXIT_SUCCESS);
195  }
196 
197  manticore::process(cli);
198 
199  return EXIT_SUCCESS;
200 } catch (std::exception &ex) {
201  mu::printException(ex);
202  return EXIT_FAILURE;
203 }
void ccfCheck()
Definition: manticore.cc:17
void process(const mutils::CommandLine &cli)
Processes multi-wavelength maps into temperature/column density maps.
Definition: process.cc:84
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
Graybody integrated flux T-derivative (erg/cm^2/s/K).
Definition: Graybody.h:106
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
Graybody integrated flux Sigma-derivative (erg/s/g).
Definition: Graybody.h:115
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
Graybody integrated flux (erg/cm^2/s).
Definition: Graybody.h:97
Graybody emission model.
Definition: Graybody.h:33
std::vector< std::pair< double, double > > tableType
Basic table data.
Definition: manticore.h:17
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
Graybody specific intensity (erg/cm^2/s/Hz/sr).
Definition: Graybody.h:73
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:99
void printException(std::exception &ex)
Prints exception message.
Definition: Exception.h:194
Dust model.
Definition: Dust.h:28