Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and unify the interface for the raster image, contours, and vector overlay. #123

Merged
merged 96 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
1c6b3f2
Add apply_vector_overlay and clear_vector_overlay
I-Chenn Mar 9, 2023
c1c0ebd
Add set_vector_overlay_color and set_vector_overlay_colormap
I-Chenn Mar 11, 2023
43c8dd0
Minor modification
I-Chenn Mar 11, 2023
6e924e8
Add configure_vector_overlay
I-Chenn Mar 13, 2023
ce98bd7
Minor modification for comments
I-Chenn Mar 13, 2023
32aae92
Deduce pixel_averaging_enabled and threshold_enabled
I-Chenn Mar 13, 2023
cb56287
Deduce debiasing and modify description
I-Chenn Mar 14, 2023
cbdce93
Minor modification
I-Chenn Mar 14, 2023
401652e
Add set_style plot set_visible show hide for vector overlay
I-Chenn Mar 15, 2023
4ab2286
Minor modification
I-Chenn Mar 15, 2023
26aac1f
Modify plot_vector_overlay
I-Chenn Mar 15, 2023
406ef91
Minor modification
I-Chenn Mar 15, 2023
a330edc
Modify setIntensityRange and setLengthRange
I-Chenn Mar 17, 2023
e947e96
Modification of setting intensity range in set_vector_overlay_style
I-Chenn Mar 21, 2023
a77a30c
Monor modification
I-Chenn Mar 21, 2023
3b7d4ce
Merge branch 'dev' into icchen/79_render_vector_overlay
I-Chenn Mar 22, 2023
7169d88
Replace None with non-empty string
I-Chenn Mar 28, 2023
3ccac4f
Adopt macro in configure_vector_overlay
I-Chenn Apr 3, 2023
d8554c4
Modification to set_vector_overlay_style
I-Chenn Apr 3, 2023
e47a216
Modify plot_vector_overlay
I-Chenn Apr 4, 2023
a250939
Logic modification to set_vector_overlay_style
I-Chenn Apr 4, 2023
892014f
Minor modification to description
I-Chenn Apr 4, 2023
6e61813
Merge branch 'dev' into icchen/79_render_vector_overlay
I-Chenn Apr 4, 2023
91eac81
Modify validate check for intensity_max and intensity_min
I-Chenn Apr 4, 2023
84fea86
Move bias and contrast fom set_colormap to set_scaling
I-Chenn May 18, 2023
081bc63
Merge branch 'dev' into icchen/79_render_vector_overlay
I-Chenn May 24, 2023
bc80d47
Update outdated syntax
I-Chenn May 26, 2023
285433b
Add Undefined class in util
I-Chenn May 30, 2023
556eb32
Simplify intensity_min and intensity_max definition
I-Chenn May 30, 2023
142c3b7
Modification to description and setIntensityRange logic
I-Chenn May 30, 2023
5b9103a
Description modified
I-Chenn Jun 2, 2023
910c2a5
Add colormap default description
I-Chenn Jun 2, 2023
2a4df7f
Add default value for color
I-Chenn Jun 2, 2023
dfbb4be
Merge branch 'dev' into icchen/58_move_bias_contrast_to_set_scaling
I-Chenn Jun 14, 2023
017ad6b
Merge branch 'dev' into icchen/79_render_vector_overlay
I-Chenn Jul 4, 2023
1e7d13e
Format fix
I-Chenn Jul 4, 2023
b9e1ec4
Merge branch 'dev' into icchen/58_move_bias_contrast_to_set_scaling
I-Chenn Jul 4, 2023
0d5160b
Merge remote-tracking branch 'origin/dev' into icchen/58_move_bias_co…
confluence Aug 7, 2023
49fafc8
Fix complaint in latest flake8
confluence Aug 7, 2023
ef5f780
Make all parameters to set_scaling optional; set alpha and gamma rega…
confluence Aug 7, 2023
e953d8b
Updated descriptions for alpha and gamma
confluence Aug 7, 2023
168592c
Added some min/max validation; added unit tests
confluence Aug 7, 2023
aba9fa7
Merge remote-tracking branch 'origin/dev' into icchen/79_render_vecto…
confluence Aug 7, 2023
d9d336c
formatting pass and flake8 fix
confluence Aug 7, 2023
08a61fe
Added some magic for specifying optional and repeated validation para…
confluence Aug 7, 2023
390de89
Some tests; minor fixes and refactoring
confluence Aug 8, 2023
8b8c076
Merge remote-tracking branch 'origin/dev' into icchen/79_render_vecto…
confluence Aug 10, 2023
e4aef53
Merge remote-tracking branch 'origin/dev' into icchen/79_render_vecto…
confluence Aug 10, 2023
265e31f
Merge remote-tracking branch 'origin/dev' into icchen/58_move_bias_co…
confluence Aug 10, 2023
5a5d1ab
Simplified optional parameters
confluence Aug 10, 2023
416a18c
Merge remote-tracking branch 'origin/dev' into icchen/79_render_vecto…
confluence Aug 10, 2023
87a563f
Merge remote-tracking branch 'origin/dev' into icchen/58_move_bias_co…
confluence Aug 10, 2023
5d50246
Merge remote-tracking branch 'origin/dev' into icchen/79_render_vecto…
confluence Oct 24, 2023
295d2f5
Moved vector overlay functions to sub-object.
confluence Oct 24, 2023
bb7223c
Refactored plot function to avoid unnecessary calls. Completed vector…
confluence Oct 25, 2023
6f1d8e0
Added check for subobjects on image
confluence Oct 25, 2023
fc91eee
Added missing module to docs.
confluence Oct 25, 2023
9d941ff
Merge branch 'icchen/79_render_vector_overlay' into icchen/58_move_bi…
confluence Oct 26, 2023
e0773d5
First pass to split up image subobjects. Contour and raster tests to …
confluence Oct 26, 2023
90e3848
Removed unnecessary fixture
confluence Oct 27, 2023
578feca
Merge remote-tracking branch 'origin/dev' into icchen/58_move_bias_co…
confluence Oct 27, 2023
516c8b2
Refactored raster functions. Moved contours histogram flag to contour…
confluence Oct 31, 2023
8a40e58
formatting pass
confluence Oct 31, 2023
299e63a
Finished refactoring vector overlay and test. Added helper function f…
confluence Nov 3, 2023
8dcac08
Refactored contours and added contour tests
confluence Nov 3, 2023
e2c88c6
Factored WCS overlay functions out of session and into subobject
confluence Nov 7, 2023
c5d11bc
Moved WCS overlay settings out of session into a subobject, and refac…
confluence Nov 17, 2023
fe71073
Fixed syntax bug.
confluence Nov 17, 2023
ae0d6b1
Added basic tests for overlay functions, and fixed some bugs.
confluence Nov 27, 2023
0a4e5a4
Updated quickstart examples for refactored interface
confluence Nov 28, 2023
bd74678
Split contour dash mode and thickness into two functions.
confluence Jan 9, 2024
c32a696
Renamed beam.beam_type and beam.set_beam_type to remove extra beam
confluence Jan 10, 2024
8545807
Removed histogram functions based on feedback
confluence Jan 10, 2024
4ee96a4
Fixed global_ name in docs.
confluence Jan 15, 2024
2e58e9b
Set session attribute on overlay components correctly. Escape backsla…
confluence Jan 15, 2024
e4f1840
Correctly pass the session to the overlay component constructor(s)
confluence Jan 15, 2024
4d34dac
Rename session's overlay attribute to wcs
confluence Jan 15, 2024
890ee7d
Fixed names of beam type property and action
confluence Jan 16, 2024
52ab504
Remove bogus custom text from colorbar numbers component
confluence Jan 17, 2024
3eb27d2
Fixed broken font style pattern
confluence Jan 17, 2024
8fb3388
Added missing font size functionality to overlay components with fonts
confluence Jan 17, 2024
aae0519
Merge remote-tracking branch 'origin/dev' into icchen/58_move_bias_co…
confluence Feb 27, 2024
0639491
Remove bogus visibility settings from ticks
confluence Mar 12, 2024
b452208
Remove ticks from visibility tests
confluence Mar 12, 2024
2649ea8
Fixed path of method to enable custom colorbar label text. Added test…
confluence Mar 13, 2024
fe43720
Merge remote-tracking branch 'origin/dev' into icchen/58_move_bias_co…
confluence Apr 3, 2024
0131929
Refactored and expanded image-specific WCS overlay properties
confluence May 21, 2024
266976f
Rename wcs subobject in instructions
confluence May 21, 2024
146e6f5
Make custom text API match the beam API
confluence May 21, 2024
61f3a8f
Added session.raster with pixel grid controls; fixed test logic for c…
confluence May 23, 2024
7f6f89a
remove outdated TODO comments
confluence May 23, 2024
040f536
Added spectral conversion for PV images to image class
confluence May 28, 2024
0303172
Added missing modules to generated docs
confluence May 28, 2024
8ae577c
Updated docstrings for spectral conversion functions.
confluence May 30, 2024
1b79f39
remove function for toggling labels
confluence May 30, 2024
5f5d8df
Merge remote-tracking branch 'origin/dev' into icchen/58_move_bias_co…
confluence May 30, 2024
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
102 changes: 97 additions & 5 deletions carta/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class LabelType(StrEnum):

