|
1 | 1 | import ast
|
| 2 | +import math |
2 | 3 | from ast import literal_eval
|
3 | 4 | from typing import Dict
|
4 | 5 |
|
@@ -442,6 +443,62 @@ def test_set_miscut():
|
442 | 443 | assert ubcalc.U is not None
|
443 | 444 |
|
444 | 445 |
|
| 446 | +def test_set_miscut_with_existing_u(): |
| 447 | + ubcalc = UBCalculation("LSMO_327_001") |
| 448 | + hkl = HklCalculation(ubcalc, Constraints()) |
| 449 | + client = Client(hkl).client |
| 450 | + |
| 451 | + ubcalc.set_lattice("LSMO_327", "Triclinic", 3.78, 3.78, 20.1, 90.0, 90.0, 90.0) |
| 452 | + ubcalc.add_orientation( |
| 453 | + [0, 0, 1], [0, 0, 1], Position(60.0585, 0, 90.4052, 0, -29.5624, 39.1178) |
| 454 | + ) |
| 455 | + ubcalc.add_orientation( |
| 456 | + [0, 1, 0], [0, 1, 0], Position(60.0585, 0, 90.4052, 0, -29.5624, 39.1178) |
| 457 | + ) |
| 458 | + ubcalc.calc_ub() |
| 459 | + ubcalc.n_phi = [0.0, 1.0, 0.0] |
| 460 | + |
| 461 | + angle_in_rad = math.radians(11) |
| 462 | + rotation_axis = {"x": 0, "y": 1, "z": 0} |
| 463 | + |
| 464 | + client.put( |
| 465 | + "/ub/test/miscut?collection=B07", |
| 466 | + params={"angle": angle_in_rad, "add_miscut": True}, |
| 467 | + json=rotation_axis, |
| 468 | + ) |
| 469 | + |
| 470 | + get_response = client.get("/ub/test/miscut?collection=B07") |
| 471 | + get_response_payload = ast.literal_eval(get_response.content.decode())["payload"] |
| 472 | + |
| 473 | + assert get_response_payload["angle"] == 1.0540812808041131 |
| 474 | + |
| 475 | + |
| 476 | +def test_set_and_get_miscut(): |
| 477 | + ubcalc = UBCalculation() |
| 478 | + hkl = HklCalculation(ubcalc, Constraints()) |
| 479 | + client = Client(hkl).client |
| 480 | + |
| 481 | + # angle = 0.85212 |
| 482 | + # rotation_axis = {"x": -0.25142, "y": -0.96788, "z": 0.0} |
| 483 | + |
| 484 | + angle_in_rad = math.radians(11) |
| 485 | + rotation_axis = {"x": 0, "y": 1, "z": 0} |
| 486 | + |
| 487 | + client.put( |
| 488 | + "/ub/test/miscut?collection=B07", |
| 489 | + params={"angle": angle_in_rad, "add_miscut": False}, |
| 490 | + json=rotation_axis, |
| 491 | + ) |
| 492 | + |
| 493 | + get_response = client.get("/ub/test/miscut?collection=B07") |
| 494 | + get_response_payload = ast.literal_eval(get_response.content.decode())["payload"] |
| 495 | + |
| 496 | + assert get_response_payload["angle"] == pytest.approx(angle_in_rad) |
| 497 | + |
| 498 | + for key, value in get_response_payload["rotation_axis"].items(): |
| 499 | + assert np.round(value, 5) == np.round(rotation_axis[key], 5) |
| 500 | + |
| 501 | + |
445 | 502 | def test_calc_ub():
|
446 | 503 | ubcalc = UBCalculation()
|
447 | 504 | hkl = HklCalculation(ubcalc, Constraints())
|
|
0 commit comments