Package: pyp-beagle
PyP-BEAGLEPyP-BEAGLE (PythonPostprocessing ofBEAGLE) is a Python package to postprocess the analyses performed with the galaxy SED modelling toolBeagle(BayEsianAnalysis ofGaLaxy sEds). PyP-BEAGLE allows one to create different types of publication-quality plots, LaTeX tables, as well as several higher level "summary" catalogues.Installing PyP-BEAGLEMake sure that you have a (science-ready!) installation of Python 3.x (starting from PyP-BEAGLE version 0.7.0), for instanceAnacondaTo install PyP-BEAGLE simply runpip install pyp_beagleKnown issuesOn a Mac OS, multiprocessing only works with theAggbackend. Make sure that your~/.matplotlib/matplotlibrcfile contains the linebackend      : AggIf you encounter errors related to LaTeX, or if the visual appearance of the plots is not satisfying, you can copy the matplotlib configuration filescript/matplotlibrcinto your$HOME/.matplotlib/folder (if the folder does not exist, create it). If you already have a customizedmatplotlibrcfile, then you can use the GNUdiffcommand to update it.PyP-BEAGLE assumes that the Beagle environment variables are correctly set on your machine. Note that while these are the same environment variables used by Docker-Beagle (seehere), they have to point to the actual folders on your machine, not to the "virtual" folder that Docker-Beagle uses. To correctly set the environment variables, you can use thescripts/BEAGLE_env_variable.bashorscripts/BEAGLE_env_variable.cshfiles. In practice, after modifying the file to reflect your Beagle folder tree, you can simply add at the end of your.bashrc(or.tcshrc, or equivalent) the linesource<fullpathtothefile>/BEAGLE_env_variable.bashUsing PyP-BEAGLEThe post-processing of Beagle results is performed by means of the commandpyp_beagle. Since PyP-BEAGLE is often updated, you can visualize the (entire) possible options via the PyP-BEAGLEhelp, with the commandpyp_beagle --helpBelow we report a few of some common PyP-BEAGLE use cases and related commands.triangle plotsmarginal plotssummary cataloguetrue vs retrieved parametersPlotting the posterior probability distributions (aka "triangle plots")Commandpyp_beagle -r <your Beagle results folder>\--plot-triangle\[-np <number of processors>]\[--json-triangle <JSON triangle file>]\[--mock-catalogue <input mock catalogue>]\[--json-mock <JSON mock file>]where<your Beagle results folder>must be replaced by the full path to the Beagle output directory;<number of processors>is an integer indicating how many processors can be used for the parallel execution of the script. This is particularly important when producing plots for large (> 1000) samples, as the creation of each individual plot can take several tens of seconds.<JSON triangle file>is a JSON file used for the configuration of the triangle plot (which parameters should be plotted, log scale, plot limits, ...), an example can be foundhere;<input mock catalogue>indicates a Beagle FITS file containing the input (i.e. "true") physical parameters used to construct the noiseless SEDs which have then been fitted with Beagle (after the noise addition, which must be performedoutsideBeagle). Note that in this case, a<JSON mock file>must be passed, since we must instruct PyP-BEAGLE where (in which FITS extension and column) to find the "true" parameters. An example of the<JSON mock file>to be used in this case can be foundhere.OutputThe successful execution of the script will create a set of*_triangle.pdffiles (one per object) in the<your Beagle results folder>/pyp-beagle/plotfolder.Plotting the comparison of data and model observables (aka "marginal plots")Commandpyp_beagle -r <your Beagle results folder>\--plot-marginal\[-np <number of processors>]\[--log-wavelength]\[--plot-line-labels]\[--spectral-resolution <resolution>]\where<your Beagle results folder>must be replaced by the full path to the Beagle output directory;<number of processors>is an integer indicating how many processors can be used for the parallel execution of the script. This is particularly important when producing plots for large (> 1000) samples, as the creation of each individual plot can take several tens of seconds;<resolution>is a float indicating the resolution of the spectra, and it is used to determine which emission line labels are printed on the plot.OutputThe successful execution of the script will create a set of*_marginal_SED_spec.pdffiles (one per object) in the<your Beagle results folder>/pyp-beagle/plotfolder.Computing a summary catalogueCommandpyp_beagle -r <your Beagle results folder> 
--compute-summary[--json-summary <JSON summary file>]where<your Beagle results folder>must be replaced by the full path to the Beagle output directory;<JSON summary file>is a JSON file used for the configuration of the summary catalogue, specifying for which parameters the summary statistics (posterior mean and median, 68 and 95 % credible regions) should be computed. An example can be foundhere.OutputThe successful execution of the script will create the file<your Beagle results folder>/pyp-beagle/data/BEAGLE_summary_catalogue.fits.DescriptionIn thePOSTERIOR PDFextension we have added some quantities related to the MAP = Maximum-a-Posteriori solution, namely the probability (MAP_probability), log-likelihood (MAP_ln_likelihood), chi-square (MAP_chi_square), and number of data points used in the fitting (MAP_n_data). These quantities enable a quick "frequentist-like" check of the goodness-of-the-fit of the MAP solution.The physical parameters corresponding to the MAP solution are indicated as<parameter_name>_MAP(e.g.mass_MAP).Plotting the comparison of input and retrieved parameters when fitting mock observationsCommandpyp_beagle -r <your Beagle results folder> 
--mock-catalogue <input mock catalogue>\--json-mock <JSON mock file>where<your Beagle results folder>must be replaced by the full path to the Beagle output directory;<input mock catalogue>indicates a Beagle FITS file containing the input (i.e. "true") physical parameters used to construct the noiseless SEDs which have then been fitted with Beagle (after the noise addition, which must be performedoutsideBeagle). Note that in this case, a<JSON mock file>must be passed, since we must instruct PyP-BEAGLE where (in which FITS extension and column) to find the "true" parameters. An example of the<JSON mock file>to be used in this case can be foundhere.OutputThe successful execution of the script will create the files<your Beagle results folder>/pyp-beagle/plot/BEAGLE_mock_retrieved_params_hist.pdfand<your Beagle results folder>/pyp-beagle/plot/BEAGLE_mock_retrieved_params.pdf.