Exemplo n.º 1
0
def create_spec_model(npoints=10, flux=1e-9, wave_range=(11, 13)):
    """Create a SpecModel"""

    flux = np.full(npoints, flux)
    wavelength = np.arange(*wave_range,
                           step=(wave_range[1] - wave_range[0]) / npoints)
    error = np.zeros(npoints)
    surf_bright = np.zeros(npoints)
    sb_error = np.zeros(npoints)
    var_dummy = error.copy()
    dq = np.zeros(npoints)
    background = np.zeros(npoints)
    berror = np.zeros(npoints)
    npixels = np.zeros(npoints)

    spec_dtype = datamodels.SpecModel(
    ).spec_table.dtype  # This data type is used for creating an output table.

    otab = np.array(list(
        zip(wavelength, flux, error, var_dummy, var_dummy, var_dummy,
            surf_bright, sb_error, var_dummy, var_dummy, var_dummy, dq,
            background, berror, var_dummy, var_dummy, var_dummy, npixels), ),
                    dtype=spec_dtype)

    spec_model = datamodels.SpecModel(spec_table=otab)

    return spec_model
Exemplo n.º 2
0
def user_bkg_spec_b():
    """Create "user-background" data for testing.

    `expand_to_2d` uses `np.interp` for interpolation, and the wavelength
    array that is passed to `np.interp` must be increasing.  `expand_to_2d`
    is supposed to handle the case that the wavelengths are decreasing.
    Create data for checking that the results are the same even if the
    wavelength array in `m_bkg_spec` is reversed so that the values are
    decreasing, and the corresponding flux array is also reversed to retain
    the original (wavelength, flux) relation.

    Returns
    -------
    m_bkg_spec : `~jwst.datamodels.MultiSpecModel`
    """

    # This data type is used for creating a MultiSpecModel.
    spec_dtype = datamodels.SpecModel().spec_table.dtype

    m_bkg_spec = datamodels.MultiSpecModel()
    wavelength = np.geomspace(1.5,
                              4.5,
                              num=25,
                              endpoint=True,
                              dtype=np.float64)[::-1]
    flux = np.zeros_like(wavelength)
    error = np.ones_like(wavelength)
    var_dummy = error.copy()
    surf_bright = np.linspace(13.,
                              25.,
                              num=25,
                              endpoint=True,
                              retstep=False,
                              dtype=np.float64)[::-1]
    sb_error = np.ones_like(wavelength)
    dq = np.zeros(wavelength.shape, dtype=np.uint32)
    background = np.ones_like(wavelength)
    berror = np.ones_like(wavelength)
    npixels = np.ones_like(wavelength)
    otab = np.array(list(
        zip(wavelength, flux, error, var_dummy, var_dummy, var_dummy,
            surf_bright, sb_error, var_dummy, var_dummy, var_dummy, dq,
            background, berror, var_dummy, var_dummy, var_dummy, npixels)),
                    dtype=spec_dtype)
    spec = datamodels.SpecModel(spec_table=otab)
    m_bkg_spec.spec.append(spec)

    return m_bkg_spec
Exemplo n.º 3
0
def create_spec_model(npoints=10, flux=1e-9, wave_range=(11, 13)):
    """Create a SpecModel"""

    flux = np.full(npoints, flux)
    wavelength = np.arange(*wave_range,
                           step=(wave_range[1] - wave_range[0]) / npoints)
    error = np.zeros(npoints)
    surf_bright = np.zeros(npoints)
    sb_error = np.zeros(npoints)
    dq = np.zeros(npoints)
    background = np.zeros(npoints)
    berror = np.zeros(npoints)
    npixels = np.zeros(npoints)

    data = [(i, j, k, l, m, n, o, p, q) for i, j, k, l, m, n, o, p, q in zip(
        wavelength, flux, error, surf_bright, sb_error, dq, background, berror,
        npixels)]

    spec_table = np.array(data,
                          dtype=[('WAVELENGTH', 'f8'), ('FLUX', 'f8'),
                                 ('ERROR', 'f8'), ('SURF_BRIGHT', 'f8'),
                                 ('SB_ERROR', 'f8'), ('DQ', 'u4'),
                                 ('BACKGROUND', 'f8'), ('BERROR', 'f8'),
                                 ('NPIXELS', 'f8')])
    spec_model = datamodels.SpecModel()
    spec_model.spec_table = spec_table

    return spec_model
Exemplo n.º 4
0
def user_bkg_spec_a():
    """Create "user-background" data for testing.

    Returns
    -------
    m_bkg_spec : `~jwst.datamodels.MultiSpecModel`
    """

    # This data type is used for creating a MultiSpecModel.
    spec_dtype = datamodels.SpecModel().spec_table.dtype

    # m_bkg_spec doesn't have to be a MultiSpecModel, but that's an option.
    m_bkg_spec = datamodels.MultiSpecModel()
    wavelength = np.geomspace(1.5,
                              4.5,
                              num=25,
                              endpoint=True,
                              dtype=np.float64)
    flux = np.zeros_like(wavelength)
    error = np.ones_like(wavelength)
    var_dummy = error.copy()
    surf_bright = np.linspace(13.,
                              25.,
                              num=25,
                              endpoint=True,
                              retstep=False,
                              dtype=np.float64)
    sb_error = np.ones_like(wavelength)
    dq = np.zeros(wavelength.shape, dtype=np.uint32)
    background = np.ones_like(wavelength)
    berror = np.ones_like(wavelength)
    # The npixels column should no longer be used.  Set it to a large value
    # to make it more obvious in case it actually is still used.
    npixels = np.zeros_like(wavelength) + 2000.
    otab = np.array(list(
        zip(wavelength, flux, error, var_dummy, var_dummy, var_dummy,
            surf_bright, sb_error, var_dummy, var_dummy, var_dummy, dq,
            background, berror, var_dummy, var_dummy, var_dummy, npixels)),
                    dtype=spec_dtype)
    spec = datamodels.SpecModel(spec_table=otab)
    m_bkg_spec.spec.append(spec)

    return m_bkg_spec
Exemplo n.º 5
0
def make_datamodel():
    """Make data for white light tests"""

    model = datamodels.MultiSpecModel()
    model.meta.exposure.group_time = 0.15904
    model.meta.exposure.ngroups = 60
    model.meta.exposure.start_time = 58627.0
    model.meta.exposure.integration_start = 1
    model.meta.exposure.integration_end = 2

    # Make data arrays
    flux = np.random.rand(200) * 1e-9
    wavelength = np.arange(11, 13, step=0.01)
    error = np.random.rand(200)
    surf_bright = np.zeros(200)
    sb_error = np.zeros(200)
    dq = np.ones(200)
    background = np.zeros(200)
    berror = np.zeros(200)
    npixels = np.zeros(200)

    data = [(i, j, k, l, m, n, o, p, q) for i, j, k, l, m, n, o, p, q in zip(
        wavelength, flux, error, surf_bright, sb_error, dq, background, berror,
        npixels)]

    spec_table = np.array(data,
                          dtype=[('WAVELENGTH', 'f8'), ('FLUX', 'f8'),
                                 ('ERROR', 'f8'), ('SURF_BRIGHT', 'f8'),
                                 ('SB_ERROR', 'f8'), ('DQ', 'u4'),
                                 ('BACKGROUND', 'f8'), ('BERROR', 'f8'),
                                 ('NPIXELS', 'f8')])

    spectrum = datamodels.SpecModel()
    spectrum.spec_table = spec_table

    model.spec.append(spectrum)

    integrations = [
        (1, 58627.53891071, 58627.53896565, 58627.5390206, 0., 0., 0.),
        (2, 58627.5390206, 58627.53907555, 58627.5391305, 0., 0., 0.),
        (3, 58627.5391305, 58627.53918544, 58627.53924039, 0., 0., 0.)
    ]

    integration_table = np.array(integrations,
                                 dtype=[('integration_number', 'i4'),
                                        ('int_start_MJD_UTC', 'f8'),
                                        ('int_mid_MJD_UTC', 'f8'),
                                        ('int_end_MJD_UTC', 'f8'),
                                        ('int_start_BJD_TDB', 'f8'),
                                        ('int_mid_BJD_TDB', 'f8'),
                                        ('int_end_BJD_TDB', 'f8')])
    model.int_times = (integration_table)

    return model
