예제 #1
0
class PipelineTest(unittest.TestCase):
    loadOptions = tasks.LoadOptions()
    buildChannels = tasks.BuildChannels()
    buildInstrument = tasks.BuildInstrument()
    loadPayload = tasks.LoadPayload()
    loadTargetList = tasks.LoadTargetList()

    payload = loadOptions(filename=payload_file())
    wl_min, wl_max = payload['common']['wl_min']['value'], \
                     payload['common']['wl_max']['value']
    channels = buildChannels(payload=payload, write=False, output=None)
    targets = loadTargetList(
        target_list=os.path.join(data_dir, 'test_target.csv'))

    def test_full_pipe(self):
        prepareTarget = tasks.PrepareTarget()
        estimateForegrounds = tasks.EstimateForegrounds()
        propagateForegroundLight = tasks.PropagateForegroundLight()
        propagateTargetLight = tasks.PropagateTargetLight()
        estimateNoise = tasks.EstimateNoise()
        loadSource = tasks.LoadSource()

        for target in self.targets.target:
            target = prepareTarget(target=target, channels=self.channels)

            if 'foreground' in self.payload['common']:
                target = estimateForegrounds(
                    foregrounds=self.payload['common']['foreground'],
                    target=target,
                    wl_range=(self.wl_min, self.wl_max))
                target = propagateForegroundLight(channels=self.channels,
                                                  target=target)

            target, sed = loadSource(
                target=target,
                source=self.payload['common']['sourceSpectrum'],
                wl_range=(self.wl_min, self.wl_max))
            target = propagateTargetLight(channels=self.channels,
                                          target=target)

            target = estimateNoise(target=target, channels=self.channels)

    def test_obsTarget(self):
        observeTarget = tasks.ObserveTarget()

        for target in self.targets.target:
            target = observeTarget(target=target,
                                   payload=self.payload,
                                   channels=self.channels,
                                   wl_range=(self.wl_min, self.wl_max))

    def test_obsTargetList(self):
        observeTargetList = tasks.ObserveTargetlist()

        targets = observeTargetList(targets=self.targets.target,
                                    payload=self.payload,
                                    channels=self.channels,
                                    wl_range=(self.wl_min, self.wl_max),
                                    plot=False,
                                    out_dir=None)
예제 #2
0
class PrepareTargeTest(unittest.TestCase):
    from exorad.tasks import PreparePayload

    setLogLevel(logging.INFO)
    loadTargetList = LoadTargetList()
    target_list = os.path.join(data_dir, 'test_target.csv')
    targets = loadTargetList(target_list=target_list)
    target = targets.target[0]
    loadSource = LoadSource()
    target, sed = loadSource(target=target,
                             source='planck',
                             wl_range=(0.45, 2.2))

    preparePayload = PreparePayload()
    payload, channels, (wl_min,
                        wl_max) = preparePayload(payload_file=payload_file(),
                                                 output=None)

    setLogLevel(logging.DEBUG)

    prepareTarget = PrepareTarget()
    target = prepareTarget(target=target, channels=channels)
    print(target.table)

    def test_write(self):
        print(self.target.to_dict())
        fname = 'test.h5'
        with HDF5Output(fname, append=True) as out:
            self.target.write(out)

        os.remove(fname)
예제 #3
0
class NoiseTest(unittest.TestCase):
    disableLogging()
    payload, channels, (wl_min,
                        wl_max) = preparePayload(payload_file=payload_file(),
                                                 output=None)
    targets = loadTargetList(target_list=target_list)
    target = targets.target[0]
    target = prepareTarget(target=target, channels=channels)
    target, sed = loadSource(target=target,
                             source=payload['common']['sourceSpectrum'],
                             wl_range=(wl_min, wl_max))
    target = propagateTargetLight(channels=channels, target=target)
    target = estimateForeground(
        zodi=payload['common']['foreground']['zodiacal'],
        target=target,
        wl_range=(wl_min, wl_max))
    target = propagateForegroundLight(channels=channels, target=target)

    enableLogging()
    setLogLevel(logging.DEBUG)

    from exorad.tasks.noiseHandler import EstimateNoise

    estimateNoise = EstimateNoise()
    target = estimateNoise(target=target, channels=channels)
    print(target.table.keys())
