Source#

class scarlet2.Source(center, spectrum, morphology, bbox=None)[source]#

Bases: Component

Source model

The class is the basic parameterization for sources in Scene.

Parameters:
  • center (array, astropy.coordinates.SkyCoord) – Center position in sky coordinates or pixel coordinates of the model frame.

  • spectrum (array, Spectrum) – The spectrum of the source.

  • morphology (array, Morphology) – The morphology of the source.

  • bbox (Box, optional) – Bounding box of the component in sky coordinates or pixel coordinates of the model frame.

Examples

A source declaration is restricted to a context of a Scene, which defines the Frame of the entire model.

>>> with Scene(model_frame) as scene:
>>>    source = Source(center, spectrum, morphology)

A source can comprise one or multiple Component, which can be added by add_component() or operators += (for an additive component) or *= (for a multiplicative component).

>>> with Scene(model_frame) as scene:
>>>    source = Source(center, spectrum, morphology)
>>>    source *= DustComponent(center, dust_spectrum, dust_morphology)
__call__()[source]#

What to run when Source is called

add_component(component, op)[source]#

Add component to this source

Parameters:
  • component (Component) – The component to include in this source. It will be combined with the previous component according to the operator op.

  • op (callable) – Operator to combine this component with those before it in the list components. Conventional operators from the operator package can be used. Signature: op(x,y) -> z, where all terms have the same shapes

bbox: Box#

Bounding box of the model, in sky coordinates or pixel coordinates of the model frame

center: Array#

Center position, in sky coordinates or pixel coordinates of the model frame

component_ops: list#

List of operators to combine components for the final model

components: list#

List of components in this source

get(name=None)#

Get parameter(s) from this module

Parameters:

name (str, optional) – Name of parameter. If not set, returns all parameters.

Returns:

requested data arrays for parameters

Return type:

dict

morphology: (<function array at 0x7fe56388e8e0>, <class 'scarlet2.morphology.Morphology'>)#

Morphology model

property parameters#

Parameters defined for this module

Returns:

name: (node, param) mapping for all parameters

Return type:

dict

replace(name, value)#

Replace member attribuge name with value

Parameters:
  • name (str) – Name of member to replace

  • value (any) – Value to replace member with

Returns:

The modified module.

Return type:

Module

replace_subtree(where, value, parameters=None)#

Replace the subtree where(self) with value and carry over all other parameters

Unlike replace(), value does not need to have the same structure as the subtree it replaces, e.g. an array morphology can be replaced by a SersicMorphology. Parameters defined for this module remain attached to the same nodes, except those inside the replaced subtree, which are dropped.

Parameters:
  • where (callable) – Function module -> node that selects the subtree to replace, as in equinox.tree_at()

  • value (any) – Replacement for the subtree. If this module has a frame, attributes of value given in sky coordinates are converted to pixel coordinates of that frame.

  • parameters (callable, optional) – Function module -> None that is called with the new module inside of a Parameters context to define parameters for the replacement, e.g. by calling Parameter on nodes of value.

Returns:

The modified module.

Return type:

Module

Examples

>>> sersic = SersicMorphology(n=jnp.array(2.), size=jnp.array(2.), shape=morph.shape)
>>> def sersic_parameters(morph):
>>>     Parameter(morph.n, name="n:0", prior=dist.Uniform(0.5, 6))
>>>     Parameter(morph.size, name="size:0", constraint=constraints.positive, stepsize=0.1)
>>>
>>> scene_ = scene.replace_subtree(lambda sc: sc.sources[0].morphology, sersic, sersic_parameters)

See also

remap()

set(values)#

Set parameter(s) from this module with values

Parameters:

values (dict[str,jnp.array]) – values to replace parameters with, identified by their name

Returns:

new module with parameter(s) replaced by values

Return type:

Module

spectrum: (<function array at 0x7fe56388e8e0>, <class 'scarlet2.spectrum.Spectrum'>)#

Spectrum model