Beispiel #1
0
def test_open_fits_model_s3(s3_root_dir):
    path = str(s3_root_dir.join("test.fits"))
    with DataModel() as dm:
        dm.save(path)

    model = DataModel("s3://test-s3-data/test.fits")
    assert isinstance(model, DataModel)
Beispiel #2
0
def test_skip_serializing_null(tmpdir, filename):
    """Make sure that None is not written out to the ASDF tree"""
    path = str(tmpdir.join(filename))
    with DataModel() as model:
        model.meta.telescope = None
        model.save(path)

    with DataModel(path) as model:
        # Make sure that 'telescope' is not in the tree
        with pytest.raises(KeyError):
            assert model.meta["telescope"] is None
Beispiel #3
0
def test_stringify():
    im = DataModel()
    assert str(im) == '<DataModel>'
    im.close()

    im = ImageModel((10, 100))
    assert str(im) == '<ImageModel(10, 100)>'
    im.close()

    image = ROOT_DIR + "/nircam_mask.fits"
    im = MaskModel(image)
    assert str(im) == '<MaskModel(2048, 2048) from nircam_mask.fits>'
    im.close()
Beispiel #4
0
def test_open_asdf_model(init):
    # Open an empty asdf file, pass extra arguments
    with DataModel(init=init,
                   ignore_version_mismatch=False,
                   ignore_unrecognized_tag=True) as model:
        assert not model._asdf._ignore_version_mismatch
        assert model._asdf._ignore_unrecognized_tag
Beispiel #5
0
    def _create_source():
        dm = DataModel(FITS_FILE)

        assert dm.meta.instrument.name == 'MIRI'

        dm.meta.instrument.name = 'NIRCAM'
        dm.meta.subarray.xstart = 42
        return dm
Beispiel #6
0
def test_open_asdf_s3(s3_root_dir):
    """Test opening a model from an ASDF file on S3"""
    path = str(s3_root_dir.join("test.asdf"))
    with DataModel() as dm:
        dm.save(path)

    with datamodels.open("s3://test-s3-data/test.asdf") as m:
        assert isinstance(m, DataModel)
Beispiel #7
0
def test_default_input_with_new_model():
    """Test getting input name with new model"""

    step = StepWithModel()

    model = DataModel()
    step.run(model)

    assert step._input_filename is None
Beispiel #8
0
def test_stringify():
    im = DataModel()
    assert str(im) == '<DataModel>'

    im = ImageModel((10, 100))
    assert str(im) == '<ImageModel(10, 100)>'

    image = os.path.join(ROOT_DIR, "nircam_mask.fits")
    with MaskModel(image) as im:
        assert str(im) == '<MaskModel(2048, 2048) from nircam_mask.fits>'
Beispiel #9
0
def make_models(tmpdir_factory):
    """Create basic models

    Returns
    -------
    path_just_fits, path_model : (str, str)
        `path_just_fits` is a FITS file of `DataModel` without the ASDF extension.
        `path_model` is a FITS file of `DataModel` with the ASDF extension.
    """
    path = tmpdir_factory.mktemp('skip_fits_update')
    path_just_fits = str(path / 'just_fits.fits')
    path_model = str(path / 'model.fits')
    primary_hdu = fits.PrimaryHDU()
    primary_hdu.header['exp_type'] = 'NRC_IMAGE'
    hduls = fits.HDUList([primary_hdu])
    hduls.writeto(path_just_fits)
    model = DataModel(hduls)
    model.save(path_model)
    return {'just_fits': path_just_fits, 'model': path_model}
Beispiel #10
0
def test_stringify(tmpdir):
    im = DataModel()
    assert str(im) == '<DataModel>'

    im = ImageModel((10, 100))
    assert str(im) == '<ImageModel(10, 100)>'

    path = str(tmpdir.join("nircam_mask.fits"))
    m = MaskModel((2048, 2048))
    m.save(path)
    m.close()
    with MaskModel(path) as im:
        assert str(im) == '<MaskModel(2048, 2048) from nircam_mask.fits>'
Beispiel #11
0
def test_open_asdf_model():
    # Open an empty asdf file, pass extra arguments

    model = DataModel(init=None,
                      ignore_version_mismatch=False,
                      ignore_unrecognized_tag=True)

    assert model._asdf._ignore_version_mismatch == False
    assert model._asdf._ignore_unrecognized_tag == True
    model.close()

    # Open an existing asdf file

    model = DataModel(ASDF_FILE,
                      ignore_version_mismatch=False,
                      ignore_unrecognized_tag=True)

    assert model._asdf._ignore_version_mismatch == False
    assert model._asdf._ignore_unrecognized_tag == True
    model.close()