예제 #4
0
class Spectrometer_from_pickle_Test(unittest.TestCase):
    setLogLevel(logging.DEBUG)
    loadOptions = LoadOptions()
    options2 = loadOptions(filename=payload_file(
        name='payload_test_pickle_spec.xml'))
    spectrometer = Spectrometer('Spec', options2['channel']['Spec'], options2)
    spectrometer.build()

    def test_spectrometer_table(self):
        self.assertEqual(self.spectrometer.table['Wavelength'].size, 12)
        # self.assertListEqual(list(self.spectrometer.table['TR'].value), [0.5] * 12)
        self.assertListEqual(list(self.spectrometer.table['QE'].value),
                             [0.7] * 12)
예제 #5
0
class PlotterTest(unittest.TestCase):
    loadOptions = tasks.LoadOptions()
    buildChannels = tasks.BuildChannels()
    buildInstrument = tasks.BuildInstrument()
    loadPayload = tasks.LoadPayload()
    loadTargetList = tasks.LoadTargetList()
    loadSource = tasks.loadSource.LoadSource()
    mergeChannelsOutput = tasks.MergeChannelsOutput()
    observeTargetList = tasks.ObserveTargetlist()

    disableLogging()
    payload = loadOptions(filename=payload_file())
    wl_min, wl_max = payload['common']['wl_min']['value'], \
                     payload['common']['wl_max']['value']
    channels = buildChannels(payload=payload, write=False, output=None)
    table = mergeChannelsOutput(channels=channels)

    targets = loadTargetList(
        target_list=os.path.join(data_dir, 'test_target.csv'))
    targets = observeTargetList(targets=targets.target,
                                payload=payload,
                                channels=channels,
                                wl_range=(wl_min, wl_max),
                                plot=False,
                                out_dir=None)
    enableLogging()

    @unittest.skipIf(skip_plot, "This test only produces plots")
    def test_efficiency(self):
        setLogLevel(logging.DEBUG)

        plotter = Plotter(channels=self.channels, input_table=self.table)
        plotter.plot_efficiency()
        plt.show()

    @unittest.skipIf(skip_plot, "This test only produces plots")
    def test_efficiency_catcher(self):
        setLogLevel(logging.DEBUG)

        plotter = Plotter(input_table=self.table)
        plotter.plot_efficiency()
        plotter.save_fig('test.png', efficiency=True)

    @unittest.skipIf(skip_plot, "This test only produces plots")
    def test_table(self):
        setLogLevel(logging.DEBUG)
        for target in self.targets:
            plotter = Plotter(input_table=self.targets[target].table)
            plotter.plot_table()
            plt.show()
예제 #6
0
from exorad.log import setLogLevel
from exorad.tasks import PreparePayload, PrepareTarget, PropagateTargetLight, \
    LoadTargetList, LoadSource, \
    PropagateForegroundLight, EstimateZodi
from test_options import payload_file

preparePayload = PreparePayload()
loadTargetList = LoadTargetList()
loadSource = LoadSource()
prepareTarget = PrepareTarget()
estimateBackground = EstimateZodi()

path = pathlib.Path(__file__).parent.absolute()
data_dir = os.path.join(path.parent.absolute(), 'examples')

options_filename = payload_file()
target_list = os.path.join(data_dir, 'test_target.csv')


class TargetPropagationTest(unittest.TestCase):
    payload, channels, (wl_min, wl_max) = preparePayload(
        payload_file=options_filename, output=None)
    targets = loadTargetList(target_list=target_list)
    target = targets.target[0]
    target, sed = loadSource(target=target,
                             source=payload['common']['sourceSpectrum'],
                             wl_range=(wl_min, wl_max))
    target = prepareTarget(target=target, channels=channels)

    setLogLevel(logging.DEBUG)
예제 #7
0
import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np

from conf import skip_plot
from exorad.log import setLogLevel
from exorad.models.instruments import Photometer, Spectrometer
from exorad.models.optics.opticalPath import OpticalPath
from exorad.tasks.loadOptions import LoadOptions
from test_options import payload_file

path = pathlib.Path(__file__).parent.absolute()
data_dir = os.path.join(path.parent.absolute(), 'examples')

loadOptions = LoadOptions()
options = loadOptions(filename=payload_file())


class InstrumentDiffuseLightTest(unittest.TestCase):
    def test_transmission(self):

        wl_grid = np.logspace(
            np.log10(options['channel']['Phot']['detector']['wl_min']
                     ['value'].value),
            np.log10(options['channel']['Phot']['detector']['cut_off']
                     ['value'].value), 6000) * u.um
        telescope = OpticalPath(wl=wl_grid, description=options)
        tel = telescope.chain()
        phot = OpticalPath(wl=wl_grid, description=options['channel']['Phot'])
        phot.prepend_optical_elements(telescope.optical_element_dict)
        phot.build_transmission_table()