Skip to content

Commit 4bc05e5

Browse files
committed
Fix saved grids and cache when using >4B models or >4B galaxies
1 parent a1a1052 commit 4bc05e5

File tree

6 files changed

+312
-275
lines changed

6 files changed

+312
-275
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Features:
1010

1111
Bug fixes:
1212
- Fixed crash when saving extra outputs and using an absolute path in CATALOG
13+
- Fixed invalid cache and grid files if using extremely large number of models or galaxies
1314

1415

1516
v1.3.2 (16/07/2022)

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ cmake ../
7676
make install
7777
```
7878

79-
This will create an executable called ```fast++``` in the ```fastpp/bin``` directory, which you can use immediately to replace FAST. If you have not installed FAST, you will have to download some template libraries from [the FAST website](http://w.astro.berkeley.edu/~mariska/FAST_Download.html) before you can start fitting galaxies (note that some libraries can only be obtained by downloading FAST itself, such as ```ised_exp.pr```). The latest FAST template error function and EAzY filter response database are provided with FAST++ in the ```fastpp/share``` directory.
79+
This will create an executable called ```fast++``` in the ```fastpp/bin``` directory, which you can use immediately to replace FAST. If you have not installed FAST, you will have to download some template libraries from [the FAST website](http://w.astro.berkeley.edu/~mariska/FAST_Download.html) before you can start fitting galaxies (note that some libraries can only be obtained by downloading FAST itself, such as ```ised_exp.pr```). _Update 10/08/2023_: The FAST website seem to have been taken down, but the download links to the following template libraries still appear to work:
80+
- [ised_del.lr](http://pepper.astro.berkeley.edu/~mariska/FAST_Libraries/ised_del.lr.tar.gz)
81+
- [ised_del.hr](http://pepper.astro.berkeley.edu/~mariska/FAST_Libraries/ised_del.hr.tar.gz)
82+
- [ised_tru.hr](http://pepper.astro.berkeley.edu/~mariska/FAST_Libraries/ised_tru.hr.tar.gz)
83+
- [ised_exp.hr](http://pepper.astro.berkeley.edu/~mariska/FAST_Libraries/ised_exp.hr.tar.gz)
84+
85+
The latest (as of June 2019) FAST template error function and EAzY filter response database are provided with FAST++ in the ```fastpp/share``` directory for convenience.
8086

8187
If you want to use arbitrary star formation histories beyond what the original FAST supports, you will have to download the single stellar populations libraries from Bruzual & Charlot (2003). To simplify this task for you, a script is provided in the ```fastpp/share/libraries``` folder. This script will download the libraries and rename the files to FAST++ convention for you, all you have to do is run this script and it will take care of the rest. You will need about 400 MB of free disk space.
8288

@@ -221,15 +227,15 @@ While the implementation of FAST++ was designed to resemble FAST-IDL as much as
221227
* The way FAST++ computes uncertainties using the Monte Carlo simulations is different from FAST-IDL, and this can lead to small differences in the resulting confidence intervals. In particular, the Monte Carlo simulations always use the same constraints on the redshift as the best-fit solution (unless ```BEST_AT_ZPHOT``` is set). Second, uncertainties are derived directly from the scatter of the best-fitting values in the Monte Carlo simulations, rather than from their chi2 distribution in the observed grid. This should not be significant, and the accuracy of the uncertainties computed by FAST++ was verified using mock catalogs with known physical parameters.
222228

223229
## Chi2 grid
224-
* FAST-IDL uses the IDL "save" format to write the chi2 grid on the disk. This format is proprietary and can only be opened by IDL itself. Instead, FAST++ uses a custom, open binary format, described below. In addition, a convenience tool called ``fast++-grid2fits`` is provided to convert the grid file into a FITS table.
230+
* FAST-IDL uses the IDL "save" format to write the chi2 grid on the disk when ```SAVE_CHI_GRID=1```. This format is proprietary and can only be opened by IDL itself. Instead, FAST++ uses a custom, open binary format, described below. In addition, a convenience tool called ``fast++-grid2fits`` is provided to convert the grid file into a FITS table.
225231

226232
The binary grid format is the following. The file starts with a header, and then lists the chi2 data for each model of the grid. In addition to the chi2, the model's best-fitting properties are also saved.
227233
```
228234
# Begin header
229235
# ------------
230236
[uint32]: number of bytes in header
231-
[uchar]: 'C' (identifies the file type)
232-
[uint32]: number of galaxies
237+
[uchar]: 'D' (identifies the file type)
238+
[uint64]: number of galaxies
233239
[uint32]: number of properties (mass, sfr, etc)
234240
# For each property:
235241
[char*]: name of the property ("lmass", "lsfr", etc)
@@ -328,7 +334,7 @@ To get the closest behavior to that of FAST-IDL, you should set ```C_INTERVAL=68
328334
# Begin header
329335
# ------------
330336
[uint32]: number of bytes in header
331-
[uchar]: 'B' (identifies the file type)
337+
[uchar]: 'E' (identifies the file type)
332338
[uint32]: number of properties (mass, sfr, etc)
333339
# For each property:
334340
[char*]: name of the property ("lmass", "lsfr", etc)
@@ -343,7 +349,7 @@ To get the closest behavior to that of FAST-IDL, you should set ```C_INTERVAL=68
343349
# Begin data
344350
# ----------
345351
# For each good model
346-
[uint32]: ID of the model in the grid (= modelID, see description of SAVE_CHI_GRID)
352+
[uint64]: ID of the model in the grid (= modelID, see description of SAVE_CHI_GRID)
347353
[float]: chi2 of the model
348354
[float*]: values of the properties of this model
349355
# --------

