Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
6087d69
Add ColormapSet for color blending
izkgao Apr 30, 2025
d6961b2
Update Image.make_active to support CARTA 5.0.0+ API changes
izkgao Apr 30, 2025
9fa89de
Add ColorBlending class with layer management and color blending func…
izkgao May 5, 2025
85b3528
Add color blending documentation and update image handling examples
izkgao May 5, 2025
06445bc
Add ColorBlending.from_files method to create blended images directly…
izkgao Sep 10, 2025
266f1c1
Add tests for ColorBlending and Layer classes
izkgao Sep 10, 2025
606c9f3
Improve mock consistency
izkgao Sep 11, 2025
8e560b9
Merge branch 'dev' into color_blending
izkgao Apr 10, 2026
34bf41b
Fix duplicate imports and docstring formatting in colorblending and i…
izkgao Apr 10, 2026
5d4fca4
Add colorblending module to API documentation
izkgao Apr 10, 2026
032949d
Refactor layers property to use Layer.from_list method
izkgao Apr 10, 2026
2e0abce
Fix indentation in Layer class docstring
izkgao Apr 10, 2026
5c52466
Rename reorder_layers to set_layer_sequence and add support for layer…
izkgao Apr 14, 2026
06fff60
Simplify layer_list implementation by using frames.length instead of …
izkgao Apr 14, 2026
b7af8dc
Add explicit validation to prevent deletion of base layer in ColorBle…
izkgao Apr 14, 2026
fbcf72f
Add validation to prevent alpha list length mismatch in set_alpha method
izkgao Apr 14, 2026
6596ab3
Refactor ColorBlending to use store_id instead of image_id and add fr…
izkgao Apr 14, 2026
9a20cfa
Add color_blending_list method to Session class for retrieving open c…
izkgao Apr 14, 2026
d9bcab4
Update quickstart documentation to clarify ColorBlending layer termin…
izkgao Apr 14, 2026
a34e646
Drop support for carta version < 5.0 for make_active
izkgao Apr 14, 2026
4ce4429
Update documentation references to use new wcs_overlay module paths f…
izkgao Apr 14, 2026
25e0baa
Add validation test for invalid colormap name in Layer.set_colormap m…
izkgao Apr 14, 2026
cb22ed5
Fix indentation in Layer.from_layer_ids docstring return section
izkgao Apr 14, 2026
91e952d
Add validation to prevent exceeding maximum initial layer count in Co…
izkgao Apr 14, 2026
3f1c4fe
Rename set_vectoroverlay_visible method to set_vector_overlay_visible…
izkgao Apr 14, 2026
d337759
Rename ColormapSet.Rainbow to RAINBOW for consistent uppercase enum n…
izkgao Apr 14, 2026
345c17d
Add module docstring to colorblending.py describing color blending fu…
izkgao Apr 14, 2026
2bf9d1f
Replace explicit type annotations with placeholder format strings in …
izkgao Apr 14, 2026
e16c9f4
Change periods to colons in ColorBlending section introductory senten…
izkgao Apr 14, 2026
2812ffa
Update test_make_active to use setActiveImageByFileId action instead …
izkgao Apr 14, 2026
509d4e2
Fix ColorBlending initialization to rebuild layers from requested ima…
izkgao Apr 15, 2026
af48cf3
Add validation to reject duplicate layer indices in ColorBlending.set…
izkgao Apr 15, 2026
2f7d76b
Remove automatic inversion reset when applying colormap sets in Color…
izkgao Apr 15, 2026
56e019d
Fix imageview_id property to search imageList by store_id instead of …
izkgao Apr 15, 2026
6e02ba2
Convert layer_indices to list before comparing with current_layer_ind…
izkgao Apr 15, 2026
9ea1a66
Style check
izkgao Apr 15, 2026
f024c5c
Merge branch 'dev' into zhenkai/color_blending
izkgao Apr 20, 2026
50a21bc
Implement ImageBase class
izkgao Apr 20, 2026
6c2d9a1
Update Image.__repr__ to use [Closed] label instead of [Invalid] for …
izkgao Apr 20, 2026
ace85cb
Update ColorBlending and Layer to use color_blending_id and improve _…
izkgao Apr 20, 2026
566dfb0
Add get_image method and refactor image list handling to support hete…
izkgao Apr 20, 2026
07353f1
Filter image_list to return only Image instances in _images helper me…
izkgao Apr 20, 2026
4302da5
Update tests
izkgao Apr 20, 2026
d424e90
Update terminology from "file-based" to "frame-backed" in image docst…
izkgao Apr 20, 2026
5c9e334
Set default colormap set based on number of files for open_as_color_b…
izkgao Apr 20, 2026
ac58b5f
Extract ImageBase class into separate module
izkgao Apr 20, 2026
7be1e65
Add parametrized test for default colormap set selection in open_as_c…
izkgao Apr 20, 2026
4a06836
Reorganize ColorBlending methods with section comments for better cod…
izkgao Apr 20, 2026
ec1501a
Add image_view_order property to Layer class and update __repr__ to u…
izkgao Apr 20, 2026
68f6b27
Set default colormap set based on number of images for create_color_b…
izkgao Apr 20, 2026
57bdb55
Add documentation for image list inspection and update color blending…
izkgao Apr 20, 2026
e7a8370
Add validation to prevent rebasing existing color blendings when crea…
izkgao Apr 21, 2026
e13fd3a
Rename active_frame to active_image and add support for ColorBlending…
izkgao Apr 22, 2026
b47334b
Rename get_image to image_by_id and update signature to use keyword a…
izkgao Apr 22, 2026
a4630de
Update set_cursor to use activeFrame.setCursorPosition action and rem…
izkgao Apr 22, 2026
c6e8a54
Remove ColorBlending factory methods and simplify create_color_blendi…
izkgao Apr 22, 2026
d6a479e
Reorganize Session methods with section comments for color blending a…
izkgao Apr 22, 2026
9d86616
Fix default colormap set selection to use layer count instead of tota…
izkgao Apr 22, 2026
bebe9e4
Add carta_version property to Session and include it in __repr__ when…
izkgao Apr 22, 2026
76a6c37
Update documentation references to use new wcs module paths and impro…
izkgao Apr 22, 2026
49e4e78
Add zoom_to_size method to ColorBlending class with validation and de…
izkgao Apr 22, 2026
21b22f0
Refactor ImageBase to use ABC pattern, move image_view_order implemen…
izkgao Apr 22, 2026
1c5b8ab
Update quickstart documentation to use unpacked layer variables inste…
izkgao Apr 22, 2026
8940ca3
Update test regex pattern to match abstract method error messages mor…
izkgao Apr 22, 2026
f0b86ae
Fix a test warning
izkgao Apr 22, 2026
1e4d2fe
Add test coverage
izkgao Apr 22, 2026
8620e85
Improve error messages to include actual values and update tests to v…
izkgao Apr 22, 2026
c982c89
Add session.clear_spatial_reference() call before setting new spatial…
izkgao Apr 22, 2026
ab1753d
Add validation to reject empty file list in open_as_color_blending me…
izkgao Apr 22, 2026
8f6ab9e
Optimize active_image method to retrieve activeImage object once inst…
izkgao Apr 22, 2026
65eaced
Refactor _find_image_view_order to use imageViewConfigStore.getImageL…
izkgao Apr 23, 2026
298043c
Rename loop variable from 'call' to 'call_' to avoid shadowing built-…
izkgao Apr 23, 2026
d421fe9
Simplify __repr__ method by removing manual cache checking and relyin…
izkgao Apr 28, 2026
c69d57a
Merge branch 'dev' into zhenkai/color_blending
izkgao Apr 28, 2026
8a5e6f2
Rename colorblending module to color_blending and update all referenc…
izkgao May 4, 2026
e4c89bf
Remove set_layer_sequence method from ColorBlending class because it …
izkgao May 21, 2026
c411b4c
Remove set_layer_sequence tests after removing the method from ColorB…
izkgao May 21, 2026
0d8c8bc
Rename set_layer to set_layer_image and swap parameter order to put l…
izkgao Aug 12, 2026
955ff8c
Refactor ImageBase to use class-level IMAGE_TYPE constant and add ima…
izkgao Aug 12, 2026
51e2c48
Add False parameter to setSpatialReference action call to disable col…
izkgao Aug 12, 2026
d46311f
Add Layer.delete method and update ColorBlending.delete_layer to hand…
izkgao Aug 12, 2026
4168f29
Refactor set_alpha validation to use Evaluate validator with depth at…
izkgao Aug 12, 2026
69aedb9
Add colormap and alpha properties to Layer class and improve docstrin…
izkgao Aug 13, 2026
638b032
Add Layer.set_image method and allow ColorBlending.set_layer_image to…
izkgao Aug 13, 2026
26f4983
Add Session.images and Session.color_blendings methods to retrieve im…
izkgao Aug 13, 2026
9f44dec
Update quickstart documentation
izkgao Aug 13, 2026
14de716
Rename image_ids parameter to file_ids in wcs_overlay for consistency…
izkgao Aug 13, 2026
e6d93ce
Add inverted property to Layer class and include it in repr output
izkgao Aug 13, 2026
2f49b2a
Update validate decorator to support keyword-only parameters by inclu…
izkgao Aug 13, 2026
8ea65e8
Add validation decorators to ColorBlending.add_layer, ColorBlending.s…
izkgao Aug 13, 2026
272366c
Simplify Session.image_by_id to directly instantiate Image and ColorB…
izkgao Aug 13, 2026
03be496
Rename image_view_order to view_index and file_id to image_id through…
izkgao Aug 13, 2026
189a3a7
Rename alpha to alphas and layer_list to layers, add optional layer_i…
izkgao Aug 13, 2026
8643125
Add validation to ColorBlending.set_layer_image to prevent duplicate …
izkgao Aug 13, 2026
eac8119
Add optional images parameter to Session.create_color_blending to all…
izkgao Aug 13, 2026
665cef5
Refactor views, images, and color_blendings methods to use single fro…
izkgao Aug 14, 2026
c33caa5
Remove unnecessary docstring modifications
izkgao Aug 14, 2026
ef07dae
Refactor views, images, and color_blendings methods to use walrus ope…
izkgao Aug 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
553 changes: 553 additions & 0 deletions carta/color_blending.py

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions carta/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ class ComplexComponent(StrEnum):
Colormap.__doc__ = """All available colormaps."""


class ColormapSet(StrEnum):
"""Colormap sets for color blending."""
RGB = "RGB"
CMY = "CMY"
RAINBOW = "Rainbow"


class ImageType(IntEnum):
"""View item types, corresponding to the frontend ImageType enum."""
FRAME = 0
COLOR_BLENDING = 1
PV_PREVIEW = 2


Scaling = IntEnum('Scaling', ('LINEAR', 'LOG', 'SQRT', 'SQUARE', 'POWER', 'GAMMA'), start=0)
Scaling.__doc__ = """Colormap scaling types."""

Expand Down
58 changes: 27 additions & 31 deletions carta/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
"""


from .constants import Polarization, SpatialAxis, SpectralSystem, SpectralType, SpectralUnit
from .util import Macro, cached, BasePathMixin, Point as Pt
from .constants import ImageType, Polarization, SpatialAxis, SpectralSystem, SpectralType, SpectralUnit
from .view import View
from .util import Macro, cached, BasePathMixin, CartaScriptingException, Point as Pt
from .units import AngularSize, WorldCoordinate
from .validation import validate, Number, Constant, Boolean, Evaluate, Attr, Attrs, OneOf, Size, Coordinate, NoneOr, IterableOf, Point
from .metadata import parse_header

from .raster import Raster
from .contours import Contours
from .vector_overlay import VectorOverlay
from .wcs_overlay import ImageWCSOverlay
from .region import RegionSet


class Image(BasePathMixin):
class Image(View, BasePathMixin):
"""This object corresponds to an image open in a CARTA frontend session.

This class should not be instantiated directly. Instead, use the session object's methods for opening new images or retrieving existing images.
Expand Down Expand Up @@ -47,8 +47,10 @@ class Image(BasePathMixin):
Functions for manipulating regions associated with this image.
"""

VIEW_TYPE = ImageType.FRAME

def __init__(self, session, image_id):
self.session = session
super().__init__(session)
self.image_id = image_id

self._base_path = f"frameMap[{image_id}]"
Expand All @@ -61,6 +63,10 @@ def __init__(self, session, image_id):
self.wcs = ImageWCSOverlay(self)
self.regions = RegionSet(self)

@property
def _stable_id(self):
return self.image_id

@classmethod
def new(cls, session, directory, file_name, hdu, append, image_arithmetic, make_active=True, update_directory=False):
"""Open or append a new image in the session and return an image object associated with it.
Expand Down Expand Up @@ -102,29 +108,23 @@ def new(cls, session, directory, file_name, hdu, append, image_arithmetic, make_
image_id = session.call_action(command, *params, return_path="frameInfo.fileId")
return cls(session, image_id)

@classmethod
def from_list(cls, session, image_list):
"""Create a list of image objects from a list of open images retrieved from the frontend.

This method should not be used directly. It is wrapped by :obj:`carta.session.Session.image_list`.
def __repr__(self):
"""A human-readable representation of this image object."""
cls = type(self).__name__
cached_name = getattr(self, "_cache", {}).get("file_name")
name_part = f", file_name={cached_name!r}" if cached_name is not None else ""

Parameters
----------
session : :obj:`carta.session.Session`
The session object.
image_list : list of dicts
The JSON object representing frame names retrieved from the frontend.
try:
index = self.view_index
except (CartaScriptingException, RuntimeError):
return f"[Closed] {cls}(view_index=None{name_part}, image_id={self.image_id})"

Returns
-------
list of :obj:`carta.image.Image`
A list of new image objects.
"""
return [cls(session, f["value"]) for f in image_list]
try:
name = self.file_name
except CartaScriptingException:
return f"[Closed] {cls}(view_index={index}{name_part}, image_id={self.image_id})"

def __repr__(self):
"""A human-readable representation of this image object."""
return f"{self.session.session_id}:{self.image_id}:{self.file_name}"
return f"{cls}(view_index={index}, file_name={name!r}, image_id={self.image_id})"

# METADATA

Expand Down Expand Up @@ -254,13 +254,9 @@ def polarizations(self):

# SELECTION

def make_active(self):
"""Make this the active image."""
self.session.call_action("setActiveFrameById", self.image_id)

def make_spatial_reference(self):
"""Make this image the spatial reference."""
self.session.call_action("setSpatialReference", self._frame)
self.session.call_action("setSpatialReference", self._frame, False)

@validate(Boolean())
def set_spatial_matching(self, state):
Expand Down Expand Up @@ -362,7 +358,7 @@ def valid_wcs(self):
def set_center(self, x, y):
"""Set the center position, in image or world coordinates.

World coordinates are interpreted according to the session's globally set coordinate system and any custom number formats. These can be changed using :obj:`carta.session.set_coordinate_system` and :obj:`set_custom_number_format`.
World coordinates are interpreted according to the session's globally set coordinate system and any custom number formats. These can be changed using :obj:`carta.session.wcs.global_.set_coordinate_system` and :obj:`carta.session.wcs.numbers.set_format`.

Coordinates must either both be image coordinates or match the current number formats. Numbers are interpreted as image coordinates, and numeric strings with no units are interpreted as degrees.

Expand Down
Loading