fix(v5): reconstruct inverse fft from saved spectrum

This commit is contained in:
2026-07-09 15:01:47 +03:30
parent ca447c71cc
commit 30e1d250ef
5 changed files with 157 additions and 18 deletions

View File

@@ -273,7 +273,7 @@ class ApiTests(TestCase):
)
self.assertEqual(response.status_code, 400)
def test_inverse_fft_reconstruction_matches_input_shape_and_values(self):
def test_inverse_fft_reconstruction_rejects_non_fft_state(self):
upload = self.client.post("/api/images/", {"image": png_upload(color=(32, 64, 128), size=(4, 4))}, format="multipart")
s0_id = upload.data["states"][0]["state_id"]
response = self.client.post(
@@ -282,8 +282,39 @@ class ApiTests(TestCase):
format="json",
)
self.assertEqual(response.status_code, 400)
def test_fft_spectrum_state_stores_complex_data(self):
upload = self.client.post("/api/images/", {"image": png_upload(color=(32, 64, 128), size=(4, 4))}, format="multipart")
s0_id = upload.data["states"][0]["state_id"]
spectrum = self.client.post(
f"/api/states/{s0_id}/operations/",
{"operation": "fft_spectrum", "params": {"mode": "log_magnitude"}},
format="json",
)
self.assertEqual(spectrum.status_code, 201)
state = ImageState.objects.get(id=spectrum.data["state_id"])
self.assertEqual(state.operation, "fft_spectrum")
self.assertIn("fft_data_path", state.params)
self.assertTrue((Path(self.tmp.name) / state.params["fft_data_path"]).exists())
def test_inverse_fft_reconstruction_undoes_saved_fft_state(self):
upload = self.client.post("/api/images/", {"image": png_upload(color=(32, 64, 128), size=(4, 4))}, format="multipart")
s0_id = upload.data["states"][0]["state_id"]
spectrum = self.client.post(
f"/api/states/{s0_id}/operations/",
{"operation": "fft_spectrum", "params": {"mode": "log_magnitude"}},
format="json",
)
response = self.client.post(
f"/api/states/{spectrum.data['state_id']}/operations/",
{"operation": "inverse_fft_reconstruction", "params": {}},
format="json",
)
self.assertEqual(response.status_code, 201)
self.assertEqual(response.data["channels"], 3)
self.assertEqual(response.data["parent_state_id"], spectrum.data["state_id"])
result = load_image_array(ImageState.objects.get(id=response.data["state_id"]).image)
expected = load_image_array(ImageState.objects.get(id=s0_id).image)
np.testing.assert_allclose(result, expected, atol=1)
@@ -291,8 +322,13 @@ class ApiTests(TestCase):
def test_inverse_fft_reconstruction_preserves_grayscale(self):
upload = self.client.post("/api/images/", {"image": grayscale_png_upload(value=96)}, format="multipart")
s0_id = upload.data["states"][0]["state_id"]
response = self.client.post(
spectrum = self.client.post(
f"/api/states/{s0_id}/operations/",
{"operation": "fft_spectrum", "params": {"mode": "log_magnitude"}},
format="json",
)
response = self.client.post(
f"/api/states/{spectrum.data['state_id']}/operations/",
{"operation": "inverse_fft_reconstruction", "params": {}},
format="json",
)