I’m working on incorporating pylinac into a C# app. Is it possible to pass the results image e.g. histogram or picket fence images, back to the method that called the analysis? I know you can save the image but wondered if the actual image could be sent along? If not, how bout the underlying data, not just a summary of the results?
I’m not sure what you mean to pass the results image back to the method that called the analysis. You can grab the current image by doing (assuming picket fence but could be any module):
import matplotlib.pyplot as plt
pf = ...
pf.analyze()
pf.plot_analyzed_image(...)
fig = plt.gcf()
fig
is the current matplotlib figure which you can pass around how you like. However, if you’re trying to pass figures around between languages, saving to disk or stream is probably the way to go.
For data, saving to JSON is the common way to move data between languages. By default, the results_data
object won’t go to JSON natively, but can be done so easily with the pydantic package like so:
from pydantic import RootModel
pf.analyze(...)
data = pf.results_data()
json_string = RootModel[data.__class__](data).model_dump_json(indent=4)
You can save json_string
to disk or pass to something else as a valid JSON string.
Thank you. Yes, I was referring to passing the image, the plot for example, back to C#. Thinking about this, I agree that it’s probably easiest to save the image to a file and import that into C#.