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

DM-15333 Apply pan and scale at time of image display in display_firefly #16

Merged
merged 3 commits into from
Aug 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 54 additions & 5 deletions python/lsst/display/firefly/firefly.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def __init__(self, display, verbose=False, url=None,

global _fireflyClient
if not _fireflyClient:
import os
if ('html_file' not in kwargs) and ('FIREFLY_HTML' not in os.environ):
kwargs['html_file'] = 'slate.html'
try:
if url is None:
_fireflyClient = firefly_client.FireflyClient(channel=name, **kwargs)
Expand Down Expand Up @@ -123,6 +126,7 @@ def __init__(self, display, verbose=False, url=None,
self._maskDict = {}
self._lastZoom = None
self._lastPan = None
self._lastStretch = None

def _getRegionLayerId(self):
return "lsstRegions%s" % self.display.frame if self.display else "None"
Expand Down Expand Up @@ -159,6 +163,12 @@ def _mtv(self, image, mask=None, wcs=None, title=""):
if self._lastZoom:
extraParams['InitZoomLevel'] = self._lastZoom
extraParams['ZoomType'] = 'LEVEL'
if self._lastPan:
extraParams['InitialCenterPosition'] = '{0:.3f};{1:.3f};PIXEL'.format(
self._lastPan[0],
self._lastPan[1])
if self._lastStretch:
extraParams['RangeValues'] = self._lastStretch

ret = _fireflyClient.show_fits(self._fireflyFitsID, plot_id=str(self.display.frame),
**extraParams)
Expand Down Expand Up @@ -208,6 +218,7 @@ def _flush(self):

if self.verbose:
print("Flushing %d regions" % len(self._regions))
print(self._regions)

self._regionLayerId = self._getRegionLayerId()
_fireflyClient.add_region_data(region_data=self._regions, plot_id=str(self.display.frame),
Expand Down Expand Up @@ -286,6 +297,37 @@ def _getEvent(self):
#

def _scale(self, algorithm, min, max, unit=None, *args, **kwargs):
"""Scale the image stretch and limits

Parameters:
-----------
algorithm : `str`
stretch algorithm, e.g. 'linear', 'log', 'loglog', 'equal', 'squared',
'sqrt', 'asinh', powerlaw_gamma'
min : `float` or `str`
lower limit, or 'minmax' for full range, or 'zscale'
max : `float` or `str`
upper limit; overrriden if min is 'minmax' or 'zscale'
unit : `str`
unit for min and max. 'percent', 'absolute', 'sigma'.
if not specified, min and max are presumed to be in 'absolute' units.

*args, **kwargs : additional position and keyword arguments.
The options are shown below:

**Q** : `float`, optional
The asinh softening parameter for asinh stretch.
Use Q=0 for linear stretch, increase Q to make brighter features visible.
When not specified or None, Q is calculated by Firefly to use full color range.
**gamma**
The gamma value for power law gamma stretch (default 2.0)
**zscale_contrast** : `int`, optional
Contrast parameter in percent for zscale algorithm (default 25)
**zscale_samples** : `int`, optional
Number of samples for zscale algorithm (default 600)
**zscale_samples_perline** : `int`, optional
Number of samples per line for zscale algorithm (default 120)
"""
stretch_algorithms = ('linear', 'log', 'loglog', 'equal', 'squared', 'sqrt',
'asinh', 'powerlaw_gamma')
interval_methods = ('percent', 'maxmin', 'absolute', 'zscale', 'sigma')
Expand Down Expand Up @@ -342,19 +384,24 @@ def _scale(self, algorithm, min, max, unit=None, *args, **kwargs):
if interval_type not in interval_methods:
raise FireflyError('Interval method %s is invalid' % interval_type)

rval = {}
if interval_type is not 'zscale':
_fireflyClient.set_stretch(str(self.display.frame), stype=interval_type, algorithm=algorithm,
rval = _fireflyClient.set_stretch(str(self.display.frame), stype=interval_type, algorithm=algorithm,
lower_value=min, upper_value=max, **kwargs)
else:
if 'zscale_constrast' not in kwargs:
if 'zscale_contrast' not in kwargs:
kwargs['zscale_contrast'] = 25
if 'zscale_samples' not in kwargs:
kwargs['zscale_samples'] = 600
if 'zscale_samples_perline' not in kwargs:
kwargs['zscale_samples_perline'] = 120
_fireflyClient.set_stretch(str(self.display.frame), stype='zscale', algorithm=algorithm,
rval = _fireflyClient.set_stretch(str(self.display.frame), stype='zscale', algorithm=algorithm,
**kwargs)

if 'rv_string' in rval:
self._lastStretch = rval['rv_string']


def _setMaskTransparency(self, transparency, maskplane):
"""Specify mask transparency (percent); or None to not set it when loading masks"""
if maskplane is not None:
Expand Down Expand Up @@ -412,7 +459,9 @@ def _pan(self, colc, rowc):
Parameters:
-----------
colc, rowc : `float`
column and row in units of pixels
column and row in units of pixels (zero-based convention,
with the xy0 already subtracted off)
"""
self._lastPan = [colc, rowc] # saved for future use in _mtv
self._lastPan = [colc+0.5, rowc+0.5] # saved for future use in _mtv
# Firefly's internal convention is first pixel is (0.5, 0.5)
_fireflyClient.set_pan(plot_id=str(self.display.frame), x=colc, y=rowc)