Noise & Random Deviates

Random deviates

class jax_galsim.BaseDeviate(seed=None)[source]

Bases: object

Base class for all the various random deviates.

LAX-backend implementation of galsim.random.BaseDeviate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim PRNGs have some support for linking states, but it may not always work and/or may cause issues.

  • Linked states across JIT boundaries or devices will not work.

  • Within a single routine linking may work.

  • You may encounter errors related to global side effects for some combinations of linked states and jitted/vmapped routines.

Seeding the JAX-GalSim PRNG can be done in a few ways:

  • pass seed=None (This is equivalent to passing seed=0.)

  • pass an integer seed (This method will throw errors if the integer is traced by JAX.)

  • pass another JAX-GalSim PRNG

  • pass a JAX PRNG key made via jax.random.key.

JAX PRNG keys made via `jax.random.PRNGKey` are not supported.

When using JAX-GalSim PRNGs and JIT, you should always return the PRNG from the function and then set the state on input PRNG via prng.reset(new_prng). This will ensure that the PRNG state is propagated correctly outside the JITed code.

Original GalSim Documentation

This holds the essential random number generator that all the other classes use.

All deviates take an initial seed argument that is used to seed the underlying random number generator. It has three different kinds of behavior.

  1. An integer value can be provided to explicitly seed the random number generator with a particular value. This is useful to have deterministic behavior. If you seed with an integer value, the subsequent series of “random” values will be the same each time you run the program.

  2. A seed of 0 or None means to pick some arbitrary value that will be different each time you run the program. Currently, this tries to get a seed from /dev/urandom if possible. If that doesn’t work, then it creates a seed from the current time. You can also get this behavior by omitting the seed argument entirely. (i.e. the default is None.)

  3. Providing another BaseDeviate object as the seed will make the new BaseDeviate share the same underlying random number generator as the other BaseDeviate. So you can make one BaseDeviate (of any type), and seed it with a particular deterministic value. Then if you pass that BaseDeviate to any other one you make, they will both be using the same RNG and the series of “random” values will be deterministic.

Usage:

The only kind of random number you can obtain from a pure BaseDeviate (i.e. one that is not actually one of the variosu subclasses) is a “raw” value. This is an unsigned 32-bit integer that behind the scenes is used by all sub-classes to generate floating point values with various distributions.

>>> rng = galsim.BaseDeviate(215324)
>>> rng.raw()
3559052779

Most other usage is effected by creating sub-classes corresponding to particular random deviates with various distributions. E.g. UniformDeviate generates random values following a uniform distribution between 0 and 1.

>>> rng = galsim.BaseDeviate(215324)
>>> ud = galsim.UniformDeviate(rng)
>>> ud()
0.58736140513792634
>>> ud2 = galsim.UniformDeviate(215324)
>>> ud2()
0.58736140513792634
property has_reliable_discard

Indicates whether the generator always uses 1 rng per value.

LAX-backend implementation of has_reliable_discard().

Original GalSim Documentation

If it does, then discard can reliably be used to keep two generators in sync when one of them generated some values and the other didn’t.

This is False for PoissonDeviate, Chi2Deviate, and GammaDeviate.

See also BaseDeviate.generates_in_pairs.

property generates_in_pairs

Indicates whether the generator uses 2 rngs values per 2 returned values.

LAX-backend implementation of generates_in_pairs().

Original GalSim Documentation

GaussianDeviate has a slight wrinkle to the BaseDeviate.has_reliable_discard story. It always uses two rng values to generate two Gaussian deviates. So if the number of generated values is even, then discard can keep things in sync. However, if an odd number of values are generated, then you to generate one more value (and discard it) to keep things synced up.

This is only True for GaussianDeviate.

seed(seed=None)[source]

Seed the pseudo-random number generator with a given integer value.

LAX-backend implementation of galsim.random.seed().

🔪 JAX-GalSim - The Sharp Bits 🔪

The JAX version of this method does no type checking.

Parameters:

seed – An int value to be used to seed the random number generator. Using 0 means to generate a seed from the system. [default: 0]

reset(seed=None)[source]

Reset the pseudo-random number generator, severing connections to any other deviates. Providing another BaseDeviate object as the seed connects this deviate with the other one, so they will both use the same underlying random number generator.

LAX-backend implementation of galsim.random.reset().