Exemplo n.º 6
0
def user_bkg_spec_a():
    """Create "user-background" data for testing.

    Returns
    -------
    m_bkg_spec : `~jwst.datamodels.MultiSpecModel`
    """

    # This data type is used for creating a MultiSpecModel.
    spec_dtype = datamodels.SpecModel().spec_table.dtype

    # m_bkg_spec doesn't have to be a MultiSpecModel, but that's an option.
    m_bkg_spec = datamodels.MultiSpecModel()
    wavelength = np.geomspace(1.5,
                              4.5,
                              num=25,
                              endpoint=True,
                              dtype=np.float64)
    flux = np.linspace(13.,
                       25.,
                       num=25,
                       endpoint=True,
                       retstep=False,
                       dtype=np.float64)
    fl_error = np.ones_like(wavelength)
    dq = np.zeros(wavelength.shape, dtype=np.uint32)
    net = np.zeros_like(wavelength)
    nerror = np.ones_like(wavelength)
    background = np.ones_like(wavelength)
    berror = np.ones_like(wavelength)
    npixels = np.ones_like(wavelength)
    otab = np.array(list(
        zip(wavelength, flux, fl_error, dq, net, nerror, background, berror,
            npixels)),
                    dtype=spec_dtype)
    spec = datamodels.SpecModel(spec_table=otab)
    m_bkg_spec.spec.append(spec)

    return m_bkg_spec
Exemplo n.º 7
0
def make_datamodel():
    """Make data for white light tests"""

    model = datamodels.MultiSpecModel()
    model.meta.exposure.group_time = 0.15904
    model.meta.exposure.ngroups = 60
    model.meta.exposure.start_time = 58627.0
    model.meta.exposure.integration_start = 1
    model.meta.exposure.integration_end = 2

    # Make data arrays
    flux = np.random.rand(200) * 1e-9
    wavelength = np.arange(11, 13, step=0.01)
    f_var_poisson = np.random.rand(200)
    f_var_rnoise = np.random.rand(200)
    f_var_flat = np.random.rand(200)
    error = np.sqrt(f_var_poisson + f_var_rnoise + f_var_flat)

    surf_bright = np.zeros(200)
    sb_error = np.zeros(200)
    sb_var_poisson = sb_error.copy()
    sb_var_rnoise = sb_error.copy()
    sb_var_flat = sb_error.copy()
    dq = np.ones(200)
    background = np.zeros(200)
    berror = np.zeros(200)
    b_var_poisson = sb_error.copy()
    b_var_rnoise = sb_error.copy()
    b_var_flat = sb_error.copy()
    npixels = np.zeros(200)

    spec_dtype = datamodels.SpecModel(
    ).spec_table.dtype  # This data type is used for creating an output table.

    otab = np.array(list(
        zip(wavelength, flux, error, f_var_poisson, f_var_rnoise, f_var_flat,
            surf_bright, sb_error, sb_var_poisson, sb_var_rnoise, sb_var_flat,
            dq, background, berror, b_var_poisson, b_var_rnoise, b_var_flat,
            npixels), ),
                    dtype=spec_dtype)

    spec_model = datamodels.SpecModel(spec_table=otab)

    model.spec.append(spec_model)

    integrations = [
        (1, 58627.53891071, 58627.53896565, 58627.5390206, 0., 0., 0.),
        (2, 58627.5390206, 58627.53907555, 58627.5391305, 0., 0., 0.),
        (3, 58627.5391305, 58627.53918544, 58627.53924039, 0., 0., 0.)
    ]

    integration_table = np.array(integrations,
                                 dtype=[('integration_number', 'i4'),
                                        ('int_start_MJD_UTC', 'f8'),
                                        ('int_mid_MJD_UTC', 'f8'),
                                        ('int_end_MJD_UTC', 'f8'),
                                        ('int_start_BJD_TDB', 'f8'),
                                        ('int_mid_BJD_TDB', 'f8'),
                                        ('int_end_BJD_TDB', 'f8')])
    model.int_times = integration_table

    return model