Skip to content

Commit

Permalink
use recorder for fourierShift test
Browse files Browse the repository at this point in the history
  • Loading branch information
waltsims committed Jun 4, 2024
1 parent 6a58da2 commit 5822aa0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[5, 10, 5, 4] ... # 4D
};
shifts = [0, 0.12, 0.29, 0.5, 0.52, 0.85, 1.0];
output_folder = 'collectedValues/fourierShift';
output_file = 'collectedValues/fourierShift.mat';
idx = 0;

recorder = utils.TestRecorder(output_file);
for data_dim_idx=1:size(dims, 2)
data_dim = data_dims{data_dim_idx};
data = rand(data_dim);
Expand All @@ -19,22 +19,22 @@
shifted_data = fourierShift(data, shift);

% Save output
idx_padded = sprintf('%06d', idx);
filename = [output_folder '/' idx_padded '.mat'];
save(filename, 'data', 'shift', 'shifted_data');
idx = idx + 1;
recorder.recordVariable('data', data);
recorder.recordVariable('shift', shift);
recorder.recordVariable('shifted_data', shifted_data);
recorder.increment();

for shift_dim=1:size(data_dim, 2)
shifted_data = fourierShift(data, shift, shift_dim);

% Save output
idx_padded = sprintf('%06d', idx);
filename = [output_folder '/' idx_padded '.mat'];
save(filename, 'data', 'shift', 'shift_dim', 'shifted_data');
idx = idx + 1;
recorder.recordVariable('data', data);
recorder.recordVariable('shift', shift);
recorder.recordVariable('shift_dim', shift_dim);
recorder.recordVariable('shifted_data', shifted_data);
recorder.increment();
end

end

end

recorder.saveRecordsToDisk();
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
from pathlib import Path

import numpy as np
from scipy.io import loadmat

from kwave.utils.math import fourier_shift
from tests.matlab_test_data_collectors.python_testers.utils.record_reader import TestRecordReader


def test_fourier_shift():
collected_values_folder = os.path.join(Path(__file__).parent, "collectedValues/fourierShift")
num_collected_values = len(os.listdir(collected_values_folder))
collected_values_folder = os.path.join(Path(__file__).parent, "collectedValues/fourierShift.mat")
reader = TestRecordReader(collected_values_folder)

for i in range(num_collected_values):
for i in range(len(reader)):
# Read recorded data
filepath = os.path.join(collected_values_folder, f"{i:06d}.mat")
recorded_data = loadmat(filepath)

data = recorded_data["data"]
shift = float(recorded_data["shift"])
if "shift_dim" in recorded_data:
shift_dim = int(recorded_data["shift_dim"])
else:

data = reader.expected_value_of("data")
shift = reader.expected_value_of("shift")
try:
shift_dim = reader.expected_value_of("shift_dim")
except KeyError:
shift_dim = None
expected_shifted_data = recorded_data["shifted_data"]
expected_shifted_data = reader.expected_value_of("shifted_data")

# Execute implementation
shifted_data = fourier_shift(data, shift, shift_dim)
Expand Down

0 comments on commit 5822aa0

Please sign in to comment.