src/fast++-fitter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ fitter_t::fitter_t(const options_t& opt, const input_state_t& inp, const gridder
154154
try {
155155
// Write header
156156
// Format:
157-
// char: file type ('C' = chi2 grid)
157+
// char: file type ('D' = chi2 grid v2)
158158
// uint32: size of header in bytes (to skip it)
159-
// uint32: number of galaxies
159+
// uint64: number of galaxies
160160
// uint32: number of properties
161161
// for each property:
162162
// char[*]: name
@@ -165,10 +165,10 @@ fitter_t::fitter_t(const options_t& opt, const input_state_t& inp, const gridder
165165
// char[*]: name
166166
// uint32: number of values
167167
// float[*]: grid values
168-
const unsigned char ftype_chi2grid = 'C';
168+
const unsigned char ftype_chi2grid = 'D';
169169
file::write_as<std::uint32_t>(ochi2.out_file, 0);
170170
file::write(ochi2.out_file, ftype_chi2grid);
171-
file::write_as<std::uint32_t>(ochi2.out_file, input.id.size());
171+
file::write_as<std::uint64_t>(ochi2.out_file, input.id.size());
172172

173173
file::write_as<std::uint32_t>(ochi2.out_file, gridder.nprop);
174174
for (uint_t i : range(gridder.nprop)) {
@@ -241,7 +241,7 @@ fitter_t::fitter_t(const options_t& opt, const input_state_t& inp, const gridder
241241
try {
242242
if (is == 0) {
243243
// Format:
244-
// char: file type ('B' = best chi2)
244+
// char: file type ('E' = best chi2 v2)
245245
// uint32: size of header in bytes (to skip it)
246246
// uint32: number of properties
247247
// for each property:
@@ -251,7 +251,7 @@ fitter_t::fitter_t(const options_t& opt, const input_state_t& inp, const gridder
251251
// char[*]: name
252252
// uint32: number of values
253253
// float[*]: grid values
254-
const unsigned char ftype_bestchi2 = 'B';
254+
const unsigned char ftype_bestchi2 = 'E';
255255
file::write_as<std::uint32_t>(out, 0);
256256
file::write(out, ftype_bestchi2);
257257
file::write_as<std::uint32_t>(out, gridder.nprop);
@@ -366,8 +366,8 @@ void fitter_t::write_chi2(uint_t igrid, const vec1f& chi2, const vec2f& props, u
366366
file::write(out, obchi2.header);
367367

368368
while (in) {
369-
uint32_t id;
370-
float chi2;
369+
std::uint64_t id = 0;
370+
float chi2 = 0.0f;
371371
vec1f p(gridder.nprop);
372372

373373
if (file::read(in, id) && file::read(in, chi2) && file::read(in, p)) {
@@ -381,13 +381,13 @@ void fitter_t::write_chi2(uint_t igrid, const vec1f& chi2, const vec2f& props, u
381381
in.close();
382382
file::remove(chi2_filename.safe[is]+".old");
383383

384-
file::write_as<std::uint32_t>(out, igrid);
384+
file::write_as<std::uint64_t>(out, igrid);
385385
file::write(out, chi2.safe[cis]);
386386
file::write(out, vec1f(props.safe(cis,_)));
387387
out.close();
388388
} else {
389389
out.open(chi2_filename.safe[is], std::ios::binary | std::ios::out | std::ios::app);
390-
file::write_as<std::uint32_t>(out, igrid);
390+
file::write_as<std::uint64_t>(out, igrid);
391391
file::write(out, chi2.safe[cis]);
392392
file::write(out, vec1f(props.safe(cis,_)));
393393
out.close();

0 commit comments

Comments
 (0)