🔪 JAX-GalSim - The Sharp Bits 🔪

The JAX version of this method does no type checking.

Parameters:

seed – Something that can seed a BaseDeviate: an integer seed or another BaseDeviate. Using None means to generate a seed from the system. [default: None]

serialize()[source]
property np

Shorthand for self.as_numpy_generator()

LAX-backend implementation of np().

as_numpy_generator()[source]

Return a numpy.random.Generator object that uses the current BaseDeviate for the underlying bit generations.

LAX-backend implementation of galsim.random.as_numpy_generator().

Original GalSim Documentation

This allows you to use the (probably) more familiar numpy functions, while maintaining GalSim’s guarantees about random number stability across platforms.

Example:

>>> rng = galsim.BaseDeviate(1234)
>>> gen = rng.as_numpy_generator()
>>> uniform = gen.uniform(1, 10, size=10)
>>> norm = gen.normal(0, 3, size=20)

There is also a shorthand syntax that may be convenient. The property np is equivalent to this method, so you can also write:

>>> uniform = rng.np.uniform(1, 10, size=10)
>>> norm = rng.np.normal(0, 3, size=20)
clearCache()[source]

Clear the internal cache of the BaseDeviate, if any. This is currently only relevant for GaussianDeviate, since it generates two values at a time, saving the second one to use for the next output value.

LAX-backend implementation of galsim.random.clearCache().

🔪 JAX-GalSim - The Sharp Bits 🔪

This method is a no-op for the JAX version of this class.

discard(n, suppress_warnings=False)[source]

Discard n values from the current sequence of pseudo-random numbers.

LAX-backend implementation of galsim.random.discard().

🔪 JAX-GalSim - The Sharp Bits 🔪

The JAX version of this class has reliable discarding and uses one key per value so it never generates in pairs. Thus this method will never raise an error.

Parameters:
  • n – The number of raw random numbers to discard.

  • suppress_warnings – Whether to suppress warnings related to detecting when this action is not likely to reliably keep two random number generators in sync. [default: False]

Original GalSim Documentation

This is typically used to keep two random number generators in sync when one of them is used to generate some random values. The other can quickly discard the same number of random values to stay in sync with the first one.

raw()[source]

Generate the next pseudo-random number and rather than return the appropriate kind of random deviate for this class, just return the raw integer value that would have been used to generate this value.

LAX-backend implementation of galsim.random.raw().

🔪 JAX-GalSim - The Sharp Bits 🔪

The JAX version of this class does not use the raw value to generate the next value of a specific kind.

generate(array)[source]

Generate many pseudo-random values, filling in the values of a numpy array.

LAX-backend implementation of galsim.random.generate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX arrays cannot be changed in-place, so the JAX version of this method returns a new array.

add_generate(array)[source]

Generate many pseudo-random values, adding them to the values of a numpy array.

LAX-backend implementation of galsim.random.add_generate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX arrays cannot be changed in-place, so the JAX version of this method returns a new array.

duplicate()[source]

Create a duplicate of the current BaseDeviate object.

LAX-backend implementation of galsim.random.duplicate().

Original GalSim Documentation

The subsequent series from each copy of the BaseDeviate will produce identical values:

>>> u = galsim.UniformDeviate(31415926)
>>> u()
0.17100770119577646
>>> u2 = u.duplicate()
>>> u()
0.49095047544687986
>>> u()
0.10306670609861612
>>> u2()
0.49095047544687986
>>> u2()
0.10306670609861612
>>> u2()
0.13129289541393518
>>> u()
0.13129289541393518
tree_flatten()[source]

This function flattens the PRNG into a list of children nodes that will be traced by JAX and auxiliary static data.

classmethod tree_unflatten(aux_data, children)[source]

Recreates an instance of the class from flatten representation

class jax_galsim.UniformDeviate(seed=None)[source]

Bases: BaseDeviate

Pseudo-random number generator with uniform distribution in interval [0.,1.).

LAX-backend implementation of galsim.random.UniformDeviate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim PRNGs have some support for linking states, but it may not always work and/or may cause issues.

  • Linked states across JIT boundaries or devices will not work.

  • Within a single routine linking may work.

  • You may encounter errors related to global side effects for some combinations of linked states and jitted/vmapped routines.

