Update testing for multiple sample shapes
This commit is contained in:
parent
7373424fcf
commit
b414697cfb
7 changed files with 61 additions and 142 deletions
|
|
@ -253,7 +253,22 @@ def test_closest_focus_wth_large_numbers():
|
|||
|
||||
|
||||
def test_example_smart_spiral():
|
||||
_, planner = scan_test_helpers.example_smart_spiral()
|
||||
expected_planner = scan_test_helpers.get_expected_result_for_example_smart_spiral()
|
||||
assert planner.path_history == expected_planner.path_history
|
||||
assert planner.imaged_locations == expected_planner.imaged_locations
|
||||
"""Test the smart spiral scan algorithm on the sample types listed
|
||||
below and defined in scan_test_helpers.load_sample_points
|
||||
|
||||
Will fail if the locations or path between locations visited has changed
|
||||
for any of the samples listed"""
|
||||
example_samples = [
|
||||
"regular",
|
||||
"lobed",
|
||||
"core",
|
||||
]
|
||||
for sample_type in example_samples:
|
||||
_, planner = scan_test_helpers.example_smart_spiral(sample=sample_type)
|
||||
expected_planner = (
|
||||
scan_test_helpers.get_expected_result_for_example_smart_spiral(
|
||||
sample=sample_type
|
||||
)
|
||||
)
|
||||
assert planner.path_history == expected_planner.path_history
|
||||
assert planner.imaged_locations == expected_planner.imaged_locations
|
||||
|
|
|
|||
Binary file not shown.
BIN
tests/utilities/example_smart_spiral_core.pkl
Normal file
BIN
tests/utilities/example_smart_spiral_core.pkl
Normal file
Binary file not shown.
BIN
tests/utilities/example_smart_spiral_lobed.pkl
Normal file
BIN
tests/utilities/example_smart_spiral_lobed.pkl
Normal file
Binary file not shown.
BIN
tests/utilities/example_smart_spiral_regular.pkl
Normal file
BIN
tests/utilities/example_smart_spiral_regular.pkl
Normal file
Binary file not shown.
|
|
@ -111,23 +111,19 @@ def interp_closed_path(xy_points: list[tuple[int, int]], n_points: int) -> MatPa
|
|||
return MatPath(path_points, closed=True)
|
||||
|
||||
|
||||
def example_smart_spiral() -> tuple[FakeSample, scan_planners.ScanPlanner]:
|
||||
def example_smart_spiral(
|
||||
sample: str = "lobed",
|
||||
) -> tuple[FakeSample, scan_planners.ScanPlanner]:
|
||||
"""
|
||||
Run an example scan and return the sample scanned and the planner object
|
||||
after scan is complete
|
||||
"""
|
||||
xy_sample_points = [
|
||||
(-5000, -5000),
|
||||
(-2000, 10000),
|
||||
(1000, 2000),
|
||||
(6000, 7000),
|
||||
(9000, 2000),
|
||||
]
|
||||
xy_sample_points = load_sample_points(sample=sample)
|
||||
sample = FakeSample(xy_sample_points)
|
||||
img_size = (1000, 1000)
|
||||
intial_position = (0, 0)
|
||||
planner_settings = {"dx": 700, "dy": 700, "max_dist": 100000}
|
||||
planner = scan_planners.ShortSmartSpiral(
|
||||
planner_settings = {"dx": 1200, "dy": 800, "max_dist": 100000}
|
||||
planner = scan_planners.SmartSpiral(
|
||||
intial_position=intial_position, planner_settings=planner_settings
|
||||
)
|
||||
|
||||
|
|
@ -166,7 +162,7 @@ def profile_and_save_plot_for_example_smart_spiral():
|
|||
run_stats.print_stats("scan_planners.py")
|
||||
|
||||
|
||||
def update_example_smart_spiral_pickle():
|
||||
def update_example_smart_spiral_pickle(sample: str):
|
||||
"""
|
||||
Pickle the ScanPlanner for the example_smart_spiral(),
|
||||
this is done so the history can be compared by testing to check
|
||||
|
|
@ -174,23 +170,54 @@ def update_example_smart_spiral_pickle():
|
|||
|
||||
If the algorithm is purposefully changed then this will need to be
|
||||
run to update the pickle for the test to pass.
|
||||
|
||||
Takes sample, the sample type we have generated, so we can make a
|
||||
pickle for each sample type
|
||||
"""
|
||||
pkl_fname = os.path.join(THIS_DIR, "example_smart_spiral.pkl")
|
||||
pkl_fname = os.path.join(THIS_DIR, f"example_smart_spiral_{sample}.pkl")
|
||||
with open(pkl_fname, "wb") as pkl_file_obj:
|
||||
_, planner = example_smart_spiral()
|
||||
_, planner = example_smart_spiral(sample=sample)
|
||||
pickle.dump(planner, pkl_file_obj, pickle.HIGHEST_PROTOCOL)
|
||||
|
||||
|
||||
def get_expected_result_for_example_smart_spiral():
|
||||
def get_expected_result_for_example_smart_spiral(sample: str):
|
||||
"""
|
||||
Return the expected ScanPlanner object for the example_smart_spiral(),
|
||||
this is pickled, so that it can be committed.
|
||||
"""
|
||||
pkl_fname = os.path.join(THIS_DIR, "example_smart_spiral.pkl")
|
||||
pkl_fname = os.path.join(THIS_DIR, f"example_smart_spiral_{sample}.pkl")
|
||||
with open(pkl_fname, "rb") as pkl_file_obj:
|
||||
planner = pickle.load(pkl_file_obj)
|
||||
return planner
|
||||
|
||||
|
||||
def load_sample_points(sample: str):
|
||||
"""Returns the points to generate a FakeSample of sample type "sample" """
|
||||
sample_options = {
|
||||
"lobed": [
|
||||
(-5000, -5000),
|
||||
(-2000, 16000),
|
||||
(1000, 2000),
|
||||
(6000, 7000),
|
||||
(9000, 2000),
|
||||
],
|
||||
"regular": [
|
||||
(-5000, -5000),
|
||||
(-5000, 5000),
|
||||
(5000, 5000),
|
||||
(5000, -5000),
|
||||
],
|
||||
"core": [
|
||||
(-12000, 2000),
|
||||
(-12000, 1000),
|
||||
(0, -2000),
|
||||
(10000, -2000),
|
||||
(10000, -1000),
|
||||
(1000, 0),
|
||||
],
|
||||
}
|
||||
return sample_options[sample]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
profile_and_save_plot_for_example_smart_spiral()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue