Commit 11f13d80 authored by Yannick Roehlly's avatar Yannick Roehlly

Merge tag 'v0.10.0' into develop

Version 0.10.0
parents 4acbb41e 553d17a2
# Change Log
# Unreleased
# 0.10.0 (2016-09-15)
### Added
- Enable the possibility of having different normalisation factors for the star formation history. (Médéric Boquien)
### Changed
- The way to indicate the fluxes in the input table has changed because there were issues in the way upper limits were handled. (Yannick Roehlly) Here are the new rules:
- When the flux is around 0 (i.e. it's absolute value is lower than the tolerance threshold) or when it's lower than -9990 (typically -9999) it is considered as invalid and the source is not analysed.
- When the flux is negative (between -threshold and -9990) this indicates a upper-limit: the value of the upper limit is given in the flux column and the value of the error on the upper limit is given in the error column.
- When the error is negative or below the tolerance threshold, it is replaced by the default error.
- The tolerance threshold is 1e-12.
- Various descriptions have been improved and clarified. (Médéric Boquien)
- The `output\_file` and `output\_format` parameters have been removed from the `savefluxes` module. They served little purpose and made the code more complex. The same strategy as for the `pdf\_analysis` modules is now adopted, saving the output both as FITS and ASCII tables. Old configuration file still work, with these two parameters simply ignored. (Médéric Boquien)
......
......@@ -11,7 +11,7 @@ from .session.configuration import Configuration
from .analysis_modules import get_module
from .handlers.parameters_handler import ParametersHandler
__version__ = "0.1-alpha"
__version__ = "0.10.0"
def init(config):
......
......@@ -127,21 +127,9 @@ def get_module(module_name):
def adjust_data(fluxes, errors, tolerance, lim_flag, default_error=0.1,
systematic_deviation=0.1):
"""Adjust fluxes and errors
Adjust fluxes and errors provided by the user to fit CIGALE prescriptions:
- When the flux is around 0 (i.e. it's absolute value is lower than the
tolerance threshold) or when it's lower than -9990 (typically -9999) it
is considered as invalid and both flux and error are set to NaN.
- When the flux is negative (between -threshold and -9990) this indicates
a upper-limit. If the lim_flag is set to false, the flux is marked as
invalid.
- When the error is negative or below the tolerance threshold, it is
replace by the default error.
For valid fluxes, a systematic deviation is added that change the error to
sqrt(errors² + (fluxes*deviation)²).
"""Adjust the fluxes and errors replacing the invalid values by NaN, and
adding the systematic deviation. The systematic deviation changes the
errors to: sqrt(errors² + (fluxes*deviation)²)
Parameters
----------
......@@ -161,8 +149,6 @@ def adjust_data(fluxes, errors, tolerance, lim_flag, default_error=0.1,
Returns
-------
fluxes: array of floats
The corrected fluxes.
error: array of floats
The corrected errors.
......@@ -176,24 +162,25 @@ def adjust_data(fluxes, errors, tolerance, lim_flag, default_error=0.1,
fluxes = fluxes.copy()
errors = errors.copy()
# Valid fluxes mask
valid_mask = np.isfinite(fluxes)
if lim_flag:
valid_mask &= ~(np.abs(fluxes) <= tolerance) | (fluxes < -9990.)
else:
valid_mask &= ~(fluxes <= tolerance)
# We set invalid data to NaN
fluxes[~valid_mask] = np.nan
errors[~valid_mask] = np.nan
mask_invalid = np.where((fluxes <= tolerance) | (errors < -9990.))
fluxes[mask_invalid] = np.nan
errors[mask_invalid] = np.nan
# Replace missing errors by the default ones.
no_error_mask = valid_mask & (errors <= tolerance)
errors[no_error_mask] = default_error * np.abs(fluxes[no_error_mask])
mask_noerror = np.where((fluxes > tolerance) & ~np.isfinite(errors))
errors[mask_noerror] = (default_error * fluxes[mask_noerror])
# Replace upper limits by no data if lim_flag==False
if not lim_flag:
mask_limflag = np.where((fluxes > tolerance) & (errors < tolerance))
fluxes[mask_limflag] = np.nan
errors[mask_limflag] = np.nan
# Add the systematic error.
errors[valid_mask] = np.sqrt(
errors[valid_mask]**2 + (fluxes[valid_mask] * systematic_deviation)**2)
mask_ok = np.where((fluxes > tolerance) & (errors > tolerance))
errors[mask_ok] = np.sqrt(errors[mask_ok]**2 +
(fluxes[mask_ok]*systematic_deviation)**2)
return fluxes, errors
......
......@@ -25,7 +25,7 @@ entry_points = {
setup(
name="pcigale",
version="0.8.0",
version="0.10.0",
packages=find_packages(exclude=["database_builder"]),
install_requires=['numpy', 'scipy', 'sqlalchemy', 'matplotlib',
......
# -*- coding: utf-8 -*-
import numpy as np
from numpy.testing import assert_almost_equal
from pcigale.analysis_modules import adjust_data
def test_adjust_data():
fluxes = np.array([10., 0., -9999, 10., 10., 10., -10, -10., -10])
errors = np.array([0.1, 0.1, 0.1, -9999., 0, -0.1, 0.1, 0., -0.1])
adjusted_fluxes, adjusted_errors = adjust_data(
fluxes, errors, tolerance=1.e-12, lim_flag=False, default_error=0.1,
systematic_deviation=0.1)
# (10, 0.1) is ok. We just add the systematic deviation.
assert_almost_equal(adjusted_fluxes[0], 10.)
assert_almost_equal(adjusted_errors[0], np.sqrt(0.1**2+1))
# (0., 0.1) is is invalid.
assert(np.isnan([adjusted_fluxes[1], adjusted_errors[1]]).all())
# (-9999, 0.1) is invalid
assert(np.isnan([adjusted_fluxes[2], adjusted_errors[2]]).all())
# (10., -9999.) we use the default error and add the systematic deviation.
assert_almost_equal(adjusted_fluxes[3], 10.)
assert_almost_equal(adjusted_errors[3], np.sqrt(2))
# (10., 0.) With error to 0, we use the default error and add the
# systematic deviation.
assert_almost_equal(adjusted_fluxes[4], 10.)
assert_almost_equal(adjusted_errors[4], np.sqrt(2))
# (10., -0.1) Negative error is invalid, we use the default error and add
# the systematic deviation.
assert_almost_equal(adjusted_fluxes[5], 10.)
assert_almost_equal(adjusted_errors[5], np.sqrt(2))
# With lim_flag set to False, negative fluxes are invalid values
assert(np.isnan([adjusted_fluxes[6], adjusted_errors[6]]).all())
assert(np.isnan([adjusted_fluxes[7], adjusted_errors[7]]).all())
assert(np.isnan([adjusted_fluxes[8], adjusted_errors[8]]).all())
# With lim_flag set to True
adjusted_fluxes, adjusted_errors = adjust_data(
fluxes, errors, tolerance=1.e-12, lim_flag=True, default_error=0.1,
systematic_deviation=0.1)
# (-10, 0.1) Upper limit, we add the systematic deviation to the error.
assert_almost_equal(adjusted_fluxes[6], -10.)
assert_almost_equal(adjusted_errors[6], np.sqrt(0.1**2+1))
# (-10., 0.) Upper limit, we use the default error and add the systematic
# deviation.
assert_almost_equal(adjusted_fluxes[7], -10.)
assert_almost_equal(adjusted_errors[7], np.sqrt(2))
# (-10., -9999) Upper limit, we use the default error and add
# the systematic deviation.
assert_almost_equal(adjusted_fluxes[8], -10.)
assert_almost_equal(adjusted_errors[8], np.sqrt(2))
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