Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"dozor = dlstbx.wrapper.dozor:DozorWrapper",
"edna = dlstbx.wrapper.edna:EdnaWrapper",
"ep_predict = dlstbx.wrapper.ep_predict:EPPredictWrapper",
"estimate_transmission = dlstbx.wrapper.estimate_transmission:EstimateTransmissionWrapper",
"estimate_transmission = dlstbx.wrapper.estimate_transmission:EstimateTransmissionWrapper",
"fast_dp = dlstbx.wrapper.fast_dp:FastDPWrapper",
"fast_ep = dlstbx.wrapper.fast_ep:FastEPWrapper",
"fast_rdp = dlstbx.wrapper.fast_rdp:FastRDPWrapper",
Expand Down Expand Up @@ -271,7 +271,6 @@ def get_git_revision() -> str | None:
],
"zocalo.services.images.plugins": [
"diffraction = dlstbx.services.images:diffraction",
"thumbnail = dlstbx.services.images:thumbnail",
],
"zocalo.wrappers": sorted(known_wrappers),
"zocalo.mimas.handlers": sorted(mimas_scenario_handlers),
Expand Down
10 changes: 3 additions & 7 deletions src/dlstbx/mimas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,9 @@ def handle_eiger_end(
scenario: mimas.MimasScenario,
**kwargs,
) -> List[mimas.Invocation]:
stopped = scenario.runstatus == "DataCollection Stopped"
tasks: List[mimas.Invocation] = [
mimas.MimasRecipeInvocation(DCID=scenario.DCID, recipe="archive-nexus"),
]
if not stopped:
tasks.append(
mimas.MimasRecipeInvocation(
DCID=scenario.DCID, recipe="generate-diffraction-preview"
)
)
return tasks


Expand Down Expand Up @@ -240,6 +233,9 @@ def handle_rotation_end(
DCID=scenario.DCID,
recipe=f"processing-rlv{suffix}",
),
mimas.MimasRecipeInvocation(
DCID=scenario.DCID, recipe="generate-diffraction-preview"
),
]

# mmcif-gen
Expand Down
7 changes: 4 additions & 3 deletions src/dlstbx/mimas/vmxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ def handle_vmxi_end(
**kwargs,
) -> List[mimas.Invocation]:
return [
mimas.MimasRecipeInvocation(
DCID=scenario.DCID, recipe="generate-diffraction-preview"
),
mimas.MimasRecipeInvocation(DCID=scenario.DCID, recipe="archive-nexus"),
]

Expand Down Expand Up @@ -81,6 +78,10 @@ def handle_vmxi_rotation_scan(
),
# mmcif-gen
mimas.MimasRecipeInvocation(DCID=scenario.DCID, recipe="processing-mmcif-gen"),
# Diffraction preview
mimas.MimasRecipeInvocation(
DCID=scenario.DCID, recipe="generate-diffraction-preview"
),
# fast_dp
mimas.MimasISPyBJobInvocation(
DCID=scenario.DCID,
Expand Down
51 changes: 3 additions & 48 deletions src/dlstbx/services/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import time
from typing import Any, Callable, Dict, NamedTuple, Protocol

import PIL.Image
import procrunner
import workflows.recipe
from workflows.services.common_service import CommonService
Expand All @@ -31,7 +30,7 @@ class PluginInterface(NamedTuple):

class DLSImages(CommonService):
"""
A service that generates images and thumbnails.
A service that generates images.
Plugin functions can be registered under the entry point
'zocalo.services.images.plugins'. The contract is that a plugin function
takes a single argument of type PluginInterface, and returns a truthy value
Expand Down Expand Up @@ -123,8 +122,6 @@ def diffraction(plugin: PluginInterface):
if not os.path.exists(filename):
logger.error("File %s not found", filename)
return False
sizex = plugin.parameters("size-x", default=400)
sizey = plugin.parameters("size-y", default=192)
output = plugin.parameters("output")
if not output:
# split off extension
Expand All @@ -140,9 +137,7 @@ def diffraction(plugin: PluginInterface):
except OSError as e:
if e.errno != errno.EEXIST:
raise
output_small = output[: output.rindex(".")] + ".thumb.jpeg"

start = time.perf_counter()
result = procrunner.run(
[
"dials.export_bitmaps",
Expand All @@ -155,7 +150,7 @@ def diffraction(plugin: PluginInterface):
'output.file="%s"' % output,
]
)
export = time.perf_counter()

if result.returncode:
logger.error(
f"Export of {filename} failed with exitcode {result.returncode}:\n"
Expand All @@ -165,45 +160,5 @@ def diffraction(plugin: PluginInterface):
if not os.path.exists(output):
logger.error("Output file %s not found", output)
return False
with PIL.Image.open(output) as fh:
fh.thumbnail((sizex, sizey))
fh.save(output_small)
done = time.perf_counter()

logger.info(
"Created thumbnail %s -> %s (%.1f sec) -> %s (%.1f sec)",
filename,
output,
export - start,
output_small,
done - export,
)
return [output, output_small]


def thumbnail(plugin: PluginInterface):
"""Take a single file and create a smaller version of the same file."""
filename = plugin.parameters("file")
if not filename or filename == "None":
logger.debug("Skipping thumbnail generation: filename not specified")
return False
if not os.path.exists(filename):
logger.error("File %s not found", filename)
return False
sizex = plugin.parameters("size-x", default=400)
sizey = plugin.parameters("size-y", default=192)
output = plugin.parameters("output")
if not output:
# If not set add a 't' in front of the last '.' in the filename
output = (
filename[: filename.rindex(".")] + "t" + filename[filename.rindex(".") :]
)

start = time.perf_counter()
with PIL.Image.open(filename) as fh:
fh.thumbnail((sizex, sizey))
fh.save(output)
timing = time.perf_counter() - start

logger.info("Created thumbnail %s -> %s in %.1f seconds", filename, output, timing)
return [output]
return output
Loading