Skip to content

Commit

Permalink
Update image export to account for layer-specific stretches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Dec 31, 2023
1 parent 0b99b89 commit 9d1f3ce
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions glue_plotly/common/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,29 @@ def image_size_info(layer_state):
return size


def get_stretch(stretch_name):
def get_stretch_by_name(stretch_name):
try:
return stretches.members[stretch_name]
except TypeError:
return stretches[stretch_name]()


def get_stretch(layer_state):
if hasattr(layer_state, 'stretch_object'):
return layer_state.stretch_object
else:
return get_stretch_by_name(layer_state.stretch)

Check warning on line 169 in glue_plotly/common/image.py

View check run for this annotation

Codecov / codecov/patch

glue_plotly/common/image.py#L169

Added line #L169 was not covered by tests


def colorscale_info(layer_state, interval, contrast_bias):
if layer_state.v_min > layer_state.v_max:
cmap = layer_state.cmap.reversed()
bounds = [layer_state.v_max, layer_state.v_min]
else:
cmap = layer_state.cmap
bounds = [layer_state.v_min, layer_state.v_max]
mapped_bounds = get_stretch(layer_state.stretch)(contrast_bias(interval(bounds)))
stretch = get_stretch(layer_state)
mapped_bounds = stretch(contrast_bias(interval(bounds)))
unmapped_space = np.linspace(0, 1, 60)
mapped_space = np.linspace(mapped_bounds[0], mapped_bounds[1], 60)
color_space = [cmap(b)[:3] for b in mapped_space]
Expand Down Expand Up @@ -341,7 +349,8 @@ def traces_for_image_layer(layer):
if np.isscalar(array):
array = np.atleast_2d(array)

img = get_stretch(layer_state.stretch)(constrast_bias(interval(array)))
stretch = get_stretch(layer_state)
img = stretch(constrast_bias(interval(array)))
img[np.isnan(img)] = 0

z_bounds, colorscale = colorscale_info(layer_state, interval, constrast_bias)
Expand Down

0 comments on commit 9d1f3ce

Please sign in to comment.