Allow spectral resolution as velocity

This commit is contained in:
Lukas Klass 2020-06-30 11:30:32 +02:00
parent 76727a5c73
commit fc5e7dfb7c
2 changed files with 10 additions and 3 deletions

View File

@ -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.

View File

@ -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.")