fakecbed 0.3.6__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {fakecbed-0.3.6 → fakecbed-0.5.0}/.gitignore +1 -0
  2. {fakecbed-0.3.6 → fakecbed-0.5.0}/PKG-INFO +3 -2
  3. {fakecbed-0.3.6 → fakecbed-0.5.0}/examples/basic_usage.ipynb +571 -1
  4. fakecbed-0.5.0/fakecbed/discretized.py +5316 -0
  5. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed/shapes.py +1 -1
  6. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed/version.py +16 -3
  7. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed.egg-info/PKG-INFO +3 -2
  8. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed.egg-info/requires.txt +2 -1
  9. {fakecbed-0.3.6 → fakecbed-0.5.0}/pyproject.toml +2 -1
  10. {fakecbed-0.3.6 → fakecbed-0.5.0}/tests/test_discretized.py +139 -0
  11. fakecbed-0.3.6/fakecbed/discretized.py +0 -2596
  12. {fakecbed-0.3.6 → fakecbed-0.5.0}/.coveragerc +0 -0
  13. {fakecbed-0.3.6 → fakecbed-0.5.0}/.github/workflows/measure_code_coverage.yml +0 -0
  14. {fakecbed-0.3.6 → fakecbed-0.5.0}/.github/workflows/publish_documentation_website.yml +0 -0
  15. {fakecbed-0.3.6 → fakecbed-0.5.0}/.github/workflows/publish_release_to_pypi.yml +0 -0
  16. {fakecbed-0.3.6 → fakecbed-0.5.0}/.github/workflows/test_library.yml +0 -0
  17. {fakecbed-0.3.6 → fakecbed-0.5.0}/LICENSE +0 -0
  18. {fakecbed-0.3.6 → fakecbed-0.5.0}/README.md +0 -0
  19. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/INSTALL.rst +0 -0
  20. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/Makefile +0 -0
  21. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/_static/readthedocs_custom.css +0 -0
  22. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/_templates/custom_class_template.rst +0 -0
  23. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/_templates/custom_module_template.rst +0 -0
  24. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/_templates/versions.html +0 -0
  25. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/api.rst +0 -0
  26. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/build_docs.py +0 -0
  27. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/conf.py +0 -0
  28. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/examples.rst +0 -0
  29. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/index.rst +0 -0
  30. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/license.rst +0 -0
  31. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/literature.rst +0 -0
  32. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/make.bat +0 -0
  33. {fakecbed-0.3.6 → fakecbed-0.5.0}/docs/private_members_to_publish_to_docs.rst +0 -0
  34. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed/__init__.py +0 -0
  35. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed/tds.py +0 -0
  36. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed.egg-info/SOURCES.txt +0 -0
  37. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed.egg-info/dependency_links.txt +0 -0
  38. {fakecbed-0.3.6 → fakecbed-0.5.0}/fakecbed.egg-info/top_level.txt +0 -0
  39. {fakecbed-0.3.6 → fakecbed-0.5.0}/setup.cfg +0 -0
  40. {fakecbed-0.3.6 → fakecbed-0.5.0}/setup.py +0 -0
  41. {fakecbed-0.3.6 → fakecbed-0.5.0}/tests/test_shapes.py +0 -0
  42. {fakecbed-0.3.6 → fakecbed-0.5.0}/tox.ini +0 -0
@@ -13,6 +13,7 @@ pages/
13
13
  .python-version
14
14
  fakecbed/version.py
15
15
  tests/coverage.json
16
+ run_tests.sh
16
17
 
17
18
  # Ignore generated output coverage files.
18
19
  tests/coverage*
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fakecbed
3
- Version: 0.3.6
3
+ Version: 0.5.0
4
4
  Summary: A Python library for generating quickly images that imitate convergent beam electron diffraction patterns.
5
5
  Author-email: Matthew Fitzpatrick <matthew.rc.fitzpatrick@gmail.com>
6
6
  Project-URL: Homepage, https://mrfitzpa.github.io/fakecbed
@@ -21,7 +21,8 @@ Classifier: Natural Language :: English
21
21
  Requires-Python: >=3.8
22
22
  Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
- Requires-Dist: distoptica>=0.3.3
24
+ Requires-Dist: distoptica>=0.4.0
25
+ Requires-Dist: empix
25
26
  Requires-Dist: hyperspy
26
27
  Provides-Extra: tests
27
28
  Requires-Dist: pytest-cov; extra == "tests"
@@ -45,12 +45,20 @@
45
45
  "metadata": {},
46
46
  "outputs": [],
47
47
  "source": [
48
+ "# For performing deep copies.\n",
49
+ "import copy\n",
50
+ "\n",
51
+ "\n",
52
+ "\n",
48
53
  "# For general array handling.\n",
49
54
  "import numpy as np\n",
50
55
  "\n",
51
56
  "# For creating distortion models.\n",
52
57
  "import distoptica\n",
53
58
  "\n",
59
+ "# For creating Hyperspy markers.\n",
60
+ "import hyperspy.api as hs\n",
61
+ "\n",
54
62
  "\n",
55
63
  "\n",
56
64
  "# The library that is the subject of this demonstration.\n",
@@ -100,6 +108,14 @@
100
108
  "## Using the ``fakecbed`` library ##"
101
109
  ]
102
110
  },
111
+ {
112
+ "cell_type": "markdown",
113
+ "id": "60a6dd71-881c-4e24-9fc3-15f291729d52",
114
+ "metadata": {},
115
+ "source": [
116
+ "### Creating a fake CBED pattern ###"
117
+ ]
118
+ },
103
119
  {
104
120
  "cell_type": "markdown",
105
121
  "id": "07902c93-c509-48a1-9953-fc4fcb6e925a",
@@ -1275,6 +1291,560 @@
1275
1291
  " \"cmap\": \"jet\"}\n",
1276
1292
  "cbed_pattern.signal.plot(**kwargs)"
1277
1293
  ]
