2020-04-08 13:38:08 +02:00
|
|
|
from ..target.ATarget import ATarget
|
|
|
|
from ..SpectralQty import SpectralQty
|
|
|
|
import astropy.units as u
|
2020-05-08 15:06:13 +02:00
|
|
|
from ..Entry import Entry
|
|
|
|
from typing import Union
|
2020-04-08 13:38:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
class FileTarget(ATarget):
|
|
|
|
"""
|
|
|
|
A class to create a target from a file containing the spectral flux densities
|
|
|
|
"""
|
|
|
|
|
2020-04-16 15:08:47 +02:00
|
|
|
@u.quantity_input(wl_bins="length")
|
2020-06-26 19:15:43 +02:00
|
|
|
def __init__(self, file: str, wl_bins: u.Quantity):
|
2020-04-08 13:38:08 +02:00
|
|
|
"""
|
|
|
|
Initialize a new target from a file containing the spectral flux density values
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
file : str
|
|
|
|
The file to read the spectral flux density values from. The file needs to provide two columns: wavelength
|
|
|
|
and the corresponding spectral flux density. The format of the file will be guessed by
|
2020-04-16 09:35:24 +02:00
|
|
|
`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*.
|
2020-04-16 15:08:47 +02:00
|
|
|
wl_bins : length-Quantity
|
|
|
|
Wavelengths used for binning
|
2020-04-08 13:38:08 +02:00
|
|
|
"""
|
2020-04-14 12:49:51 +02:00
|
|
|
# Create spectral quantity from file
|
2020-07-14 12:00:22 +02:00
|
|
|
sfd = SpectralQty.fromFile(file, u.nm, u.W / (u.m ** 2 * u.nm)).rebin(wl_bins)
|
2020-04-14 12:49:51 +02:00
|
|
|
# Initialize the super class
|
2020-06-26 19:15:43 +02:00
|
|
|
super().__init__(sfd, wl_bins)
|
2020-05-08 15:06:13 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def check_config(conf: Entry) -> Union[None, str]:
|
|
|
|
"""
|
|
|
|
Check the configuration for this class
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
conf : Entry
|
|
|
|
The configuration entry to be checked.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
mes : Union[None, str]
|
|
|
|
The error message of the check. This will be None if the check was successful.
|
|
|
|
"""
|
|
|
|
mes = conf.check_file("file")
|
|
|
|
if mes is not None:
|
|
|
|
return mes
|