Skip to content

Commit

Permalink
Output LSF-convolved best fit model
Browse files Browse the repository at this point in the history
  • Loading branch information
cschreib committed Aug 5, 2023
1 parent fc7e38e commit 9b7eb2a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
19 changes: 19 additions & 0 deletions src/fast++-gridder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,25 @@ bool gridder_t::build_template_nodust(uint_t igrid, vec1f& lam, vec1f& flux, vec
return build_template_impl(igrid, true, lam, flux, iflux);
}

vec1f gridder_t::apply_lsf(const vec1f& lam, const vec1f& flux) const {
if (opts.spec_lsf_file.empty()) {
return flux;
}

return flatten(convolve_function(lam,
reform(flux, 1, flux.size()), 1,
[&](double l) {
if (l < input.tpllsf_lam.front()) {
return input.tpllsf_sigma.front();
} else if (l > input.tpllsf_lam.back()) {
return input.tpllsf_sigma.back();
} else {
return interpolate(input.tpllsf_sigma, input.tpllsf_lam, l);
}
}
));
}

bool gridder_t::get_sfh(uint_t igrid, const vec1d& t, vec1d& sfh) const {
switch (opts.sfh) {
case sfh_type::gridded:
Expand Down
20 changes: 15 additions & 5 deletions src/fast++-write_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void write_best_fits(const options_t& opts, const input_state_t& input, const gr
return;
}

vec1f lam, sed, sed_nodust, flx;
vec1f lam, sed, sed_nodust, sed_lsf, flx;
auto pg = progress_start(input.id.size());
for (uint_t is : range(input.id)) {
float scale = finf;
Expand Down Expand Up @@ -289,19 +289,29 @@ void write_best_fits(const options_t& opts, const input_state_t& input, const gr
sed *= scale;
flx *= scale;

if (!opts.spec_lsf_file.empty()) {
sed_lsf = gridder.apply_lsf(lam, sed);
}

// Save model
std::ofstream fout(odir+file::get_basename(opts.catalog)+"_"+input.id[is]+".fit");
fout << "# wl fl";
if (opts.intrinsic_best_fit) {
fout << "# wl fl fl_nodust (x 10^-19 ergs s^-1 cm^-2 Angstrom^-1)\n";
} else {
fout << "# wl fl (x 10^-19 ergs s^-1 cm^-2 Angstrom^-1)\n";
fout << " fl_nodust";
}
if (!opts.spec_lsf_file.empty()) {
fout << " fl_lsf";
}
fout << " (x 10^-19 ergs s^-1 cm^-2 Angstrom^-1)\n";

for (uint_t il : range(lam)) {
fout << std::setw(13) << lam.safe[il] << std::setw(13) << sed.safe[il];

if (opts.intrinsic_best_fit) {
fout << std::setw(13) << sed_nodust.safe[il];
fout << std::setw(13) << sed_nodust.safe[il];
}
if (!opts.spec_lsf_file.empty()) {
fout << std::setw(13) << sed_lsf.safe[il];
}

fout << "\n";
Expand Down
1 change: 1 addition & 0 deletions src/fast++.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ struct gridder_t {
bool build_and_send(fitter_t& fitter);
bool build_template(uint_t igrid, vec1f& lam, vec1f& flux, vec1f& iflux) const;
bool build_template_nodust(uint_t igrid, vec1f& lam, vec1f& flux, vec1f& iflux) const;
vec1f apply_lsf(const vec1f& lam, const vec1f& flux) const;
bool get_sfh(uint_t iflat, const vec1d& t, vec1d& sfh) const;
bool write_seds() const;

Expand Down

0 comments on commit 9b7eb2a

Please sign in to comment.