Frame#

class scarlet2.Frame(bbox, psf=None, wcs=None, channels=None)[source]#

Bases: Module

Definition of a view of the sky

This class combines all elements to determine how a piece of the sky will appear. It includes metadata about the spatial and spectral coverage and resolution.

property C: int#

Number of channels

property H: int#

number of pixels in the vertical direction

Type:

Height

property W: int#

number of pixels in the horizontal direction

Type:

Width

__call__()#

Evaluate the model

bbox: Box#

Bounding box of the frame

channels: list#

Identifiers for the spectral elements

convert_pixel_to(target, pixel=None)[source]#

Converts pixel coordinates from this frame to target frame

Parameters:
  • target (Frame) – target frame

  • pixel (array) – Pixel coordinates in this frame. If not set, convert all pixels in this frame

Returns:

coordinates at the location of pixel in the frame target

Return type:

array

static from_observations(observations, model_psf=None, model_wcs=None, reference_id=None, coverage='union')[source]#

Generates a suitable model frame for a set of observations.

This method generates a frame from a set of observations by identifying the highest resolution and the smallest PSF and use them to construct a common frame for all observations.

Parameters:
  • observations (list) – list of Observation to determine a common frame

  • model_psf (PSF, optional) – PSF to be adopted for the model frame. This is the effective resolution of the model, and all observations are to be deconvolved to this limit. If None, uses the smallest PSF across all observations and channels.

  • model_wcs (astropy.wcs.WCS) – WCS for the model frame. If None, uses WCS information of the observation with the smallest pixels.

  • reference_id (int, optional) – index of the reference observation. If set to None, uses the observation with the smallest pixels.

  • coverage ("union" or "intersection") – Sets the frame to incorporate the pixels covered by any observation (‘union’) or by all observations (‘intersection’).

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

get_pixel(pos)[source]#

Get the sky coordinates from a world coordinate

Parameters:

pos (jnp.ndarray or SkyCoord) – Coordinates on the sky

Return type:

pixel coordinates in the model frame

get_sky_coord(pos)[source]#

Get the sky coordinate from a pixel coordinate

Parameters:

pos (jnp.ndarray) – Coordinates in the pixel space

Return type:

astropy.coordinates.SkyCoord

map_channels(other_frame)[source]#

Map channel indices of this frame to matching indices in another frame.

Parameters:

other_frame (Frame) – Frame whose channels are to be matched against this frame’s channels.

Returns:

Mapping from each channel index in this frame to the corresponding channel index in other_frame, for all channels present in both frames. Channels unique to either frame are omitted.

Return type:

dict

Examples

>>> from scarlet2 import Frame
>>> from scarlet2.bbox import Box
>>> f1 = Frame(Box((3, 10, 10)), channels=["g", "r", "i"])
>>> f2 = Frame(Box((2, 10, 10)), channels=["r", "i"])
>>> f1.map_channels(f2)
{1: 0, 2: 1}
property parameters#

Parameters defined for this module

Returns:

name: (node, param) mapping for all parameters

Return type:

dict

pixel_to_angle(size)[source]#

Converts pixel size to celestial distance according to this frame WCS

Parameters:

size (float) – The size in pixels

Returns:

distance

Return type:

astropy.units.Quantity

psf: (<class 'scarlet2.psf.PSF'>, None)#

PSF of the frame

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

u_to_pixel(distance)[source]#

Converts celestial distance to pixel size according to this frame WCS

Parameters:

distance (astropy.units.Quantity) – Physical size, must be PhysicalType(“angle”)

Returns:

size in pixels

Return type:

float

wcs: WCS#

WCS information of the frame