How to use jwst - 10 common examples

To help you get started, we’ve selected a few jwst examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spacetelescope / jwql / jwql / instrument_monitors / common_monitors / bias_monitor.py View on Github external
Returns
        -------
        output_filename : str
            The full path to the calibrated file
        """

        output_filename = filename.replace('_uncal', '').replace('.fits', '_superbias_refpix.fits')

        if not os.path.isfile(output_filename):
            # Run the group_scale and dq_init steps on the input file
            if group_scale:
                model = GroupScaleStep.call(filename)
                model = DQInitStep.call(model)
            else:
                model = DQInitStep.call(filename)

            # Run the saturation and superbias steps
            model = SaturationStep.call(model)
            model = SuperBiasStep.call(model)

            # Run the refpix step and save the output
            model = RefPixStep.call(model, odd_even_rows=odd_even_rows, odd_even_columns=odd_even_columns, use_side_ref_pixels=use_side_ref_pixels)
            model.save(output_filename)
            set_permissions(output_filename)
        else:
            logging.info('\t{} already exists'.format(output_filename))

        return output_filename
github spacetelescope / jwql / jwql / instrument_monitors / common_monitors / bias_monitor.py View on Github external
Option to rescale pixel values to correct for instances where
            on-board frame averaging did not result in the proper values

        Returns
        -------
        output_filename : str
            The full path to the calibrated file
        """

        output_filename = filename.replace('_uncal', '').replace('.fits', '_superbias_refpix.fits')

        if not os.path.isfile(output_filename):
            # Run the group_scale and dq_init steps on the input file
            if group_scale:
                model = GroupScaleStep.call(filename)
                model = DQInitStep.call(model)
            else:
                model = DQInitStep.call(filename)

            # Run the saturation and superbias steps
            model = SaturationStep.call(model)
            model = SuperBiasStep.call(model)

            # Run the refpix step and save the output
            model = RefPixStep.call(model, odd_even_rows=odd_even_rows, odd_even_columns=odd_even_columns, use_side_ref_pixels=use_side_ref_pixels)
            model.save(output_filename)
            set_permissions(output_filename)
        else:
            logging.info('\t{} already exists'.format(output_filename))

        return output_filename
github spacetelescope / jwql / jwql / instrument_monitors / common_monitors / bad_pixel_monitor.py View on Github external
-------
    x_loc : list
        List of x locations within ``badpix_image`` containing
        ``mnemonic`` pixels.

    y_loc : list
        List of x locations within ``badpix_image`` containing
        ``mnemonic`` pixels.
    """
    mnemonic = mnemonic.upper()
    possible_mnemonics = dqflags.pixel.keys()
    if mnemonic not in possible_mnemonics:
        raise ValueError("ERROR: Unrecognized bad pixel mnemonic: {}".format(mnemonic))

    # Find locations of this type of bad pixel
    y_loc, x_loc = np.where(badpix_image & dqflags.pixel[mnemonic] > 0)

    # Convert from numpy int to python native int, in order to avoid SQL
    # error when adding to the database tables.
    y_location = [int(element) for element in y_loc]
    x_location = [int(element) for element in x_loc]

    return x_location, y_location
github spacetelescope / jwql / jwql / instrument_monitors / common_monitors / bad_pixel_monitor.py View on Github external
mnemonic : str
        The type of bad pixel to map. The mnemonic must be one of those
        in the JWST calibration pipeline's list of possible mnemonics

    Returns
    -------
    x_loc : list
        List of x locations within ``badpix_image`` containing
        ``mnemonic`` pixels.

    y_loc : list
        List of x locations within ``badpix_image`` containing
        ``mnemonic`` pixels.
    """
    mnemonic = mnemonic.upper()
    possible_mnemonics = dqflags.pixel.keys()
    if mnemonic not in possible_mnemonics:
        raise ValueError("ERROR: Unrecognized bad pixel mnemonic: {}".format(mnemonic))

    # Find locations of this type of bad pixel
    y_loc, x_loc = np.where(badpix_image & dqflags.pixel[mnemonic] > 0)

    # Convert from numpy int to python native int, in order to avoid SQL
    # error when adding to the database tables.
    y_location = [int(element) for element in y_loc]
    x_location = [int(element) for element in x_loc]

    return x_location, y_location
github spacetelescope / jwql / jwql / utils / instrument_properties.py View on Github external
if omit_reference_pixels:

        # If requested, ignore reference pixels by adjusting the indexes of
        # the amp boundaries.
        with fits.open(filename) as hdu:
            try:
                data_quality = hdu['DQ'].data
            except KeyError:
                raise KeyError('DQ extension not found.')


        # Reference pixels should be flagged in the DQ array with the
        # REFERENCE_PIXEL flag. Find the science pixels by looping for
        # pixels that don't have that bit set.
        scipix = np.where(data_quality & dqflags.pixel['REFERENCE_PIXEL'] == 0)
        ymin = np.min(scipix[0])
        xmin = np.min(scipix[1])
        ymax = np.max(scipix[0]) + 1
        xmax = np.max(scipix[1]) + 1

        # Adjust the minimum and maximum x and y values if they are within
        # the reference pixels
        for key in amp_bounds:
            bounds = amp_bounds[key]
            prev_xmin, prev_ymin = bounds[0]
            prev_xmax, prev_ymax = bounds[1]
            if prev_xmin < xmin:
                new_xmin = xmin
            else:
                new_xmin = prev_xmin
            if prev_ymin < ymin:
