コード例 #1
0
def test_flatfield_step_interface(instrument, exptype):
    """Test that the basic inferface works for data requiring a FLAT reffile"""

    shape = (20, 20)

    wfi_image = testutil.mk_level2_image(shape=shape)
    wfi_image.meta.instrument.name = instrument
    wfi_image.meta.instrument.detector = 'WFI01'
    wfi_image.meta.instrument.optical_element = 'F158'
    wfi_image.meta.exposure.type = exptype
    wfi_image.data = np.ones(shape, dtype=np.float32)
    wfi_image.dq = np.zeros(shape, dtype=np.uint32)
    wfi_image.err = np.zeros(shape, dtype=np.float32)
    wfi_image.var_poisson = np.zeros(shape, dtype=np.float32)
    wfi_image.var_rnoise = np.zeros(shape, dtype=np.float32)
    wfi_image.var_flat = np.zeros(shape, dtype=np.float32)
    wfi_image_model = ImageModel(wfi_image)
    flatref = stnode.FlatRef()
    meta = {}
    testutil.add_ref_common(meta)
    meta['instrument']['optical_element'] = 'F158'
    meta['instrument']['detector'] = 'WFI01'
    meta['reftype'] = 'FLAT'
    flatref['meta'] = meta
    flatref['data'] = np.ones(shape, dtype=np.float32)
    flatref['dq'] = np.zeros(shape, dtype=np.uint16)
    flatref['err'] = (np.random.random(shape) * 0.05).astype(np.float32)
    flatref_model = FlatRefModel(flatref)

    result = FlatFieldStep.call(wfi_image_model, override_flat=flatref_model)

    assert (result.data == wfi_image.data).all()
    assert result.var_flat.shape == shape
    assert result.meta.cal_step.flat_field == 'COMPLETE'
コード例 #2
0
def test_flat_model(tmp_path):
    # Set temporary asdf file
    file_path = tmp_path / "test.asdf"

    meta = {}
    utils.add_ref_common(meta)
    meta['reftype'] = "FLAT"
    flatref = stnode.FlatRef()
    flatref['meta'] = meta
    flatref.meta.instrument['optical_element'] = 'F062'
    shape = (4096, 4096)
    flatref['data'] = np.zeros(shape, dtype=np.float32)
    flatref['dq'] = np.zeros(shape, dtype=np.uint16)
    flatref['dq_def'] = np.zeros(10, dtype=table_definitions.DQ_DEF_DTYPE)
    flatref['err'] = np.zeros(shape, dtype=np.float32)

    # Testing flat file asdf file
    with asdf.AsdfFile(meta) as af:
        af.tree = {'roman': flatref}
        af.write_to(file_path)

        # Test that asdf file opens properly
        with datamodels.open(file_path) as model:
            with pytest.warns(None):
                model.validate()

            # Confirm that asdf file is opened as flat file model
            assert isinstance(model, datamodels.FlatRefModel)
コード例 #3
0
def generate_wfi_reffiles(tmpdir_factory):

    gainfile = str(tmpdir_factory.mktemp("ndata").join("gain.asdf"))
    readnoisefile = str(tmpdir_factory.mktemp("ndata").join('readnoise.asdf'))

    ingain = 6
    xsize = 20
    ysize = 20

    shape = (ysize, xsize)

    # Create temporary gain reference file
    gain_ref = rds.GainRef()

    meta = {}
    testutil.add_ref_common(meta)
    meta['instrument']['detector'] = 'WFI01'
    meta['instrument']['name'] = 'WF1'
    meta['author'] = 'John Doe'
    meta['reftype'] = 'GAIN'
    meta['pedigree'] = 'DUMMY'
    meta['description'] = 'DUMMY'
    meta['useafter'] = Time('2022-01-01T11:11:11.111')

    gain_ref['meta'] = meta
    gain_ref['data'] = np.ones(shape, dtype=np.float32) * ingain
    gain_ref['dq'] = np.zeros(shape, dtype=np.uint16)
    gain_ref['err'] = (np.random.random(shape) * 0.05).astype(np.float64)

    gain_ref_model = GainRefModel(gain_ref)
    gain_ref_model.save(gainfile)

    # Create temporary readnoise reference file
    rn_ref = rds.ReadnoiseRef()
    meta = {}
    testutil.add_ref_common(meta)
    meta['instrument']['detector'] = 'WFI01'
    meta['instrument']['name'] = 'WF1'
    meta['author'] = 'John Doe'
    meta['reftype'] = 'READNOISE'
    meta['pedigree'] = 'DUMMY'
    meta['description'] = 'DUMMY'
    meta['useafter'] = Time('2022-01-01T11:11:11.111')

    exposure = {}
    exposure['type'] = 'WFI_IMAGE'
    exposure['frame_time'] = 666

    rn_ref['meta'] = meta
    rn_ref['meta']['exposure'] = exposure
    rn_ref['data'] = np.ones(shape, dtype=np.float32)

    rn_ref_model = ReadnoiseRefModel(rn_ref)
    rn_ref_model.save(readnoisefile)

    return gainfile, readnoisefile
