Skip to content

Commit

Permalink
Added OUTPUT_PRECISON
Browse files Browse the repository at this point in the history
  • Loading branch information
cschreib committed Aug 25, 2023
1 parent 6fb551a commit 3fc080a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v1.x.0 (25/08/2023)
======

Features:
- Added option OUTPUT_PRECISION to control the numerical precision in the output catalog


v1.4.0 (11/08/2023)
======

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ To get the closest behavior to that of FAST-IDL, you should set ```C_INTERVAL=68
* ```'la2t'```: (only for gridded SFH) the log10 of the ratio of age to SF timescale
* ... plus any of the rest-frame magnitudes listed in ```REST_MAG``` (see above)
* ... plus any of the custom SFH parameters (see ```CUSTOM_SFH``` below)
* ```OUTPUT_PRECISION```: possible values are any power of ten between zero (included) and one (excluded), which defines the numerical precision to use when printing values in the output catalog. The default is ```0```, and means to use the standard precision, which is 1e-4 for the redshift and metallicity, and 1e-2 for everything else. Otherwise, this value will be used to round the outputs. Note, this only affects the output catalog (.fout); all other outputs (including grid files) are always stored in full precision.
* ```INTRINSIC_BEST_FIT```: possible values are ```0``` or ```1```. The default is ```0```. If set to ```1``` and ```BEST_FIT``` is also set to ```1```, the program will output the intrinsic best-fit SED of a galaxy (i.e., the SED of the galaxy prior to attenuation by dust) alongside the best-fitting template. The intrinsic model will be added as the extra column `fl_nodust` in the `best_fits/*.fit` file.
* ```LSF_BEST_FIT```: possible values are ```0``` or ```1```. The default is ```0```. If set to ```1``` and ```BEST_FIT``` is also set to ```1```, the program will output the LSF-convolved best-fit SED of a galaxy alongside the best-fitting template. This is only useful if an LSF file is provided, see ```SPEC_LSF_FILE```. The LSF-convolved model will be added as the extra column `fl_lsf` in the `best_fits/*.fit` file.
* ```BEST_SFHS```: possible values are ```0``` or ```1```. The default is ```0```. If set to ```1```, the program will output the best fit star formation history (SFH) to a file, in the ```best_fits``` directory (as for the best fit SEDs). If Monte Carlo simulations are enabled, the program will also output confidence intervals on the SFH for each time step, as well as the median SFH among all Monte Carlo simulations. This median may not correspond to any analytical form allowed by your chosen SFH model.
Expand Down
10 changes: 10 additions & 0 deletions example/cosmos-20115/fast.param
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ SPEC_LSF_FILE = ''
# an empty array (default), then all available parameters are written
# in the file (except lldust, llion, and lmform).
#
# o OUTPUT_PRECISION: define the numerical precision to use when printing
# values in the output catalog. The default (0) means to use the
# standard precision, which is 1e-4 for the redshift and metallicity,
# and 1e-2 for everything else. If set to any other power of ten
# between zero and one (excluded), this value will be used to round
# the outputs. Note, this only affects the output catalog (.fout);
# all other outputs (including grid files) are always stored in full
# precision.
#
#-----------------------------------------------------------------------

OUTPUT_DIR = ''
Expand All @@ -306,6 +315,7 @@ REST_MAG = [] # [140,142,161] for UVJ colors
CONTINUUM_INDICES = ''
SFH_QUANTITIES = ['tsf','past_sfr','sfr10','brate10','tquench10','tform50']
OUTPUT_COLUMNS = [] # ['id','Av','lmass','lsfr', ...]
OUTPUT_PRECISION = 0 # 0 / 0.01 / 0.0001 / 1e-6


#--- CHOOSE STELLAR POPULATIONS LIBRARY --------------------------------
Expand Down
10 changes: 10 additions & 0 deletions example/hdfn_fs99/fast.param
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ SPEC_LSF_FILE = ''
# an empty array (default), then all available parameters are written
# in the file (except lldust, llion, and lmform).
#
# o OUTPUT_PRECISION: define the numerical precision to use when printing
# values in the output catalog. The default (0) means to use the
# standard precision, which is 1e-4 for the redshift and metallicity,
# and 1e-2 for everything else. If set to any other power of ten
# between zero and one (excluded), this value will be used to round
# the outputs. Note, this only affects the output catalog (.fout);
# all other outputs (including grid files) are always stored in full
# precision.
#
#-----------------------------------------------------------------------

OUTPUT_DIR = ''
Expand All @@ -306,6 +315,7 @@ REST_MAG = [] # [140,142,161] for UVJ colors
CONTINUUM_INDICES = ''
SFH_QUANTITIES = [] # ['tquench10','tform50','brate10', ...]
OUTPUT_COLUMNS = [] # ['id','Av','lmass','lsfr', ...]
OUTPUT_PRECISION = 0 # 0 / 0.01 / 0.0001 / 1e-6


#--- CHOOSE STELLAR POPULATIONS LIBRARY --------------------------------
Expand Down
12 changes: 12 additions & 0 deletions src/fast++-read_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ bool read_params(options_t& opts, input_state_t& state, const std::string& filen
PARSE_OPTION(continuum_indices)
PARSE_OPTION(sfh_quantities)
PARSE_OPTION(interval_from_chi2)
PARSE_OPTION(output_precision)
PARSE_OPTION(a_v_bc_min)
PARSE_OPTION(a_v_bc_max)
PARSE_OPTION(a_v_bc_step)
Expand Down Expand Up @@ -356,6 +357,17 @@ bool read_params(options_t& opts, input_state_t& state, const std::string& filen
}
}

if (opts.output_precision < 0.0 || opts.output_precision >= 0.5) {
warning("'OUTPUT_PRECISION' must be between zero and one; using default precision (0)");
opts.output_precision = 0.0;
}

double nearest_precision = e10(round(log10(opts.output_precision)));
if (opts.output_precision > 0.0 && abs(log10(opts.output_precision) - log10(nearest_precision)) > 1e-3) {
warning("'OUTPUT_PRECISION' must be an exact power of ten (e.g., 0.1, 0.01); using nearest (", nearest_precision, ")");
opts.output_precision = nearest_precision;
}

if (!opts.best_from_sim && opts.interval_from_chi2 && !opts.save_sim && opts.n_sim != 0) {
warning("with the current setup, Monte Carlo simulations are not used; setting 'N_SIM=0'");
opts.n_sim = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/fast++-write_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ void write_catalog(const options_t& opts, const input_state_t& input, const grid
value = -2.5*log10(value) + 23.9;
}

float precision = output.param_precision.safe[iparam[ic]];
float precision = opts.output_precision > 0 ?
opts.output_precision : output.param_precision.safe[iparam[ic]];

value = round(value/precision)*precision;
if (!is_nan(value) && !is_finite(value)) {
if (value < 0) {
Expand Down
1 change: 1 addition & 0 deletions src/fast++.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ struct options_t {
vec1u rest_mag;
std::string continuum_indices;
bool interval_from_chi2 = false;
float output_precision = 0.0;

// Custom SFH
std::string custom_sfh;
Expand Down

0 comments on commit 3fc080a

Please sign in to comment.