github spacetelescope / jwql / jwql / utils / preview_image.py View on Github external
for exten in hdulist:
                    try:
                        extnames.append(exten.header['EXTNAME'])
                    except:
                        pass
                if ext in extnames:
                    dimensions = len(hdulist[ext].data.shape)
                    if dimensions == 4:
                        data = hdulist[ext].data[:, [0, -1], :, :].astype(np.float)
                    else:
                        data = hdulist[ext].data.astype(np.float)
                else:
                    raise ValueError(('WARNING: no {} extension in {}!'.format(ext, filename)))
                if 'PIXELDQ' in extnames:
                    dq = hdulist['PIXELDQ'].data
                    dq = (dq & dqflags.pixel['NON_SCIENCE'] == 0)
                else:
                    yd, xd = data.shape[-2:]
                    dq = np.ones((yd, xd), dtype="bool")

                # Collect information on aperture location within the
                # full detector. This is needed for mosaicking NIRCam
                # detectors later.
                self.xstart = hdulist[0].header['SUBSTRT1']
                self.ystart = hdulist[0].header['SUBSTRT2']
                self.xlen = hdulist[0].header['SUBSIZE1']
                self.ylen = hdulist[0].header['SUBSIZE2']
        else:
            raise FileNotFoundError(('WARNING: {} does not exist!'.format(filename)))

        return data, dq
github spacetelescope / jwql / jwql / instrument_monitors / common_monitors / bias_monitor.py View on Github external
group_scale : bool
            Option to rescale pixel values to correct for instances where
            on-board frame averaging did not result in the proper values

        Returns
        -------
        output_filename : str
            The full path to the calibrated file
        """

        output_filename = filename.replace('_uncal', '').replace('.fits', '_superbias_refpix.fits')

        if not os.path.isfile(output_filename):
            # Run the group_scale and dq_init steps on the input file
            if group_scale:
                model = GroupScaleStep.call(filename)
                model = DQInitStep.call(model)
            else:
                model = DQInitStep.call(filename)

            # Run the saturation and superbias steps
            model = SaturationStep.call(model)
            model = SuperBiasStep.call(model)

            # Run the refpix step and save the output
            model = RefPixStep.call(model, odd_even_rows=odd_even_rows, odd_even_columns=odd_even_columns, use_side_ref_pixels=use_side_ref_pixels)
            model.save(output_filename)
            set_permissions(output_filename)
        else:
            logging.info('\t{} already exists'.format(output_filename))

        return output_filename
github spacetelescope / jwql / jwql / instrument_monitors / common_monitors / bias_monitor.py View on Github external
output_filename = filename.replace('_uncal', '').replace('.fits', '_superbias_refpix.fits')

        if not os.path.isfile(output_filename):
            # Run the group_scale and dq_init steps on the input file
            if group_scale:
                model = GroupScaleStep.call(filename)
                model = DQInitStep.call(model)
            else:
                model = DQInitStep.call(filename)

            # Run the saturation and superbias steps
            model = SaturationStep.call(model)
            model = SuperBiasStep.call(model)

            # Run the refpix step and save the output
            model = RefPixStep.call(model, odd_even_rows=odd_even_rows, odd_even_columns=odd_even_columns, use_side_ref_pixels=use_side_ref_pixels)
            model.save(output_filename)
            set_permissions(output_filename)
        else:
            logging.info('\t{} already exists'.format(output_filename))

        return output_filename
github spacetelescope / jwql / jwql / instrument_monitors / common_monitors / bias_monitor.py View on Github external
output_filename : str
            The full path to the calibrated file
        """

        output_filename = filename.replace('_uncal', '').replace('.fits', '_superbias_refpix.fits')

        if not os.path.isfile(output_filename):
            # Run the group_scale and dq_init steps on the input file
            if group_scale:
                model = GroupScaleStep.call(filename)
                model = DQInitStep.call(model)
            else:
                model = DQInitStep.call(filename)

            # Run the saturation and superbias steps
            model = SaturationStep.call(model)
            model = SuperBiasStep.call(model)

            # Run the refpix step and save the output
            model = RefPixStep.call(model, odd_even_rows=odd_even_rows, odd_even_columns=odd_even_columns, use_side_ref_pixels=use_side_ref_pixels)
            model.save(output_filename)
            set_permissions(output_filename)
        else:
            logging.info('\t{} already exists'.format(output_filename))

        return output_filename
github spacetelescope / jwql / jwql / instrument_monitors / common_monitors / bias_monitor.py View on Github external
The full path to the calibrated file
        """

        output_filename = filename.replace('_uncal', '').replace('.fits', '_superbias_refpix.fits')

        if not os.path.isfile(output_filename):
            # Run the group_scale and dq_init steps on the input file
            if group_scale:
                model = GroupScaleStep.call(filename)
                model = DQInitStep.call(model)
            else:
                model = DQInitStep.call(filename)

            # Run the saturation and superbias steps
            model = SaturationStep.call(model)
            model = SuperBiasStep.call(model)

            # Run the refpix step and save the output
            model = RefPixStep.call(model, odd_even_rows=odd_even_rows, odd_even_columns=odd_even_columns, use_side_ref_pixels=use_side_ref_pixels)
            model.save(output_filename)
            set_permissions(output_filename)
        else:
            logging.info('\t{} already exists'.format(output_filename))

        return output_filename