Ejemplo n.º 1
0
def test_width_conversion(s):

    from taurex.util.util import wnwidth_to_wlwidth, create_grid_res
    res = create_grid_res(s, 0.1, 10)

    wl = res[:,0]
    wlwidths = res[:,1]

    wn = 10000/wl[::-1]
    wnwidths = wnwidth_to_wlwidth(wl, wlwidths)[::-1]
    
    np.testing.assert_array_almost_equal(wnwidth_to_wlwidth(wn, wnwidths)[::-1], wlwidths, 6)
Ejemplo n.º 2
0
    def __init__(self,
                 molecule_name,
                 wn_res=15000,
                 wn_size=(300, 30000),
                 num_p=20,
                 num_t=27):
        super().__init__('FAKE')
        self._molecule_name = molecule_name
        self._wavenumber_grid = create_grid_res(wn_res, *wn_size)[:, 0]
        self._xsec_grid = np.random.rand(num_p, num_t,
                                         self._wavenumber_grid.shape[0])

        self._temperature_grid = np.linspace(100, 10000, num_t)
        self._pressure_grid = np.logspace(-6, 6, num_p)
Ejemplo n.º 3
0
    def create_manual_binning(self, config):
        import numpy as np
        import math
        from taurex.binning import FluxBinner, SimpleBinner

        binning_class = SimpleBinner

        if 'accurate' in config:
            if config['accurate']:
                binning_class = FluxBinner

        # Handle wavelength grid
        wngrid = None
        if 'wavelength_grid' in config:
            start, end, size = config['wavelength_grid']
            wngrid = 10000 / np.linspace(start, end, int(size))
            wngrid = np.sort(wngrid)

        elif 'wavenumber_grid' in config:
            start, end, size = config['wavenumber_grid']
            wngrid = np.linspace(start, end, int(size))

        elif 'log_wavenumber_grid' in config:
            start, end, size = config['log_wavenumber_grid']
            start = math.log10(start)
            end = math.log10(end)
            wngrid = np.logspace(start, end, int(size))

        elif 'log_wavelength_grid' in config:
            start, end, size = config['log_wavelength_grid']
            start = math.log10(start)
            end = math.log10(end)
            wngrid = np.sort(10000 / np.logspace(start, end, int(size)))
        elif 'wavelength_res' in config:
            from taurex.util.util import create_grid_res
            start, end, res = config['wavelength_res']
            wlgrid = create_grid_res(res, start, end)[:, 0].flatten()
            wngrid = 10000 / wlgrid[::-1]

        if wngrid is None:
            self._logger.error(
                'manual was selected and no grid was given.'
                '(Use wavelength_grid, wavenumber_grid or log versions)')
            raise Exception('manual selected but no grid given')

        return binning_class(wngrid), wngrid
Ejemplo n.º 4
0
    def _generic_plot(self,
                      wlgrid,
                      native_grid,
                      spectra,
                      resolution,
                      color=None,
                      error=False,
                      alpha=1.0,
                      label=None):

        binned_error = None
        if resolution is not None:
            from taurex.binning import FluxBinner
            from taurex.util.util import create_grid_res, wnwidth_to_wlwidth
            _grid = create_grid_res(resolution,
                                    wlgrid.min() * 0.9,
                                    wlgrid.max() * 1.1)
            bin_wlgrid = _grid[:, 0]

            bin_wngrid = 10000 / _grid[:, 0]

            bin_sort = bin_wngrid.argsort()

            bin_wlgrid = bin_wlgrid[bin_sort]
            bin_wngrid = bin_wngrid[bin_sort]

            bin_wnwidth = wnwidth_to_wlwidth(bin_wlgrid, _grid[bin_sort, 1])
            wlgrid = _grid[bin_sort, 0]
            binner = FluxBinner(bin_wngrid, bin_wnwidth)
            native_spectra = spectra['native_spectrum'][...]
            binned_spectrum = binner.bindown(native_grid, native_spectra)[1]
            try:
                native_error = spectra['native_std']
            except KeyError:
                native_error = None
            if native_error is not None:
                binned_error = binner.bindown(native_grid, native_error)[1]

        else:
            try:
                binned_spectrum = spectra['binned_spectrum'][...]
            except KeyError:
                try:
                    binned_spectrum = spectra['bin_spectrum'][...]
                except KeyError:
                    binned_spectrum = spectra['native_spectrum'][...]
            try:
                binned_error = spectra['binned_std'][...]
            except KeyError:
                binned_error = None
        plt.plot(wlgrid, binned_spectrum, label=label, alpha=alpha)
        if binned_error is not None:
            plt.fill_between(wlgrid,
                             binned_spectrum - binned_error,
                             binned_spectrum + binned_error,
                             alpha=0.5,
                             zorder=-2,
                             color=color,
                             edgecolor='none')

            # 2 sigma
            plt.fill_between(wlgrid,
                             binned_spectrum - 2 * binned_error,
                             binned_spectrum + 2 * binned_error,
                             alpha=0.2,
                             zorder=-3,
                             color=color,
                             edgecolor='none')
Ejemplo n.º 5
0
def test_grid_res(res):
    from taurex.util.util import create_grid_res

    wn = 10000/create_grid_res(res, 10.0, 1000)[::-1,0]

    assert round(np.mean(wn/np.gradient(wn))) == res
Ejemplo n.º 6
0
def test_bin_edges(res):
    from taurex.util.util import compute_bin_edges, create_grid_res
    grid = create_grid_res(res, 300, 10000)
    edges, widths = compute_bin_edges(grid[:, 0])
    
    assert round(np.mean(grid[:, 0]/widths)) == res