|
| 1 | +from __future__ import absolute_import, annotations, division, print_function |
| 2 | + |
| 3 | +import workflows.recipe |
| 4 | +from workflows.services.common_service import CommonService |
| 5 | + |
| 6 | +from zocalo.util.pymca_fitter import plot_fluorescence_spectrum |
| 7 | + |
| 8 | +PARAMETERS = [ |
| 9 | + "inputFile", |
| 10 | + "omega", |
| 11 | + "transmission", |
| 12 | + "samplexyz", |
| 13 | + "acqTime", |
| 14 | + "energy", |
| 15 | +] |
| 16 | + |
| 17 | + |
| 18 | +class DLSPyMcaFitter(CommonService): |
| 19 | + """A service that takes an XRF dataset and sends it to PyMca for fitting""" |
| 20 | + |
| 21 | + _service_name = "DLS PyMca Fitter" |
| 22 | + |
| 23 | + _logger_name = "dlstbx.services.pymca_fitter" |
| 24 | + |
| 25 | + def initializing(self): |
| 26 | + """Subscribe to a queue. Received messages must be acknowledged.""" |
| 27 | + self.log.info("PyMca fitter service starting") |
| 28 | + workflows.recipe.wrap_subscribe( |
| 29 | + self._transport, |
| 30 | + "pymca.fitter", |
| 31 | + self.pymca_fitter_call, |
| 32 | + acknowledgement=True, |
| 33 | + log_extender=self.extend_log, |
| 34 | + ) |
| 35 | + |
| 36 | + def pymca_fitter_call(self, rw, header, message): |
| 37 | + """Call dispatcher""" |
| 38 | + args = [rw.recipe_step.get("parameters", {}).get(param) for param in PARAMETERS] |
| 39 | + |
| 40 | + self.log.debug("Commands: %s", " ".join(args)) |
| 41 | + try: |
| 42 | + plot_fluorescence_spectrum(*args) |
| 43 | + except Exception as e: |
| 44 | + self.log.warning(f"Error running PyMca: {e}", exc_info=True) |
| 45 | + rw.transport.ack(header) |
| 46 | + return |
| 47 | + self.log.info( |
| 48 | + "%s was successfully processed", |
| 49 | + rw.recipe_step.get("parameters", {}).get("inputFile"), |
| 50 | + ) |
| 51 | + rw.transport.ack(header) |
0 commit comments