scarlet.operator¶
- scarlet.operator.diagonalizeArray(arr, shape=None, dtype=<class 'numpy.float64'>)[source]¶
Convert an array to a matrix that compares each pixel to its neighbors Given an array with length N, create an 8xN array, where each row will be a diagonal in a diagonalized array. Each column in this matrix is a row in the larger NxN matrix used for an operator, except that this 2D array only contains the values used to create the bands in the band diagonal matrix. Because the off-diagonal bands have less than N elements,
getOffsets
is used to create a mask that will set the elements of the array that are outside of the matrix to zero.arr
is the vector to diagonalize, for example the distance from each pixel to the peak, or the angle of the vector to the peak.shape
is the shape of the original image.
- scarlet.operator.diagonalsToSparse(diagonals, shape, dtype=<class 'numpy.float64'>)[source]¶
Convert a diagonalized array into a sparse diagonal matrix
diagonalizeArray
creates an 8xN array representing the bands that describe the interactions of a pixel with its neighbors. This function takes that 8xN array and converts it into a sparse diagonal matrix. See diagonalizeArray for the details of the 8xN array.
- scarlet.operator.find_Q(Vs, n)[source]¶
Finds a Q that is within the solution space that can act as an appropriate target (could be rigorously constructed later)
- scarlet.operator.find_relevant_dim(Y, Q, Vs)[source]¶
Finds a dimension relevant to the problem by ‘raycasting’ from Y to Q
- scarlet.operator.getOffsets(width, coords=None)[source]¶
Get the offset and slices for a sparse band diagonal array For an operator that interacts with its neighbors we want a band diagonal matrix, where each row describes the 8 pixels that are neighbors for the reference pixel (the diagonal). Regardless of the operator, these 8 bands are always the same, so we make a utility function that returns the offsets (passed to scipy.sparse.diags). See diagonalizeArray for more on the slices and format of the array used to create NxN operators that act on a data vector.
- scarlet.operator.getRadialMonotonicWeights(shape, neighbor_weight='flat', center=None)[source]¶
Create the weights used for the Radial Monotonicity Operator This version of the radial monotonicity operator selects all of the pixels closer to the peak for each pixel and weights their flux based on their alignment with a vector from the pixel to the peak. In order to quickly create this using sparse matrices, its construction is a bit opaque.
- scarlet.operator.get_center(image, center, radius=1)[source]¶
Search around a location for the maximum flux
For monotonicity it is important to start at the brightest pixel in the center of the source. This may be off by a pixel or two, so we search for the correct center before applying monotonic_tree.
- Parameters:
- image: array-like
The image of the source.
- center: (int, int)
The suggested center of the source.
- radius: int
The number of pixels around the center to search for a higher flux value.
- Returns:
- new_center: (int, int)
The true center of the source.
- scarlet.operator.project_disk_sed(bulge_sed, disk_sed)[source]¶
Project the disk SED onto the space where it is bluer
For the majority of observed galaxies, it appears that the difference between the bulge and the disk SEDs is roughly monotonic, making the disk bluer.
This projection operator projects colors that are redder onto the same difference in color as the previous wavelength, similar to the way monotonicity works for the morphological S matrix of the model.
While a single iteration of this model is unlikely to yield results that are as good as those in project_disk_sed_mean, after many iterations it is expected to converge to a better value.
- scarlet.operator.project_disk_sed_mean(bulge_sed, disk_sed)[source]¶
Project the disk SED onto the space where it is bluer
For the majority of observed galaxies, it appears that the difference between the bulge and the disk SEDs is roughly monotonic, making the disk bluer.
This projection operator projects colors that are redder than other colors onto the average SED difference for that wavelength. This is a more accurate SED than project_disk_sed but is more likely to create discontinuities in the evaluation of A, and should probably be avoided. It is being kept for now to record its effect.
- scarlet.operator.prox_cone(X, step, G=None)[source]¶
Exact projection of components of X onto cone defined by Gx >= 0
- scarlet.operator.prox_kspace_symmetry(X, step, shift=None, padding=10)[source]¶
Symmetry in Fourier Space
This algorithm by Nate Lust uses the fact that throwing away the imaginary part in Fourier space leaves a symmetric soution in real space. So X is transformed to Fourier space, shifted by the fractional amount shift=(dy, dx), the imaginary part is discarded, shited back to its original position, then transformed back to real space.
- scarlet.operator.prox_monotonic_mask(X, step, center, center_radius=1, variance=0.0, max_iter=3)[source]¶
Apply monotonicity from any path from the center
- Parameters:
- X: array-like
The input image that the mask is created for.
- step: `int`
This parameter is ignored for this prox, but is required by prox_min.
- center: `tuple` of `int`
The location of the center of the mask.
- center_radius: `float`
Radius from the center pixel to search for a better center (ie. a pixel in X with higher flux than the pixel given by
center).
If center_radius == 0 then the center pixel is assumed to be correct.
- variance: `float`
The average variance in the image. This is used to allow pixels to be non-monotonic up to variance, so setting variance=0 will force strict monotonicity in the mask.
- max_iter: int
Maximum number of iterations to interpolate non-monotonic pixels.
- scarlet.operator.prox_sdss_symmetry(X, step)[source]¶
SDSS/HSC symmetry operator
This function uses the minimum of the two symmetric pixels in the update.
- scarlet.operator.prox_soft_symmetry(X, step, strength=1)[source]¶
Soft version of symmetry Using a strength that varies from 0 to 1, with 0 meaning no symmetry enforced at all and 1 being completely symmetric, the user can customize the level of symmetry required for a component
- scarlet.operator.prox_uncentered_symmetry(X, step, center=None, algorithm='kspace', fill=None, shift=None, strength=0.5)[source]¶
Symmetry with off-center peak
Symmetrize X for all pixels with a symmetric partner.
- Parameters:
- X: array
The parameter to update.
- step: `int`
Step size of the gradient step.
- center: tuple of `int`
The center pixel coordinates to apply the symmetry operator.
- algorithm: `string`
The algorithm to use for symmetry. * If algorithm = “kspace” then `X is shifted by shift and
symmetry is performed in kspace. This is the only symmetry algorithm in scarlet that works for fractional pixel shifts.
If algorithm = “sdss” then the SDSS symmetry is used, namely the source is made symmetric around the `center pixel by taking the minimum of each pixel and its symmetric partner. This is the algorithm used when initializing an ExtendedSource because it keeps the morphologies small, but during optimization the penalty is much stronger than the gradient and often leads to vanishing sources.
If algorithm = “soft” then soft symmetry is used, meaning `X will be allowed to differ from symmetry by the fraction strength from a perfectly symmetric solution. It is advised against using this algorithm because it does not work in general for sources shifted by a fractional amount, however it is used internally if a source is centered perfectly on a pixel.
- fill: `float`
The value to fill the region that cannot be made symmetric. When fill is None then the region of X that is not symmetric is not constrained.
- strength: `float`
The amount that symmetry is enforced. If strength=0 then no symmetry is enforced, while strength=1 enforces strict symmetry (ie. the mean of the two symmetric pixels is used for both of them). This parameter is only used when algorithm = “soft”.
- Returns:
- result: function
The update function based on the specified parameters.
- scarlet.operator.prox_weighted_monotonic(shape, neighbor_weight='flat', min_gradient=0.1, center=None)[source]¶
Build the prox_monotonic operator
- Parameters:
- neighbor_weight: [‘flat’, ‘angle’, ‘nearest’]
Which weighting scheme to average all neighbor pixels towards center as reference for the monotonicty test.
- min_gradient: `float`
Forced gradient. A thresh of zero will allow a pixel to be the same value as its reference pixels, while a thresh of one will force the pixel to zero.
- center: tuple
Location of the central (highest-value) pixel.
- Returns:
- result: function
The monotonicity function.
- scarlet.operator.proximal_disk_sed(X, step, peaks, algorithm=<function project_disk_sed_mean>)[source]¶
Ensure that each disk SED is bluer than the bulge SED
- scarlet.operator.sort_by_radius(shape, center=None)[source]¶
Sort indices distance from the center
Given a shape, calculate the distance of each pixel from the center and return the indices of each pixel, sorted by radial distance from the center, which need not be in the center of the image.
- Parameters:
- shape: `tuple`
Shape (y,x) of the source frame.
- center: array-like
Location of the center pixel.
- Returns:
- didx: ~numpy.array
Indices of elements in an image with shape shape, sorted by distance from the center.
- scarlet.operator.uncentered_operator(X, func, center=None, fill=None, **kwargs)[source]¶
Only apply the operator on a centered patch
In some cases, for example symmetry, an operator might not make sense outside of a centered box. This operator only updates the portion of X inside the centered region.
- Parameters:
- X: array
The parameter to update.
- func: `function`
The function (or operator) to apply to X.
- center: tuple
The location of the center of the sub-region to apply func to X.
- `fill`: `float`
The value to fill the region outside of centered sub-region, for example 0. If fill is None then only the subregion is updated and the rest of X remains unchanged.