model_fitting
¶
- class ComputeGraphModel(*args: Any, **kwargs: Any)¶
Bases:
CoordinateModelBase
ComputeGraphModel model
- Parameters
models (string or list of strings, corresponding to path to Onnx format models,) – (specifying more than one allows using the most efficient model based on render size.)
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
params (Dictionary of String and ParameterBase or float) – Dictionary of custom parameters for the ONNX 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.
- Return type
str
- class ConstantModel(*args: Any, **kwargs: Any)¶
Bases:
ModelBase
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.
- Return type
str
- class ConstantParameter(*args: Any, **kwargs: Any)¶
Bases:
ParameterBase
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(o)¶
- Parameters
o (object being fitted) –
- Returns
Value of the constant parameter
- Return type
float
- class CoordinateModelBase(*args: Any, **kwargs: Any)¶
Bases:
ModelBase
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:
SersicModelBase
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.
- Return type
str
- class DependentParameter(*args: Any, **kwargs: Any)¶
Bases:
ParameterBase
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:
SersicModelBase
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.
- 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:
ParameterBase
A parameter that will be fitted by the model fitting engine.
- Parameters
Examples
>>> sersic = FreeParameter(2.0, Range((1.0, 7.0), RangeType.LINEAR))
- get_init_value(o)¶
- Parameters
o (object being fitted) –
- Returns
Initial value for the free parameter
- Return type
float
- class ModelBase(*args: Any, **kwargs: Any)¶
Bases:
Id
Base class for all models.
- class ParameterBase(*args: Any, **kwargs: Any)¶
Bases:
Id
Base class for all model fitting parameter types. Can not be used directly.
- class PointSourceModel(*args: Any, **kwargs: Any)¶
Bases:
CoordinateModelBase
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.
- Return type
str
- class Prior(*args: Any, **kwargs: Any)¶
Bases:
Id
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_max(v, o)¶
- Parameters
v (initial value) –
o (object being fitted) –
- Return type
The maximum acceptable value for the range
- get_min(v, o)¶
- Parameters
v (initial value) –
o (object being fitted) –
- Return type
The minimum acceptable value for the range
- class RangeType(value)¶
Bases:
Enum
An enumeration.
- class SersicModel(*args: Any, **kwargs: Any)¶
Bases:
SersicModelBase
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.
- Return type
str
- class SersicModelBase(*args: Any, **kwargs: Any)¶
Bases:
CoordinateModelBase
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(v, o)¶
- Parameters
v (initial value) –
o (object being fitted) –
- Returns
The world value which will be normalized to 1 in engine coordinates
- Return type
float
- class WorldCoordinate(ra, dec)¶
Bases:
object
Coordinates in right ascension and declination
- Parameters
ra (float) – Right ascension
dec (float) – Declination
- 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
- 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 –
- 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) –
- 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) –
- 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
x (ParameterBase) –
y (ParameterBase) –
radius (ParameterBase) –
angle (ParameterBase) –
ratio (ParameterBase) –
- 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.radius, Range(lambda v, o: (.01 * v, 100 * v), RangeType.EXPONENTIAL)) >>> angle = FreeParameter(lambda o: o.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
x (ParameterBase) –
y (ParameterBase) –
- Returns
ra (DependentParameter)
dec (DependentParameter)
See also
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
- Return type
- 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
- 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) –
- Return type
Radius in degrees