Coverage for python/lsst/atmospec/dispersion.py: 30%
25 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-10-19 12:08 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-10-19 12:08 +0000
1# This file is part of atmospec.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import logging
23import numpy as np
26__all__ = ['DispersionRelation']
29class DispersionRelation:
30 def __init__(self, observedLines, spectralLines):
31 """The dispersion relation, relating pixel to wavelength and vice versa
33 Parameters:
34 -----------
35 observedLines : `list` of `float`
36 The central wavelength of the observed lines in the spectrum in pix
38 spectralLines : `list` of `float`
39 The central wavelength of the spectral lines present in the source
40 in nm.
42 Notes:
43 ------
44 The current implementation just supplies linear transformations
45 but future extensions can support higher order polynomials,
46 spline-fits, distortions etc
47 """
48 self.observedLines = observedLines
49 self.spectralLines = spectralLines
51 self.log = logging.getLogger('lsst.atmospec.dispersionRelation')
52 self.pix2wlCoeffs = self._calcCoefficients()
54 def _calcCoefficients(self):
55 if (self.observedLines is None) or (self.spectralLines is None):
56 self.log.warn('Missing input for _calcCoefficients, default transformation: 1 to 1 ')
57 self.observedLines = [1, 2]
58 self.spectralLines = [1, 2]
59 pix2wlCoeffs = np.polyfit(self.observedLines, self.spectralLines, deg=1)
61 # xxx change to debug
62 self.log.info('Pixel -> Wavelength linear transformation coefficients : ' + str(pix2wlCoeffs))
63 return pix2wlCoeffs
65 def Wavelength2Pixel(self, wavelength):
66 """Currently just a linear transform"""
67 wavelength = np.asarray(wavelength, dtype=np.float64)
68 coef = self.pix2wlCoeffs
69 return (wavelength-coef[1]) / coef[0]
71 def Pixel2Wavelength(self, pixel):
72 """Currently just a linear transform"""
73 pixel = np.asarray(pixel, dtype=np.float64)
74 coef = self.pix2wlCoeffs
75 return np.array(coef[1] + coef[0] * pixel)