Seeding the JAX-GalSim PRNG can be done in a few ways:

  • pass seed=None (This is equivalent to passing seed=0.)

  • pass an integer seed (This method will throw errors if the integer is traced by JAX.)

  • pass another JAX-GalSim PRNG

  • pass a JAX PRNG key made via jax.random.key.

JAX PRNG keys made via `jax.random.PRNGKey` are not supported.

When using JAX-GalSim PRNGs and JIT, you should always return the PRNG from the function and then set the state on input PRNG via prng.reset(new_prng). This will ensure that the PRNG state is propagated correctly outside the JITed code.

Parameters:

seed – Something that can seed a BaseDeviate: an integer seed or another BaseDeviate. Using 0 means to generate a seed from the system. [default: None]

Original GalSim Documentation

Successive calls to u() generate pseudo-random values distributed uniformly in the interval [0., 1.):

>>> u = galsim.UniformDeviate(31415926)
>>> u()
0.17100770119577646
>>> u()
0.49095047544687986
class jax_galsim.GaussianDeviate(seed=None, mean=0.0, sigma=1.0)[source]

Bases: BaseDeviate

Pseudo-random number generator with Gaussian distribution.

LAX-backend implementation of galsim.random.GaussianDeviate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim PRNGs have some support for linking states, but it may not always work and/or may cause issues.

  • Linked states across JIT boundaries or devices will not work.

  • Within a single routine linking may work.

  • You may encounter errors related to global side effects for some combinations of linked states and jitted/vmapped routines.

Seeding the JAX-GalSim PRNG can be done in a few ways:

  • pass seed=None (This is equivalent to passing seed=0.)

  • pass an integer seed (This method will throw errors if the integer is traced by JAX.)

  • pass another JAX-GalSim PRNG

  • pass a JAX PRNG key made via jax.random.key.

JAX PRNG keys made via `jax.random.PRNGKey` are not supported.

When using JAX-GalSim PRNGs and JIT, you should always return the PRNG from the function and then set the state on input PRNG via prng.reset(new_prng). This will ensure that the PRNG state is propagated correctly outside the JITed code.

Parameters:
  • seed – Something that can seed a BaseDeviate: an integer seed or another BaseDeviate. Using 0 means to generate a seed from the system. [default: None]

  • mean – Mean of Gaussian distribution. [default: 0.]

  • sigma – Sigma of Gaussian distribution. [default: 1.; Must be > 0]

Original GalSim Documentation

See http://en.wikipedia.org/wiki/Gaussian_distribution for further details.

Successive calls to g() generate pseudo-random values distributed according to a Gaussian distribution with the provided mean, sigma:

>>> g = galsim.GaussianDeviate(31415926)
>>> g()
0.5533754000847082
>>> g()
1.0218588970190354
property mean

The mean of the Gaussian distribution.

LAX-backend implementation of mean().

property sigma

The sigma of the Gaussian distribution.

LAX-backend implementation of sigma().

generate(array)[source]

Generate many pseudo-random values, filling in the values of a numpy array.

LAX-backend implementation of galsim.random.generate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX arrays cannot be changed in-place, so the JAX version of this method returns a new array.

generate_from_variance(array)[source]

Generate many Gaussian deviate values using the existing array values as the variance for each.

LAX-backend implementation of galsim.random.generate_from_variance().

class jax_galsim.PoissonDeviate(seed=None, mean=1.0)[source]

Bases: BaseDeviate

Pseudo-random Poisson deviate with specified mean.

LAX-backend implementation of galsim.random.PoissonDeviate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim PRNGs have some support for linking states, but it may not always work and/or may cause issues.

  • Linked states across JIT boundaries or devices will not work.

  • Within a single routine linking may work.

  • You may encounter errors related to global side effects for some combinations of linked states and jitted/vmapped routines.

Seeding the JAX-GalSim PRNG can be done in a few ways:

  • pass seed=None (This is equivalent to passing seed=0.)

  • pass an integer seed (This method will throw errors if the integer is traced by JAX.)

  • pass another JAX-GalSim PRNG

  • pass a JAX PRNG key made via jax.random.key.

JAX PRNG keys made via `jax.random.PRNGKey` are not supported.

When using JAX-GalSim PRNGs and JIT, you should always return the PRNG from the function and then set the state on input PRNG via prng.reset(new_prng). This will ensure that the PRNG state is propagated correctly outside the JITed code.

