Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the function validLib to improve the code efficiency. #255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib/onesource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,17 @@ void onesource::adapt_mag(vector<double> a0, vector<double> a1) {
/*
RETURN THE INDEX OF THE LIBRARY TO BE CONSIDERED (MAINLY ZFIX CASE)
*/
vector<size_t> onesource::validLib(vector<SED *> &thelib, const bool &zfix,
vector<size_t> onesource::validLib(const vector<double> &zLib, const bool &zfix,
const double &consideredZ) {
vector<size_t> val;
// Condition with the redshift set ZFIX YES
if (zfix) {
for (size_t i = 0; i < thelib.size(); i++) {
if ((thelib[i])->red == closest_red) val.push_back(i);
for (size_t i = 0; i < zLib.size(); i++) {
if (zLib[i] == closest_red) val.push_back(i);
}
} else {
// If not fixed redshift, use everything
for (size_t i = 0; i < thelib.size(); i++) val.push_back(i);
for (size_t i = 0; i < zLib.size(); i++) val.push_back(i);
}

return val;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/onesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class onesource {
void convertFlux(const string &catmag, const vector<flt> allFilters);
void rescale_flux_errors(const vector<double> min_err,
const vector<double> fac_err);
vector<size_t> validLib(vector<SED *> &fulllib, const bool &zfix,
vector<size_t> validLib(const vector<double> &zLib, const bool &zfix,
const double &consideredZ);
void fit(vector<SED *> &fulllib, const vector<vector<double>> &flux,
const vector<size_t> &valid, const double &funz0,
Expand Down
7 changes: 5 additions & 2 deletions src/lib/photoz_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@
/* Create a 2D array with the predicted flux.
Done to improve the performance in the fit*/
flux.resize(fullLib.size(), vector<double>(imagm, 0.));
zLib.resize(fullLib.size(), -99.);
fluxIR.resize(fullLibIR.size(), vector<double>(imagm, 0.));
// Convert the magnitude library in flux
#ifdef _OPENMP
Expand All @@ -429,6 +430,8 @@
for (size_t k = 0; k < allFilters.size(); k++) {
flux[i][k] = pow(10., -0.4 * (fullLib[i]->mag[k] + 48.6));
}
// create a vector with the redshift of the library
zLib[i] = fullLib[i]->red;
}
#ifdef _OPENMP
#pragma omp parallel for schedule(static)
Expand Down Expand Up @@ -1020,7 +1023,7 @@
oneObj->closest_red = gridz[indexz(oneObj->zs, gridz)];
// Select the valid index of the library in case of ZFIX=YES to save
// computational time
valid = oneObj->validLib(fullLib, zfix, oneObj->zs);
valid = oneObj->validLib(zLib, zfix, oneObj->zs);

Check warning on line 1026 in src/lib/photoz_lib.cpp

View check run for this annotation

Codecov / codecov/patch

src/lib/photoz_lib.cpp#L1026

Added line #L1026 was not covered by tests
// Fit the source at the spec-z value
oneObj->fit(fullLib, flux, valid, funz0, bp);
// Interpolation of the predicted magnitudes, scaling at zs, checking
Expand Down Expand Up @@ -1598,7 +1601,7 @@
oneObj->setPriors(magabsB, magabsF);
// Select the valid index of the library in case of ZFIX=YES to save
// computational time
valid = oneObj->validLib(fullLib, zfix, oneObj->zs);
valid = oneObj->validLib(zLib, zfix, oneObj->zs);
// Core of the program: compute the chi2
oneObj->fit(fullLib, flux, valid, funz0, bp);
// Try to remove some bands to improve the chi2, only as long as the chi2 is
Expand Down
1 change: 1 addition & 0 deletions src/lib/photoz_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PhotoZ {
vector<int> bapp, bappOp, pdz_fabs, emMod;
cosmo lcdm;
vector<size_t> valid;
vector<double> zLib;

public:
vector<vector<double>> flux, fluxIR;
Expand Down
Loading