1294
+ },
1295
+ {
1296
+ "cell_type": "markdown",
1297
+ "id": "012e8538-e2e9-420c-bfb9-684c18b3ac54",
1298
+ "metadata": {},
1299
+ "source": [
1300
+ "### Creating a cropped fake CBED pattern ###"
1301
+ ]
1302
+ },
1303
+ {
1304
+ "cell_type": "markdown",
1305
+ "id": "c4863267-bbd9-4950-86a5-15494a987f5a",
1306
+ "metadata": {},
1307
+ "source": [
1308
+ "Let us recover the fake CBED pattern we created prior to overriding the image:"
1309
+ ]
1310
+ },
1311
+ {
1312
+ "cell_type": "code",
1313
+ "execution_count": null,
1314
+ "id": "79dfc4f1-5621-4a75-bed7-8e3b18c871ae",
1315
+ "metadata": {},
1316
+ "outputs": [],
1317
+ "source": [
1318
+ "kwargs = cbed_pattern.core_attrs\n",
1319
+ "cbed_pattern = fakecbed.discretized.CBEDPattern(**kwargs)\n",
1320
+ "\n",
1321
+ "kwargs = {\"axes_off\": False, \n",
1322
+ " \"scalebar\": False, \n",
1323
+ " \"colorbar\": False, \n",
1324
+ " \"gamma\": 0.3,\n",
1325
+ " \"cmap\": \"jet\"}\n",
1326
+ "cbed_pattern.signal.plot(**kwargs)"
1327
+ ]
1328
+ },
1329
+ {
1330
+ "cell_type": "markdown",
1331
+ "id": "abe6a2d9-9c85-46a9-a34a-f46fb0c4b28b",
1332
+ "metadata": {},
1333
+ "source": [
1334
+ "With this fake CBED pattern we can create a cropped fake CBED pattern:"
1335
+ ]
1336
+ },
1337
+ {
1338
+ "cell_type": "code",
1339
+ "execution_count": null,
1340
+ "id": "5318265c-5934-4285-8a63-76634b059f44",
1341
+ "metadata": {},
1342
+ "outputs": [],
1343
+ "source": [
1344
+ "kwargs = {\"cbed_pattern\": cbed_pattern, \n",
1345
+ " \"cropping_window_center\": (0.35, 0.35),\n",
1346
+ " \"cropping_window_dims_in_pixels\": (300, 300),\n",
1347
+ " \"principal_disk_idx\": 1,\n",
1348
+ " \"disk_boundary_sample_size\": 64, \n",
1349
+ " \"mask_frame\": (10, 50, 30, 5)}\n",
1350
+ "cropped_cbed_pattern = fakecbed.discretized.CroppedCBEDPattern(**kwargs)"
1351
+ ]
1352
+ },
1353
+ {
1354
+ "cell_type": "markdown",
1355
+ "id": "5829c2c2-e7d0-4cd0-afd1-88345f6677c3",
1356
+ "metadata": {},
1357
+ "source": [
1358
+ "A subset of the attribute names of the\n",
1359
+ "``fakecbed.discretized.CroppedCBEDPattern`` class is equal to the entire set of\n",
1360
+ "attribute names of the ``fakecbed.discretized.CBEDPattern`` class. For instance,\n",
1361
+ "the attribute ``cropped_cbed_pattern.signal`` stores a hyperspy signal\n",
1362
+ "representation of the cropped fake CBED pattern. See\n",
1363
+ "[here](https://mrfitzpa.github.io/fakecbed/_autosummary/fakecbed.discretized.CroppedCBEDPattern.html#fakecbed.discretized.CroppedCBEDPattern.signal)\n",
1364
+ "for a description of the signal representation of the fake cropped CBED pattern.\n",
1365
+ "Note that the image of the discretized cropped CBED pattern is always\n",
1366
+ "automatically min-max normalized. Also, note that the positions of the pixels in\n",
1367
+ "the signal representation of the cropped fake CBED pattern are expressed in the\n",
1368
+ "fractional coordinates of the uncropped fake CBED pattern."
1369
+ ]
1370
+ },
1371
+ {
1372
+ "cell_type": "code",
1373
+ "execution_count": null,
1374
+ "id": "fd130608-2d5e-4fd2-8832-f013a45223dd",
1375
+ "metadata": {},
1376
+ "outputs": [],
1377
+ "source": [
1378
+ "cropped_cbed_pattern_signal = cropped_cbed_pattern.signal\n",
1379
+ "\n",
1380
+ "kwargs = {\"axes_off\": False, \n",
1381
+ " \"scalebar\": False, \n",
1382
+ " \"colorbar\": False, \n",
1383
+ " \"gamma\": 0.3,\n",
1384
+ " \"cmap\": \"jet\"}\n",
1385
+ "cropped_cbed_pattern_signal.plot(**kwargs)\n",
1386
+ "\n",
1387
+ "cropped_cbed_pattern_signal.metadata"
1388
+ ]
1389
+ },
1390
+ {
1391
+ "cell_type": "markdown",
1392
+ "id": "0aa6554a-0036-4ee6-8138-4eaab5d14789",
1393
+ "metadata": {},
1394
+ "source": [
1395
+ "The ``fakecbed.discretized.CroppedCBEDPattern`` class has additional attributes,\n",
1396
+ "one of which is ``principal_disk_is_clipped``, which indicates whether the\n",
1397
+ "\"principal\" CBED disk is clipped in the image of the cropped fake CBED pattern:"
1398
+ ]
1399
+ },
1400
+ {
1401
+ "cell_type": "code",
1402
+ "execution_count": null,
1403
+ "id": "7ea653c5-03bc-4918-82e6-4ff08e5341b8",
1404
+ "metadata": {},
1405
+ "outputs": [],
1406
+ "source": [
1407
+ "cropped_cbed_pattern.principal_disk_is_clipped"
1408
+ ]
1409
+ },
1410
+ {
1411
+ "cell_type": "markdown",
1412
+ "id": "80824fd9-43ca-4500-9709-6979e6c3559c",
1413
+ "metadata": {},
1414
+ "source": [
1415
+ "In our current example, the principal CBED disk is not clipped. If the principal\n",
1416
+ "CBED disk does not exist, i.e. if the construction parameter\n",
1417
+ "``principal_disk_idx`` is set to a nonnegative integer greater than or equal to\n",
1418
+ "the number of CBED disks defined in the uncropped fake CBED pattern, then\n",
1419
+ "``principal_disk_is_clipped`` will return ``True``. To be clear,\n",
1420
+ "``principal_disk_is_clipped`` can return ``True`` even if the principal CBED\n",
1421
+ "disk exists. In such a scenario, the principal CBED disk corresponds to a CBED\n",
1422
+ "disk that has been defined, but is clipped in the image of the uncropped fake\n",
1423
+ "CBED pattern."
1424
+ ]
1425
+ },
1426
+ {
1427
+ "cell_type": "markdown",
1428
+ "id": "569d50f7-7354-448c-abf0-3124eb8b0ecc",
1429
+ "metadata": {},
1430
+ "source": [
1431
+ "Another attribute is ``principal_disk_is_absent``, which indicates whether the\n",
1432
+ "\"principal\" CBED disk is absent in the image of the cropped fake CBED pattern:"
1433
+ ]
1434
+ },
1435
+ {
1436
+ "cell_type": "code",
1437
+ "execution_count": null,
1438
+ "id": "fa747739-8f91-4bb1-bc17-23d79018bcda",
1439
+ "metadata": {},
1440
+ "outputs": [],
1441
+ "source": [
1442
+ "cropped_cbed_pattern.principal_disk_is_absent"
1443
+ ]
1444
+ },
1445
+ {
1446
+ "cell_type": "markdown",
1447
+ "id": "ec76677f-46d2-4aea-a11f-158173f09ebc",
1448
+ "metadata": {},
1449
+ "source": [
1450
+ "In our current example, the principal CBED disk is not absent. If the principal\n",
1451
+ "CBED disk does not exist, then ``principal_disk_is_absent`` will be set to\n",
1452
+ "``True``. To be clear, ``principal_disk_is_absent`` can be set to ``True`` even\n",
1453
+ "if the principal CBED disk exists. In such a scenario, the principal CBED disk\n",
1454
+ "corresponds to a CBED disk that has been defined, but is absent in the image of\n",
1455
+ "the uncropped fake CBED pattern."
1456
+ ]
1457
+ },
1458
+ {
1459
+ "cell_type": "markdown",
1460
+ "id": "64410367-6786-4d22-98e0-dc2330fd774b",
1461
+ "metadata": {},
1462
+ "source": [
1463
+ "Another attribute is ``principal_disk_is_overlapping``, which indicates whether\n",
1464
+ "the \"principal\" CBED disk is overlapping with another CBED disk in the image of\n",
1465
+ "the cropped fake CBED pattern:"
1466
+ ]
1467
+ },
1468
+ {
1469
+ "cell_type": "code",
1470
+ "execution_count": null,
1471
+ "id": "76ac4578-e7fc-4f4f-83a8-e03f1ac45e4b",
1472
+ "metadata": {},
1473
+ "outputs": [],
1474
+ "source": [
1475
+ "cropped_cbed_pattern.principal_disk_is_overlapping"
1476
+ ]
1477
+ },
1478
+ {
1479
+ "cell_type": "markdown",
1480
+ "id": "151710c6-6ac8-4f0d-8588-81016d5d4156",
1481
+ "metadata": {},
1482
+ "source": [
1483
+ "In our current example, the principal CBED disk is not overlapping. If the\n",
1484
+ "principal CBED disk does not exist, then ``principal_disk_is_overlapping`` will\n",
1485
+ "be set to ``False``."
1486
+ ]
1487
+ },
1488
+ {
1489
+ "cell_type": "markdown",
1490
+ "id": "9e091d44-7f20-4256-b148-4205460a13e0",
1491
+ "metadata": {},
1492
+ "source": [
1493
+ "Another attribute is\n",
1494
+ "``principal_disk_bounding_box_in_uncropped_image_fractional_coords``, which\n",
1495
+ "stores the bounding box of the unclipped support of the principal CBED disk,\n",
1496
+ "should it exist, in fractional coordinates of the uncropped fake CBED pattern:"
1497
+ ]
1498
+ },
1499
+ {
1500
+ "cell_type": "code",
1501
+ "execution_count": null,
1502
+ "id": "b91e8b37-a136-4c57-b1cb-95ed11934c19",
1503
+ "metadata": {},
1504
+ "outputs": [],
1505
+ "source": [
1506
+ "attr_name = \\\n",
1507
+ " \"principal_disk_bounding_box_in_uncropped_image_fractional_coords\"\n",
1508
+ "principal_disk_bounding_box_in_uncropped_image_fractional_coords = \\\n",
1509
+ " getattr(cropped_cbed_pattern, attr_name)\n",
1510
+ "\n",
1511
+ "principal_disk_bounding_box_in_uncropped_image_fractional_coords"
1512
+ ]
1513
+ },
1514
+ {
1515
+ "cell_type": "markdown",
1516
+ "id": "f48a054e-8fc1-46a7-b72e-9198d97d7a18",
1517
+ "metadata": {},
1518
+ "source": [
1519
+ "In the order that they appear, the coordinates are those of the left, right,\n",
1520
+ "bottom and top sides of the bounding box respectively. If the principal CBED\n",
1521
+ "disk does not exist, then the attribute is set to ``None``.\n",
1522
+ "\n",
1523
+ "We can add the box to the signal representations of the cropped and uncropped\n",
1524
+ "fake CBED patterns:"
1525
+ ]
1526
+ },
1527
+ {
1528
+ "cell_type": "code",
1529
+ "execution_count": null,
1530
+ "id": "23ffa504-3d7d-4784-9a2f-1fd3849aa687",
1531
+ "metadata": {},
1532
+ "outputs": [],
1533
+ "source": [
1534
+ "L, R, B, T = principal_disk_bounding_box_in_uncropped_image_fractional_coords\n",
1535
+ "\n",
1536
+ "kwargs = {\"axes_off\": False, \n",
1537
+ " \"scalebar\": False, \n",
1538
+ " \"colorbar\": False, \n",
1539
+ " \"gamma\": 0.3,\n",
1540
+ " \"cmap\": \"jet\"}\n",
1541
+ "cropped_cbed_pattern_signal.plot(**kwargs)\n",
1542
+ "\n",
1543
+ "try: # For Hyperspy versions >= 2.\n",
1544
+ " x_box = (R+L)/2\n",
1545
+ " y_box = (B+T)/2\n",
1546
+ " box_center = (x_box, y_box)\n",
1547
+ " kwargs = {\"edgecolors\": \"green\",\n",
1548
+ " \"linewidths\": 3, \n",
1549
+ " \"facecolors\": \"none\",\n",
1550
+ " \"offsets\": (box_center,), \n",
1551
+ " \"widths\": (R-L), \n",
1552
+ " \"heights\": (B-T)}\n",
1553
+ " marker = hs.plot.markers.Rectangles(**kwargs)\n",
1554
+ "except: # For Hyperspy versions < 2.\n",
1555
+ " kwargs = {\"edgecolor\": \"green\",\n",
1556
+ " \"linewidth\": 3, \n",
1557
+ " \"x1\": L, \n",
1558
+ " \"x2\": R, \n",
1559
+ " \"y1\": T, \n",
1560
+ " \"y2\": B}\n",
1561
+ " marker = hs.plot.markers.rectangle(**kwargs)\n",
1562
+ "\n",
1563
+ "cropped_cbed_pattern_signal.add_marker(marker, permanent=False)"
1564
+ ]
1565
+ },
1566
+ {
1567
+ "cell_type": "code",
1568
+ "execution_count": null,
1569
+ "id": "62f80164-125a-4757-a61a-226768c6323b",
1570
+ "metadata": {},
1571
+ "outputs": [],
1572
+ "source": [
1573
+ "cbed_pattern_signal = cbed_pattern.signal\n",
1574
+ "\n",
1575
+ "kwargs = {\"axes_off\": False, \n",
1576
+ " \"scalebar\": False, \n",
1577
+ " \"colorbar\": False, \n",
1578
+ " \"gamma\": 0.3,\n",
1579
+ " \"cmap\": \"jet\"}\n",
1580
+ "cbed_pattern_signal.plot(**kwargs)\n",
1581
+ "\n",
1582
+ "marker = copy.deepcopy(marker)\n",
1583
+ "cbed_pattern_signal.add_marker(marker, permanent=False)"
1584
+ ]
1585
+ },
1586
+ {
1587
+ "cell_type": "markdown",
1588
+ "id": "18fe97c8-1692-4076-bb6f-b1dd90fabe80",
1589
+ "metadata": {},
1590
+ "source": [
1591
+ "Another attribute is\n",
1592
+ "``principal_disk_boundary_pts_in_uncropped_image_fractional_coords``, which\n",
1593
+ "stores a sample of points on the boundary of the unclipped support of the\n",
1594
+ "principal CBED disk, should it exist, in fractional coordinates of the uncropped\n",
1595
+ "fake CBED pattern:"
1596
+ ]
1597
+ },
1598
+ {
1599
+ "cell_type": "code",
1600
+ "execution_count": null,
1601
+ "id": "f71e51a6-b251-4e4a-ad73-a273e3b600c1",
1602
+ "metadata": {},
1603
+ "outputs": [],
1604
+ "source": [
1605
+ "attr_name = \\\n",
1606
+ " \"principal_disk_boundary_pts_in_uncropped_image_fractional_coords\"\n",
1607
+ "principal_disk_boundary_pts_in_uncropped_image_fractional_coords = \\\n",
1608
+ " getattr(cropped_cbed_pattern, attr_name)\n",
1609
+ "\n",
1610
+ "principal_disk_boundary_pts_in_uncropped_image_fractional_coords"
1611
+ ]
1612
+ },
1613
+ {
1614
+ "cell_type": "markdown",
1615
+ "id": "b57fd54c-341c-425a-8bc5-10df91147ab7",
1616
+ "metadata": {},
1617
+ "source": [
1618
+ "If the principal CBED disk does not exist, then the attribute is set to ``None``.\n",
1619
+ "\n",
1620
+ "We can add the sample of points to the signal representations of the cropped and\n",
1621
+ "uncropped fake CBED patterns:"
1622
+ ]
1623
+ },
1624
+ {
1625
+ "cell_type": "code",
1626
+ "execution_count": null,
1627
+ "id": "fd90ebc0-5626-444f-9b59-0e9322dba409",
1628
+ "metadata": {},
1629
+ "outputs": [],
1630
+ "source": [
1631
+ "pts = principal_disk_boundary_pts_in_uncropped_image_fractional_coords.tolist()\n",
1632
+ "\n",
1633
+ "kwargs = {\"axes_off\": False, \n",
1634
+ " \"scalebar\": False, \n",
1635
+ " \"colorbar\": False, \n",
1636
+ " \"gamma\": 0.3,\n",
1637
+ " \"cmap\": \"jet\"}\n",
1638
+ "cropped_cbed_pattern_signal.plot(**kwargs)\n",
1639
+ "\n",
1640
+ "markers = tuple()\n",
1641
+ "\n",
1642
+ "try: # For Hyperspy versions >= 2.\n",
1643
+ " for pt in pts:\n",
1644
+ " kwargs = {\"color\": \"black\", \n",
1645
+ " \"sizes\": 3, \n",
1646
+ " \"offsets\": pt}\n",
1647
+ " marker = hs.plot.markers.Points(**kwargs)\n",
1648
+ " markers += (marker,)\n",
1649
+ " cropped_cbed_pattern_signal.add_marker(marker, permanent=False)\n",
1650
+ "except: # For Hyperspy versions < 2.\n",
1651
+ " for pt in pts:\n",
1652
+ " kwargs = {\"color\": \"black\", \n",
1653
+ " \"size\": 3, \n",
1654
+ " \"x\": pt[0], \n",
1655
+ " \"y\": pt[1]}\n",
1656
+ " marker = hs.plot.markers.point(**kwargs)\n",
1657
+ " markers += (marker,)\n",
1658
+ " cropped_cbed_pattern_signal.add_marker(marker, permanent=False)"
1659
+ ]
1660
+ },
1661
+ {
1662
+ "cell_type": "code",
1663
+ "execution_count": null,
1664
+ "id": "ecd4c53e-78a4-40e5-86da-c65da6e17626",
1665
+ "metadata": {},
1666
+ "outputs": [],
1667
+ "source": [
1668
+ "kwargs = {\"axes_off\": False, \n",
1669
+ " \"scalebar\": False, \n",
1670
+ " \"colorbar\": False, \n",
1671
+ " \"gamma\": 0.3,\n",
1672
+ " \"cmap\": \"jet\"}\n",
1673
+ "cbed_pattern_signal.plot(**kwargs)\n",
1674
+ "\n",
1675
+ "markers = copy.deepcopy(markers)\n",
1676
+ "\n",
1677
+ "for marker in markers:\n",
1678
+ " cbed_pattern_signal.add_marker(marker, permanent=False)"
1679
+ ]
1680
+ },
1681
+ {
1682
+ "cell_type": "markdown",
1683
+ "id": "84c9c73a-4014-49c4-96ae-76f1697ed644",
1684
+ "metadata": {},
1685
+ "source": [
1686
+ "Another attribute is\n",
1687
+ "``principal_disk_bounding_box_in_cropped_image_fractional_coords``, which stores\n",
1688
+ "the bounding box of the unclipped support of the principal CBED disk, should it\n",
1689
+ "exist, in fractional coordinates of the cropped fake CBED pattern:"
1690
+ ]
1691
+ },
1692
+ {
1693
+ "cell_type": "code",
1694
+ "execution_count": null,
1695
+ "id": "3e9bf369-fab6-4f19-a11c-995c2951a42b",
1696
+ "metadata": {},
1697
+ "outputs": [],
1698
+ "source": [
1699
+ "attr_name = \\\n",
1700
+ " \"principal_disk_bounding_box_in_cropped_image_fractional_coords\"\n",
1701
+ "principal_disk_bounding_box_in_cropped_image_fractional_coords = \\\n",
1702
+ " getattr(cropped_cbed_pattern, attr_name)\n",
1703
+ "\n",
1704
+ "principal_disk_bounding_box_in_cropped_image_fractional_coords"
1705
+ ]
1706
+ },
1707
+ {
1708
+ "cell_type": "markdown",
1709
+ "id": "bb3e6eb4-c41f-4bfa-b2c1-038e717aa651",
1710
+ "metadata": {},
1711
+ "source": [
1712
+ "If the principal CBED disk does not exist, then the attribute is set to ``None``.\n",
1713
+ "\n",
1714
+ "In order to add properly the box to the signal representation of the cropped\n",
1715
+ "fake CBED pattern, we need to modify signal axes such that the pixel coordinates\n",
1716
+ "are expressed in fractional units of the cropped fake CBED pattern:"
1717
+ ]
1718
+ },
1719
+ {
1720
+ "cell_type": "code",
1721
+ "execution_count": null,
1722
+ "id": "b76124a3-2f4f-48be-afb3-78ef50f97183",
1723
+ "metadata": {},
1724
+ "outputs": [],
1725
+ "source": [
1726
+ "N_h = cropped_cbed_pattern_signal.axes_manager[1].size\n",
1727
+ "N_v = cropped_cbed_pattern_signal.axes_manager[2].size\n",
1728
+ "\n",
1729
+ "cropped_cbed_pattern_signal.axes_manager[1].scale = 1/N_h\n",
1730
+ "cropped_cbed_pattern_signal.axes_manager[2].scale = -1/N_v\n",
1731
+ "\n",
1732
+ "cropped_cbed_pattern_signal.axes_manager[1].offset = 0.5/N_h\n",
1733
+ "cropped_cbed_pattern_signal.axes_manager[2].offset = 1-(1-0.5)/N_v\n",
1734
+ "\n",
1735
+ "cropped_cbed_pattern_signal.axes_manager[1].name = (\"fractional horizontal \"\n",
1736
+ " \"coordinate of cropped \"\n",
1737
+ " \"fake CBED pattern\")\n",
1738
+ "cropped_cbed_pattern_signal.axes_manager[2].name = (\"fractional vertical \"\n",
1739
+ " \"coordinate of cropped \"\n",
1740
+ " \"fake CBED pattern\")\n",
1741
+ "\n",
1742
+ "L, R, B, T = principal_disk_bounding_box_in_cropped_image_fractional_coords\n",
1743
+ "\n",
1744
+ "kwargs = {\"axes_off\": False, \n",
1745
+ " \"scalebar\": False, \n",
1746
+ " \"colorbar\": False, \n",
1747
+ " \"gamma\": 0.3,\n",
1748
+ " \"cmap\": \"jet\"}\n",
1749
+ "cropped_cbed_pattern_signal.plot(**kwargs)\n",
1750
+ "\n",
1751
+ "try: # For Hyperspy versions >= 2.\n",
1752
+ " x_box = (R+L)/2\n",
1753
+ " y_box = (B+T)/2\n",
1754
+ " box_center = (x_box, y_box)\n",
1755
+ " kwargs = {\"edgecolors\": \"green\",\n",
1756
+ " \"linewidths\": 3, \n",
1757
+ " \"facecolors\": \"none\",\n",
1758
+ " \"offsets\": (box_center,), \n",
1759
+ " \"widths\": (R-L), \n",
1760
+ " \"heights\": (B-T)}\n",
1761
+ " marker = hs.plot.markers.Rectangles(**kwargs)\n",
1762
+ "except: # For Hyperspy versions < 2.\n",
1763
+ " kwargs = {\"edgecolor\": \"green\",\n",
1764
+ " \"linewidth\": 3, \n",
1765
+ " \"x1\": L, \n",
1766
+ " \"x2\": R, \n",
1767
+ " \"y1\": T, \n",
1768
+ " \"y2\": B}\n",
1769
+ " marker = hs.plot.markers.rectangle(**kwargs)\n",
1770
+ "\n",
1771
+ "cropped_cbed_pattern_signal.add_marker(marker, permanent=False)"
1772
+ ]
1773
+ },
1774
+ {
1775
+ "cell_type": "markdown",
1776
+ "id": "04be66ce-9e31-4610-941b-e8326c85981a",
1777
+ "metadata": {},
1778
+ "source": [
1779
+ "Lastly, another attribute is\n",
1780
+ "``principal_disk_boundary_pts_in_cropped_image_fractional_coords``, which stores\n",
1781
+ "a sample of points on the boundary of the unclipped support of the principal\n",
1782
+ "CBED disk, should it exist, in fractional coordinates of the cropped fake CBED\n",
1783
+ "pattern:"
1784
+ ]
1785
+ },
1786
+ {
1787
+ "cell_type": "code",
1788
+ "execution_count": null,
1789
+ "id": "ad6787ca-c22a-4546-a1d6-8bc89df90bcd",
1790
+ "metadata": {},
1791
+ "outputs": [],
1792
+ "source": [
1793
+ "attr_name = \\\n",
1794
+ " \"principal_disk_boundary_pts_in_cropped_image_fractional_coords\"\n",
1795
+ "principal_disk_boundary_pts_in_cropped_image_fractional_coords = \\\n",
1796
+ " getattr(cropped_cbed_pattern, attr_name)\n",
1797
+ "\n",
1798
+ "principal_disk_boundary_pts_in_cropped_image_fractional_coords"
1799
+ ]
1800
+ },
1801
+ {
1802
+ "cell_type": "markdown",
1803
+ "id": "fdcc74bc-9ec4-469e-923d-610c38cd6c4e",
1804
+ "metadata": {},
1805
+ "source": [
1806
+ "If the principal CBED disk does not exist, then the attribute is set to ``None``.\n",
1807
+ "\n",
1808
+ "We can add the sample of points to the signal representations of the cropped and\n",
1809
+ "uncropped fake CBED patterns:"
1810
+ ]
1811
+ },
1812
+ {
1813
+ "cell_type": "code",
1814
+ "execution_count": null,
1815
+ "id": "5280b166-8806-4322-90f3-3deb4e9fd8d2",
1816
+ "metadata": {},
1817
+ "outputs": [],
1818
+ "source": [
1819
+ "pts = principal_disk_boundary_pts_in_cropped_image_fractional_coords.tolist()\n",
1820
+ "\n",
1821
+ "kwargs = {\"axes_off\": False, \n",
1822
+ " \"scalebar\": False, \n",
1823
+ " \"colorbar\": False, \n",
1824
+ " \"gamma\": 0.3,\n",
1825
+ " \"cmap\": \"jet\"}\n",
1826
+ "cropped_cbed_pattern_signal.plot(**kwargs)\n",
1827
+ "\n",
1828
+ "markers = tuple()\n",
1829
+ "\n",
1830
+ "try: # For Hyperspy versions >= 2.\n",
1831
+ " for pt in pts:\n",
1832
+ " kwargs = {\"color\": \"black\", \n",
1833
+ " \"sizes\": 3, \n",
1834
+ " \"offsets\": pt}\n",
1835
+ " marker = hs.plot.markers.Points(**kwargs)\n",
1836
+ " markers += (marker,)\n",
1837
+ " cropped_cbed_pattern_signal.add_marker(marker, permanent=False)\n",
1838
+ "except: # For Hyperspy versions < 2.\n",
1839
+ " for pt in pts:\n",
1840
+ " kwargs = {\"color\": \"black\", \n",
1841
+ " \"size\": 3, \n",
1842
+ " \"x\": pt[0], \n",
1843
+ " \"y\": pt[1]}\n",
1844
+ " marker = hs.plot.markers.point(**kwargs)\n",
1845
+ " markers += (marker,)\n",
1846
+ " cropped_cbed_pattern_signal.add_marker(marker, permanent=False)"
1847
+ ]
1278
1848
  }
1279
1849
  ],
1280
1850
  "metadata": {
@@ -1293,7 +1863,7 @@
1293
1863
  "name": "python",
1294
1864
  "nbconvert_exporter": "python",
1295
1865
  "pygments_lexer": "ipython3",
1296
- "version": "3.12.8"
1866
+ "version": "3.12.11"
1297
1867
  }
1298
1868
  },
1299
1869
  "nbformat": 4,