model_fitting

class ConstantModel(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

A model that is constant through all the image.

Parameters

value (ParameterBase or float) – Value to add to the value of all pixels from the model.

to_string(show_params=False)

Return a human readable representation of the model.

Parameters

show_params (bool) – If True, include information about the parameters.

Returns

Return type

str

class ConstantParameter(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

A parameter with a single value that remains constant. It will not be fitted.

Parameters

value (float, or callable that receives a source and returns a float) – Value for this parameter

get_value()
Returns

Receives a source and returns a value for the parameter

Return type

callable

class CoordinateModelBase(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Base class for positioned models with a flux. It can not be used directly.

Parameters
  • x_coord (ParameterBase or float) – X coordinate (in the detection image)

  • y_coord (ParameterBase or float) – Y coordinate (in the detection image)

  • flux (ParameterBase or float) – Total flux

class DeVaucouleursModel(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Model a source with a De Vaucouleurs profile (Sersic model with an index of 4)

Parameters
  • x_coord (ParameterBase or float) – X coordinate (in the detection image)

  • y_coord (ParameterBase or float) – Y coordinate (in the detection image)

  • flux (ParameterBase or float) – Total flux

  • effective_radius (ParameterBase or float) – Ellipse semi-major axis, in pixels on the detection image.

  • aspect_ratio (ParameterBase or float) – Ellipse ratio.

  • angle (ParameterBase or float) – Ellipse rotation, in radians

to_string(show_params=False)

Return a human readable representation of the model.

Parameters

show_params (bool) – If True, include information about the parameters.

Returns

Return type

str

class DependentParameter(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

A DependentParameter is not fitted by itself, but its value is derived from another Parameters, whatever their type: FreeParameter, ConstantParameter, or other DependentParameter

Parameters
  • func (callable) – A callable that will be called with all the parameters specified in this constructor each time a new evaluation is needed.

  • params (list of ParameterBase) – List of parameters on which this DependentParameter depends.

Examples

>>> flux = get_flux_parameter()
>>> mag = DependentParameter(lambda f: -2.5 * np.log10(f) + args.mag_zeropoint, flux)
>>> add_output_column('mf_mag_' + band, mag)
class ExponentialModel(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Model a source with an exponential profile (Sersic model with an index of 1)

Parameters
  • x_coord (ParameterBase or float) – X coordinate (in the detection image)

  • y_coord (ParameterBase or float) – Y coordinate (in the detection image)

  • flux (ParameterBase or float) – Total flux

  • effective_radius (ParameterBase or float) – Ellipse semi-major axis, in pixels on the detection image.

  • aspect_ratio (ParameterBase or float) – Ellipse ratio.

  • angle (ParameterBase or float) – Ellipse rotation, in radians

to_string(show_params=False)

Return a human readable representation of the model.

Parameters

show_params (bool) – If True, include information about the parameters.

Returns

Return type

str

class FluxParameterType

Bases: object

Possible flux types to use as initial value for the flux parameter. Right now, only isophotal is supported.

class FreeParameter(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

A parameter that will be fitted by the model fitting engine.

Parameters
  • init_value (float or callable that receives a source, and returns a float) – Initial value for the parameter.

  • range (instance of Range or Unbounded) – Defines if this parameter is unbounded or bounded, and how.

See also

Unbounded, Range

Examples

>>> sersic = FreeParameter(2.0, Range((1.0, 7.0), RangeType.LINEAR))
get_init_value()
Returns

Receives a source, and returns an initial value for the parameter.

Return type

callable

get_range()
Returns

Return type

Unbounded or Range

class ModelBase(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Base class for all models.

class ParameterBase(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Base class for all model fitting parameter types. Can not be used directly.

class PointSourceModel(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Models a source as a point, spread by the PSF.

Parameters
  • x_coord (ParameterBase or float) – X coordinate (in the detection image)

  • y_coord (ParameterBase or float) – Y coordinate (in the detection image)

  • flux (ParameterBase or float) – Total flux

to_string(show_params=False)

Return a human readable representation of the model.

Parameters

show_params (bool) – If True, include information about the parameters.

Returns

Return type

str

class Prior(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Model a Gaussian prior on a given parameter.

Parameters
  • param (ParameterBase) – Model fitting parameter

  • value (float or callable that receives a source and returns a float) – Mean of the Gaussian

  • sigma (float or callable that receives a source and returns a float) – Standard deviation of the Gaussian

class Range(limits, type)

Bases: object

Limit, and normalize, the range of values for a model fitting parameter.

Parameters
  • limits (a tuple (min, max), or a callable that receives a source, and returns a tuple (min, max)) –

  • type (RangeType) –

Notes

RangeType.LINEAR

Normalized to engine space using a sigmoid function

\[\begin{split}engine = \ln \frac{world - min}{max-world} \\ world = min + \frac{max - min}{1 + e^{engine}}\end{split}\]
RangeType.EXPONENTIAL

Normalized to engine space using an exponential sigmoid function

\[\begin{split}engine = \ln \left( \frac{\ln(world/min)}{\ln(max /world)} \right) \\ world = min * e^\frac{ \ln(max / min) }{ (1 + e^{-engine}) }\end{split}\]
get_limits()
Returns

Receives a source, and returns a tuple (min, max)

Return type

callable

get_type()
Returns

Return type

RangeType

class RangeType(value)

Bases: enum.Enum

An enumeration.

class SersicModel(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Model a source with a Sersic profile.

Parameters
  • x_coord (ParameterBase or float) – X coordinate (in the detection image)

  • y_coord (ParameterBase or float) – Y coordinate (in the detection image)

  • flux (ParameterBase or float) – Total flux

  • effective_radius (ParameterBase or float) – Ellipse semi-major axis, in pixels on the detection image.

  • aspect_ratio (ParameterBase or float) – Ellipse ratio.

  • angle (ParameterBase or float) – Ellipse rotation, in radians

  • n (ParameterBase or float) – Sersic index

to_string(show_params=False)

Return a human readable representation of the model.

Parameters

show_params (bool) – If True, include information about the parameters.

Returns

Return type

str

class SersicModelBase(*args: Any, **kwargs: Any)

Bases: _SourceXtractorPy.

Base class for the Sersic, Exponential and de Vaucouleurs models. It can not be used directly.

Parameters
  • x_coord (ParameterBase or float) – X coordinate (in the detection image)

  • y_coord (ParameterBase or float) – Y coordinate (in the detection image)

  • flux (ParameterBase or float) – Total flux

  • effective_radius (ParameterBase or float) – Ellipse semi-major axis, in pixels on the detection image.

  • aspect_ratio (ParameterBase or float) – Ellipse ratio.

  • angle (ParameterBase or float) – Ellipse rotation, in radians

class Unbounded(normalization_factor=1)

Bases: object

Unbounded, but normalize, value of a model fitting parameter

Parameters

normalization_factor (float, or a callable that receives the initial value parameter value and a source,) – and returns a float The world value which will be normalized to 1 in engine coordinates

get_normalization_factor()
Returns

Receives the initial parameter value and a source, and returns the world value which will be normalized to 1 in engine coordinates

Return type

callable

class WorldCoordinate(ra, dec)

Bases: object

Coordinates in right ascension and declination

Parameters
  • ra (float) – Right ascension

  • dec (float) – Declination

add_model(group, model)

Add a model to be fitted to the given group.

Parameters
add_prior(param, value, sigma)

Add a prior to the given parameter.

Parameters
  • param (ParameterBase) –

  • value (float or callable that receives a source and returns a float) – Mean of the Gaussian

  • sigma (float or callable that receives a source and returns a float) – Standard deviation of the Gaussian

get_flux_parameter(type=1, scale=1)

Convenience function for the flux parameter.

Parameters
  • type (int) – One of the values defined in FluxParameterType

  • scale (float) – Scaling of the initial flux. Defaults to 1.

Returns

flux – Flux parameter, starting at the flux defined by type, and limited to +/- 1e3 times the initial value.

Return type

FreeParameter

get_pos_parameters()

Convenience function for the position parameter X and Y.

Returns

  • x (FreeParameter) – X coordinate, starting at the X coordinate of the centroid and linearly limited to X +/- the object radius.

  • y (FreeParameter) – Y coordinate, starting at the Y coordinate of the centroid and linearly limited to Y +/- the object radius.

Notes

X and Y are fitted on the detection image X and Y coordinates. Internally, these are translated to measurement images using the WCS headers.

get_position_angle(x1, y1, x2, y2)

Get the position angle in sky coordinates for two points defined in pixels on the detection image.

Parameters
  • x1

  • y1

  • x2

  • y2

Returns

Return type

Position angle in degrees, normalized to -/+ 90

get_separation_angle(x1, y1, x2, y2)

Get the separation angle in sky coordinates for two points defined in pixels on the detection image.

Parameters
  • x1 (float) –

  • y1 (float) –

  • x2 (float) –

  • y2 (float) –

Returns

Return type

Separation in degrees

get_sky_coord(x, y)

Transform an (X, Y) in pixel coordinates on the detection image to astropy SkyCoord.

Parameters
  • x (float) –

  • y (float) –

Returns

Return type

SkyCoord

get_world_parameters(x, y, radius, angle, ratio)

Convenience function for generating five dependent parameters, in world coordinates, for the position and shape of a model.

Parameters
Returns

  • ra (DependentParameter) – Right ascension

  • dec (DependentParameter) – Declination

  • rad (DependentParameter) – Radius as degrees

  • angle (DependentParameter) – Angle in degrees

  • ratio (DependentParameter) – Aspect ratio. It has to be recomputed as the axis of the ellipse may have different ratios in image coordinates than in world coordinates

Examples

>>> flux = get_flux_parameter()
>>> x, y = get_pos_parameters()
>>> radius = FreeParameter(lambda o: o.get_radius(), Range(lambda v, o: (.01 * v, 100 * v), RangeType.EXPONENTIAL))
>>> angle = FreeParameter(lambda o: o.get_angle(), Range((-np.pi, np.pi), RangeType.LINEAR))
>>> ratio = FreeParameter(1, Range((0, 10), RangeType.LINEAR))
>>> add_model(group, ExponentialModel(x, y, flux, radius, ratio, angle))
>>> ra, dec, wc_rad, wc_angle, wc_ratio = get_world_parameters(x, y, radius, angle, ratio)
>>> add_output_column('mf_world_angle', wc_angle)
get_world_position_parameters(x, y)

Convenience function for generating two dependent parameter with world (alpha, delta) coordinates from image (X, Y) coordinates.

Parameters
Returns

  • ra (DependentParameter)

  • dec (DependentParameter)

Examples

>>> x, y = get_pos_parameters()
>>> ra, dec = get_world_position_parameters(x, y)
>>> add_output_column('mf_ra', ra)
>>> add_output_column('mf_dec', dec)
pixel_to_world_coordinate(x, y)

Transform an (X, Y) in pixel coordinates on the detection image to (RA, DEC) in world coordinates. :param x: :type x: float :param y: :type y: float

Returns

Return type

WorldCoordinate

print_model_fitting_info(group, show_params=False, prefix='', file=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>)

Print a human-readable representation of the configured models.

Parameters
  • group (MeasurementGroup) – Print the models for this group.

  • show_params (bool) – If True, print also the parameters that belong to the model

  • prefix (str) – Prefix each line with this string. Used internally for indentation.

  • file (file object) – Where to print the representation. Defaults to sys.stderr

print_parameters(file=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>)

Print a human-readable representation of the configured model fitting parameters.

Parameters

file (file object) – Where to print the representation. Defaults to sys.stderr

radius_to_wc_angle(x, y, rad)

Transform a radius in pixels on the detection image to a radius in sky coordinates.

Parameters
  • x (float) –

  • y (float) –

  • rad (float) –

Returns

Return type

Radius in degrees

set_coordinate_system(cs)

Set the global coordinate system. This function is used internally by SourceXtractor++.

set_engine(engine)
Parameters

engine (str) – Minimization engine for the model fitting : levmar or gsl

set_max_iterations(iterations)
Parameters

iterations (int) – Max number of iterations for the model fitting.

set_modified_chi_squared_scale(scale)
Parameters

scale (float) – Sets u0, as used by the modified chi squared residual comparator, a function that reduces the effect of large deviations. Refer to the SourceXtractor++ documentation for a better explanation of how residuals are computed and how this value affects the model fitting.