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

Move pymca fitter service to python-zocalo #252

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ GitHub = "https://github.com/DiamondLightSource/python-zocalo"

[project.entry-points."workflows.services"]
Dispatcher = "zocalo.service.dispatcher:Dispatcher"
DLSPyMcaFitter = "zocalo.service.pymca_fitter:DLSPyMcaFitter"
JSONLines = "zocalo.service.jsonlines:JSONLines"
Mailer = "zocalo.service.mailer:Mailer"
Schlockmeister = "zocalo.service.schlockmeister:Schlockmeister"
Expand Down
51 changes: 51 additions & 0 deletions src/zocalo/service/pymca_fitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from __future__ import absolute_import, annotations, division, print_function

import workflows.recipe
from workflows.services.common_service import CommonService

from zocalo.util.pymca_fitter import plot_fluorescence_spectrum

PARAMETERS = [
"inputFile",
"omega",
"transmission",
"samplexyz",
"acqTime",
"energy",
]


class DLSPyMcaFitter(CommonService):
"""A service that takes an XRF dataset and sends it to PyMca for fitting"""

_service_name = "DLS PyMca Fitter"

_logger_name = "dlstbx.services.pymca_fitter"

def initializing(self):
"""Subscribe to a queue. Received messages must be acknowledged."""
self.log.info("PyMca fitter service starting")
workflows.recipe.wrap_subscribe(
self._transport,
"pymca.fitter",
self.pymca_fitter_call,
acknowledgement=True,
log_extender=self.extend_log,
)

def pymca_fitter_call(self, rw, header, message):
"""Call dispatcher"""
args = [rw.recipe_step.get("parameters", {}).get(param) for param in PARAMETERS]

self.log.debug("Commands: %s", " ".join(args))
try:
plot_fluorescence_spectrum(*args)
except Exception as e:
self.log.warning(f"Error running PyMca: {e}", exc_info=True)
rw.transport.ack(header)
return
self.log.info(
"%s was successfully processed",
rw.recipe_step.get("parameters", {}).get("inputFile"),
)
rw.transport.ack(header)
Loading
Loading