class BeamType(StrEnum):
"""Beam types."""
OPEN = "Open"
SOLID = "Solid"
OPEN = "open"
SOLID = "solid"


# BlueprintJS colour palettes (2 and 4)
Expand Down Expand Up @@ -103,7 +103,7 @@ class BeamType(StrEnum):


class PaletteColor(StrEnum):
"""Palette colours used for overlay elements.
"""Palette colours used for WCS overlay elements.

Members of this enum class have additional attributes.

Expand All @@ -129,9 +129,9 @@ def __init__(self, value):


Overlay = StrEnum('Overlay', [(c.upper(), c) for c in ("global", "title", "grid", "border", "ticks", "axes", "numbers", "labels", "colorbar")] + [('BEAM', 'beam.settingsForDisplay')])
Overlay.__doc__ = """Overlay elements.
Overlay.__doc__ = """WCS overlay elements.

Member values are paths to stores corresponding to these elements, relative to the overlay store.
Member values are paths to stores corresponding to these elements, relative to the WCS overlay store.
"""


Expand Down Expand Up @@ -214,3 +214,95 @@ class GridMode(StrEnum):
"""Grid modes."""
DYNAMIC = "dynamic"
FIXED = "fixed"


class FontFamily(IntEnum):
"""Font family used in WCS overlay components."""
SANS_SERIF = 0
TIMES = 1
ARIAL = 2
PALATINO = 3
COURIER_NEW = 4


class FontStyle(IntEnum):
"""Font style used in WCS overlay components."""
NORMAL = 0
ITALIC = 1
BOLD = 2
BOLD_ITALIC = 3


class ColorbarPosition(StrEnum):
"""Colorbar positions."""
RIGHT = "right"
TOP = "top"
BOTTOM = "bottom"


class SpectralSystem(StrEnum):
"""Spectral systems."""
LSRK = "LSRK"
LSRD = "LSRD"
BARY = "BARYCENT"
TOPO = "TOPOCENT"


class SpectralUnit(StrEnum):
"""Spectral units."""
KMS = "km/s"
MS = "m/s"
GHZ = "GHz"
MHZ = "MHz"
KHZ = "kHz"
HZ = "Hz"
M = "m"
MM = "mm"
UM = "um"
NM = "nm"
ANGSTROM = "Angstrom"


SPECTRAL_TYPE_DESCRIPTION = {
"VRAD": "Radio velocity",
"VOPT": "Optical velocity",
"FREQ": "Frequency",
"WAVE": "Vacuum wavelength",
"AWAV": "Air wavelength",
}


SPECTRAL_TYPE_UNITS = {
"VRAD": (SpectralUnit.KMS, SpectralUnit.MS),
"VOPT": (SpectralUnit.KMS, SpectralUnit.MS),
"FREQ": (SpectralUnit.GHZ, SpectralUnit.MHZ, SpectralUnit.KHZ, SpectralUnit.HZ),
"WAVE": (SpectralUnit.MM, SpectralUnit.M, SpectralUnit.UM, SpectralUnit.NM, SpectralUnit.ANGSTROM),
"AWAV": (SpectralUnit.MM, SpectralUnit.M, SpectralUnit.UM, SpectralUnit.NM, SpectralUnit.ANGSTROM),
}


class SpectralType(StrEnum):
"""Spectral types.

Members of this enum class have additional attributes.

Attributes
----------
description : string
The human-readable description of this type.
units : set of :obj:`carta.constants.SpectralUnit`
The units supported for this type.
default_unit : :obj:`carta.constants.SpectralUnit`
The default unit for this type.
"""

def __init__(self, value):
self.description = SPECTRAL_TYPE_DESCRIPTION[self.name]
self.units = set(SPECTRAL_TYPE_UNITS[self.name])
self.default_unit = SPECTRAL_TYPE_UNITS[self.name][0]

VRAD = "VRAD",
VOPT = "VOPT",
FREQ = "FREQ",
WAVE = "WAVE",
AWAV = "AWAV",
186 changes: 186 additions & 0 deletions carta/contours.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
"""This module contains functionality for interacting with the contours of an image. The class in this module should not be instantiated directly. When an image object is created, a contours object is automatically created as a property."""

from .util import BasePathMixin
from .constants import Colormap, SmoothingMode, ContourDashMode
from .validation import validate, Number, Color, Constant, Boolean, IterableOf, all_optional, vargs


class Contours(BasePathMixin):
"""Utility object for collecting image functions related to contours.

Parameters
----------
image : :obj:`carta.image.Image` object
The image associated with this contours object.

Attributes
----------
image : :obj:`carta.image.Image` object
The image associated with this contours object.
session : :obj:`carta.session.Session` object
The session object associated with this contours object.
"""

def __init__(self, image):
self.image = image
self.session = image.session
self._base_path = f"{image._base_path}.contourConfig"

@validate(*all_optional(IterableOf(Number()), Constant(SmoothingMode), Number()))
def configure(self, levels=None, smoothing_mode=None, smoothing_factor=None):
"""Configure contours.