Parameters:
  • seed – Something that can seed a BaseDeviate: an integer seed or another BaseDeviate. Using 0 means to generate a seed from the system. [default: None]

  • mean – Mean of the distribution. [default: 1; Must be > 0]

Original GalSim Documentation

The input mean sets the mean and variance of the Poisson deviate. An integer deviate with this distribution is returned after each call. See http://en.wikipedia.org/wiki/Poisson_distribution for more details.

Successive calls to p() generate pseudo-random integer values distributed according to a Poisson distribution with the specified mean:

>>> p = galsim.PoissonDeviate(31415926, mean=100)
>>> p()
94
>>> p()
106
property mean

The mean of the distribution.

LAX-backend implementation of mean().

generate(array)[source]

Generate many pseudo-random values, filling in the values of a numpy array.

LAX-backend implementation of galsim.random.generate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX arrays cannot be changed in-place, so the JAX version of this method returns a new array.

generate_from_expectation(array)[source]

Generate many Poisson deviate values using the existing array values as the expectation value (aka mean) for each.

LAX-backend implementation of galsim.random.generate_from_expectation().

class jax_galsim.Chi2Deviate(seed=None, n=1.0)[source]

Bases: BaseDeviate

Pseudo-random Chi^2-distributed deviate for degrees-of-freedom parameter n.

LAX-backend implementation of galsim.random.Chi2Deviate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim PRNGs have some support for linking states, but it may not always work and/or may cause issues.

  • Linked states across JIT boundaries or devices will not work.

  • Within a single routine linking may work.

  • You may encounter errors related to global side effects for some combinations of linked states and jitted/vmapped routines.

Seeding the JAX-GalSim PRNG can be done in a few ways:

  • pass seed=None (This is equivalent to passing seed=0.)

  • pass an integer seed (This method will throw errors if the integer is traced by JAX.)

  • pass another JAX-GalSim PRNG

  • pass a JAX PRNG key made via jax.random.key.

JAX PRNG keys made via `jax.random.PRNGKey` are not supported.

When using JAX-GalSim PRNGs and JIT, you should always return the PRNG from the function and then set the state on input PRNG via prng.reset(new_prng). This will ensure that the PRNG state is propagated correctly outside the JITed code.

Parameters:
  • seed – Something that can seed a BaseDeviate: an integer seed or another BaseDeviate. Using 0 means to generate a seed from the system. [default: None]

  • n – Number of degrees of freedom for the output distribution. [default: 1; Must be > 0]

Original GalSim Documentation

See http://en.wikipedia.org/wiki/Chi-squared_distribution (note that k=n in the notation adopted in the Boost.Random routine called by this class). The Chi^2 distribution is a real-valued distribution producing deviates >= 0.

Successive calls to chi2() generate pseudo-random values distributed according to a chi-square distribution with the specified degrees of freedom, n:

>>> chi2 = galsim.Chi2Deviate(31415926, n=7)
>>> chi2()
7.9182211987712385
>>> chi2()
6.644121724269535
property n

The number of degrees of freedom.

LAX-backend implementation of n().

generate(array)[source]

Generate many pseudo-random values, filling in the values of a numpy array.

LAX-backend implementation of galsim.random.generate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX arrays cannot be changed in-place, so the JAX version of this method returns a new array.

class jax_galsim.GammaDeviate(seed=None, k=1.0, theta=1.0)[source]

Bases: BaseDeviate

A Gamma-distributed deviate with shape parameter k and scale parameter theta. See http://en.wikipedia.org/wiki/Gamma_distribution. (Note: we use the k, theta notation. If you prefer alpha, beta, use k=alpha, theta=1/beta.) The Gamma distribution is a real valued distribution producing deviates >= 0.

LAX-backend implementation of galsim.random.GammaDeviate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim PRNGs have some support for linking states, but it may not always work and/or may cause issues.

  • Linked states across JIT boundaries or devices will not work.

  • Within a single routine linking may work.

  • You may encounter errors related to global side effects for some combinations of linked states and jitted/vmapped routines.

Seeding the JAX-GalSim PRNG can be done in a few ways:

  • pass seed=None (This is equivalent to passing seed=0.)

  • pass an integer seed (This method will throw errors if the integer is traced by JAX.)

  • pass another JAX-GalSim PRNG

  • pass a JAX PRNG key made via jax.random.key.

