NAME

PDL::Algorithm::Center - Various methods of finding the center of a sample

VERSION

version 0.11

DESCRIPTION

PDL::Algorithm::Center is a collection of algorithms which specialize in centering datasets.

SUBROUTINES

See "TYPES" for information on the types used in the subroutine descriptions.

sigma_clip

$results = sigma_clip(
    center      => Optional [ Center | CodeRef ],
    clip        => Optional [PositiveNum],
    coords      => Optional [Coords],
    dtol        => PositiveNum,
    iterlim     => Optional [PositiveInt],
    log         => Optional [Bool | CodeRef],
    mask        => Optional [ Undef | Piddle_min1D_ne ],
    save_mask   => Optional [Bool],
    save_weight => Optional [Bool],
    nsigma      => PositiveNum,
    weight      => Optional [ Undef | Piddle_min1D_ne ],
);

Center a dataset by iteratively excluding data outside of a radius equal to a specified number of standard deviations. The dataset may be specified as a list of coordinates and optional weights, or as a weight piddle of shape NxM (e.g., an image). If only the weight piddle is provided, it is converted internally into a list of coordinates with associated weights.

To operate on a subset of the input data, specify the mask option.

A PDL::Algorithm::Center::Failure::parameter exception will be thrown if there is a parameter error.

The center of a data set is determined by:

  1. clipping (ignoring) the data whose distance to the current center is greater than a specified number of standard deviations
  2. calculating a new center by performing a (weighted) centroid of the remaining data
  3. calculating the standard deviation of the distance from the remaining data to the center
  4. repeat step 1 until either a convergence tolerance has been met or the iteration limit has been exceeded

The initial center may be explicitly specified, or may be calculated by performing a (weighted) centroid of the data.

The initial standard deviation is calculated using the initial center and either the entire dataset, or from a clipped region about the initial center.

Options

The following options are available:

Sigma Clip Results

sigma_clip returns an object which includes all of the attributes from the final iteration object (See "Sigma Clip Iterations" ), with the following additional attributes/methods:

Sigma Clip Iterations

The results for each iteration are stored in an object with the following attributes/methods:

iterate

$result = iterate(
  center       => Center | CodeRef,
  initialize   => CodeRef,
  calc_center  => CodeRef,
  calc_wmask   => CodeRef,
  is_converged => CodeRef,
  coords       => Coords,
  iterlim      => PositiveInt,
  log          => Optional [CodeRef],
  mask         => Optional [Piddle1D_ne],
  save_mask    => Optional [Bool],
  save_weight  => Optional [Bool],
  weight       => Optional [Piddle1D_ne],
);

A generic iteration loop for centering data using callbacks for calculating centers, included element masks, weight, and iteration completion.

A PDL::Algorithm::Center::Failure::parameter exception will be thrown if there is a parameter error.

Options

The following options are accepted:

Callbacks are provided with Hash::Wrap based objects which contain the data for the current iteration. They should add data to the objects underlying hash which records particulars about their specific operation,

Work Space

Callbacks are passed Hash::Wrap based iteration objects and a reference to a $work hash. The iteration objects may have additional elements added to them (which will be available to the caller), but should refrain from storing unnecessary data there, as each new iteration's object is copied from that for the previous iteration.

Instead, use the passed $work hash. It is shared amongst the callbacks, so use it to store data which will not be returned to the caller.

Results

iterate returns an object which includes all of the attributes from the final iteration object (See "Iteration Object" ), with the following additional attributes/methods:

The value of the center attribute in the last iteration will be undefined if all of the elements have been clipped.

Iteration Object

The results for each iteration are stored in an object with the following attributes/methods (in addition to those added by the callbacks).

Iteration Steps

Before the first iteration:

  1. Extract an initial center from center.
  2. Create a new iteration object.
  3. Call initialize.
  4. Call log

For each iteration:

  1. Creat a new iteration object by copying the old one.
  2. Call calc_wmask, with a copy of the initial mask and weights. calc_mask should update (in place) at least one of them
  3. Update summed weight and number of elements if calc_wmask sets them to undef.
  4. Call calc_center with the current mask and weights.
  5. Call is_converged with the current mask and weights.
  6. Call log
  7. Goto step 1 if not converged and iteration limit has not been reached.

TYPES

In the description of the subroutines, the following types are specified:

ERRORS

Errors are represented as objects in the following classes:

The objects stringify to a failure message.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=PDL-Algorithm-Center

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Diab Jerius djerius@cpan.org

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.

This is free software, licensed under:

The GNU General Public License, Version 3, June 2007