コード例 #4
0
ファイル: test_dq_init.py プロジェクト: ddavis-stsci/romancal
def test_dqinit_refpix(instrument, exptype):
    """Test that the basic inferface works for data requiring a DQ reffile"""

    # Set test size
    shape = (2, 20, 20)

    # Create test science raw model
    wfi_sci_raw = testutil.mk_level1_science_raw(shape)
    wfi_sci_raw.meta.instrument.name = instrument
    wfi_sci_raw.meta.instrument.detector = 'WFI01'
    wfi_sci_raw.meta.instrument.optical_element = 'F158'
    wfi_sci_raw.meta.exposure.type = exptype
    wfi_sci_raw.data = np.ones(shape, dtype=np.uint16)
    wfi_sci_raw_model = ScienceRawModel(wfi_sci_raw)

    # Create mask model
    maskref = stnode.MaskRef()
    meta = {}
    testutil.add_ref_common(meta)
    meta['instrument']['optical_element'] = 'F158'
    meta['instrument']['detector'] = 'WFI01'
    meta['reftype'] = 'MASK'
    maskref['meta'] = meta
    maskref['data'] = np.ones(shape[1:], dtype=np.float32)
    maskref['dq'] = np.zeros(shape[1:], dtype=np.uint16)
    maskref['err'] = (np.random.random(shape[1:]) * 0.05).astype(np.float32)
    maskref_model = MaskRefModel(maskref)


    # Perform Data Quality application step
    result = DQInitStep.call(wfi_sci_raw_model, override_mask=maskref_model)

    # check if reference pixels are correct
    assert result.data.shape == (2, 20, 20)  # no pixels should be trimmed
    assert result.amp33.shape == (2, 4096 ,128)
    assert result.border_ref_pix_right.shape == (2, 20, 4)
    assert result.border_ref_pix_left.shape == (2, 20, 4)
    assert result.border_ref_pix_top.shape == (2, 4, 20)
    assert result.border_ref_pix_bottom.shape == (2, 4, 20)
    assert result.dq_border_ref_pix_right.shape == (20, 4)
    assert result.dq_border_ref_pix_left.shape == (20, 4)
    assert result.dq_border_ref_pix_top.shape == (4, 20)
    assert result.dq_border_ref_pix_bottom.shape == (4, 20)
コード例 #5
0
ファイル: test_dq_init.py プロジェクト: ddavis-stsci/romancal
def test_dqinit_step_interface(instrument, exptype):
    """Test that the basic inferface works for data requiring a DQ reffile"""

    # Set test size
    shape = (2, 20, 20)

    # Create test science raw model
    wfi_sci_raw = testutil.mk_level1_science_raw(shape)
    wfi_sci_raw.meta.instrument.name = instrument
    wfi_sci_raw.meta.instrument.detector = 'WFI01'
    wfi_sci_raw.meta.instrument.optical_element = 'F158'
    wfi_sci_raw.meta.exposure.type = exptype
    wfi_sci_raw.data = np.ones(shape, dtype=np.uint16)
    wfi_sci_raw_model = ScienceRawModel(wfi_sci_raw)

    # Create mask model
    maskref = stnode.MaskRef()
    meta = {}
    testutil.add_ref_common(meta)
    meta['instrument']['optical_element'] = 'F158'
    meta['instrument']['detector'] = 'WFI01'
    meta['reftype'] = 'MASK'
    maskref['meta'] = meta
    maskref['data'] = np.ones(shape[1:], dtype=np.float32)
    maskref['dq'] = np.zeros(shape[1:], dtype=np.uint16)
    maskref['err'] = (np.random.random(shape[1:]) * 0.05).astype(np.float32)
    maskref_model = MaskRefModel(maskref)

    # Perform Data Quality application step
    result = DQInitStep.call(wfi_sci_raw_model, override_mask=maskref_model)

    # Test dq_init results
    assert (result.data == wfi_sci_raw.data).all()
    assert result.pixeldq.shape == shape[1:]
    assert result.meta.cal_step.dq_init == 'COMPLETE'
    assert result.data.dtype == np.float32
    assert result.err.dtype == np.float32
    assert result.pixeldq.dtype == np.uint32
    assert result.groupdq.dtype == np.uint8