JAX PRNG keys made via `jax.random.PRNGKey` are not supported.

When using JAX-GalSim PRNGs and JIT, you should always return the PRNG from the function and then set the state on input PRNG via prng.reset(new_prng). This will ensure that the PRNG state is propagated correctly outside the JITed code.

Parameters:
  • seed – Something that can seed a BaseDeviate: an integer seed or another BaseDeviate. Using 0 means to generate a seed from the system. [default: None]

  • k – Shape parameter of the distribution. [default: 1; Must be > 0]

  • theta – Scale parameter of the distribution. [default: 1; Must be > 0]

Original GalSim Documentation

Successive calls to g() generate pseudo-random values distributed according to a gamma distribution with the specified shape and scale parameters k and theta:

>>> gam = galsim.GammaDeviate(31415926, k=1, theta=2)
>>> gam()
0.37508882726316
>>> gam()
1.3504199388358704
property k

The shape parameter, k.

LAX-backend implementation of k().

property theta

The scale parameter, theta.

LAX-backend implementation of theta().

generate(array)[source]

Generate many pseudo-random values, filling in the values of a numpy array.

LAX-backend implementation of galsim.random.generate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX arrays cannot be changed in-place, so the JAX version of this method returns a new array.

class jax_galsim.WeibullDeviate(seed=None, a=1.0, b=1.0)[source]

Bases: BaseDeviate

Pseudo-random Weibull-distributed deviate for shape parameter a and scale parameter b.

LAX-backend implementation of galsim.random.WeibullDeviate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim PRNGs have some support for linking states, but it may not always work and/or may cause issues.

  • Linked states across JIT boundaries or devices will not work.

  • Within a single routine linking may work.

  • You may encounter errors related to global side effects for some combinations of linked states and jitted/vmapped routines.

Seeding the JAX-GalSim PRNG can be done in a few ways:

  • pass seed=None (This is equivalent to passing seed=0.)

  • pass an integer seed (This method will throw errors if the integer is traced by JAX.)

  • pass another JAX-GalSim PRNG

  • pass a JAX PRNG key made via jax.random.key.

JAX PRNG keys made via `jax.random.PRNGKey` are not supported.

When using JAX-GalSim PRNGs and JIT, you should always return the PRNG from the function and then set the state on input PRNG via prng.reset(new_prng). This will ensure that the PRNG state is propagated correctly outside the JITed code.

Parameters:
  • seed – Something that can seed a BaseDeviate: an integer seed or another BaseDeviate. Using 0 means to generate a seed from the system. [default: None]

  • a – Shape parameter of the distribution. [default: 1; Must be > 0]

  • b – Scale parameter of the distribution. [default: 1; Must be > 0]

Original GalSim Documentation

The Weibull distribution is related to a number of other probability distributions; in particular, it interpolates between the exponential distribution (a=1) and the Rayleigh distribution (a=2). See http://en.wikipedia.org/wiki/Weibull_distribution (a=k and b=lambda in the notation adopted in the Wikipedia article) for more details. The Weibull distribution is real valued and produces deviates >= 0.

Successive calls to w() generate pseudo-random values distributed according to a Weibull distribution with the specified shape and scale parameters a and b:

>>> w = galsim.WeibullDeviate(31415926, a=1.3, b=4)
>>> w()
1.1038481241018219
>>> w()
2.957052966368049
property a

The shape parameter, a.

LAX-backend implementation of a().

property b

The scale parameter, b.

LAX-backend implementation of b().

generate(array)[source]

Generate many pseudo-random values, filling in the values of a numpy array.

LAX-backend implementation of galsim.random.generate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX arrays cannot be changed in-place, so the JAX version of this method returns a new array.

class jax_galsim.BinomialDeviate(seed=None, N=1, p=0.5)[source]

Bases: BaseDeviate

Pseudo-random Binomial deviate for N trials each of probability p.

LAX-backend implementation of galsim.random.BinomialDeviate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim PRNGs have some support for linking states, but it may not always work and/or may cause issues.

  • Linked states across JIT boundaries or devices will not work.

  • Within a single routine linking may work.

  • You may encounter errors related to global side effects for some combinations of linked states and jitted/vmapped routines.

