Esempio n. 1
0
def simple_norm(data, stretch='linear', power=1.0, asinh_a=0.1, log_a=1000,
                min_cut=None, max_cut=None, min_percent=None, max_percent=None,
                percent=None, clip=True):

    if percent is not None:
        interval = PercentileInterval(percent)
    elif min_percent is not None or max_percent is not None:
        interval = AsymmetricPercentileInterval(min_percent or 0.,
                                                max_percent or 100.)
    elif min_cut is not None or max_cut is not None:
        interval = ManualInterval(min_cut, max_cut)
    else:
        interval = MinMaxInterval()

    if stretch == 'linear':
        stretch = LinearStretch()
    elif stretch == 'sqrt':
        stretch = SqrtStretch()
    elif stretch == 'power':
        stretch = PowerStretch(power)
    elif stretch == 'log':
        stretch = LogStretch(log_a)
    elif stretch == 'asinh':
        stretch = AsinhStretch(asinh_a)
    else:
        raise ValueError('Unknown stretch: {0}.'.format(stretch))

    vmin, vmax = interval.get_limits(data)

    return ImageNormalize(vmin=vmin, vmax=vmax, stretch=stretch, clip=clip)
Esempio n. 2
0
    def test_invalid_data(self):
        data = np.arange(25.).reshape((5, 5))
        data[2, 2] = np.nan
        data[1, 2] = np.inf
        percent = 85.0
        interval = PercentileInterval(percent)

        # initialized without data
        norm = ImageNormalize(interval=interval)
        norm(data)  # sets vmin/vmax
        assert_equal((norm.vmin, norm.vmax), (1.65, 22.35))

        # initialized with data
        norm2 = ImageNormalize(data, interval=interval)
        assert_equal((norm2.vmin, norm2.vmax), (norm.vmin, norm.vmax))

        norm3 = simple_norm(data, 'linear', percent=percent)
        assert_equal((norm3.vmin, norm3.vmax), (norm.vmin, norm.vmax))

        assert_allclose(norm(data), norm2(data))
        assert_allclose(norm(data), norm3(data))

        norm4 = ImageNormalize()
        norm4(data)  # sets vmin/vmax
        assert_equal((norm4.vmin, norm4.vmax), (0, 24))

        norm5 = ImageNormalize(data)
        assert_equal((norm5.vmin, norm5.vmax), (norm4.vmin, norm4.vmax))
Esempio n. 3
0
def showNorm(imaOrCcd, **kwargs):
    from astropy.visualization import imshow_norm, SqrtStretch
    from astropy.visualization.mpl_normalize import PercentileInterval
    from astropy.nddata import CCDData

    plt.clf()
    fig = plt.gcf()
    if isinstance(imaOrCcd, CCDData):
        arr = imaOrCcd.data
        wcs = imaOrCcd.wcs
        if wcs is None:
            ax = plt.subplot()
        else:
            ax = plt.subplot(projection=wcs)
            ax.coords.grid(True, color='white', ls='solid')
    else:
        arr = imaOrCcd
        ax = plt.subplot()
    if 'interval' not in kwargs:
        kwargs['interval'] = PercentileInterval(99.7)
    if 'stretch' not in kwargs:
        kwargs['stretch'] = SqrtStretch()
    if 'origin' not in kwargs:
        kwargs['origin'] = 'lower'

    im, _ = imshow_norm(arr, ax=ax, **kwargs)

    cb = fig.colorbar(im)
    cb.ax.tick_params(labelsize=11)
Esempio n. 4
0
def showStarsFromIRAFTable(ima,
                           table,
                           color,
                           perc_interval=98,
                           aperture_radius=7):
    from photutils.aperture.circle import CircularAperture

    positions = (table['xcentroid'], table['ycentroid'])
    apertures = CircularAperture(positions, r=aperture_radius)
    showNorm(ima, interval=PercentileInterval(perc_interval))
    apertures.plot(color=color)
Esempio n. 5
0
def simple_norm(data,
                stretch='linear',
                power=1.0,
                asinh_a=0.1,
                log_a=1000,
                min_cut=None,
                max_cut=None,
                min_percent=None,
                max_percent=None,
                percent=None,
                clip=True):

    if percent is not None:
        interval = PercentileInterval(percent)
    elif min_percent is not None or max_percent is not None:
        interval = AsymmetricPercentileInterval(min_percent or 0., max_percent
                                                or 100.)
    elif min_cut is not None or max_cut is not None:
        interval = ManualInterval(min_cut, max_cut)
    else:
        interval = MinMaxInterval()

    if stretch == 'linear':
        stretch = LinearStretch()
    elif stretch == 'sqrt':
        stretch = SqrtStretch()
    elif stretch == 'power':
        stretch = PowerStretch(power)
    elif stretch == 'log':
        stretch = LogStretch(log_a)
    elif stretch == 'asinh':
        stretch = AsinhStretch(asinh_a)
    else:
        raise ValueError('Unknown stretch: {0}.'.format(stretch))

    vmin, vmax = interval.get_limits(data)

    return ImageNormalize(vmin=vmin, vmax=vmax, stretch=stretch, clip=clip)
Esempio n. 6
0
 def test_percentile(self):
     interval = PercentileInterval(62.2)
     vmin, vmax = interval.get_limits(self.data)
     np.testing.assert_allclose(vmin, -4.88)
     np.testing.assert_allclose(vmax, 44.88)
Esempio n. 7
0
 def test_percentile(self):
     interval = PercentileInterval(62.2)
     vmin, vmax = interval.get_limits(self.data)
     np.testing.assert_allclose(vmin, -4.88)
     np.testing.assert_allclose(vmax, 44.88)