How to use the photutils.utils.check_random_state function in photutils

To help you get started, we’ve selected a few photutils 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 astropy / photutils / photutils / datasets / make.py View on Github external
>>> param_ranges = OrderedDict(param_ranges)
    >>> sources = make_random_models_table(n_sources, param_ranges,
    ...                                    random_state=12345)
    >>> for col in sources.colnames:
    ...     sources[col].info.format = '%.8g'  # for consistent table output
    >>> print(sources)
    amplitude   x_mean    y_mean   x_stddev  y_stddev   theta
    --------- --------- --------- --------- --------- ----------
    964.80805 297.77235 224.31444 3.6256447 3.5699013  2.2923859
    658.18778 482.25726 288.39202 4.2392502 3.8698145  3.1227889
    591.95941 326.58855 2.5164894 4.4887037  2.870396  2.1264615
    602.28014 374.45332 31.933313 4.8585904 2.3023387  2.4844422
    783.86251 326.78494 89.611114 3.8947414 2.7585784 0.53694298
    """

    prng = check_random_state(random_state)

    sources = Table()
    for param_name, (lower, upper) in param_ranges.items():
        # Generate a column for every item in param_ranges, even if it
        # is not in the model (e.g. flux).  However, such columns will
        # be ignored when rendering the image.
        sources[param_name] = prng.uniform(lower, upper, n_sources)

    return sources
github astropy / photutils / photutils / datasets / make.py View on Github external
stddev=5.)
        image2 = make_noise_image(shape, distribution='poisson', mean=5.)

        # plot the images
        import matplotlib.pyplot as plt
        fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))
        ax1.imshow(image1, origin='lower', interpolation='nearest')
        ax1.set_title('Gaussian noise ($\\mu=0$, $\\sigma=5.$)')
        ax2.imshow(image2, origin='lower', interpolation='nearest')
        ax2.set_title('Poisson noise ($\\mu=5$)')
    """

    if mean is None:
        raise ValueError('"mean" must be input')

    prng = check_random_state(random_state)

    if distribution == 'gaussian':
        if stddev is None:
            raise ValueError('"stddev" must be input for Gaussian noise')
        image = prng.normal(loc=mean, scale=stddev, size=shape)
    elif distribution == 'poisson':
        image = prng.poisson(lam=mean, size=shape)
    else:
        raise ValueError('Invalid distribution: {0}. Use either "gaussian" '
                         'or "poisson".'.format(distribution))

    return image
github astropy / photutils / photutils / datasets / make.py View on Github external
data2 = apply_poisson_noise(data1, random_state=12345)

        # plot the images
        import matplotlib.pyplot as plt
        fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 8))
        ax1.imshow(data1, origin='lower', interpolation='nearest')
        ax1.set_title('Original image')
        ax2.imshow(data2, origin='lower', interpolation='nearest')
        ax2.set_title('Original image with Poisson noise applied')
    """

    data = np.asanyarray(data)
    if np.any(data < 0):
        raise ValueError('data must not contain any negative values')

    prng = check_random_state(random_state)

    return prng.poisson(data)