diff --git a/esbo_etc/classes/target/ATarget.py b/esbo_etc/classes/target/ATarget.py index 73f0191..21359a0 100644 --- a/esbo_etc/classes/target/ATarget.py +++ b/esbo_etc/classes/target/ATarget.py @@ -11,7 +11,8 @@ class ATarget(IRadiant): """ @abstractmethod - def __init__(self, sfd: SpectralQty): + @u.quantity_input(wl_bins="length") + def __init__(self, sfd: SpectralQty, wl_bins: u.Quantity): """ Initialize a new target @@ -21,6 +22,7 @@ class ATarget(IRadiant): The spectral flux density of the target """ self.__sfd = sfd + self.__wl_bins = wl_bins def calcNoise(self) -> SpectralQty: """ @@ -31,7 +33,7 @@ class ATarget(IRadiant): noise : SpectralQty The spectral radiance of the target's noise """ - return SpectralQty(self.__sfd.wl, np.repeat(0, len(self.__sfd.wl)) << u.W / (u.m**2 * u.nm * u.sr)) + return SpectralQty(self.__wl_bins, np.repeat(0, len(self.__wl_bins)) << u.W / (u.m**2 * u.nm * u.sr)) def calcSignal(self) -> SpectralQty: """ diff --git a/esbo_etc/classes/target/BlackBodyTarget.py b/esbo_etc/classes/target/BlackBodyTarget.py index 5105712..43721a7 100644 --- a/esbo_etc/classes/target/BlackBodyTarget.py +++ b/esbo_etc/classes/target/BlackBodyTarget.py @@ -53,4 +53,4 @@ class BlackBodyTarget(ATarget): sfd = bb(wl_bins) * factor * 10 ** (- 2 / 5 * mag / u.mag) # Initialize super class - super().__init__(SpectralQty(wl_bins, sfd)) + super().__init__(SpectralQty(wl_bins, sfd), wl_bins) diff --git a/esbo_etc/classes/target/FileTarget.py b/esbo_etc/classes/target/FileTarget.py index 872eeda..3d4c00f 100644 --- a/esbo_etc/classes/target/FileTarget.py +++ b/esbo_etc/classes/target/FileTarget.py @@ -8,7 +8,8 @@ class FileTarget(ATarget): A class to create a target from a file containing the spectral flux densities """ - def __init__(self, file: str): + @u.quantity_input(wl_bins="length") + def __init__(self, file: str, wl_bins: u.Quantity): """ Initialize a new target from a file containing the spectral flux density values @@ -19,8 +20,10 @@ class FileTarget(ATarget): and the corresponding spectral flux density. The format of the file will be guessed by `astropy.io.ascii.read(). If the file doesn't provide units via astropy's enhanced CSV format, the units will be read from the column headers or otherwise assumed to be *nm* and *W / m^2 / nm*. + wl_bins : length-Quantity + Wavelengths used for binning """ # Create spectral quantity from file sfd = SpectralQty.fromFile(file, u.nm, u.W / (u.m ** 2 * u.nm)) # Initialize the super class - super().__init__(sfd) + super().__init__(sfd, wl_bins) diff --git a/tests/target/test_FileTarget.py b/tests/target/test_FileTarget.py index 35baf78..ec174db 100644 --- a/tests/target/test_FileTarget.py +++ b/tests/target/test_FileTarget.py @@ -7,7 +7,7 @@ import numpy as np class TestFileTarget(TestCase): def setUp(self): - self.target = FileTarget("../data/target/target_demo_1.csv") + self.target = FileTarget("../data/target/target_demo_1.csv", np.arange(200, 210, 1) << u.nm) def test_signal(self): signal = SpectralQty(np.arange(200, 210, 1) << u.nm,