Skip to content

Commit

Permalink
Modernize some string formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 5, 2024
1 parent 27fbe4e commit 7543b7f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
44 changes: 22 additions & 22 deletions python/lsst/display/firefly/firefly.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import firefly_client
_fireflyClient = None
except ImportError as e:
raise RuntimeError("Cannot import firefly_client: %s" % (e))
raise RuntimeError(f"Cannot import firefly_client: {e}")
from ws4py.client import HandshakeError

_LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -70,7 +70,7 @@ def __handleCallbacks(event):

_LOG.debug("Callback event info: %s", event)
return
data = dict((_.split('=') for _ in event.get('data', {}).split('&')))
data = dict(_.split('=') for _ in event.get('data', {}).split('&'))
if data.get('type') == "POINT":
_LOG.debug("Event Received: %s", data.get('id'))

Expand Down Expand Up @@ -121,14 +121,13 @@ def __init__(self, display, verbose=False, url=None,
token=token)

except (HandshakeError, gaierror) as e:
raise RuntimeError("Unable to connect to %s: %s" % (url or '', e))
raise RuntimeError(f"Unable to connect to {url or ''}: {e}")

try:
_fireflyClient.add_listener(self.__handleCallbacks)
except Exception as e:
raise RuntimeError("Cannot add listener. Browser must be connected" +
"to %s: %s" %
(_fireflyClient.get_firefly_url(), e))
raise RuntimeError("Cannot add listener. Browser must be connected"
f"to {_fireflyClient.get_firefly_url()}: {e}")

self._isBuffered = False
self._regions = []
Expand All @@ -147,7 +146,7 @@ def __init__(self, display, verbose=False, url=None,
self._lastStretch = None

def _getRegionLayerId(self):
return "lsstRegions%s" % self.display.frame if self.display else "None"
return f"lsstRegions{self.display.frame}" if self.display else "None"

def _clearImage(self):
"""Delete the current image in the Firefly viewer
Expand All @@ -172,10 +171,9 @@ def _mtv(self, image, mask=None, wcs=None, title=""):
self._fireflyFitsID = _fireflyClient.upload_data(fd, 'FITS')

try:
viewer_id = ('image-' + str(_fireflyClient.render_tree_id) + '-' +
str(self.frame))
viewer_id = f'image-{_fireflyClient.render_tree_id}-{self.frame}'
except AttributeError:
viewer_id = 'image-' + str(self.frame)
viewer_id = f'image-{self.frame}'
extraParams = dict(Title=title,
MultiImageIdx=0,
PredefinedOverlayIds=' ',
Expand All @@ -187,8 +185,7 @@ def _mtv(self, image, mask=None, wcs=None, title=""):
extraParams['InitZoomLevel'] = self._lastZoom
extraParams['ZoomType'] = 'LEVEL'
if self._lastPan:
extraParams['InitialCenterPosition'] = '{0:.3f};{1:.3f};PIXEL'.format(
self._lastPan[0], self._lastPan[1])
extraParams['InitialCenterPosition'] = f'{self._lastPan[0]:.3f};{self._lastPan[1]:.3f};PIXEL'
if self._lastStretch:
extraParams['RangeValues'] = self._lastStretch

Expand Down Expand Up @@ -295,7 +292,7 @@ def _drawLines(self, points, ctype):
def _erase(self):
"""Erase all overlays on the image"""
if self.verbose:
print('region layer id is {}'.format(self._regionLayerId))
print(f'region layer id is {self._regionLayerId}')
if self._regionLayerId:
_fireflyClient.delete_region_layer(self._regionLayerId, plot_id=str(self.display.frame))

Expand All @@ -308,18 +305,16 @@ def _setCallback(self, what, func):
if not status['success']:
pass
except Exception as e:
raise RuntimeError("Cannot set callback. Browser must be (re)opened " +
"to %s%s : %s" %
(_fireflyClient.url_bw,
_fireflyClient.channel, e))
raise RuntimeError("Cannot set callback. Browser must be (re)opened "
f"to {_fireflyClient.url_bw}{_fireflyClient.channel} : {e}")

def _getEvent(self):
"""Return an event generated by a keypress or mouse click
"""
ev = interface.Event("q")

if self.verbose:
print("virtual[%s]._getEvent() -> %s" % (self.display.frame, ev))
print(f"virtual[{self.display.frame}]._getEvent() -> {ev}")

return ev
#
Expand Down Expand Up @@ -369,8 +364,11 @@ def _scale(self, algorithm, min, max, unit=None, *args, **kwargs):
algorithm = dict((a.lower(), a) for a in stretch_algorithms).get(algorithm.lower(), algorithm)

if algorithm not in stretch_algorithms:
raise FireflyError('Algorithm %s is invalid; please choose one of "%s"' %
(algorithm, '", "'.join(stretch_algorithms)))
raise FireflyError(
'Algorithm {} is invalid; please choose one of "{}"'.format(
algorithm, '", "'.join(stretch_algorithms)
)
)
self._stretchAlgorithm = algorithm
else:
algorithm = 'linear'
Expand Down Expand Up @@ -398,7 +396,9 @@ def _scale(self, algorithm, min, max, unit=None, *args, **kwargs):

units = ('percent', 'absolute', 'sigma')
if unit not in units:
raise FireflyError('Unit %s is invalid; please choose one of "%s"' % (unit, '", "'.join(units)))
raise FireflyError(
'Unit {} is invalid; please choose one of "{}"'.format(unit, '", "'.join(units))
)

if unit == 'sigma':
interval_type = 'sigma'
Expand All @@ -412,7 +412,7 @@ def _scale(self, algorithm, min, max, unit=None, *args, **kwargs):
self._stretchUnit = unit

if interval_type not in interval_methods:
raise FireflyError('Interval method %s is invalid' % interval_type)
raise FireflyError(f'Interval method {interval_type} is invalid')

rval = {}
if interval_type != 'zscale':
Expand Down
7 changes: 4 additions & 3 deletions python/lsst/display/firefly/footprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def recordSelector(record, selection):
elif selection == 'isolated':
return ((parentId == 0) and (nChildren == 0))
else:
raise RuntimeError('invalid selection: {}'.format(selection) +
'\nMust be one of "all", "blended parents", ' +
'"deblended children", "isolated"')
raise RuntimeError(
f'invalid selection: {selection}\n'
'Must be one of "all", "blended parents", "deblended children", "isolated"'
)


def createFootprintsTable(catalog, xy0=None, insertColumn=4):
Expand Down

0 comments on commit 7543b7f

Please sign in to comment.