MCPcopy Create free account
hub / github.com/MAC-VO/MAC-VO / implement

Method implement

Utility/Visualize/Matplotlib_Visualize.py:60–83  ·  view source on GitHub ↗
(file_prefix: str, *args: T_Input.args, **kwargs: T_Input.kwargs)

Source from the content-addressed store, hash-verified

58 """
59 @wraps(func)
60 def implement(file_prefix: str, *args: T_Input.args, **kwargs: T_Input.kwargs) -> None:
61 if func.__name__ not in Matplotlib_Visualizer.func_mode:
62 Matplotlib_Visualizer.func_mode[func.__name__] = "default"
63
64 func_calls: int = implement.calls #type: ignore # PyRight does not support this.
65 implement.calls += 1 #type: ignore
66 func_mode = Matplotlib_Visualizer.func_mode[func.__name__]
67 if func_mode == 'default': func_mode = Matplotlib_Visualizer.default_mode
68
69 match func_mode:
70 case "none":
71 return None
72 case "image":
73 fig = func(*args, **kwargs)
74 fig.savefig(Path(Matplotlib_Visualizer.default_save, (save_path := f"{file_prefix}_{func_calls:05}.png")), dpi=Matplotlib_Visualizer.default_dpi)
75 Logger.write("info", f"Save figure at {save_path}")
76 plt.close(fig)
77 case "rerun":
78 assert rr is not None
79 fig = func(*args, **kwargs)
80 buf = BytesIO()
81 fig.savefig(buf, format='jpg', dpi=Matplotlib_Visualizer.default_dpi)
82 buf.seek(0)
83 rr.log(file_prefix, rr.ImageEncoded(contents=buf, format=rr.ImageFormat.JPEG))
84 implement.calls = 0 #type: ignore # PyRight does not support this.
85 return implement
86

Callers

nothing calls this directly

Calls 2

writeMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected