From d69734d38310d9bb1fbf0d0f0abff1413d864e66 Mon Sep 17 00:00:00 2001 From: StefanThoene Date: Tue, 1 Aug 2023 16:43:46 +0200 Subject: [PATCH 1/2] add xmp import example: example_reading_xmp_txt.py --- .../application/example_reading_xmp_txt.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ansys_optical_automation/application/example_reading_xmp_txt.py diff --git a/ansys_optical_automation/application/example_reading_xmp_txt.py b/ansys_optical_automation/application/example_reading_xmp_txt.py new file mode 100644 index 00000000..92631471 --- /dev/null +++ b/ansys_optical_automation/application/example_reading_xmp_txt.py @@ -0,0 +1,44 @@ +import tkinter as tk +from tkinter import filedialog + +import numpy as np + +from ansys_optical_automation.post_process.dpf_xmp_viewer import DpfXmpViewer + +# import sys +# repo_path=r"your repository location" +# sys.path.append(repo_path) + + +def getfilename(extension, save=False): + """ + Parameters + ---------- + extension : str + containing the which file extension in *.ending format + save : Bool + option to define to open(default) or save. The default is False. + + Returns + ------- + str + string containing the selected file path + """ + root = tk.Tk() + root.withdraw() + if not save: + file_path = filedialog.askopenfilename(filetypes=[("Rayfile", extension)]) + else: + file_path = filedialog.asksaveasfilename(filetypes=[("Rayfile", extension)]) + if not file_path.endswith(extension.strip("*")): + file_path += extension.strip("*") + return file_path + + +file_dir = getfilename("*.txt") +xmp = DpfXmpViewer() +data = xmp.read_txt_export(file_dir, inc_data=True) +test = data.data.reshape((5, 5, 81)) +print(data.wl_res) +print(test[:, :, 0]) +print(np.sum(test * 5, 2).transpose()) From 89605f9d9bba9747881ae41c64eb2f71f6315910 Mon Sep 17 00:00:00 2001 From: StefanThoene Date: Wed, 2 Aug 2023 08:24:08 +0200 Subject: [PATCH 2/2] add xmp import example: example_reading_xmp_txt.py --- .../application/example_reading_xmp_txt.py | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ansys_optical_automation/application/example_reading_xmp_txt.py b/ansys_optical_automation/application/example_reading_xmp_txt.py index 92631471..33e4b0e5 100644 --- a/ansys_optical_automation/application/example_reading_xmp_txt.py +++ b/ansys_optical_automation/application/example_reading_xmp_txt.py @@ -1,6 +1,8 @@ import tkinter as tk from tkinter import filedialog +import matplotlib as mpl +import matplotlib.pyplot as plt import numpy as np from ansys_optical_automation.post_process.dpf_xmp_viewer import DpfXmpViewer @@ -35,10 +37,25 @@ def getfilename(extension, save=False): return file_path -file_dir = getfilename("*.txt") +# file_dir = getfilename("*.txt") +# file_dir = r"path to xmp" +file_dir = r"C:\temp\mytest_xmp_7.xmpexport.extended.txt_001.txt" xmp = DpfXmpViewer() data = xmp.read_txt_export(file_dir, inc_data=True) -test = data.data.reshape((5, 5, 81)) -print(data.wl_res) -print(test[:, :, 0]) -print(np.sum(test * 5, 2).transpose()) +# if there is one layer just reshape if there are mor sum them +if data.data.shape[0] == 1: + test = data.data.reshape(data.data.shape[1:]) +else: + test = np.sum(data.data, 0) + +# if not spectral just reshape if ther is to simple integration +if data.data.shape[3] == 1: + test = test.reshape(data.data.shape[1:2]) +else: + factor = (data.wl_res[1] - data.wl_res[0]) / (data.wl_res[2] - 1) + plot_data = np.sum(test * factor, 2).transpose() +# plot data in grayscale to compare to speos result select grayscale in speos and adjust maximum +max_scale = 2000 +plt.imshow(plot_data, cmap=mpl.colormaps["gray"], vmin=0, vmax=max_scale) +plt.colorbar() +plt.show()