Seeding the JAX-GalSim PRNG can be done in a few ways:

  • pass seed=None (This is equivalent to passing seed=0.)

  • pass an integer seed (This method will throw errors if the integer is traced by JAX.)

  • pass another JAX-GalSim PRNG

  • pass a JAX PRNG key made via jax.random.key.

JAX PRNG keys made via `jax.random.PRNGKey` are not supported.

When using JAX-GalSim PRNGs and JIT, you should always return the PRNG from the function and then set the state on input PRNG via prng.reset(new_prng). This will ensure that the PRNG state is propagated correctly outside the JITed code.

Parameters:
  • seed – Something that can seed a BaseDeviate: an integer seed or another BaseDeviate. Using 0 means to generate a seed from the system. [default: None]

  • N – The number of ‘coin flips’ per trial. [default: 1; Must be > 0]

  • p – The probability of success per coin flip. [default: 0.5; Must be > 0]

Original GalSim Documentation

N is number of ‘coin flips,’ p is probability of ‘heads,’ and each call returns an integer value where 0 <= value <= N gives the number of heads. See http://en.wikipedia.org/wiki/Binomial_distribution for more information.

Successive calls to b() generate pseudo-random integer values distributed according to a binomial distribution with the provided N, p:

>>> b = galsim.BinomialDeviate(31415926, N=10, p=0.3)
>>> b()
2
>>> b()
3
property n

The number of ‘coin flips’.

LAX-backend implementation of n().

property p

The probability of success per ‘coin flip’.

LAX-backend implementation of p().

generate(array)[source]

Generate many pseudo-random values, filling in the values of a numpy array.

LAX-backend implementation of galsim.random.generate().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX arrays cannot be changed in-place, so the JAX version of this method returns a new array.

Noise models

class jax_galsim.BaseNoise(rng=None)[source]

Bases: object

Base class for all noise classes.

LAX-backend implementation of galsim.noise.BaseNoise().

Original GalSim Documentation

This class should not be constructed directly. Rather, you should instantiate one of the subclasses:

  • GaussianNoise

  • PoissonNoise

  • CCDNoise

  • VariableGaussianNoise

  • DeviateNoise

which define what kind of noise you want to implement. This base class mostly just serves as a way to check if an object is a valid noise object with:

>>> isinstance(noise, galsim.BaseNoise)
property rng

The BaseDeviate of this noise object.

LAX-backend implementation of rng().

getVariance()[source]

Get variance in current noise model.

LAX-backend implementation of galsim.noise.getVariance().

withVariance(variance)[source]

Return a new noise object (of the same type as the current one) with the specified variance.

LAX-backend implementation of galsim.noise.withVariance().

Parameters:

variance – The desired variance in the noise.

Original GalSim Documentation
Returns:

a new Noise object with the given variance.

withScaledVariance(variance_ratio)[source]

Return a new noise object with the variance scaled up by the specified factor.

LAX-backend implementation of galsim.noise.withScaledVariance().

Parameters:

variance_ratio – The factor by which to scale the variance of the correlation function profile.

Original GalSim Documentation

This is equivalent to noise * variance_ratio.

Returns:

a new Noise object whose variance has been scaled by the given amount.

applyTo(image)[source]

Add noise to an input Image.

LAX-backend implementation of galsim.noise.applyTo().

Original GalSim Documentation

e.g.:

>>> noise.applyTo(image)

On output the Image instance image will have been given additional noise according to the current noise model.

Note: This is equivalent to the alternate syntax:

>>> image.addNoise(noise)

which may be more convenient or clearer.

tree_flatten()[source]

This function flattens the BaseNoise into a list of children nodes that will be traced by JAX and auxiliary static data.

classmethod tree_unflatten(aux_data, children)[source]

Recreates an instance of the class from flatten representation

class jax_galsim.GaussianNoise(rng=None, sigma=1.0)[source]

Bases: BaseNoise

Class implementing simple Gaussian noise.

LAX-backend implementation of galsim.noise.GaussianNoise().

Parameters:
  • rng – A BaseDeviate instance to use for generating the random numbers.

  • sigma – The rms noise on each pixel. [default: 1.]

Original GalSim Documentation

This is a simple noise model where each pixel in the image gets Gaussian noise with a given sigma.

Example:

The following will add Gaussian noise to every element of an image:

>>> gaussian_noise = galsim.GaussianNoise(rng, sigma=1.0)
>>> image.addNoise(gaussian_noise)
Attributes:

rng: The internal random number generator (read-only) sigma: The value of the constructor parameter sigma (read-only)

property sigma

The input sigma value.

LAX-backend implementation of sigma().

copy(rng=None)[source]

Returns a copy of the Gaussian noise model.

LAX-backend implementation of galsim.noise.copy().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim RNGs cannot be shared so a copy is made if None is given.

Original GalSim Documentation

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
tree_flatten()[source]

This function flattens the GaussianNoise into a list of children nodes that will be traced by JAX and auxiliary static data.

classmethod tree_unflatten(aux_data, children)[source]

Recreates an instance of the class from flatten representation

class jax_galsim.PoissonNoise(rng=None, sky_level=0.0)[source]

Bases: BaseNoise

Class implementing Poisson noise according to the flux (and sky level) present in the image.

LAX-backend implementation of galsim.noise.PoissonNoise().

Parameters:
  • rng – A BaseDeviate instance to use for generating the random numbers.

  • sky_level – The sky level in electrons per pixel that was originally in the input image, but which is taken to have already been subtracted off. [default: 0.]

Original GalSim Documentation

The PoissonNoise class encapsulates a simple version of the noise model of a normal CCD image where each pixel has Poisson noise corresponding to the number of electrons in each pixel (including an optional extra sky level).

Note that if the image to which you are adding noise already has a sky level on it, then you should not provide the sky level here as well. The sky level here corresponds to a level that is taken to be already subtracted from the image, but that originally contributed to the addition of Poisson noise.

Example:

The following will add Poisson noise to every element of an image:

>>> poisson_noise = galsim.PoissonNoise(rng, sky_level=0.)
>>> image.addNoise(poisson_noise)
Attributes:

rng: The internal random number generator (read-only) sky_level: The value of the constructor parameter sky_level (read-only)

property sky_level

The input sky_level.

LAX-backend implementation of sky_level().

copy(rng=None)[source]

Returns a copy of the Poisson noise model.

LAX-backend implementation of galsim.noise.copy().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim RNGs cannot be shared so a copy is made if None is given.

Original GalSim Documentation

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
tree_flatten()[source]

This function flattens the PoissonNoise into a list of children nodes that will be traced by JAX and auxiliary static data.

classmethod tree_unflatten(aux_data, children)[source]

Recreates an instance of the class from flatten representation

class jax_galsim.DeviateNoise(dev)[source]

Bases: BaseNoise

Class implementing noise with an arbitrary BaseDeviate object.

LAX-backend implementation of galsim.noise.DeviateNoise().

Parameters:

dev – A BaseDeviate subclass to use as the noise deviate for each pixel.

Original GalSim Documentation

The DeviateNoise class provides a way to treat an arbitrary deviate as the noise model for each pixel in an image.

The following will add noise according to a given random deviate to every element of an image:

>>> dev_noise = galsim.DeviateNoise(dev)
>>> image.addNoise(dev_noise)
Attributes:

rng: The internal random number generator (read-only)

copy(rng=None)[source]

Returns a copy of the DeviateNoise instance.

LAX-backend implementation of galsim.noise.copy().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim RNGs cannot be shared so a copy is made if None is given.

Original GalSim Documentation

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
tree_flatten()[source]

This function flattens the DeviateNoise into a list of children nodes that will be traced by JAX and auxiliary static data.

classmethod tree_unflatten(aux_data, children)[source]

Recreates an instance of the class from flatten representation

class jax_galsim.VariableGaussianNoise(rng, var_image)[source]

Bases: BaseNoise

Class implementing Gaussian noise that has a different variance in each pixel.

LAX-backend implementation of galsim.noise.VariableGaussianNoise().

Parameters:
  • rng – A BaseDeviate instance to use for generating the random numbers.

  • var_image – The variance of the noise to apply to each pixel. This image must be the same shape as the image for which you eventually call addNoise().

Original GalSim Documentation

The following will add variable Gaussian noise to every element of an image:

>>> variable_noise = galsim.VariableGaussianNoise(rng, var_image)
>>> image.addNoise(variable_noise)
Attributes:

rng: The internal random number generator (read-only) var_image: The value of the constructor parameter var_image (read-only)

property var_image

The input var_image.

