From fc5e7dfb7c0d69c40f16cc51f07e10eed83dbc3b Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Tue, 30 Jun 2020 11:30:32 +0200 Subject: [PATCH] Allow spectral resolution as velocity --- docs/source/configuration/common.rst | 2 +- esbo_etc/classes/Config.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/source/configuration/common.rst b/docs/source/configuration/common.rst index bc8a16d..a99156c 100644 --- a/docs/source/configuration/common.rst +++ b/docs/source/configuration/common.rst @@ -58,7 +58,7 @@ Attributes: * | **val:** float | The value of the spectral resolution. * | **val_unit:** str, *optional* = "" - | The unit of the spectral resolution. This has to be emtpy (dimensionless). The default is ``dimensionless``. + | The unit of the spectral resolution. This has to be emtpy (dimensionless) or one of [``m/s``, ``km/s``]. The default is ``dimensionless``. .. note:: Either :ref:`wl_delta` or :ref:`res` must be given in the configuration. diff --git a/esbo_etc/classes/Config.py b/esbo_etc/classes/Config.py index cf09d12..b6dddcc 100644 --- a/esbo_etc/classes/Config.py +++ b/esbo_etc/classes/Config.py @@ -1,6 +1,7 @@ import xml.etree.ElementTree as eT import numpy as np import astropy.units as u +from astropy.constants import c import os from ..lib.helpers import readCSV from ..lib.logger import logger @@ -93,7 +94,11 @@ class Configuration(object): if hasattr(self.conf.common, "wl_delta"): wl_delta = self.conf.common.wl_delta() else: - wl_delta = (self.conf.common.wl_min() + self.conf.common.wl_max()) / (2 * self.conf.common.res()) + if self.conf.common.res().unit == u.dimensionless_unscaled: + wl_delta = (self.conf.common.wl_min() + self.conf.common.wl_max()) / (2 * self.conf.common.res()) + else: + wl_delta = (self.conf.common.wl_min() + self.conf.common.wl_max()) / 2 * ( + self.conf.common.res() / c).decompose() setattr(self.conf.common, 'wl_delta', Entry(val=wl_delta)) setattr(self.conf.common, 'wl_bins', Entry(val=np.append(np.arange(self.conf.common.wl_min().to(u.nm).value, @@ -120,7 +125,9 @@ class Configuration(object): mes is not None and logger.error("Configuration check: common -> wl_delta: " + mes) elif hasattr(self.conf.common, "res"): mes = self.conf.common.res.check_quantity("val", u.dimensionless_unscaled) - mes is not None and logger.error("Configuration check: common -> res: " + mes) + if mes is not None: + mes = self.conf.common.res.check_quantity("val", u.m / u.s) + mes is not None and logger.error("Configuration check: common -> res: " + mes) else: logger.error( "Configuration check: common: Expected one of the containers 'wl_delta' or 'res' but got none.")