Commit bb2fd787 authored by Médéric Boquien's avatar Médéric Boquien

The optionally saved spectra in the pdf_analysis and savefluxes modules were...

The optionally saved spectra in the pdf_analysis and savefluxes modules were saved in the VO-table format. The most important downside is that it is very slow to write to, which proves to be a major bottleneck in the computing speed. To overcome this issue, we rather save the spectra using the FITS formation. Instead of having one file containing the spectra (including the various components) and the SFH in a single file, now we have one file for the spectra and one file for the SFH.
parent aef1188f
......@@ -17,6 +17,7 @@
- The sfhdelayed module is now initialised with _init_code() to be consistent with the way things are done in other modules. This should give a slight speedup under some sircumstances too. (Médéric Boquien)
- In sfhfromfile, the specification of the time grid was vague and therefore could lead to incorrect results if it was not properly formatted by the end user. The description has been clarified and we now check that the time starts from 0 and that the time step is always 1 Myr. If it is not the case we raise an exception. (Médéric Boquien)
- When the redshift is not indicated in pcigale.ini, the analysis module fills the list of redshifts from the redshifts indicated in the input flux file. This is inefficient as analysis modules should have have to modify the configuration. Now this is done when interpreting pcigale.ini before calling the relevant analysis module. As a side effect, "pigale check" now returns the total number of models that cigale will compute rather than the number of models per redshift bin. (Médéric Boquien)
- The optionally saved spectra in the pdf_analysis and savefluxes modules were saved in the VO-table format. The most important downside is that it is very slow to write to, which proves to be a major bottleneck in the computing speed. To overcome this issue, we rather save the spectra using the FITS formation. Instead of having one file containing the spectra (including the various components) and the SFH in a single file, now we have one file for the spectra and one file for the SFH.
### Fixed
- To estimate parameters in log, pcigale determines which variables end with the "_log" string and removed it to compute the models. However in some circumstances, it was overzealous. This has been fixed. (Médéric Boquien)
......
......@@ -29,7 +29,7 @@ def save_best_sed(obsid, sed, norm):
Normalisation factor to scale the scale to the observations
"""
sed.to_votable(OUT_DIR + "{}_best_model.xml".format(obsid), mass=norm)
sed.to_fits(OUT_DIR + "{}".format(obsid), mass=norm)
def _save_pdf(obsid, name, model_variable, likelihood):
......
......@@ -99,7 +99,6 @@ class SaveFluxes(AnalysisModule):
info = conf['analysis_params']['variables']
n_info = len(info)
model_fluxes = (RawArray(ctypes.c_double, n_params * n_filters),
(n_params, n_filters))
model_parameters = (RawArray(ctypes.c_double, n_params * n_info),
......
......@@ -93,7 +93,7 @@ def fluxes(idx):
gbl_variables])
if gbl_save_sed is True:
sed.to_votable(OUT_DIR + "{}_best_model.xml".format(idx))
sed.to_fits(OUT_DIR + "{}".format(idx))
with gbl_n_computed.get_lock():
gbl_n_computed.value += 1
n_computed = gbl_n_computed.value
......
......@@ -35,6 +35,7 @@ from scipy.constants import c, parsec
from . import utils
from .io.vo import save_sed_to_vo
from .io.fits import save_sed_to_fits
from ..data import Database
......@@ -339,6 +340,21 @@ class SED(object):
"""
save_sed_to_vo(self, filename, mass)
def to_fits(self, prefix, mass=1.):
"""
Save the SED to FITS files.
Parameters
----------
prefix: string
Prefix of the fits file containing the path and the id of the model
mass: float
Galaxy mass in solar masses. When needed, the data will be scaled
to this mass
"""
save_sed_to_fits(self, prefix, mass)
def copy(self):
"""
Create a new copy of the object. This is done manually rather than
......
# -*- coding: utf-8 -*-
# Copyright (C) 2016, Universidad de Antofagasta
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Médéric Boquien
from collections import OrderedDict
from astropy.table import Table, Column
def save_sed_to_fits(sed, prefix, norm=1.):
"""
Save a SED object to fits files
Parameters
----------
sed: a pcigale.sed.SED object
The SED to save
prefix: string
Prefix of the fits file containing the path and the id of the model
norm: float
Normalisation factor of the SED
"""
info = OrderedDict()
for name in sed.mass_proportional_info:
Please register or sign in to reply
info[name] = str(norm * sed.info[name])
else:
info[name] = str(sed.info[name])
table = Table(meta=info)
table['wavelength'] = Column(sed.wavelength_grid, unit="nm")
table['Fnu'] = Column(norm * sed.fnu, unit="mJy")
table['L_lambda_total'] = Column(norm * sed.luminosity, unit="W/nm")
for name in sed.contribution_names:
table[name] = Column(norm * sed.get_lumin_contribution(name),
unit="W/nm")
table.write("{}_best_model.fits".format(prefix))
table = Table(meta=info)
table["time"] = Column(sed.sfh[0], unit="Myr")
table["SFR"] = Column(norm * sed.sfh[1], unit="Msun/yr")
table.write("{}_SFH.fits".format(prefix))
......@@ -115,10 +115,9 @@ def _sed_worker(obs, mod, filters, sed_type, nologo):
"""
if os.path.isfile(OUT_DIR + "{}_best_model.xml".format(obs['id'])):
if os.path.isfile(OUT_DIR + "{}_best_model.fits".format(obs['id'])):
sed = Table.read(OUT_DIR + "{}_best_model.xml".format(obs['id']),
table_id="Llambda")
sed = Table.read(OUT_DIR + "{}_best_model.fits".format(obs['id']))
filters_wl = np.array([filt.effective_wavelength
for filt in filters.values()])
......
Markdown is supported
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