Beispiel #12
0
def data_model_list():
    pytest.importorskip("jwst")
    from jwst.datamodels import DataModel, ModelContainer

    models = []
    for k in range(6):
        m = DataModel()
        m.meta.observation.program_number = '0001'
        m.meta.observation.observation_number = '1'
        m.meta.observation.visit_number = '1'
        m.meta.observation.visit_group = '1'
        m.meta.observation.sequence_id = '01'
        m.meta.observation.activity_id = '1'
        m.meta.observation.exposure_number = '1'
        m.meta.instrument.name = 'NIRCAM'
        m.meta.instrument.channel = 'SHORT'
        m.meta.filename = 'file{:d}.fits'.format(k)
        models.append(m)

    models[-3].meta.observation.observation_number = '2'
    models[-2].meta.observation.observation_number = '3'
    models[-1].meta.observation.observation_number = '3'

    return ModelContainer(models)
Beispiel #13
0
def test_from_fits_write(dm):
    dm.to_fits(TMP_FITS, overwrite=True)
    return DataModel.from_fits(TMP_FITS)
Beispiel #14
0
def test_hasattr():
    model = DataModel()
    assert model.meta.hasattr('date')
    assert not model.meta.hasattr('filename')
Beispiel #15
0
def test_datamodel_raises_filenotfound():
    with pytest.raises(FileNotFoundError):
        DataModel(init='file_does_not_exist.fits')
Beispiel #16
0
def inputs(request):
    table = None

    instrument, exptype = request.param

    dm = DataModel()
    dm.meta.instrument.name = instrument
    dm.meta.exposure.type = exptype

    if instrument == 'MIRI':
        if 'LRS' in exptype:
            dm.meta.subarray.name = 'FULL'
            table = Table(
                {
                    'subarray': ['FULL', 'sub02'],
                    'nelem_wl': [3, 3],
                    'nelem_size': [3, 3],
                    'wavelength': [[1, 2, 3, 0], [1, 2, 3, 0]],
                    'size': [[1, 2, 3, 0], [1, 2, 3, 0]],
                    'apcorr': np.full((2, 4, 4), 0.5)
                }
            )

    if instrument == 'NIRSPEC':  # Too complicated to come up with silly example data; using "dummy" ref file
        dm.meta.instrument.filter = 'CLEAR'
        dm.meta.instrument.grating = 'PRISM'

        if 'FIXEDSLIT' in dm.meta.exposure.type:
            dm.meta.instrument.fixed_slit = 'S200A1'
            table = Table.read(NIR_TEST_FILES['FIXEDSLIT/BRIGHTOBJ'], format='fits')[:2]
        else:
            table = Table.read(NIR_TEST_FILES['MSASPEC'], format='fits')[:2]

        table['APCORR'] = table['APCORR'].reshape((len(table), 3, 2048, 3))  # Reshape test data to expected shape

    if instrument == 'NIRCAM':
        dm.meta.instrument.filter = 'F322W2'
        dm.meta.instrument.pupil = 'GRISMR'

        table = Table(
            {
                'filter': ['F322W2', 'filter02'],
                'pupil': ['GRISMR', 'pupil02'],
                'nelem_wl': [3, 3],
                'nelem_size': [3, 3],
                'wavelength': [[1, 2, 3, 0], [1, 2, 3, 0]],
                'size': [[1, 2, 3, 0], [1, 2, 3, 0]],
                'apcorr': np.full((2, 4, 4), 0.5)
            }
        )

    if instrument == 'NIRISS':
        dm.meta.instrument.filter = 'GR150R'
        dm.meta.instrument.pupil = 'F090W'

        table = Table(
            {
                'filter': ['GR150R', 'filter02'],
                'pupil': ['F090W', 'pupil02'],
                'nelem_wl': [3, 3],
                'nelem_size': [3, 3],
                'wavelength': [[1, 2, 3, 0], [1, 2, 3, 0]],
                'size': [[1, 2, 3, 0], [1, 2, 3, 0]],
                'apcorr': np.full((2, 4, 4), 0.5)
            }
        )

    return dm, fits.table_to_hdu(table).data
Beispiel #17
0
def empty_model():
    """Create an empy model"""
    return DataModel()
Beispiel #18
0
in the certification of reference files. 
"""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import os.path
import re

from crds import (log, rmap, data_file, config, utils, timestamp)
from . import tpn

# =======================================================================

try:
    from jwst.datamodels import DataModel
    MODEL = DataModel()
except Exception:
    MODEL = None

# =======================================================================

HERE = os.path.dirname(__file__) or "./"

# =======================================================================

def test():
    """Run the module doctests."""
    import doctest
    from . import locate
    return doctest.testmod(locate)
Beispiel #19
0
def test_copy_model():
    with DataModel() as dm:
        with DataModel(dm) as dm2:
            assert hasattr(dm2, 'meta')
Beispiel #20
0
def test_base_model_has_no_arrays():
    with pytest.raises(AttributeError):
        with DataModel() as dm:
            dm.data
Beispiel #21
0
def test_subarray():
    with DataModel(FITS_FILE) as dm:
        dm.meta.subarray.xstart
Beispiel #22
0
def test_delete():
    with DataModel() as dm:
        dm.meta.instrument.name = 'NIRCAM'
        assert dm.meta.instrument.name == 'NIRCAM'
        del dm.meta.instrument.name
        assert dm.meta.instrument.name is None