Commit d6d28672 authored by Johann Cohen-Tanuji's avatar Johann Cohen-Tanuji
Browse files

Merge branch '48-improve-output-key-management-and-header-construction' into 'u/jct/dev'

change readOutKeyword method so that it reads a txt file with all licit output...

See merge request Galaxies/LEPHARE!59
parents 66d444c6 db074444
......@@ -67,7 +67,6 @@ SCALE_BEST
NBAND_USED
CONTEXT
ZSPEC
STRING_INPUT
#MAG_MOD()
####### Far-IR PARAMETERS derived from FIR_LIB library ###########
#LUM_TIR_BEST
......@@ -137,4 +136,3 @@ LUM_K_BEST
# Predicted magnitudes in a spare filter set
# ABSMAG_PRED()
MAG_PRED()
IDENT
Z_BEST
Z_BEST68_LOW
Z_BEST68_HIGH
Z_BEST90_LOW
Z_BEST90_HIGH
Z_BEST99_LOW
Z_BEST99_HIGH
Z_ML
Z_ML68_LOW
Z_ML68_HIGH
Z_ML90_LOW
Z_ML90_HIGH
Z_ML99_LOW
Z_ML99_HIGH
MOD_BEST
EXTLAW_BEST
EBV_BEST
MASS_BEST
LDUST_BEST
LUM_TIR_BEST
LUM_NUV_BEST
LUM_R_BEST
LUM_K_BEST
PDZ_BEST
CHI_BEST
SCALE_BEST
AGE_BEST
SFR_BEST
SSFR_BEST
CONTEXT
NBAND_USED
NBAND_ULIM
ZSPEC
MAG_OBS()
ERR_MAG_OBS()
MAG_MOD()
MAG_PRED()
ABSMAG_PRED()
MOD_QSO
MOD_STAR
Z_QSO
Z_ML_QSO
Z_ML68_LOW_QSO
Z_ML68_HIGH_QSO
CHI_QSO
CHI_STAR
MOD_SEC
EXTLAW_SEC
Z_SEC
EBV_SEC
PDZ_SEC
CHI_SEC
SCALE_SEC
AGE_SEC
AGE_MED
AGE_INF
AGE_SUP
LDUST_MED
LDUST_INF
LDUST_SUP
LUM_TIR_MED
LUM_TIR_INF
LUM_TIR_SUP
MASS_MED
MASS_INF
MASS_SUP
EBV_MED
EBV_INF
EBV_SUP
SFR_MED
SFR_INF
SFR_SUP
SSFR_MED
SSFR_INF
SSFR_SUP
COL1_MED
COL1_INF
COL1_SUP
COL2_MED
COL2_INF
COL2_SUP
MREF_MED
MREF_INF
MREF_SUP
LIMITS_ZMAX
LIMITS_MFAINT
EM_FLUX_LYA
EM_FLUX_OII
EM_FLUX_HB
EM_FLUX_OIIIA
EM_FLUX_OIIIB
EM_FLUX_HA
EM_FLUX_SIIIA
EM_FLUX_SIIIB
EM_FLUX()
EM_EW_LYA
EM_EW_OII
EM_EW_HB
EM_EW_OIIIA
EM_EW_OIIIB
EM_EW_HA
EM_EW_SIIIA
EM_EW_SIIIB
MABS_FLUX()
MABS_FILT()
K_COR()
MAG_ABS()
EMAG_ABS()
STRING_INPUT
......@@ -359,9 +359,6 @@ PhotoZ::PhotoZ(keymap& key_analysed)
if(filtNameAdd!="none"){
allFiltersAdd = read_doc_filters(filtNameAdd);
}
/* Read the output parameter file */
outkeywords = readOutKeywords(outpara);
}
keymap read_keymap_from_doc(const string libName) {
......@@ -532,7 +529,7 @@ void PhotoZ::read_lib(vector<SED*> & libFull, int & ind, int nummodpre[3], const
read the keywords of the ouput parameter file
*/
vector<string> readOutKeywords(const string outpara){
//first get the list of all the keys from the master file
string lit;
ifstream stoutpara;
......@@ -548,86 +545,53 @@ vector<string> readOutKeywords(const string outpara){
}
}
stoutpara.close();
if(allkeys.size()==0)
throw runtime_error("alloutputkeys.txt reading resulted in an empty vector!");
// if the output parameter file is not provided,
// default is to output all keywords
if (outpara == nonestring){
return allkeys;
}
vector<string> vecKey;
int nbLines=0;
bool inString=false;
// check that an output parameter file exists
if (outpara.compare(nonestring) != 0){
// open the output parameter file into a stream
stoutpara.open(outpara.c_str());
if(!stoutpara){
cerr << "Can't open output parameter file " << outpara << endl;
exit(1);
}
//Take the stream line by line
while(getline( stoutpara, lit)){
//If the first character of the line is not #
if(test_first_char(lit)) {
//put the line into the stream ss again
stringstream ss(lit);
ss >> fakeString ;
// Check that the string is not a deprecated keyword
//check_deprecated(fakeString) ;
// Check that the string is not "STRING_INPUT"
if (fakeString.compare("STRING_INPUT") != 0){
vecKey.push_back(fakeString);
}else{
inString=true;
}
//Count lines
nbLines++;
// open the output parameter file into a stream
stoutpara.open(outpara.c_str());
if(!stoutpara)
throw invalid_argument("Cannot open output parameter file "+ outpara);
//Take the stream line by line
while(getline( stoutpara, lit)){
if(test_first_char(lit)) {
stringstream ss(lit);
ss >> fakeString ;
// "STRING_INPUT" if present needs to be put at the end of the vector
if (fakeString != "STRING_INPUT"){
vecKey.push_back(fakeString);
}else{
inString=true;
}
}
}
stoutpara.close();
if(nbLines == 0 )cout << "No keyword for the output parameter file " << endl;
if( vecKey.size()==0 )
throw runtime_error("No keyword read from "+outpara);
// Put "STRING_INPUT" at the end
if(inString)vecKey.push_back("STRING_INPUT");
//Close the stream
stoutpara.close();
for(vector<string>::iterator it=allkeys.begin(); it!=allkeys.end(); ){
if(find(vecKey.begin(), vecKey.end(), *it) == vecKey.end()){
//cout<<*it<<" not found"<<endl;
it = allkeys.erase(it);
} else{
++it;
//cout<<*it<<" found"<<endl;
if(inString)
vecKey.push_back("STRING_INPUT");
//check that all user output parameters are licit
for(vector<string>::iterator it=vecKey.begin(); it!=vecKey.end(); it++){
if(find(allkeys.begin(), allkeys.end(), *it) == allkeys.end()){
throw invalid_argument(*it+" is not a licit output parameter. Check licit parameters in source/alloutputkeys.txt.");
}
}
return allkeys;
}
/*
check that the keyword is not deprecated and replace if necessary
*/
void check_deprecated(string& checkString){
// List of the keywords which changed
string oldkey[] = {"Z_ML","Z_ML68_LOW","Z_ML68_HIGH","Z_ML90_LOW","Z_ML90_HIGH","Z_ML99_LOW","Z_ML99_HIGH","AGE_MED","AGE_INF","AGE_SUP","LDUST_MED","LDUST_INF","LDUST_SUP","LUM_TIR_MED","LUM_TIR_INF","LUM_TIR_SUP","MASS_MED","MASS_INF","MASS_SUP","EBV_MED","EBV_INF","EBV_SUP","SFR_MED","SFR_INF","SFR_SUP","SSFR_MED","SSFR_INF","SSFR_SUP","COL1_MED","COL1_INF","COL1_SUP","COL2_MED","COL2_INF","COL2_SUP","MREF_MED","MREF_INF","MREF_SUP","Z_ML_QSO","Z_ML68_LOW_QSO","Z_ML68_HIGH_QSO"};
string newkey[] = {"Z_MOD","Z_MOD68_LOW","Z_MOD68_HIGH","Z_MOD90_LOW","Z_MOD90_HIGH","Z_MOD99_LOW","Z_MOD99_HIGH","AGE_MOD","AGE_LOW","AGE_HIGH","LDUST_MOD","LDUST_LOW","LDUST_HIGH","LUM_TIR_MOD","LUM_TIR_LOW","LUM_TIR_HIGH","MASS_MOD","MASS_LOW","MASS_HIGH","EBV_MOD","EBV_LOW","EBV_HIGH","SFR_MOD","SFR_LOW","SFR_HIGH","SSFR_MOD","SSFR_LOW","SSFR_HIGH","COL1_MOD","COL1_LOW","COL1_HIGH","COL2_MOD","COL2_LOW","COL2_HIGH","MREF_MOD","MREF_LOW","MREF_HIGH","Z_MOD_QSO","Z_MOD68_LOW_QSO","Z_MOD68_HIGH_QSO"};
// List on the keywords which need to be changed
for (int k=0;k<int(sizeof(oldkey)/sizeof(oldkey[0])); k++){
// Test if it is a deprecated keyword
if (checkString.compare(oldkey[k]) == 0){
cout << "Output keyword " << oldkey[k] << " deprecated. Replaced by " << newkey[k] << endl;
// replace
checkString = newkey[k];
break;
}
}
return;
return vecKey;
}
......@@ -662,25 +626,24 @@ string prep_header(vector<string> outkeywords, const int & imagm, const int & im
form += "# Format topcat: \n#";
// Loop over each keyword
for(auto& key : outkeywords){
if(key.find("()") == string::npos ) {
for(auto& key : outkeywords){
if(key.find("()") == string::npos ) {
form += " "+key+" ";
} else {
key = key.substr(0, key.size()-2);//remove ()
for(const auto& key2 : {"MAG_OBS", "MAG_MOD", "K_COR", "MABS_FILT", "MAG_ABS"} ){
if(key.find(key2) != string::npos)
{for (int l=0; l<imagm; l++)form += " "+ key + to_string(l)+" ";}
} else {
key = key.substr(0, key.size()-2);//remove ()
for(const auto& key2 : {"MAG_OBS", "MAG_MOD", "K_COR", "MABS_FILT", "MAG_ABS"} ){
if(key.find(key2) != string::npos)
{for (int l=0; l<imagm; l++)form += " "+ key + to_string(l)+" ";}
}
if(key.find("MAG_PRED()") != string::npos)
{for (int l=0; l<imagmAdd; l++)form += " "+ key + to_string(l)+" ";}
if(key == "EM_FLUX()")
{for (int l=0; l<65; l++)form += " "+ key + to_string(l)+" ";}
}
if(key.find("MAG_PRED()") != string::npos)
{for (int l=0; l<imagmAdd; l++)form += " "+ key + to_string(l)+" ";}
if(key == "EM_FLUX()")
{for (int l=0; l<65; l++)form += " "+ key + to_string(l)+" ";}
}
}
form += '\n';
return form;
}
form += '\n';
return form;
}
/*
......
......@@ -31,6 +31,7 @@ $LEPHAREDIR/bin/mag_gal -c $LEPHAREDIR/examples/COSMOS.para -t G --GAL_LIB_IN L
cat_out=zphot_short.out
$LEPHAREDIR/bin/zphota -c $LEPHAREDIR/examples/COSMOS.para --CAT_IN $LEPHAREDIR/examples/COSMOS.in --CAT_OUT $cat_out --ZPHOTLIB VISTA_COSMOS_FREE,ALLSTAR_COSMOS,QSO_COSMOS --ADD_EMLINES 0,100 --AUTO_ADAPT YES --CAT_LINES 1,100 --SPEC_OUT YES --PARA_OUT $LEPHAREDIR/examples/output.para --VERBOSE NO --ZFIX YES
$LEPHAREDIR/bin/zphota -c $LEPHAREDIR/examples/COSMOS.para --CAT_IN $LEPHAREDIR/examples/COSMOS.in --CAT_OUT $cat_out --ZPHOTLIB VISTA_COSMOS_FREE,ALLSTAR_COSMOS,QSO_COSMOS --ADD_EMLINES 0,100 --AUTO_ADAPT NO --CAT_LINES 1,10 --SPEC_OUT NO --PARA_OUT $LEPHAREDIR/examples/output.para --VERBOSE NO --ZFIX NO
mv $cat_out Id*.spec $LEPHAREWORK/zphota/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment