diff --git a/docs/notebooks/README.md b/docs/notebooks/README.md index 58a44606..6d8fd603 100644 --- a/docs/notebooks/README.md +++ b/docs/notebooks/README.md @@ -3,7 +3,10 @@ This repository contains a number of notebooks designed to introduce key aspects of the Python interface to lephare. Here is a biref outline of each notebook and its purpose: -- [Example_full_run.ipynb](Example_full_run.ipynb) This is an example of how to conduct a full photomoetric redshift run over an input catalogue. All intermediate stages are performed. +- [Minimal_photoz_run.ipynb] (Minimal_photoz_run.ipynb) This is a minimal run of photo-z. +- [Typical_use_case.ipynb] (Typical_use_case.ipynb) This is a run showing how to compute the photo-z for a reduced part of the COSMOS2020 catalogue. +- [Typical_use_case_physicalParameters.ipynb] (Typical_use_case_physicalParameters.ipynb) This is a run showing how to compute the physical parameters for a reduced part of the COSMOS2020 catalogue. +- [Example_full_run.ipynb](Example_full_run.ipynb) This is an example of how to conduct a full photometric redshift run over an input catalogue. All intermediate stages are performed. - [Building_list_of_onesources.ipynb](Building_list_of_onesources.ipynb) This notebook creates a list of sources with similar photometric data which can be looped over to compute photometric redshift estimates. - [Example_of_usage_of_magSvc.ipynb](Example_of_usage_of_magSvc.ipynb) This notebook demonstrates the magSvc class which can return magnitudes for a given SED template under given conditions. - [Testing_fit_of_one_object_of_the_catalogue.ipynb](Testing_fit_of_one_object_of_the_catalogue.ipynb) Demonstrating a simple fit and plotting functions. diff --git a/docs/notebooks/Typical_use_case_physicalParameters.ipynb b/docs/notebooks/Typical_use_case_physicalParameters.ipynb new file mode 100644 index 00000000..3801fe9a --- /dev/null +++ b/docs/notebooks/Typical_use_case_physicalParameters.ipynb @@ -0,0 +1,298 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "da7fc884-bc5d-4758-aede-087ac6cd18c3", + "metadata": {}, + "source": [ + "# Typical use case for physical parameters\n", + "\n", + "This example notebook shows a run on the COSMOS2020 (Weaver et al. 2022) data set in order to estimate the physical parameters.\n", + "\n", + "In this notebook we follow what has been done for photo-z. We will be looking at the same COSMOS data set but only use the ugrizy bands. The main difference is the use of BC03 templates to compute physical parameters, and we set the redshift to its spectrosocpic value." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "37a53404-5eca-4634-8a76-24617cd42af7", + "metadata": {}, + "outputs": [], + "source": [ + "import lephare as lp\n", + "from astropy.table import Table\n", + "import numpy as np\n", + "import os\n", + "from matplotlib import pylab as plt\n", + "import time\n", + "\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "id": "25dd1907-2e49-45f2-b56b-3bdd220cb887", + "metadata": {}, + "source": [ + "## Update the config\n", + "We will start with the COSMOS configuration as a basis. We will update the various keywords needed for this example. We use the default which is shipped with lephare. You could also download the example text file config from [here](https://github.com/lephare-photoz/lephare-data/blob/main/examples/COSMOS.para) or write it completely from scratch." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f10ab2c-5d4c-42c6-bfab-340c7316ae5b", + "metadata": {}, + "outputs": [], + "source": [ + "config = lp.default_cosmos_config.copy()\n", + "\n", + "# You could also load this from a local text file:\n", + "# !curl -s -o https://raw.githubusercontent.com/lephare-photoz/lephare-data/refs/heads/main/examples/COSMOS.para\n", + "# config = lp.read_config(\"./COSMOS.para\")\n", + "\n", + "config.update(\n", + " {\n", + " # For a quick demonstration we use a very sparse redshift grid. DO NOT USE FOR SCIENCE!\n", + " # Comment out the following line to improve results.\n", + " \"Z_STEP\": \"0.1,0.,3.\",\n", + " # SED\n", + " # In order to get the physical parameters you need to use\n", + " # Composite Stellar Population synthesis models. Here Bruzual & Charlot (2003).\n", + " # This can be done only for galaxies.\n", + " \"GAL_SED\": \"$LEPHAREDIR/sed/GAL/BC03_CHAB/BC03COMB_MOD.list\",\n", + " # Limit the number of ages\n", + " \"SEL_AGE\": \"$LEPHAREDIR/sed/GAL/BC03_CHAB/AGE_BC03COMB.dat\",\n", + " \"MOD_EXTINC\": \"0,12,0,12\",\n", + " \"EXTINC_LAW\": \"SB_calzetti.dat,SMC_prevot.dat\",\n", + " \"EM_LINES\": \"PHYS\",\n", + " \"EM_DISPERSION\": \"1.\",\n", + " # FILTERS\n", + " # A reduced list of filters:\n", + " \"FILTER_LIST\": \"cosmos/u_new.pb,hsc/gHSC.pb,hsc/rHSC.pb,hsc/iHSC.pb,hsc/zHSC.pb,hsc/yHSC.pb\",\n", + " \"FILTER_CALIB\": \"0\",\n", + " \"FILTER_FILE\": \"filter_test\",\n", + " # FIT\n", + " # We set the redshift to the spec-z value\n", + " \"ZFIX\": \"YES\",\n", + " \"ERR_SCALE\": \"0.02\",\n", + " \"ERR_FACTOR\": \"1.5\",\n", + " \"SPEC_OUT\": \"NO\", # We would like to see the output\n", + " }\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "b1c8ca77-639f-41e3-9b40-2ac27ef26722", + "metadata": {}, + "source": [ + "## Download the missing data\n", + "One does not need to use this functionality if already cloned the full auxiliary data.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5e666b41-e71e-4174-b939-17ca828e3197", + "metadata": {}, + "outputs": [], + "source": [ + "lp.data_retrieval.get_auxiliary_data(\n", + " keymap=config,\n", + " # The additional extinction laws for galaxies are not in the principle config\n", + " # so we must add them to be downloaded:\n", + " additional_files=[\n", + " # We also want the example cosmos catalogue to experiment with\n", + " \"examples/COSMOS.in\",\n", + " \"ext/SMC_prevot.dat\",\n", + " \"ext/SB_calzetti.dat\",\n", + " ],\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "681eb30e-c277-4fde-a1c6-4579a8d0ca1b", + "metadata": {}, + "source": [ + "## Run prepare\n", + "\n", + "These are the key preparatory stages that calculate the filters in the LePHARE format, calculate the library of SEDs and finally calculate the library of magnitudes for all the models. The prepare method runs *filter*, *sedtolib*, and *mag_gal* that would be run independently at the command line. These are all explained in detail in the [documentation](https://lephare.readthedocs.io/en/latest/original.html#detailed-lephare-user-manual)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b20daf8d-8881-4dc5-a338-9f86121ec2be", + "metadata": {}, + "outputs": [], + "source": [ + "lp.prepare(\n", + " config,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "7f91e803-33ce-4ba4-837f-9a6c52625f68", + "metadata": {}, + "source": [ + "### Creating the input table\n", + "\n", + "We need to make an astropy table as input. This can be done using the standard column order:\n", + "id, flux0, err0, flux1, err1,..., context, zspec, arbitrary_string. A simple example table with two filters might look like this:\n", + "| id | flux_filt1 | fluxerr_filt1 | flux_filt2 | fluxerr_filt2 | context | zspec | string_data |\n", + "|---|---|---|---|---|---|---|---|\n", + "| 0 | 1.e-31 | 1.e-32 | 1.e-31 | 2.e-32 | 3 | NaN | \"This is just a note\" |\n", + "| 1 | 2.e-31 | 1.e-32 | 1.e-31 | 2.e-32 |3 | 1. | \"This has a specz\" |\n", + "| 2 | 2.e-31 | 1.e-32 | 2.e-31 | 2.e-32 | 2 | NaN| \"This context only uses the second filter\" |\n", + "\n", + "The context detemermines which bands are used but can be -99 or a numpy.nan. We do not need to have units on the flux columns but LePHARE assumes they are in erg /s /cm**2 / Hz if we are using fluxes. The number of columns must be two times the number of filters plus the four additional columns.\n", + "\n", + "This input table **must use** the standard column ordering to determine column meaning. This odering depends on the filter order in the config FILTER_LIST value. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c43e9307-4dc7-4b26-bb8b-5126f29874f7", + "metadata": {}, + "outputs": [], + "source": [ + "# Load the full cosmos example we downloaded at the start\n", + "cosmos_full = Table.read(f\"{lp.LEPHAREDIR}/examples/COSMOS.in\", format=\"ascii\")\n", + "# Lets just look at the first 1000 specz between 0 and 3 to be fast and have a small sample to test\n", + "specz_colname = cosmos_full.colnames[-2]\n", + "mask = cosmos_full[specz_colname] > 0\n", + "mask &= cosmos_full[specz_colname] < 3\n", + "cosmos_full = cosmos_full[mask][:1000]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "391d66ef-1108-47d7-8ca0-15c1eab04065", + "metadata": {}, + "outputs": [], + "source": [ + "input_table = Table()\n", + "# The id is in the first column\n", + "input_table[\"id\"] = cosmos_full[cosmos_full.colnames[0]]\n", + "# Loop over the filters we want to keep to get the number of the filter, n, and the name, b,\n", + "filter_names = config[\"FILTER_LIST\"].split(\",\")\n", + "for n, filter_name in enumerate(filter_names):\n", + " # The ugrizy fluxes and errors are in cols 3 to 14\n", + " f_col = cosmos_full.colnames[2 * n + 3]\n", + " ferr_col = cosmos_full.colnames[2 * n + 4]\n", + " # By default lephare uses column order so names are irrelevant\n", + " input_table[f\"f_{filter_name}\"] = cosmos_full[f_col]\n", + " input_table[f\"ferr_{filter_name}\"] = cosmos_full[ferr_col]\n", + "# The context is a binary flag. Here we set it to use all filters.\n", + "input_table[\"context\"] = np.sum(2 ** np.arange(len(filter_names)))\n", + "input_table[\"zspec\"] = cosmos_full[specz_colname]\n", + "input_table[\"string_data\"] = \"arbitrary_info\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "13754ace-2852-4073-a36b-62609645759b", + "metadata": {}, + "outputs": [], + "source": [ + "# Look at the first 5 lines of the input table\n", + "input_table[:5]" + ] + }, + { + "cell_type": "markdown", + "id": "d80599b6-529e-4565-be0e-2dc51445c54c", + "metadata": {}, + "source": [ + "## Run process\n", + "\n", + "Finally we run the main fitting process which is equivalent to *zphota* when using the command line. We also need to update some of the config values to make them consistent with the number of filters." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3ca129de-1bc1-479f-b1c7-d0b0a3e041a0", + "metadata": {}, + "outputs": [], + "source": [ + "# Compute physical parameters\n", + "output, _ = lp.process(config, input_table)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "495ca7bf-b03e-4102-8381-5185772cf2f5", + "metadata": {}, + "outputs": [], + "source": [ + "# the output is an astropy tabel that can be manipulated in the standard ways.\n", + "output[:5]" + ] + }, + { + "cell_type": "markdown", + "id": "8f56984e-b3cb-4cde-9ef1-1b13e157dc20", + "metadata": {}, + "source": [ + "Next we can perform some simple plots to check the output" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a2335825-4cba-492f-a277-8349a43f88c4", + "metadata": {}, + "outputs": [], + "source": [ + "logmass = output[\"MASS_MED\"]\n", + "logSFR = output[\"SFR_MED\"]\n", + "z = output[\"Z_BEST\"]\n", + "cond = (z > 0.5) & (z < 1) & (logmass > 0)\n", + "plt.hist(logmass[cond], bins=20)\n", + "plt.xlabel(\"log(stellar mass)\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8f1fb5cd-bbdb-4574-85b6-7f209bc65736", + "metadata": {}, + "outputs": [], + "source": [ + "plt.scatter(logmass[cond], logSFR[cond], s=2.0)\n", + "plt.xlabel(\"log(stellar mass)\")\n", + "plt.ylabel(\"log(SFR)\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/python_usage.rst b/docs/python_usage.rst index b4c7cc05..da65155e 100644 --- a/docs/python_usage.rst +++ b/docs/python_usage.rst @@ -30,6 +30,7 @@ They should all be able to run independently following installation. Minimal full run Typical use case + Typical use case: physical parameters Detailed run Developer example: Building a list of onesources Developer example: Example of usage of magSvc diff --git a/src/lephare/data_retrieval.py b/src/lephare/data_retrieval.py index 37d2fcec..c423d479 100644 --- a/src/lephare/data_retrieval.py +++ b/src/lephare/data_retrieval.py @@ -409,8 +409,15 @@ def config_to_required_files(keymap, base_url=None): sed_keys = ["STAR_SED", "GAL_SED", "QSO_SED"] for key in sed_keys: try: - list_file = base_url + keymap[key].value - required_files += [keymap[key].value] + # If find sed/ in the path, assume the list is present in lephare-data + # and try to retreive the files + list_file = keymap[key].value + # Remove the beginning of the path before sed/ + if list_file.find("sed/") > 0: + list_file = (list_file[list_file.find("sed/") :]).strip() + required_files += [list_file] + # Add the url to retrieve the files + list_file = base_url + list_file file_names = read_list_file(list_file, prefix=f"sed/{key.split('_')[0]}/") required_files += file_names except KeyError: diff --git a/src/lephare/default_cosmos_config.py b/src/lephare/default_cosmos_config.py index 721a0466..bb22ceba 100644 --- a/src/lephare/default_cosmos_config.py +++ b/src/lephare/default_cosmos_config.py @@ -45,7 +45,7 @@ "GAL_LIB": "LIB_CE", "GAL_LIB_IN": "LIB_CE", "GAL_LIB_OUT": "CE_COSMOS", - "GAL_SED": "examples/COSMOS_MOD.list", + "GAL_SED": f"{lp.LEPHAREDIR}/examples/COSMOS_MOD.list", "GLB_CONTEXT": "0", "INP_TYPE": "F", "LIB_ASCII": "NO", @@ -71,7 +71,7 @@ "QSO_LIB": "LIB_QSO", "QSO_LIB_IN": "LIB_QSO", "QSO_LIB_OUT": "QSO_COSMOS", - "QSO_SED": "sed/QSO/SALVATO09/AGN_MOD.list", + "QSO_SED": f"{lp.LEPHAREDIR}/sed/QSO/SALVATO09/AGN_MOD.list", "RF_COLORS": "32,4,4,13", "RM_DISCREPANT_BD": "500", "SPEC_OUT": "NO", @@ -79,7 +79,7 @@ "STAR_LIB": "LIB_STAR", "STAR_LIB_IN": "LIB_STAR", "STAR_LIB_OUT": "STAR_COSMOS", - "STAR_SED": "sed/STAR/STAR_MOD_ALL.list", + "STAR_SED": f"{lp.LEPHAREDIR}/sed/STAR/STAR_MOD_ALL.list", "TRANS_TYPE": "1", "VERBOSE": "NO", "ZFIX": "NO", diff --git a/src/lephare/prepare.py b/src/lephare/prepare.py index a457e67a..fef1e25d 100644 --- a/src/lephare/prepare.py +++ b/src/lephare/prepare.py @@ -72,7 +72,10 @@ def prepare(config, star_config=None, gal_config=None, qso_config=None): mag_output = os.path.join(os.environ["LEPHAREWORK"], "lib_mag", mag_out_name) # Run sedtolib sedlib = lp.Sedtolib(config_keymap=updated_config) - list_loc = os.path.join(lp.LEPHAREDIR, updated_config[f"{object_type}_SED"].value) + list_loc = updated_config[f"{object_type}_SED"].value + # if find sed/ in the path, assume it is in lephare-data and not an absolute path + if list_loc.find("sed/") >= 0: + list_loc = os.path.join(lp.LEPHAREDIR, list_loc) sedtolib_kwargs = {f"{object_type.lower()}_sed": list_loc} print(sedtolib_kwargs) sedlib.run(typ=object_type, **sedtolib_kwargs) diff --git a/src/lephare/zphota.py b/src/lephare/zphota.py index 3315727a..401a4fca 100644 --- a/src/lephare/zphota.py +++ b/src/lephare/zphota.py @@ -1,7 +1,5 @@ import time -import numpy as np - from lephare._lephare import ( # , read_lib, read_doc_filters, readOutKeywords, GalMag, bestFilter, maxkcolor GalMag, PhotoZ, @@ -102,9 +100,6 @@ def run(self, **kwargs): if autoadapt: adapt_srcs = photoz.read_autoadapt_sources() a0, a1 = photoz.run_autoadapt(adapt_srcs) - offsets = ",".join(np.array(a0).astype(str)) - offsets = "# Offsets from auto-adapt: " + offsets + "\n" - photoz.outputHeader += offsets else: a0 = [] a1 = [] diff --git a/src/lib/SED.cpp b/src/lib/SED.cpp index b169f378..d202eed5 100644 --- a/src/lib/SED.cpp +++ b/src/lib/SED.cpp @@ -114,7 +114,8 @@ void SED::read(const string &sedFile) { // open the SED template file into a stream ssed.open(sedFile.c_str()); if (!ssed) { - throw invalid_argument("Can't open SED file " + sedFile); + throw invalid_argument( + "Can't open the file with the list of SED to be used " + sedFile); } // Take the stream line by line @@ -1631,7 +1632,8 @@ void GalSED::writeMag(bool outasc, ofstream &ofsBin, ofstream &ofsDat, if (outasc) { // Write output ofsDat << setw(6) << nummod << " "; - ofsDat << setw(3) << extlawId << " "; + // start the numbering of attenuation curves at 1 in output + ofsDat << setw(3) << extlawId + 1 << " "; ofsDat << setw(3) << ebv << " "; ofsDat << setw(12) << ltir << " "; ofsDat << setw(5) << red << " "; @@ -1892,7 +1894,8 @@ void QSOSED::writeMag(bool outasc, ofstream &ofsBin, ofstream &ofsDat, if (outasc) { // Write output ofsDat << setw(6) << nummod << " "; - ofsDat << setw(3) << extlawId << " "; + // start the numbering of attenuation curves at 1 in output + ofsDat << setw(3) << extlawId + 1 << " "; ofsDat << setw(3) << ebv << " "; ofsDat << setw(5) << red << " "; ofsDat << setw(12) << distMod << " "; diff --git a/src/lib/SED.h b/src/lib/SED.h index 776a258b..3f527de1 100644 --- a/src/lib/SED.h +++ b/src/lib/SED.h @@ -172,16 +172,19 @@ class SED { ofstream sdocOut, sphysOut, sbinOut; sdocOut.open(docFile.c_str()); if (!sdocOut) { - throw invalid_argument("Can't open doc file " + docFile); + throw invalid_argument("Can't open doc file compiling the SED " + + docFile); } sbinOut.open(binFile.c_str(), ios::binary | ios::out); if (!sbinOut) { - throw invalid_argument("Can't open bin file " + binFile); + throw invalid_argument("Can't open binary file compiling the SED " + + binFile); } if (nlib == GAL) { sphysOut.open(physFile.c_str()); if (!sphysOut) { - throw invalid_argument("Can't open phys file " + physFile); + throw invalid_argument( + "Can't open physical para file associated to SED " + physFile); } } writeSED(sbinOut, sphysOut, sdocOut); @@ -194,7 +197,8 @@ class SED { ifstream sbinIn; sbinIn.open(fname.c_str(), ios::binary); if (!sbinIn) { - throw invalid_argument("Can't open file " + fname); + throw invalid_argument("Can't open the binary file compiling the SED " + + fname); } readSEDBin(sbinIn); } diff --git a/src/lib/SEDLib.cpp b/src/lib/SEDLib.cpp index c5eb52da..bbaa3375 100644 --- a/src/lib/SEDLib.cpp +++ b/src/lib/SEDLib.cpp @@ -43,11 +43,11 @@ vector readBC03(string sedFile, int nummod, string type, // conversion from Lum {Lo/A} to flux {erg/cm2/s/A}: fluxconv = 3.197e-07 double convol = Lsol / (4 * pi * 100 * pow(pc, 2)); - // open the filter file into a stream + // open the SED file into a stream ssed.open(sedFile.c_str()); // Check if file is opened if (!ssed) { - throw invalid_argument("Can't open file " + sedFile); + throw invalid_argument("Can't open the BC03 file " + sedFile); } // Number of ages and read the ages diff --git a/src/lib/SEDLib.h b/src/lib/SEDLib.h index b7f821f3..f3be9a97 100644 --- a/src/lib/SEDLib.h +++ b/src/lib/SEDLib.h @@ -108,7 +108,6 @@ template SEDLib::SEDLib(keymap &key_analysed, string config, string t) : SEDLib(config, t) { path = "/sed/" + typ + "/"; - // cout<::open_output_files() { docFile = lepharework + "/lib_bin/" + libOut + ".doc"; sdocOut.open(docFile.c_str()); if (!sdocOut) { - throw invalid_argument("Can't open doc file " + docFile); + throw invalid_argument("Can't open doc file of the SED library in " + + docFile); } binFile = lepharework + "/lib_bin/" + libOut + ".bin"; sbinOut.open(binFile.c_str(), ios::binary | ios::out); if (!sbinOut) { - throw invalid_argument("Can't open bin file " + binFile); + throw invalid_argument("Can't open binary file of the SED library in " + + binFile); } if (typ == "GAL") { physFile = lepharework + "/lib_bin/" + libOut + ".phys"; sphysOut.open(physFile.c_str()); if (!sphysOut) { - throw invalid_argument("Can't open phys file " + physFile); + throw invalid_argument("Can't open phys file of the SED library in " + + physFile); } } } @@ -239,7 +241,8 @@ void SEDLib::read_model_list() { // open the template list file into a stream smod.open(modList.c_str()); if (!smod) { - throw invalid_argument("Can't open mod file " + modList); + throw invalid_argument("Can't open file with the list of SED to be used " + + modList); } // Take the template list line by line @@ -290,7 +293,8 @@ void SEDLib::read_age(string ageFich) { sage.open(ageFile.c_str()); // Check if file has opened properly if (!sage) { - cerr << "Can't open age file " << ageFile << endl; + cerr << "Can't open file with the ages to be selected " << ageFile + << endl; cerr << "No selection by age. " << endl; // throw "Failing opening ",ageFile.c_str(); } diff --git a/src/lib/ext.cpp b/src/lib/ext.cpp index e545878b..d5785eef 100644 --- a/src/lib/ext.cpp +++ b/src/lib/ext.cpp @@ -31,7 +31,8 @@ void ext::read(string extFile) { sext.open(extFile.c_str()); // Check if file is opened if (!sext) { - throw invalid_argument("Can't open file " + extFile); + throw invalid_argument("Can't open file with the attenuation curve in " + + extFile); } // Take the stream line by line diff --git a/src/lib/flt.cpp b/src/lib/flt.cpp index d12ff6b9..9f40ed79 100644 --- a/src/lib/flt.cpp +++ b/src/lib/flt.cpp @@ -34,7 +34,7 @@ void flt::read(const string &fltFile) { // open the filter file into a stream sflt.open(fltFile.c_str()); if (!(sflt)) { - throw invalid_argument("Can't open file " + fltFile); + throw invalid_argument("Can't open filter file " + fltFile); } // Take the stream line by line @@ -452,12 +452,13 @@ void write_output_filter(string &filtfile, string &filtdoc, stfiltfile.open(filtfile.c_str()); // Check if file is opened if (!stfiltfile) { - throw invalid_argument("Can't open file " + filtfile); + throw invalid_argument("Can't open file compiling all filters " + filtfile); } stfiltdoc.open(filtdoc.c_str()); // Check if file is opened if (!stfiltdoc) { - throw invalid_argument("Can't open file " + filtdoc); + throw invalid_argument("Can't open doc file compiling all filters " + + filtdoc); } // documentation on the screen diff --git a/src/lib/mag.cpp b/src/lib/mag.cpp index 16474288..7e5cc24a 100644 --- a/src/lib/mag.cpp +++ b/src/lib/mag.cpp @@ -107,7 +107,8 @@ void Mag::open_files() { ssedIn.open(sedlibFile.c_str(), ios::binary); // Check if file is opened if (!ssedIn) { - throw invalid_argument("Can't open file " + sedlibFile); + throw invalid_argument("Can't open binary file compiling all SEDs " + + sedlibFile); } // Name of the input SED doc file @@ -118,7 +119,8 @@ void Mag::open_files() { sdocOut.open(docFile.c_str()); // Check if file is opened if (!sdocOut) { - throw invalid_argument("Can't open file " + docFile); + throw invalid_argument("Can't open the doc file compiling all SEDs " + + docFile); } // Name of the output binary and doc files, open it in binary @@ -126,7 +128,8 @@ void Mag::open_files() { sbinOut.open(binOutFile.c_str(), ios::binary | ios::out); // Check if file is opened if (!sbinOut) { - throw invalid_argument("Can't open file " + binOutFile); + throw invalid_argument( + "Can't open the binary file with the predicted flux " + binOutFile); } // Open an ascii file to store the predicted magnitudes @@ -136,9 +139,11 @@ void Mag::open_files() { sdatOut.open(datFile.c_str()); // Check if file is opened if (!sdatOut) { - throw invalid_argument("Can't open file " + datFile); + throw invalid_argument( + "Can't open the ascii file with the predicted flux " + datFile); } + sdatOut << "# Filter list: \n"; if (allFlt.size() != 0) { for (const auto f : allFlt) { sdatOut << "#" << f.name << "\n"; @@ -154,7 +159,7 @@ void Mag::open_files() { << endl; break; case object_type::QSO: - sdatOut << "# model ext_law E(B-V) L_T(IR) redshift dist_modulus age " + sdatOut << "# model ext_law E(B-V) redshift dist_modulus " "N_filt magnitude[N_filt] kcorr[N_filt] " << endl; break; @@ -175,7 +180,7 @@ ifstream Mag::open_opa_files() { stream.open(opaListFile.c_str()); // Check if file is opened if (!stream) { - throw invalid_argument("Can't open file " + opaListFile); + throw invalid_argument("Can't open file with opacity " + opaListFile); } return stream; } @@ -249,7 +254,8 @@ void Mag::read_flt(const string &inputfile) { sfiltIn.open(inputfile.c_str()); // Check if file is opened if (!sfiltIn) { - throw invalid_argument("Can't open file " + inputfile); + throw invalid_argument("Can't open file compiling all filters in " + + inputfile); } string dummy; diff --git a/src/lib/onesource.cpp b/src/lib/onesource.cpp index 2d719bf2..9cd3f177 100644 --- a/src/lib/onesource.cpp +++ b/src/lib/onesource.cpp @@ -542,7 +542,9 @@ void onesource::compute_best_fit_physical_quantities(vector &fulllib) { double age = best_gal_sed->age; results["AGE_BEST"] = (age != INVALID_PHYS) ? LOG10D(age) : INVALID_PHYS; results["EBV_BEST"] = best_gal_sed->ebv; - results["EXTLAW_BEST"] = best_gal_sed->extlawId; + // Add +1 to have the first dust attenuation curve starting at 1 in the + // output + results["EXTLAW_BEST"] = best_gal_sed->extlawId + 1; results["LUM_NUV_BEST"] = best_gal_sed->luv + LOG10D(3.e18 * 400 / pow(2300, 2) * tmp2); results["LUM_R_BEST"] = @@ -1363,9 +1365,10 @@ void onesource::write_out(vector &fulllib, vector &fulllibIR, // ABSOLUTE MAGNITUDES stout.setf(ios::fixed); stout.precision(0); // Integer: + // Add +1 to the filter to have the first filter starting at 1 in the output if (outkey == "MABS_FILT()") { for (size_t l = 0; l < absfilt.size(); l++) - stout << setw(4) << absfilt[l] << " "; + stout << setw(4) << absfilt[l] + 1 << " "; } stout.setf(ios::fixed, ios::floatfield); stout.precision(3); // Float: diff --git a/src/lib/photoz_lib.cpp b/src/lib/photoz_lib.cpp index a8a356d3..32df44d0 100644 --- a/src/lib/photoz_lib.cpp +++ b/src/lib/photoz_lib.cpp @@ -319,8 +319,8 @@ PhotoZ::PhotoZ(keymap &key_analysed) { to_string(magabsF[0]) + '\n'; outputHeader += "# MAG_ABS_AGN : " + to_string(magabsB[1]) + ' ' + to_string(magabsF[1]) + '\n'; - outputHeader += "# MAG_REF : " + to_string(babs) + '\n'; - outputHeader += "# NZ_PRIOR : " + to_string(bp[0]) + ' ' + + outputHeader += "# MAG_REF : " + to_string(babs + 1) + '\n'; + outputHeader += "# NZ_PRIOR : " + to_string(bp[0] + 1) + ' ' + to_string(bp[1]) + '\n'; outputHeader += "# Z_INTERP : " + bool2string(zintp) + '\n'; outputHeader += @@ -339,7 +339,7 @@ PhotoZ::PhotoZ(keymap &key_analysed) { outputHeader += '\n'; outputHeader += "# MABS_REF : "; for (int k = 0; k < nbapp; k++) { - outputHeader += to_string(bapp[k]) + ' '; + outputHeader += to_string(bapp[k] + 1) + ' '; }; outputHeader += '\n'; // AUTO-ADAPT @@ -351,7 +351,7 @@ PhotoZ::PhotoZ(keymap &key_analysed) { // Need to substract one because the convention in the .para file start at 1, // but 0 in the code fl_auto--; - outputHeader += "# ADAPT_BAND : " + to_string(fl_auto) + '\n'; + outputHeader += "# ADAPT_BAND : " + to_string(fl_auto + 1) + '\n'; // ADAPT_LIM limit for the selection in auto-adapt auto_thresmin = ((key_analysed["ADAPT_LIM"]).split_double("15", 2))[0]; auto_thresmax = ((key_analysed["ADAPT_LIM"]).split_double("35", 2))[1]; diff --git a/src/lib/sedtolib.cpp b/src/lib/sedtolib.cpp index 0b30fc22..c1b3eec3 100644 --- a/src/lib/sedtolib.cpp +++ b/src/lib/sedtolib.cpp @@ -27,6 +27,7 @@ vector readSED(string sedFile, string sedFormat, int nummod, string type, template void runner(SEDLib &sedlib) { + cout << "Start Runner SED " << endl; // INFO PARAMETERS ON SCREEN AND DOC sedlib.print_info(); // READ THE MODEL LIST diff --git a/tests/data/alloutputkeys.txt b/tests/data/alloutputkeys.txt index c99b7491..39df51c3 100644 --- a/tests/data/alloutputkeys.txt +++ b/tests/data/alloutputkeys.txt @@ -32,7 +32,6 @@ LUM_R_BEST float results["LUM_R_BEST"] LUM_K_BEST float results["LUM_K_BEST"] LUM_TIR_BEST float results["LUM_TIR_BEST"] MOD_BEST int imasmin[0] -#PDZ_BEST CHI_BEST float chimin[0] SCALE_BEST float dmmin[0] CONTEXT long cont @@ -89,9 +88,6 @@ LUM_TIR_SUP float LIRmed[2] MASS_MED float massmed[0] MASS_INF float massmed[1] MASS_SUP float massmed[2] -#EBV_MED float med[0] -#EBV_INF float med[1] -#EBV_SUP float med[2] SFR_MED float SFRmed[0] SFR_INF float SFRmed[1] SFR_SUP float SFRmed[2] @@ -126,7 +122,6 @@ EM_EW_OIIIB float results_emission_lines["EM_FLUX_LYA"] EM_EW_HA float results_emission_lines["EM_FLUX_LYA"] EM_EW_SIIIA float results_emission_lines["EM_FLUX_LYA"] EM_EW_SIIIB float results_emission_lines["EM_FLUX_LYA"] -#MABS_FLUX MABS_FILT() float absfilt K_COR() float kap MAG_ABS() float mabs