Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion ledsa/analysis/ExtinctionCoefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,15 @@ def save(self) -> None:
path.mkdir(parents=True)
path = path / f'extinction_coefficients_{self.solver}_channel_{self.experiment.channel}_{self.reference_property}_led_array_{self.experiment.led_array}.csv'
header = str(self)
header += 'Experiment_Time[s],'
header += 'layer0'
for i in range(self.experiment.layers.amount - 1):
header += f',layer{i + 1}'
np.savetxt(path, self.coefficients_per_image_and_layer, delimiter=',', header=header)

experiment_times = _get_experiment_times_from_image_infos_file(self.average_images)
coefficients_per_time_and_layer = np.column_stack(
(experiment_times, self.coefficients_per_image_and_layer))
np.savetxt(path, coefficients_per_time_and_layer, delimiter=',', header=header)

def calc_distance_array(self) -> np.ndarray:
"""
Expand Down Expand Up @@ -214,3 +219,11 @@ def multiindex_series_to_nparray(multi_series: pd.Series) -> np.ndarray:
for i in range(num_imgs):
array[i] = multi_series.loc[i + 1]
return array

def _get_experiment_times_from_image_infos_file(average_images):
if average_images == True:
image_infos_file = 'analysis/image_infos_analysis_avg.csv'
else:
image_infos_file = 'analysis/image_infos_analysis.csv'
image_info_df = pd.read_csv(image_infos_file)
return image_info_df['Experiment_Time[s]'].to_numpy()
9 changes: 6 additions & 3 deletions ledsa/postprocessing/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ def _get_extco_df_from_path(self):
"""
extco_list = []
files_list = glob.glob(
os.path.join(self.path_simulation, 'analysis', 'extinction_coefficients', self.solver, f'extinction_coefficients*.csv'))
os.path.join(self.path_simulation, 'analysis', 'extinction_coefficients', self.solver,
f'extinction_coefficients*.csv'))
for file in files_list:
file_df = pd.read_csv(file, skiprows=4)
channel = int(file.split('channel_')[1].split('_')[0])
led_array = int(file.split('array_')[1].split('.')[0])
n_layers = len(file_df.columns)
time = self.image_info_df['Experiment_Time[s]'].astype(int)
file_df = file_df.merge(time, left_index=True, right_index=True)
# For backwards compatibility, check if Experiment_Time[s] is already in the dataframe
if 'Experiment_Time[s]' not in file_df.columns:
time = self.image_info_df['Experiment_Time[s]'].astype(int)
file_df = file_df.merge(time, left_index=True, right_index=True)
file_df.set_index('Experiment_Time[s]', inplace=True)
iterables = [[channel], [led_array], [i for i in range(0, n_layers)]]
file_df.columns = pd.MultiIndex.from_product(iterables, names=["Channel", "LED Array", "Layer"])
Expand Down
21 changes: 14 additions & 7 deletions ledsa/tests/AcceptanceTests/LedsaATestLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,16 @@ def extco_quad(z):

@keyword
def plot_input_vs_computed_extinction_coefficients(self, solver, first=1, last=4, led_array=0, channel=0):
filename = f'extinction_coefficients_{solver}_channel_{channel}_sum_col_val_led_array_{led_array}.csv'
extinction_coefficients_computed = (
np.loadtxt(os.path.join('analysis', 'extinction_coefficients', solver, filename), skiprows=5, delimiter=','))
time, extinction_coefficients_computed = load_extinction_coefficients_computed(solver, channel, led_array)

for image_id in range(first, last + 1):
extinction_coefficients_input = np.loadtxt(os.path.join('test_data', f'test_extinction_coefficients_input_{image_id}.csv'), delimiter=',')
num_of_layers = extinction_coefficients_input.shape[0]
plt.plot(extinction_coefficients_input, range(num_of_layers, 0, -1), '.-', label='Input')
plt.plot(extinction_coefficients_computed[image_id - 1, :], range(num_of_layers, 0, -1), '.-', label='Computed')
plt.xlabel('Extinction coefficient / $\mathrm{m}^{-1}$')
plt.ylabel('Layer / -')
plt.title(f'Input vs Computed {solver} Extinction Coefficients - Image {image_id}')
plt.title(f'Input vs Computed {solver} Extinction Coefficients - Image {image_id}, t = {time[image_id - 1]} s')
plt.xlim(-0.1, 0.6)
plt.ylim(num_of_layers, 0)
plt.grid(linestyle='--', alpha=0.5)
Expand All @@ -90,9 +89,7 @@ def plot_input_vs_computed_extinction_coefficients(self, solver, first=1, last=4

@keyword
def check_input_vs_computed_extinction_coefficients(self, image_id, solver, led_array=0, channel=0):
filename = f'extinction_coefficients_{solver}_channel_{channel}_sum_col_val_led_array_{led_array}.csv'
extinction_coefficients_computed = (
np.loadtxt(os.path.join('analysis', 'extinction_coefficients',solver, filename), skiprows=5, delimiter=','))
_, extinction_coefficients_computed = load_extinction_coefficients_computed(solver, channel, led_array)
extinction_coefficients_input = np.loadtxt(os.path.join('test_data', f'test_extinction_coefficients_input_{image_id}.csv'), delimiter=',')
rmse = np.sqrt(
np.mean((extinction_coefficients_input - extinction_coefficients_computed[int(image_id) - 1, :]) ** 2))
Expand Down Expand Up @@ -152,6 +149,16 @@ def create_cc_matrix_file(self):
file.write("2,3,4\n1,2,7\n3,4,5")
file.close()

def load_extinction_coefficients_computed(solver, channel, led_array):
filename = f'extinction_coefficients_{solver}_channel_{channel}_sum_col_val_led_array_{led_array}.csv'
data = np.loadtxt(
os.path.join('analysis', 'extinction_coefficients', solver, filename),
skiprows=5,
delimiter=','
)
time = data[:, 0]
extinction_coefficients_computed = data[:, 1:]
return time, extinction_coefficients_computed

def create_test_image(image_id, experiment):
""" Creates three test images with black and gray pixels representing 3 leds and sets the exif data needed
Expand Down
Loading