コード例 #1
0
class InstrumentFile(Instrument):
    """
    Loads a 2-3 column file with wlgrid
    and noise and maybe wlgrid


    Parameters
    ----------

    filename: str
        Filename of file containing the binning and error


    """
    def __init__(self, filename=None):
        super().__init__()

        self._spectrum = np.loadtxt(filename)

        self._wlgrid = self._spectrum[:, 0]

        sortedwl = self._wlgrid.argsort()[::-1]

        self._wlgrid = self._wlgrid[sortedwl]

        self._wngrid = 10000 / self._wlgrid

        self._noise = self._spectrum[sortedwl, 1]

        try:
            self._wlwidths = self._spectrum[sortedwl, 2]
        except IndexError:
            from taurex.util.util import compute_bin_edges

            self._wlwidths - compute_bin_edges(self._wlgrid)[-1]

        self.create_wn_widths()

        self._binner = FluxBinner(self._wngrid, wngrid_width=self._wnwidths)

    def create_wn_widths(self):

        self._wnwidths = wnwidth_to_wlwidth(self._wlgrid, self._wlwidths)

    def model_noise(self, model, model_res=None, num_observations=1):

        if model_res is None:
            model_res = model.model()

        wngrid, spectrum, error, grid_width = self._binner.bin_model(model_res)

        return wngrid, spectrum, self._noise / math.sqrt(
            num_observations), grid_width

    @classmethod
    def input_keywords(self):
        return [
            'file',
            'fromfile',
        ]
コード例 #2
0
class ExampleInstrument(Instrument):
    """
    An example implementation of an instrument
    An instument function thats uses the WFC3
    spectral grid and applies a gaussian noise
    with a scale ``noise_scale`` for each spectrum
    point.

    """
    def __init__(self, noise_scale=1):
        super().__init__()

        self._scale = noise_scale

        # Wavelength and widths for WFC3
        wfc3_grid = np.array([
            1.126, 1.156, 1.184, 1.212, 1.238, 1.265, 1.292, 1.318, 1.345, 
            1.372, 1.399, 1.428, 1.457, 1.487, 1.518, 1.551, 1.586, 1.623,
        ])

        wfc3_wlwidths = np.array([
            3.079e-2, 2.930e-2, 2.790e-2, 2.689e-2, 2.649e-2, 2.689e-2,
            2.670e-2, 2.629e-2, 2.649e-2, 2.739e-2, 2.800e-2, 2.849e-2,
            2.940e-2, 3.079e-2, 3.180e-2, 3.370e-2, 3.600e-2, 3.899e-2,
        ])

        # convert to wavenumber widths
        wfc3_wnwidths = wnwidth_to_wlwidth(wfc3_grid, wfc3_wlwidths)

        self._wfc3_size = wfc3_grid.shape[0]

        # Create our grid resampler
        self._binner = FluxBinner(wngrid=10000/wfc3_grid,
                                  wngrid_width=wfc3_wnwidths)

    def model_noise(self, model, model_res=None, num_observations=1):

        if model_res is None:
            model_res = model.model()

        # Generate our noise
        noise = np.random.normal(scale=self._scale, size=self._wfc3_size)

        # Bin down our model
        wngrid, depth, _, widths = self._binner.bin_model(model_res)

        return wngrid, depth, noise, widths
コード例 #3
0
data = ascii.read("0000_HD 209458 b.csv")
wlgrid0, noise0 = (np.array([]) for k in range(2))
for i in range(len(data)):
    wlgrid0 = np.append(wlgrid0, data[i][1])
    noise0 = np.append(noise0, data[i][6])  # noise on transit floor

###################### NUMBER OF TRANSITS #######################
num_transits = 1
noise0 = noise0 / np.sqrt(num_transits)
#################################################################
from taurex.binning import FluxBinner
wngrid3 = 10000 / wlgrid0
wngrid3 = np.sort(wngrid3)
bn = FluxBinner(wngrid=wngrid3)
bin_wn, bin_rprs3, _, _ = bn.bin_model(tm.model(wngrid=wngrid3))
x = np.flip(10000 / bin_wn)
y = np.flip(bin_rprs3)

#%%
# =============================================================================
#                    BINDOWN FROM TIER3 TO TIER2
# =============================================================================
# Load the spectral data, the first column is wavelength, second flux density and third flux density uncertainty

tier2file = np.loadtxt('tier2-grid.txt')
wl = x
wlbinned = tier2file[:, 0]

spectrum = y
noise = noise0