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