LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
|
Public Member Functions | |
__init__ (self, np.ndarray data, Sequence|None bands=None, tuple[int, int]|None yx0=None) | |
tuple[int,...] | shape (self) |
DTypeLike | dtype (self) |
tuple | bands (self) |
int | n_bands (self) |
bool | is_multiband (self) |
int | height (self) |
int | width (self) |
tuple[int, int] | yx0 (self) |
int | y0 (self) |
int | x0 (self) |
Box | bbox (self) |
np.ndarray | data (self) |
tuple[int,...]|slice | spectral_indices (self, Sequence|slice bands) |
tuple[tuple[int,...]|slice, tuple[int,...]|slice] | matched_spectral_indices (self, Image other) |
tuple[tuple[slice,...], tuple[slice,...]] | matched_slices (self, Box bbox) |
Image | project (self, object|tuple[object]|None bands=None, Box|None bbox=None) |
tuple[tuple[int,...]|slice, slice, slice] | multiband_slices (self) |
Image | insert_into (self, Image image, Callable op=operator.add) |
Image | insert (self, Image image, Callable op=operator.add) |
Image | repeat (self, tuple bands) |
Image | copy (self, order=None) |
copy_with (self, np.ndarray|None data=None, str|None order=None, tuple[str,...]|None bands=None, tuple[int, int]|None yx0=None) | |
Image | __eq__ (self, object other) |
Image | __ne__ (self, object other) |
Image | __ge__ (self, Image|ScalarLike other) |
Image | __le__ (self, Image|ScalarLike other) |
Image | __gt__ (self, Image|ScalarLike other) |
Image | __lt__ (self, Image|ScalarLike other) |
__neg__ (self) | |
__pos__ (self) | |
__invert__ (self) | |
Image | __add__ (self, Image|ScalarLike other) |
Image | __iadd__ (self, Image|ScalarLike other) |
Image | __radd__ (self, Image|ScalarLike other) |
Image | __sub__ (self, Image|ScalarLike other) |
Image | __isub__ (self, Image|ScalarLike other) |
Image | __rsub__ (self, Image|ScalarLike other) |
Image | __mul__ (self, Image|ScalarLike other) |
Image | __imul__ (self, Image|ScalarLike other) |
Image | __rmul__ (self, Image|ScalarLike other) |
Image | __truediv__ (self, Image|ScalarLike other) |
Image | __itruediv__ (self, Image|ScalarLike other) |
Image | __rtruediv__ (self, Image|ScalarLike other) |
Image | __floordiv__ (self, Image|ScalarLike other) |
Image | __ifloordiv__ (self, Image|ScalarLike other) |
Image | __rfloordiv__ (self, Image|ScalarLike other) |
Image | __pow__ (self, Image|ScalarLike other) |
Image | __ipow__ (self, Image|ScalarLike other) |
Image | __rpow__ (self, Image|ScalarLike other) |
Image | __mod__ (self, Image|ScalarLike other) |
Image | __imod__ (self, Image|ScalarLike other) |
Image | __rmod__ (self, Image|ScalarLike other) |
Image | __and__ (self, Image|ScalarLike other) |
Image | __iand__ (self, Image|ScalarLike other) |
Image | __rand__ (self, Image|ScalarLike other) |
Image | __or__ (self, Image|ScalarLike other) |
Image | __ior__ (self, Image|ScalarLike other) |
Image | __ror__ (self, Image|ScalarLike other) |
Image | __xor__ (self, Image|ScalarLike other) |
Image | __ixor__ (self, Image|ScalarLike other) |
Image | __rxor__ (self, Image|ScalarLike other) |
Image | __lshift__ (self, ScalarLike other) |
Image | __ilshift__ (self, ScalarLike other) |
Image | __rlshift__ (self, ScalarLike other) |
Image | __rshift__ (self, ScalarLike other) |
Image | __irshift__ (self, ScalarLike other) |
Image | __rrshift__ (self, ScalarLike other) |
__str__ (self) | |
tuple[tuple[slice,...], tuple[slice,...]] | overlapped_slices (self, Box bbox) |
Image | __getitem__ (self, Any indices) |
Image | __setitem__ (self, indices, Image value) |
Static Public Member Functions | |
Image | from_box (Box bbox, tuple|None bands=None, DTypeLike dtype=float) |
Public Attributes | |
bands | |
n_bands | |
bbox | |
Protected Member Functions | |
Image | _i_update (self, Callable op, Image|ScalarLike other) |
Image | _check_equality (self, Image|ScalarLike other, Callable op) |
bool | _is_spectral_index (self, Any index) |
tuple[slice, slice] | _get_box_slices (self, Box bbox) |
Image | _get_sliced (self, Any indices, Image|None value=None) |
Protected Attributes | |
_data | |
_yx0 | |
_bands | |
A numpy array with an origin and (optional) bands This class contains a 2D numpy array with the addition of an origin (``yx0``) and an optional first index (``bands``) that allows an immutable named index to be used. Notes ----- One of the main limitations of using numpy arrays to store image data is the lack of an ``origin`` attribute that allows an array to retain knowledge of it's location in a larger scene. For example, if a numpy array ``x`` is sliced, eg. ``x[10:20, 30:40]`` the result will be a new ``10x10`` numpy array that has no meta data to inform the user that it was sliced from a larger image. In addition, astrophysical images are also multi-band data cubes, with a 2D image in each band (in fact this is the simplifying assumption that distinguishes scarlet lite from scarlet main). However, the ordering of the bands during processing might differ from the ordering of the bands to display multiband data. So a mechanism was also desired to simplify the sorting and index of an image by band name. Thus, scarlet lite creates a numpy-array like class with the additional ``bands`` and ``yx0`` attributes to keep track of the bands contained in an array and the origin of that array (we specify ``yx0`` as opposed to ``xy0`` to be consistent with the default numpy/C++ ``(y, x)`` ordering of arrays as opposed to the traditional cartesian ``(x, y)`` ordering used in astronomy and other modules in the science pipelines. While this may be a small source of confusion for the user, it is consistent with the ordering in the original scarlet package and ensures the consistency of scarlet lite images and python index slicing. Examples -------- The easiest way to create a new image is to use ``Image(numpy_array)``, for example >>> import numpy as np >>> from lsst.scarlet.lite import Image >>> >>> x = np.arange(12).reshape(3, 4) >>> image = Image(x) >>> print(image) Image: [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] bands=() bbox=Box(shape=(3, 4), origin=(0, 0)) This will create a single band :py:class:`~lsst.scarlet.lite.Image` with origin ``(0, 0)``. To create a multi-band image the input array must have 3 dimensions and the ``bands`` property must be specified: >>> x = np.arange(24).reshape(2, 3, 4) >>> image = Image(x, bands=("i", "z")) >>> print(image) Image: [[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] <BLANKLINE> [[12 13 14 15] [16 17 18 19] [20 21 22 23]]] bands=('i', 'z') bbox=Box(shape=(3, 4), origin=(0, 0)) It is also possible to create an empty single-band image using the ``from_box`` static method: >>> from lsst.scarlet.lite import Box >>> image = Image.from_box(Box((3, 4), (100, 120))) >>> print(image) Image: [[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]] bands=() bbox=Box(shape=(3, 4), origin=(100, 120)) Similarly, an empty multi-band image can be created by passing a tuple of ``bands``: >>> image = Image.from_box(Box((3, 4)), bands=("r", "i")) >>> print(image) Image: [[[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]] <BLANKLINE> [[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]]] bands=('r', 'i') bbox=Box(shape=(3, 4), origin=(0, 0)) To select a sub-image use a ``Box`` to select a spatial region in either a single-band or multi-band image: >>> x = np.arange(60).reshape(3, 4, 5) >>> image = Image(x, bands=("g", "r", "i"), yx0=(20, 30)) >>> bbox = Box((2, 2), (21, 32)) >>> print(image[bbox]) Image: [[[ 7 8] [12 13]] <BLANKLINE> [[27 28] [32 33]] <BLANKLINE> [[47 48] [52 53]]] bands=('g', 'r', 'i') bbox=Box(shape=(2, 2), origin=(21, 32)) To select a single-band image from a multi-band image, pass the name of the band as an index: >>> print(image["r"]) Image: [[20 21 22 23 24] [25 26 27 28 29] [30 31 32 33 34] [35 36 37 38 39]] bands=() bbox=Box(shape=(4, 5), origin=(20, 30)) Multi-band images can also be sliced in the spatial dimension, for example >>> print(image["g":"r"]) Image: [[[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19]] <BLANKLINE> [[20 21 22 23 24] [25 26 27 28 29] [30 31 32 33 34] [35 36 37 38 39]]] bands=('g', 'r') bbox=Box(shape=(4, 5), origin=(20, 30)) and >>> print(image["r":"r"]) Image: [[[20 21 22 23 24] [25 26 27 28 29] [30 31 32 33 34] [35 36 37 38 39]]] bands=('r',) bbox=Box(shape=(4, 5), origin=(20, 30)) both extract a slice of a multi-band image. .. warning:: Unlike numerical indices, where ``slice(x, y)`` will select the subset of an array from ``x`` to ``y-1`` (excluding ``y``), a spectral slice of an ``Image`` will return the image slice including band ``y``. It is also possible to change the order or index a subset of bands in an image. For example: >>> print(image[("r", "g", "i")]) Image: [[[20 21 22 23 24] [25 26 27 28 29] [30 31 32 33 34] [35 36 37 38 39]] <BLANKLINE> [[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19]] <BLANKLINE> [[40 41 42 43 44] [45 46 47 48 49] [50 51 52 53 54] [55 56 57 58 59]]] bands=('r', 'g', 'i') bbox=Box(shape=(4, 5), origin=(20, 30)) will return a new image with the bands re-ordered. Images can be combined using the standard arithmetic operations similar to numpy arrays, including ``+, -, *, /, **`` etc, however, if two images are combined with different bounding boxes, the _union_ of the two boxes is used for the result. For example: >>> image1 = Image(np.ones((2, 3, 4)), bands=tuple("gr")) >>> image2 = Image(np.ones((2, 3, 4)), bands=tuple("gr"), yx0=(2, 3)) >>> result = image1 + image2 >>> print(result) Image: [[[1. 1. 1. 1. 0. 0. 0.] [1. 1. 1. 1. 0. 0. 0.] [1. 1. 1. 2. 1. 1. 1.] [0. 0. 0. 1. 1. 1. 1.] [0. 0. 0. 1. 1. 1. 1.]] <BLANKLINE> [[1. 1. 1. 1. 0. 0. 0.] [1. 1. 1. 1. 0. 0. 0.] [1. 1. 1. 2. 1. 1. 1.] [0. 0. 0. 1. 1. 1. 1.] [0. 0. 0. 1. 1. 1. 1.]]] bands=('g', 'r') bbox=Box(shape=(5, 7), origin=(0, 0)) If instead you want to additively ``insert`` image 1 into image 2, so that they have the same bounding box as image 2, use >>> _ = image2.insert(image1) >>> print(image2) Image: [[[2. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.]] <BLANKLINE> [[2. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.]]] bands=('g', 'r') bbox=Box(shape=(3, 4), origin=(2, 3)) To insert an image using a different operation use >>> from operator import truediv >>> _ = image2.insert(image1, truediv) >>> print(image2) Image: [[[2. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.]] <BLANKLINE> [[2. 1. 1. 1.] [1. 1. 1. 1.] [1. 1. 1. 1.]]] bands=('g', 'r') bbox=Box(shape=(3, 4), origin=(2, 3)) However, depending on the operation you may get unexpected results since now there could be ``NaN`` and ``inf`` values due to the zeros in the non-overlapping regions. Instead, to select only the overlap region one can use >>> result = image1 / image2 >>> print(result[image1.bbox & image2.bbox]) Image: [[[0.5]] <BLANKLINE> [[0.5]]] bands=('g', 'r') bbox=Box(shape=(1, 1), origin=(2, 3)) Parameters ---------- data: The array data for the image. bands: The bands coving the image. yx0: The (y, x) offset for the lower left of the image.
lsst.scarlet.lite.image.Image.__init__ | ( | self, | |
np.ndarray | data, | ||
Sequence | None | bands = None, | ||
tuple[int, int] | None | yx0 = None ) |
Definition at line 358 of file image.py.
Check if this image is equal to another.
Definition at line 814 of file image.py.
Check if this image is greater than or equal to another.
Definition at line 824 of file image.py.
Image lsst.scarlet.lite.image.Image.__getitem__ | ( | self, | |
Any | indices ) |
Get the subset of an image Parameters ---------- indices: The indices to select a subsection of the image. Returns ------- result: The resulting image obtained by selecting subsets of the iamge based on the `indices`.
Definition at line 1199 of file image.py.
Check if this image is greater than or equal to another.
Definition at line 836 of file image.py.
Combine this image and another image using addition and update in place.
Definition at line 864 of file image.py.
Image lsst.scarlet.lite.image.Image.__ilshift__ | ( | self, | |
ScalarLike | other ) |
Combine this image and another image using multiplication, with this image on the right.
Definition at line 900 of file image.py.
lsst.scarlet.lite.image.Image.__invert__ | ( | self | ) |
Image lsst.scarlet.lite.image.Image.__irshift__ | ( | self, | |
ScalarLike | other ) |
Combine this image and another image using subtraction, with this image on the right.
Definition at line 882 of file image.py.
Check if this image is less than or equal to another.
Definition at line 830 of file image.py.
Image lsst.scarlet.lite.image.Image.__lshift__ | ( | self, | |
ScalarLike | other ) |
Shift this image to the left by other bits.
Definition at line 1012 of file image.py.
Check if this image is less than or equal to another.
Definition at line 842 of file image.py.
lsst.scarlet.lite.image.Image.__neg__ | ( | self | ) |
lsst.scarlet.lite.image.Image.__pos__ | ( | self | ) |
Combine this image and another image using addition, with this image on the right.
Definition at line 870 of file image.py.
Take the bitwise and of other and this.
Definition at line 978 of file image.py.
Floor divide this image by `other` with this on the right.
Definition at line 936 of file image.py.
Image lsst.scarlet.lite.image.Image.__rlshift__ | ( | self, | |
ScalarLike | other ) |
Take the modulus of other % this.
Definition at line 964 of file image.py.
Combine this image and another image using multiplication, with this image on the right.
Definition at line 906 of file image.py.
Take the binary or of other or this.
Definition at line 992 of file image.py.
Raise this other to the power of this image.
Definition at line 950 of file image.py.
Image lsst.scarlet.lite.image.Image.__rrshift__ | ( | self, | |
ScalarLike | other ) |
Image lsst.scarlet.lite.image.Image.__rshift__ | ( | self, | |
ScalarLike | other ) |
Shift this image to the right by other bits.
Definition at line 1027 of file image.py.
Combine this image and another image using subtraction, with this image on the right.
Definition at line 888 of file image.py.
Divide this image by `other` with this on the right.
Definition at line 922 of file image.py.
Take the binary xor of other xor this.
Definition at line 1006 of file image.py.
Set a subset of an image to a given value Parameters ---------- indices: The indices to select a subsection of the image. value: The value to use for the subset of the image. Returns ------- result: The resulting image obtained by selecting subsets of the image based on the `indices`.
Definition at line 1215 of file image.py.
lsst.scarlet.lite.image.Image.__str__ | ( | self | ) |
|
protected |
Compare this array to another. This performs an element by element equality check. Parameters ---------- other: The image to compare this image to. op: The operator used for the comparision (==, !=, >=, <=). Returns ------- image: Image An image made by checking all of the elements in this array with another. Raises ------ TypeError: If `other` is not an `Image`. MismatchedBandsError: If `other` has different bands. MismatchedBoxError: if `other` exists in a different bounding box.
Definition at line 771 of file image.py.
|
protected |
Get the slices of the image to insert it into the overlapping region with `bbox`.
Definition at line 1070 of file image.py.
|
protected |
Select a subset of an image Parameters ---------- indices: The indices to select a subsection of the image. The spectral index can either be a tuple of indices, a slice of indices, or a single index used to select a single-band 2D image. The spatial index (if present) is a `Box`. value: The value used to set this slice of the image. This allows the single `_get_sliced` method to be used for both getting a slice of an image and setting it. Returns ------- result: Image | np.ndarray The resulting image obtained by selecting subsets of the iamge based on the `indices`.
Definition at line 1086 of file image.py.
|
protected |
Update the data array in place. This is typically implemented by `__i<op>__` methods, like `__iadd__`, to apply an operator and update this image with the data in place. Parameters ---------- op: Operator used to combine this image with the `other` image. other: The other image that is combined with this one using the operator `op`. Returns ------- image: Image This image, after being updated by the operator
Definition at line 737 of file image.py.
|
protected |
Check to see if an index is a spectral index. Parameters ---------- index: Either a slice, a tuple, or an element in `Image.bands`. Returns ------- result: ``True`` if `index` is band or tuple of bands.
Definition at line 1046 of file image.py.
tuple lsst.scarlet.lite.image.Image.bands | ( | self | ) |
Box lsst.scarlet.lite.image.Image.bbox | ( | self | ) |
Image lsst.scarlet.lite.image.Image.copy | ( | self, | |
order = None ) |
Make a copy of this image. Parameters ---------- order: The ordering to use for storing the bytes. This is unlikely to be needed, and just defaults to the numpy behavior (C) ordering. Returns ------- image: Image The copy of this image.
Definition at line 680 of file image.py.
lsst.scarlet.lite.image.Image.copy_with | ( | self, | |
np.ndarray | None | data = None, | ||
str | None | order = None, | ||
tuple[str, ...] | None | bands = None, | ||
tuple[int, int] | None | yx0 = None ) |
Copy of this image with some parameters updated. Any parameters not specified by the user will be copied from the current image. Parameters ---------- data: An update for the data in the image. order: The ordering for stored bytes, from numpy.copy. bands: The bands that the resulting image will have. The number of bands must be the same as the first dimension in the data array. yx0: The lower-left of the image bounding box. Returns ------- image: Image The copied image.
Definition at line 697 of file image.py.
np.ndarray lsst.scarlet.lite.image.Image.data | ( | self | ) |
DTypeLike lsst.scarlet.lite.image.Image.dtype | ( | self | ) |
|
static |
Initialize an empty image from a bounding Box and optional bands Parameters ---------- bbox: The bounding box that contains the image. bands: The bands for the image. If bands is `None` then a 2D image is created. dtype: The numpy dtype of the image. Returns ------- image: An empty image contained in ``bbox`` with ``bands`` bands.
Definition at line 380 of file image.py.
int lsst.scarlet.lite.image.Image.height | ( | self | ) |
Insert another image into this image in place. Parameters ---------- image: The image to insert this image into. op: The operator to use when combining the images. Returns ------- result: This instance with `image` inserted.
Definition at line 642 of file image.py.
Insert this image into another image in place. Parameters ---------- image: The image to insert this image into. op: The operator to use when combining the images. Returns ------- result: `image` updated by inserting this instance.
Definition at line 621 of file image.py.
bool lsst.scarlet.lite.image.Image.is_multiband | ( | self | ) |
tuple[tuple[slice, ...], tuple[slice, ...]] lsst.scarlet.lite.image.Image.matched_slices | ( | self, | |
Box | bbox ) |
Get the slices to match this image to a given bounding box Parameters ---------- bbox: The bounding box to match this image to. Returns ------- result: Tuple of indices/slices to match this image to the given bbox.
Definition at line 548 of file image.py.
tuple[tuple[int, ...] | slice, tuple[int, ...] | slice] lsst.scarlet.lite.image.Image.matched_spectral_indices | ( | self, | |
Image | other ) |
Match bands between two images Parameters ---------- other: The other image to match spectral indices to. Returns ------- result: A tuple with a tuple of indices/slices for each dimension, including the spectral dimension.
Definition at line 513 of file image.py.
tuple[tuple[int, ...] | slice, slice, slice] lsst.scarlet.lite.image.Image.multiband_slices | ( | self | ) |
Return the slices required to slice a multiband image
Definition at line 617 of file image.py.
int lsst.scarlet.lite.image.Image.n_bands | ( | self | ) |
Number of bands in the image. If `n_bands == 0` then the image is 2D and does not have a spectral dimension.
Definition at line 424 of file image.py.
tuple[tuple[slice, ...], tuple[slice, ...]] lsst.scarlet.lite.image.Image.overlapped_slices | ( | self, | |
Box | bbox ) |
Get the slices needed to insert this image into a bounding box. Parameters ---------- bbox: The region to insert this image into. Returns ------- overlap: The slice of this image and the slice of the `bbox` required to insert the overlapping portion of this image.
Definition at line 1179 of file image.py.
Image lsst.scarlet.lite.image.Image.project | ( | self, | |
object | tuple[object] | None | bands = None, | ||
Box | None | bbox = None ) |
Project this image into a different set of bands Parameters ---------- bands: Spectral bands to project this image into. Not all bands have to be contained in the image, and not all bands contained in the image have to be used in the projection. bbox: A bounding box to project the image into. Results ------- image: A new image creating by projecting this image into `bbox` and `bands`.
Definition at line 569 of file image.py.
Image lsst.scarlet.lite.image.Image.repeat | ( | self, | |
tuple | bands ) |
Project a 2D image into the spectral dimension Parameters ---------- bands: The bands in the projected image. Returns ------- result: Image The 2D image repeated in each band in the spectral dimension.
Definition at line 659 of file image.py.
tuple[int, ...] lsst.scarlet.lite.image.Image.shape | ( | self | ) |
tuple[int, ...] | slice lsst.scarlet.lite.image.Image.spectral_indices | ( | self, | |
Sequence | slice | bands ) |
The indices to extract each band in `bands` in order from the image This converts a band name, or list of band names, into numerical indices that can be used to slice the internal numpy `data` array. Parameters --------- bands: If `bands` is a list of band names, then the result will be an index corresponding to each band, in order. If `bands` is a slice, then the ``start`` and ``stop`` properties should be band names, and the result will be a slice with the appropriate indices to start at `bands.start` and end at `bands.stop`. Returns ------- band_indices: Tuple of indices for each band in this image.
Definition at line 472 of file image.py.
int lsst.scarlet.lite.image.Image.width | ( | self | ) |
int lsst.scarlet.lite.image.Image.x0 | ( | self | ) |
int lsst.scarlet.lite.image.Image.y0 | ( | self | ) |
tuple[int, int] lsst.scarlet.lite.image.Image.yx0 | ( | self | ) |