LAX-backend implementation of var_image().

applyTo(image)[source]

Add noise to an input Image.

LAX-backend implementation of galsim.noise.applyTo().

Original GalSim Documentation

e.g.:

>>> noise.applyTo(image)

On output the Image instance image will have been given additional noise according to the current noise model.

Note: This is equivalent to the alternate syntax:

>>> image.addNoise(noise)

which may be more convenient or clearer.

copy(rng=None)[source]

Returns a copy of the variable Gaussian noise model.

LAX-backend implementation of galsim.noise.copy().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim RNGs cannot be shared so a copy is made if None is given.

Original GalSim Documentation

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
tree_flatten()[source]

This function flattens the VariableGaussianNoise into a list of children nodes that will be traced by JAX and auxiliary static data.

classmethod tree_unflatten(aux_data, children)[source]

Recreates an instance of the class from flatten representation

class jax_galsim.CCDNoise(rng=None, sky_level=0.0, gain=1.0, read_noise=0.0)[source]

Bases: BaseNoise

Class implementing a basic CCD noise model.

LAX-backend implementation of galsim.noise.CCDNoise().

Parameters:
  • rng – A BaseDeviate instance to use for generating the random numbers.

  • sky_level – The sky level in ADU per pixel that was originally in the input image, but which is taken to have already been subtracted off. [default: 0.]

  • gain – The gain for each pixel in electrons per ADU; setting gain<=0 will shut off the Poisson noise, and the Gaussian rms will take the value read_noise as being in units of ADU rather than electrons. [default: 1.]

  • read_noise – The read noise on each pixel in electrons (gain > 0.) or ADU (gain <= 0.). Setting read_noise=0. will shut off the Gaussian noise. [default: 0.]

Original GalSim Documentation

The CCDNoise class encapsulates the noise model of a normal CCD image. The noise has two components: first, Poisson noise corresponding to the number of electrons in each pixel (including an optional extra sky level); second, Gaussian read noise.

Note that if the image to which you are adding noise already has a sky level on it, then you should not provide the sky level here as well. The sky level here corresponds to a level is taken to be already subtracted from the image, but which was present for the Poisson noise.

The units here are slightly confusing. We try to match the most common way that each of these quantities is usually reported. Note: ADU stands for Analog/Digital Units; they are the units of the numbers in the final image. Some places use the term “counts” for this.

  • sky_level is normally measured from the image itself, so it is normally quoted in ADU/pixel.

  • gain is a property of the detector and is normally measured in the laboratory. The units are normally e-/ADU. This is backwards what might be more intuitive, ADU/e-, but that’s how astronomers use the term gain, so we follow suit here.

  • read_noise is also a property of the detector and is usually quoted in e-/pixel.

If you are manually applying the quantum efficiency of the detector (e-/photon), then this would normally be applied before the noise. However, it is also fine to fold in the quantum efficiency into the gain to give units photons/ADU. Either way is acceptable. Just make sure you give the read noise in photons as well in this case.

Example:

The following will add CCD noise to every element of an image:

>>> ccd_noise = galsim.CCDNoise(rng, sky_level=0., gain=1., read_noise=0.)
>>> image.addNoise(ccd_noise)
Attributes:

rng: The internal random number generator (read-only) sky_level: The value of the constructor parameter sky_level (read-only) gain: The value of the constructor parameter gain (read-only) read_noise: The value of the constructor parameter read_noise (read-only)

property sky_level

The input sky_level.

LAX-backend implementation of sky_level().

property gain

The input gain.

LAX-backend implementation of gain().

property read_noise

The input read_noise.

LAX-backend implementation of read_noise().

copy(rng=None)[source]

Returns a copy of the CCD noise model.

LAX-backend implementation of galsim.noise.copy().

🔪 JAX-GalSim - The Sharp Bits 🔪

JAX-GalSim RNGs cannot be shared so a copy is made if None is given.

Original GalSim Documentation

By default, the copy will share the BaseDeviate random number generator with the parent instance. However, you can provide a new rng to use in the copy if you want with:

>>> noise_copy = noise.copy(rng=new_rng)
tree_flatten()[source]

This function flattens the CCDNoise into a list of children nodes that will be traced by JAX and auxiliary static data.

classmethod tree_unflatten(aux_data, children)[source]

Recreates an instance of the class from flatten representation