From f16e71c72b7d150fd4086171f3ad93b3d8792349 Mon Sep 17 00:00:00 2001 From: kl3z00 <2232565@my.ipleiria.pt> Date: Tue, 27 Oct 2026 10:12:25 +0000 Subject: [PATCH] =?UTF-8?q?atualiza=C3=A7=C3=A3o=20ingl=C3=AAs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/bar_plot.py | 2 +- examples/scatter_plot.py | 2 +- src/spectralforensics/features.py | 1 - src/spectralforensics/plotting.py | 40 ++++++------- src/spectralforensics/plotting_box.py | 4 +- src/spectralforensics/plotting_correlation.py | 58 +++++++++---------- 6 files changed, 53 insertions(+), 54 deletions(-) diff --git a/examples/bar_plot.py b/examples/bar_plot.py index ed10def..c80f6ae 100644 --- a/examples/bar_plot.py +++ b/examples/bar_plot.py @@ -7,5 +7,5 @@ if __name__ == "__main__": "spectral_entropy": [2.1, 2.5, 2.2, 2.9], "anisotropy": [0.1, -0.3, 0.2, 0.4]}, x="model", y="spectral_entropy", - title="Análise espectral — barras", + title="Spectral analysis — bar plot", ) diff --git a/examples/scatter_plot.py b/examples/scatter_plot.py index 3fd7c1a..a208475 100644 --- a/examples/scatter_plot.py +++ b/examples/scatter_plot.py @@ -7,5 +7,5 @@ if __name__ == "__main__": "anisotropy": [0.1, 0.3, 0.2, 0.4, 0.25], "spectral_entropy": [2.1, 2.5, 2.2, 2.9, 2.6]}, x="dominant_frequency", y="anisotropy", - title="Análise espectral — dispersão", + title="Spectral analysis — scatter plot", ) diff --git a/src/spectralforensics/features.py b/src/spectralforensics/features.py index d50388f..4beefe0 100644 --- a/src/spectralforensics/features.py +++ b/src/spectralforensics/features.py @@ -5,7 +5,6 @@ from scipy.ndimage import median_filter, sobel, uniform_filter from skimage.filters.rank import entropy from skimage.morphology import disk - def extract_features(image_path, image_size=(255, 255), high_freq_threshold=0.65, center_exclusion=5, output="all"): image_path = Path(image_path) output = str(output).lower() diff --git a/src/spectralforensics/plotting.py b/src/spectralforensics/plotting.py index 0f091d0..1e46f09 100644 --- a/src/spectralforensics/plotting.py +++ b/src/spectralforensics/plotting.py @@ -24,7 +24,7 @@ def _clip_segment(a, b): def _copy_canvas(canvas): if sys.platform != "win32": - raise RuntimeError("A cópia de imagem está disponível no Windows.") + raise RuntimeError("Image copying is only available on Windows.") canvas.update_idletasks() x, y = canvas.winfo_rootx(), canvas.winfo_rooty() image = ImageGrab.grab((x, y, x + canvas.winfo_width(), @@ -44,20 +44,20 @@ def _copy_canvas(canvas): user.SetClipboardData.restype = wintypes.HANDLE handle = kernel.GlobalAlloc(0x0002, len(data)) if not handle: - raise RuntimeError("Não foi possível reservar memória para a imagem.") + raise RuntimeError("Could not allocate memory for the image.") try: pointer = kernel.GlobalLock(handle) if not pointer: - raise RuntimeError("Não foi possível preparar a imagem.") + raise RuntimeError("Could not prepare the image.") try: ctypes.memmove(pointer, data, len(data)) finally: kernel.GlobalUnlock(handle) if not user.OpenClipboard(canvas.winfo_id()): - raise RuntimeError("A área de transferência está ocupada. Tente novamente.") + raise RuntimeError("The clipboard is busy. Please try again.") try: if not user.EmptyClipboard() or not user.SetClipboardData(8, handle): - raise RuntimeError("Não foi possível copiar a imagem.") + raise RuntimeError("Could not copy the image.") handle = None finally: user.CloseClipboard() @@ -172,7 +172,7 @@ def _interactive_plot(data, x=None, y=None, *, title="SpectralForensics", sort_x quantitative_var = tk.StringVar(window, y) quantitative_filter = CheckCombobox( controls, textvariable=quantitative_var, state="readonly", width=28) - ttk.Label(controls, text="Y" if kind == "box" else "Y múltiplos").grid( + ttk.Label(controls, text="Y" if kind == "box" else "Multiple Y").grid( row=0, column=2, padx=(0, 6), sticky="w") quantitative_filter.grid(row=0, column=3, sticky="ew") @@ -181,7 +181,7 @@ def _interactive_plot(data, x=None, y=None, *, title="SpectralForensics", sort_x ("☑ " if name in selected_variables else "☐ ") + name for name in columns]) quantitative_var.set(", ".join(name for name in columns if name in selected_variables) - or "Selecionar variáveis Y") + or "Select Y variables") update_quantitative_choices() if kind == "box": @@ -190,7 +190,7 @@ def _interactive_plot(data, x=None, y=None, *, title="SpectralForensics", sort_x palette_var = tk.StringVar(window, palette) box_options = ttk.Frame(controls) box_options.grid(row=3, column=0, columnspan=4, sticky="w", pady=(8, 0)) - ttk.Checkbutton(box_options, text="Preencher caixas", variable=fill_var, + ttk.Checkbutton(box_options, text="Fill boxes", variable=fill_var, command=lambda: schedule()).pack(side="left", padx=(0, 12)) ttk.Label(box_options, text="Gap").pack(side="left", padx=(0, 6)) gap_selector = ttk.Combobox(box_options, textvariable=gap_var, @@ -205,7 +205,7 @@ def _interactive_plot(data, x=None, y=None, *, title="SpectralForensics", sort_x state="readonly", width=18) palette_selector.pack(side="left") palette_selector.bind("<>", lambda event: schedule()) - filter_label = ttk.Label(controls, text="Categorias") + filter_label = ttk.Label(controls, text="Categories") status = ttk.Label(controls) category_var = tk.StringVar(window) category_selector = CheckCombobox(controls, textvariable=category_var, @@ -217,17 +217,17 @@ def _interactive_plot(data, x=None, y=None, *, title="SpectralForensics", sort_x def update_category_choices(): all_selected = bool(category_labels) and len(selected_categories) == len(category_labels) category_selector.configure(values=[ - ("☑ " if all_selected else "☐ ") + "Selecionar todos", + ("☑ " if all_selected else "☐ ") + "Select all", *[("☑ " if index in selected_categories else "☐ ") + label for index, label in enumerate(category_labels)]]) - status.configure(text=f"{len(selected_categories)}/{len(category_labels)} categorias selecionadas; " - + ("todos os valores em barras." if kind == "bar" - else "distribuição por categoria." if kind == "box" - else "todas as observações em pontos." if kind == "scatter" - else "todos os pontos por linha.")) + status.configure(text=f"{len(selected_categories)}/{len(category_labels)} categories selected; " + + ("all values shown as bars." if kind == "bar" + else "distribution by category." if kind == "box" + else "all observations shown as points." if kind == "scatter" + else "all points shown per line.")) category_var.set(", ".join(label for index, label in enumerate(category_labels) if index in selected_categories) - or "Selecionar categorias") + or "Select categories") from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk from matplotlib.ticker import MaxNLocator, FixedLocator, FormatStrFormatter @@ -292,9 +292,9 @@ def _interactive_plot(data, x=None, y=None, *, title="SpectralForensics", sort_x for spine in axes.spines.values(): spine.set_color("#b9c7db") axes.set_title(title, color="#edf2fa") - axes.set_xlabel("Observação por categoria — " + x_var.get() + axes.set_xlabel("Observation by category — " + x_var.get() if labels is not None else x_var.get(), color="#edf2fa") - axes.set_ylabel(variables[0] if len(variables) == 1 else "Variáveis quantitativas", + axes.set_ylabel(variables[0] if len(variables) == 1 else "Quantitative variables", color="#edf2fa") axes.set_axisbelow(True) axes.grid(axis="y", color="#29364a") @@ -310,7 +310,7 @@ def _interactive_plot(data, x=None, y=None, *, title="SpectralForensics", sort_x else np.empty((0, 2))) finite = values[np.isfinite(values).all(axis=1)] if not len(finite): - axes.text(.5, .5, "Sem pares válidos nas categorias selecionadas", + axes.text(.5, .5, "No valid pairs in the selected categories", ha="center", va="center", transform=axes.transAxes, color="#edf2fa") else: group_width = None @@ -397,7 +397,7 @@ def _interactive_plot(data, x=None, y=None, *, title="SpectralForensics", sort_x window.update_idletasks() _copy_canvas(canvas.get_tk_widget()) except Exception as error: - messagebox.showerror("Copiar gráfico", str(error), parent=window) + messagebox.showerror("Copy plot", str(error), parent=window) actions = ttk.Frame(controls) actions.grid(row=1, column=3, sticky="ew", padx=(0, 18), pady=(8, 0)) diff --git a/src/spectralforensics/plotting_box.py b/src/spectralforensics/plotting_box.py index fabf096..5405116 100644 --- a/src/spectralforensics/plotting_box.py +++ b/src/spectralforensics/plotting_box.py @@ -9,14 +9,14 @@ def _draw_boxplot(axes, frame, x, y, categories, selected, *, fill, gap, palette axes.set_ylabel(y or "Y", color="#edf2fa") chosen = sorted(selected) if y is None or not chosen: - axes.text(.5, .5, "Selecione categorias e uma variável Y", ha="center", + axes.text(.5, .5, "Select categories and a Y variable", ha="center", va="center", transform=axes.transAxes, color="#edf2fa") return codes = pd.Categorical(frame[x], categories=categories).codes values = frame[y].to_numpy(dtype=float, na_value=np.nan) valid = np.isin(codes, chosen) & np.isfinite(values) if not valid.any(): - axes.text(.5, .5, "Sem valores válidos nas categorias selecionadas", + axes.text(.5, .5, "No valid values in the selected categories", ha="center", va="center", transform=axes.transAxes, color="#edf2fa") return colors = sns.color_palette(palette, n_colors=len(categories)) diff --git a/src/spectralforensics/plotting_correlation.py b/src/spectralforensics/plotting_correlation.py index 716d776..c0a101c 100644 --- a/src/spectralforensics/plotting_correlation.py +++ b/src/spectralforensics/plotting_correlation.py @@ -14,7 +14,7 @@ __all__ = ["correlation_plot"] def _correlation_figure(data, correlation_columns=None, *, method="pearson", cmap="coolwarm", center=0, annot=True, fmt=".2f", target=None, kind="barh", by=None, ascending=True, - figsize=None, title="Matriz de Correlação das Features", + figsize=None, title="Feature Correlation Matrix", target_title=None, show=False, page="matrix"): frame = pd.DataFrame(data) if not frame.columns.is_unique: @@ -64,8 +64,8 @@ def _correlation_figure(data, correlation_columns=None, *, method="pearson", heatmap_ax.set_title(title) if target_ax is not None: corr_target.plot(kind=kind, ax=target_ax, legend=False) - method_name = method.capitalize() if isinstance(method, str) else "personalizada" - correlation_label = f"Correlação ({method_name}) com {target}" + method_name = method.capitalize() if isinstance(method, str) else "Custom" + correlation_label = f"Correlation ({method_name}) with {target}" if kind == "barh": target_ax.set_xlabel(correlation_label) target_ax.set_ylabel("Feature") @@ -76,7 +76,7 @@ def _correlation_figure(data, correlation_columns=None, *, method="pearson", target_ax.set_xlabel("Feature") target_ax.axhline(0, linewidth=1, color="gray") target_ax.set_ylim(-1, 1) - target_ax.set_title(target_title or f"Correlação das Features com {target}") + target_ax.set_title(target_title or f"Feature Correlation with {target}") figure.tight_layout() return {"figure": figure, "axes": {"heatmap": heatmap_ax, "target": target_ax}, @@ -84,7 +84,7 @@ def _correlation_figure(data, correlation_columns=None, *, method="pearson", def correlation_plot(data, correlation_columns=None, *, method="pearson", cmap="coolwarm", center=0, annot=True, fmt=".2f", target=None, kind="barh", by=None, ascending=True, - figsize=None, title="Matriz de Correlação das Features", + figsize=None, title="Feature Correlation Matrix", target_title=None, show=True, master=None, block=None): options = dict(method=method, cmap=cmap, center=center, annot=annot, fmt=fmt, target=target, kind=kind, by=by, ascending=ascending, @@ -119,12 +119,12 @@ def correlation_plot(data, correlation_columns=None, *, method="pearson", controls.pack(fill="x") status = tk.StringVar(window) feature_var = tk.StringVar(window) - method_var = tk.StringVar(window, method if isinstance(method, str) else "Personalizado") + method_var = tk.StringVar(window, method if isinstance(method, str) else "Custom") cmap_var = tk.StringVar(window, cmap if isinstance(cmap, str) else cmap.name) center_var = tk.StringVar(window, "" if center is None else str(center)) annot_var = tk.BooleanVar(window, annot) fmt_var = tk.StringVar(window, fmt) - target_var = tk.StringVar(window, "(Sem target)" if target is None else target) + target_var = tk.StringVar(window, "(No target)" if target is None else target) kind_var = tk.StringVar(window, kind) by_var = tk.StringVar(window, "" if target is None else target) ascending_var = tk.BooleanVar(window, ascending) @@ -158,15 +158,15 @@ def correlation_plot(data, correlation_columns=None, *, method="pearson", window.result = result pending = None page = "matrix" - page_label = tk.StringVar(window, "1/2 — Matriz de correlação" if target is not None - else "Matriz de correlação") + page_label = tk.StringVar(window, "1/2 — Correlation matrix" if target is not None + else "Correlation matrix") def update_plot(): nonlocal pending, page pending = None try: - chosen_target = None if target_var.get() == "(Sem target)" else target_var.get() + chosen_target = None if target_var.get() == "(No target)" else target_var.get() current_page = page if chosen_target is not None else "matrix" - current_method = method if method_var.get() == "Personalizado" else method_var.get() + current_method = method if method_var.get() == "Custom" else method_var.get() current = _correlation_figure( frame, [name for name in columns if name in selected], method=current_method, cmap=cmap_var.get(), @@ -188,10 +188,10 @@ def correlation_plot(data, correlation_columns=None, *, method="pearson", window.result = current page = current_page toolbar.set_history_buttons() - page_label.set(("1/2 — Matriz de correlação" if page == "matrix" - else "2/2 — Correlação com o target") if chosen_target is not None - else "Matriz de correlação") - status.set("Atualizado.") + page_label.set(("1/2 — Correlation matrix" if page == "matrix" + else "2/2 — Target correlation") if chosen_target is not None + else "Correlation matrix") + status.set("Updated.") def schedule(event=None): nonlocal pending if pending is not None: @@ -209,9 +209,9 @@ def correlation_plot(data, correlation_columns=None, *, method="pearson", features = combo("Features", feature_var, [], 0, 0, multiple=True) def refresh_features(): features.configure(values=[ - ("☑ " if len(selected) == len(columns) else "☐ ") + "Selecionar todos", + ("☑ " if len(selected) == len(columns) else "☐ ") + "Select all", *[("☑ " if name in selected else "☐ ") + str(name) for name in columns]]) - feature_var.set(f"{len(selected)}/{len(columns)} features selecionadas") + feature_var.set(f"{len(selected)}/{len(columns)} features selected") def select_feature(event=None): index = features.current() if index == 0: @@ -229,20 +229,20 @@ def correlation_plot(data, correlation_columns=None, *, method="pearson", schedule() features.bind("<>", select_feature) refresh_features() - combo("Método", method_var, - ["pearson", "spearman", "kendall"] + (["Personalizado"] if callable(method) else []), 0, 2) - combo("Cmap", cmap_var, sorted(colormaps), 0, 4) - target_selector = combo("Target", target_var, ["(Sem target)", *columns], 1, 0) - combo("Kind", kind_var, ["bar", "barh"], 1, 2) - by_selector = combo("Ordenar por (by)", by_var, [] if target is None else [target], 1, 4) + combo("Method", method_var, + ["pearson", "spearman", "kendall"] + (["Custom"] if callable(method) else []), 0, 2) + combo("Color map", cmap_var, sorted(colormaps), 0, 4) + target_selector = combo("Target", target_var, ["(No target)", *columns], 1, 0) + combo("Plot type", kind_var, ["bar", "barh"], 1, 2) + by_selector = combo("Sort by", by_var, [] if target is None else [target], 1, 4) def change_target(event=None): - value = "" if target_var.get() == "(Sem target)" else target_var.get() + value = "" if target_var.get() == "(No target)" else target_var.get() by_var.set(value) by_selector.configure(values=[value] if value else []) schedule() target_selector.bind("<>", change_target) - for label, variable, column in (("Centro (vazio = automático)", center_var, 0), - ("Formato (fmt)", fmt_var, 2)): + for label, variable, column in (("Center (empty = automatic)", center_var, 0), + ("Format (fmt)", fmt_var, 2)): ttk.Label(controls, text=label).grid(row=2, column=column, sticky="w", padx=5) entry = ttk.Entry(controls, textvariable=variable, width=22) entry.grid(row=2, column=column + 1, sticky="ew", padx=5) @@ -250,15 +250,15 @@ def correlation_plot(data, correlation_columns=None, *, method="pearson", entry.bind("", schedule) checks = ttk.Frame(controls) checks.grid(row=2, column=4, columnspan=2, sticky="w") - ttk.Checkbutton(checks, text="Annot", variable=annot_var, command=schedule).pack(side="left") - ttk.Checkbutton(checks, text="Ordem crescente", variable=ascending_var, command=schedule).pack(side="left") + ttk.Checkbutton(checks, text="Annotations", variable=annot_var, command=schedule).pack(side="left") + ttk.Checkbutton(checks, text="Ascending order", variable=ascending_var, command=schedule).pack(side="left") def copy_plot(): try: window.lift() canvas.draw() _copy_canvas(canvas.get_tk_widget()) except Exception as error: - messagebox.showerror("Copiar gráfico", str(error), parent=window) + messagebox.showerror("Copy plot", str(error), parent=window) actions = ttk.Frame(controls) actions.grid(row=3, column=0, columnspan=6, sticky="w", pady=(8, 0)) def navigate(destination):