Skip to content

Commit

Permalink
increase max message size and implement (lossy) compression
Browse files Browse the repository at this point in the history
  • Loading branch information
kadrlica committed Nov 28, 2024
1 parent 65a72fb commit 38cfdc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions python/lsst/rubintv/analysis/service/commands/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ class GetFitsImageCommand(BaseCommand):
data_id : dict
The data ID of the image. Depending on the type of image this could
include things like "band" or "visit" or "detector".
compress : bool
Compress the image before sending.
"""

repo: str
image_name: str
collection: dict
data_id: dict
compress: bool
response_type: str = "fits"

def build_contents(self, data_center: DataCenter) -> dict:
Expand All @@ -161,9 +164,20 @@ def build_contents(self, data_center: DataCenter) -> dict:
logger.info("Received exposure.")

manager = MemFileManager()
exposure.writeFits(manager)
content = base64.b64encode(manager.getData()).decode('utf-8')
logger.info("Encoded exposure.")
opts = dict()
if self.compress:
from lsst.afw.fits import ImageCompressionOptions, ImageWriteOptions, ImageScalingOptions
logger.info("Configuring compression.")
quantize = 10.0
compression = ImageCompressionOptions(ImageCompressionOptions.RICE, True, 0.0)
scaling = ImageScalingOptions(ImageScalingOptions.STDEV_BOTH, 32, quantizeLevel=quantize)
opts['imageOptions'] = ImageWriteOptions(compression, scaling)
opts['maskOptions'] = ImageWriteOptions(compression)
opts['varianceOptions'] = opts['imageOptions']
exposure.writeFits(manager, **opts)

logger.info("Encoding exposure...")
content = base64.b64encode(manager.getData()).decode('ascii')

Check failure on line 181 in python/lsst/rubintv/analysis/service/commands/butler.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

W293

blank line contains whitespace
return {
"fits": content,
Expand Down
1 change: 1 addition & 0 deletions scripts/mock_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
workers: dict[str, WorkerPod] = dict() # Keep track of connected worker pods
clients: dict[str, WebSocketHandler] = dict() # Keep track of connected clients
queue: list[QueueItem] = list() # Queue of messages to be processed
max_message_size: int = 100 * 1024 * 1024 # Maximum message size

Check failure on line 54 in scripts/mock_server.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E261

at least two spaces before inline comment

@classmethod
def urls(cls) -> list[tuple[str, type[tornado.web.RequestHandler], dict[str, str]]]:
Expand Down

0 comments on commit 38cfdc2

Please sign in to comment.