Commit 1da063f6 authored by  Hector Salas's avatar Hector Salas

Include properties in _check_filters, _check_errors, _check_invalid (only...

Include properties in _check_filters, _check_errors, _check_invalid (only extensive) and add_model_error functions in observations.py. rename errors as bands_errors
parent d943a86b
......@@ -42,8 +42,8 @@ class ObservationsManagerPassbands(object):
self.table = read_table(config['data_file'])
self.bands = [band for band in config['bands'] if not
band.endswith('_err')]
self.errors = [band for band in config['bands'] if
band.endswith('_err')]
self.bands_err = [band for band in config['bands'] if
band.endswith('_err')]
self.intprops = [prop for prop in config['properties'] if (prop not in
self.massproportional and not prop.endswith('_err'))]
self.intprops_err = [prop for prop in config['properties'] if
......@@ -54,6 +54,8 @@ class ObservationsManagerPassbands(object):
self.extprops_err = [prop for prop in config['properties'] if
(prop.endswith('_err') and prop[:-4] in
self.massproportional)]
self.tofit = self.bands + self.intprops + self.extprops
self.tofit_err = self.bands_err + self.intprops_err + self.extprops_err
# Sanitise the input
self._check_filters()
......@@ -88,16 +90,16 @@ class ObservationsManagerPassbands(object):
the fit, a warning is displayed
"""
for band in self.bands + self.errors:
for band in self.tofit + self.tofit_err:
if band not in self.table.colnames:
raise Exception("{} to be taken in the fit but not present "
"in the observation table.".format(band))
for band in self.table.colnames:
if (band != 'id' and band != 'redshift' and
band not in self.bands + self.errors):
if (band != 'id' and band != 'redshift' and band not in self.tofit +
self.tofit_err):
self.table.remove_column(band)
print("Warning: {} in the input file but not to be taken into "
print("Warning: {} in the input file but not to be taken into"
"account in the fit.".format(band))
def _check_errors(self, defaulterror=0.1):
......@@ -122,16 +124,19 @@ class ObservationsManagerPassbands(object):
if defaulterror < 0.:
raise ValueError("The relative default error must be positive.")
for band in self.bands:
banderr = band + '_err'
if banderr not in self.errors or banderr not in self.table.colnames:
colerr = Column(data=np.fabs(self.table[band] * defaulterror),
name=banderr)
for item in self.tofit:
error = item + '_err'
if item in self.intprops:
if error not in self.intprops_err or error not in self.table.colnames:
raise ValueError("Instensive properties errors must be in input file.")
elif error not in self.tofit_err or error not in self.table.colnames:
colerr = Column(data=np.fabs(self.table[item] * defaulterror),
name=error)
self.table.add_column(colerr,
index=self.table.colnames.index(band)+1)
index=self.table.colnames.index(item)+1)
print("Warning: {}% of {} taken as errors.".format(defaulterror *
100.,
band))
item))
def _check_invalid(self, upperlimits=False, threshold=-9990.):
"""Check whether invalid data are correctly marked as such.
......@@ -152,25 +157,30 @@ class ObservationsManagerPassbands(object):
"""
allinvalid = []
for band in self.bands:
banderr = band + '_err'
w = np.where((self.table[band] < threshold) |
(self.table[banderr] < threshold))
self.table[band][w] = np.nan
for item in self.bands + self.extprops:
error = item + '_err'
w = np.where((self.table[item] < threshold) |
(self.table[error] < threshold))
self.table[item][w] = np.nan
if upperlimits is False:
w = np.where(self.table[banderr] <= 0.)
self.table[band][w] = np.nan
w = np.where(self.table[error] <= 0.)
self.table[item][w] = np.nan
else:
w = np.where(self.table[banderr] == 0.)
self.table[band][w] = np.nan
if np.all(~np.isfinite(self.table[band])):
allinvalid.append(band)
for band in allinvalid:
self.bands.remove(band)
self.errors.remove(band + '_err')
self.table.remove_columns([band, band + '_err'])
print("Warning: {} removed as no valid data was found.".format(allinvalid))
w = np.where(self.table[error] == 0.)
self.table[item][w] = np.nan
if np.all(~np.isfinite(self.table[item])):
allinvalid.append(item)
for item in allinvalid:
if item in self.bands:
self.bands.remove(item)
self.bands_err.remove(item + '_err')
elif item in self.extprops:
self.extprops.remove(item)
self.extprops_err.remove(item + '_err')
self.table.remove_columns([item, item + '_err'])
print("Warning: {} removed as no valid data was found.".format(
allinvalid))
def _add_model_error(self, modelerror=0.1):
"""Add in quadrature the error of the model to the input error.
......@@ -178,17 +188,18 @@ class ObservationsManagerPassbands(object):
Parameters
----------
modelerror: float
Relative error of the models relative to the flux. By default 10%.
Relative error of the models relative to the flux (or property). By
default 10%.
"""
if modelerror < 0.:
raise ValueError("The relative model error must be positive.")
for band in self.bands:
banderr = band + '_err'
w = np.where(self.table[banderr] >= 0.)
self.table[banderr][w] = np.sqrt(self.table[banderr][w]**2. +
(self.table[band][w]*modelerror)**2.)
for item in self.tofit:
error = item + '_err'
w = np.where(self.table[error] >= 0.)
self.table[error][w] = np.sqrt(self.table[error][w]**2. + (
self.table[item][w]*modelerror)**2.)
def generate_mock(self, fits):
"""Replaces the actual observations with a mock catalogue. It is
......@@ -241,7 +252,7 @@ class ObservationsManagerVirtual(object):
# We set the other class members to None as they do not make sense in
# this situation
self.errors = None
self.bands_err = None
self.table = None
def __len__(self):
......
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