Parameters
----------
levels : {0}
The contour levels. This may be a numeric numpy array; e.g. the output of ``arange``. If this is unset, the current configured levels will be used.
smoothing_mode : {1}
The smoothing mode. If this is unset, the frontend default will be used.
smoothing_factor : {2}
The smoothing kernel size in pixels. If this is unset, the frontend default will be used.
"""
if levels is not None or smoothing_mode is not None or smoothing_factor is not None:
if levels is None:
levels = self.macro("", "levels")
if smoothing_mode is None:
smoothing_mode = self.macro("", "smoothingMode")
if smoothing_factor is None:
smoothing_factor = self.macro("", "smoothingFactor")
self.call_action("setContourConfiguration", levels, smoothing_mode, smoothing_factor)

@validate(Constant(ContourDashMode))
def set_dash_mode(self, dash_mode):
"""Set the contour dash mode.

Parameters
----------
dash_mode : {0}
The dash mode.
"""
self.call_action("setDashMode", dash_mode)

@validate(Number())
def set_thickness(self, thickness):
"""Set the contour thickness.

Parameters
----------
thickness : {0}
The thickness.
"""
self.call_action("setThickness", thickness)

@validate(Color())
def set_color(self, color):
"""Set the contour color.

This automatically disables use of the contour colormap.

Parameters
----------
color : {0}
The color. The default is green.
"""
self.call_action("setColor", color)
self.call_action("setColormapEnabled", False)

@validate(Constant(Colormap))
def set_colormap(self, colormap):
"""Set the contour colormap.

This also automatically enables the colormap.

Parameters
----------
colormap : {0}
The colormap. The default is :obj:`carta.constants.Colormap.VIRIDIS`.
"""
self.call_action("setColormap", colormap)
self.call_action("setColormapEnabled", True)

@validate(*all_optional(Number(-1, 1), Number(0, 2)))
def set_bias_and_contrast(self, bias=None, contrast=None):
"""Set the contour bias and contrast.

Parameters
----------
bias : {0}
The colormap bias. The initial value is ``0``.
contrast : {1}
The colormap contrast. The initial value is ``1``.
"""
if bias is not None:
self.call_action("setColormapBias", bias)
if contrast is not None:
self.call_action("setColormapContrast", contrast)

def apply(self):
"""Apply the contour configuration."""
self.image.call_action("applyContours")

@validate(*all_optional(*vargs(configure, set_dash_mode, set_thickness, set_color, set_colormap, set_bias_and_contrast)))
def plot(self, levels=None, smoothing_mode=None, smoothing_factor=None, dash_mode=None, thickness=None, color=None, colormap=None, bias=None, contrast=None):
"""Configure contour levels, scaling, dash, and colour or colourmap; and apply contours; in a single step.

If both a colour and a colourmap are provided, the colourmap will be visible.

Parameters
----------
levels : {0}
The contour levels. This may be a numeric numpy array; e.g. the output of ``arange``. If this is unset, the current configured levels will be used.
smoothing_mode : {1}
The smoothing mode. If this is unset, the frontend default will be used.
smoothing_factor : {2}
The smoothing kernel size in pixels. If this is unset, the frontend default will be used.
dash_mode : {3}
The dash mode.
thickness : {4}
The thickness.
color : {5}
The color. The default is green.
colormap : {6}
The colormap. The default is :obj:`carta.constants.Colormap.VIRIDIS`.
bias : {7}
The colormap bias.
contrast : {8}
The colormap contrast.
"""
changes_made = False

for method, args in [
(self.configure, (levels, smoothing_mode, smoothing_factor)),
(self.set_dash_mode, (dash_mode,)),
(self.set_thickness, (thickness,)),
(self.set_color, (color,)),
(self.set_colormap, (colormap,)),
(self.set_bias_and_contrast, (bias, contrast)),
]:
if any(a is not None for a in args):
method(*args)
changes_made = True

if changes_made:
self.apply()

def clear(self):
"""Clear the contours."""
self.image.call_action("clearContours", True)

@validate(Boolean())
def set_visible(self, state):
"""Set the contour visibility.

Parameters
----------
state : {0}
The desired visibility state.
"""
self.call_action("setVisible", state)

def show(self):
"""Show the contours."""
self.set_visible(True)

def hide(self):
"""Hide the contours."""
self.set_visible(False)
Loading
Loading