Пример #1
0
def blot_segmap(filename, files):
    """
    Blots the segmap values from the drizzled image onto the individual
    files than went into the drizzle, and write these out as new segmaps.

    Parameters
    ----------
    filename : str
        The drizzled file.

    files : list
        The files that went into creating the drizzled file.

    Outputs
    -------
    {file}_seg.fits
        A corresponding segmap for each file in files.
    """

    # Make an image model using the drizzled image WCS and the corresponding
    # segmentation maps data.
    drizzle_model = ImageModel(filename)
    drizzle_segmap = fits.getdata(filename.replace('.fits', '_seg.fits'))
    drizzle_segmap[drizzle_segmap != 0] = 1
    drizzle_model.data = drizzle_segmap

    # Blot the segmap data from the drizzled image onto each individual file,
    # and write out the corresponding segmap for each.
    for f in files:
        outfile = f.replace('.fits', '_seg.fits')
        model = ImageModel(f)
        blotted_data = gwcs_blot(drizzle_model, model, interp='nearest')
        fits.writeto(outfile, blotted_data, overwrite=True)
Пример #2
0
def test_boundingbox_from_indices():
    dm = ImageModel()
    dm.data = np.ones((10,10))

    bbox = ((1,2), (3,4))

    result = boundingbox_to_indices(dm, bbox)

    assert (result == (1, 3, 3, 5))
Пример #3
0
    def _im(ysize, xsize):
        # create the data arrays
        im = ImageModel((ysize, xsize))
        im.data = np.random.rand(ysize, xsize)

        return im
im.meta.wcsinfo.pa_v3 = header_slp['PA_V3']
print(im.meta.wcsinfo.pa_v3)
im.meta.wcsinfo.ra_ref = header_slp['RA_REF']
im.meta.wcsinfo.dec_ref = header_slp['DEC_REF']
im.meta.wcsinfo.roll_ref = header_slp['ROLL_REF']

references = {
    "area": "crds/jwst_nircam_area_0017.fits",
    "distortion": "crds/jwst_nircam_distortion_0093.asdf",
    "drizpars": "crds/jwst_nircam_drizpars_0001.fits",
    "flat": "crds/jwst_nircam_flat_0337.fits",
    "photom": "crds/jwst_nircam_photom_0074.fits"
}
load_wcs(im, references)

im.data = hdul_rate['SCI'].data
im.err = hdul_rate['ERR'].data
im.dq = hdul_rate['DQ'].data
im.var_poisson = hdul_rate['VAR_POISSON'].data
im.var_rnoise = hdul_rate['VAR_RNOISE'].data

im.meta.target.proper_motion_epoch = "2000"
im.meta.dither.primary_type = "IMAGING"

ra_ref = header_slp['RA_REF']
dec_ref = header_slp['DEC_REF']
crval1_ra = header_slp['CRVAL1']
crval2_dec = header_slp['CRVAL2']
targ_ra = header_slp['TARG_RA']
targ_dec = header_slp['TARG_DEC']
Пример #5
0
def test_flag():
    wcsinfo = {
        'dec_ref': -0.00601415671349804,
        'ra_ref': -0.02073605215697509,
        'roll_ref': -0.0,
        'v2_ref': -453.5134,
        'v3_ref': -373.4826,
        'v3yangle': 0.0,
        'vparity': -1}

    instrument = {
        'detector': 'NRS1',
        'filter': 'F100LP',
        'grating': 'G140M',
        'name': 'NIRSPEC',
        'gwa_tilt': 37.0610,
        'gwa_xtilt': 0.0001,
        'gwa_ytilt': 0.0001,
        'msa_metadata_id':12}

    observation = {
        'date': '2016-09-05',
        'time': '8:59:37'}

    exposure = {
        'duration': 11.805952,
        'end_time': 58119.85416,
        'exposure_time': 11.776,
        'frame_time': 0.11776,
        'group_time': 0.11776,
        'groupgap': 0,
        'integration_time': 11.776,
        'nframes': 1,
        'ngroups': 100,
        'nints': 1,
        'nresets_between_ints': 0,
        'nsamples': 1,
        'readpatt': 'NRSRAPID',
        'sample_time': 10.0,
        'start_time': 58119.8333,
        'type': 'NRS_MSASPEC',
        'zero_frame': False}

    im = ImageModel()
    im.data = np.random.rand(2048, 2048)
    im.error = np.random.rand(2048, 2048)
    im.dq = np.zeros((2048, 2048))

    im.meta.wcsinfo._instance.update(wcsinfo)
    im.meta.instrument._instance.update(instrument)
    im.meta.observation._instance.update(observation)
    im.meta.exposure._instance.update(exposure)

    metafl = get_file_path('msa_configuration.fits')
    im.meta.instrument.msa_metadata_file = metafl
    im.meta.dither.position_number = 1

    step = AssignWcsStep()
    msa_oper = step.get_reference_file(im, 'msaoper')

    im = step.call(im)

    wcs_ref_files = create_reference_filename_dictionary(im)

    failed_slitlets = create_slitlets(im, msa_oper)

    result = flag(im, failed_slitlets, wcs_ref_files)

    msa_open_dq = 536870912

    # Get all dqflags that are nonzero
    nonzero = np.nonzero(result.dq)

    # Make sure that all nonzero dqs are equal to the msa_open_dq
    assert (all(x == msa_open_dq for x in result.dq[nonzero]))