fakecbed 0.2.1__tar.gz → 0.3.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 (41) hide show
  1. {fakecbed-0.2.1 → fakecbed-0.3.0}/PKG-INFO +1 -1
  2. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed/discretized.py +52 -1
  3. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed/version.py +2 -2
  4. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed.egg-info/PKG-INFO +1 -1
  5. {fakecbed-0.2.1 → fakecbed-0.3.0}/tests/test_discretized.py +29 -0
  6. {fakecbed-0.2.1 → fakecbed-0.3.0}/.coveragerc +0 -0
  7. {fakecbed-0.2.1 → fakecbed-0.3.0}/.github/workflows/measure_code_coverage.yml +0 -0
  8. {fakecbed-0.2.1 → fakecbed-0.3.0}/.github/workflows/publish_documentation_website.yml +0 -0
  9. {fakecbed-0.2.1 → fakecbed-0.3.0}/.github/workflows/publish_release_to_pypi.yml +0 -0
  10. {fakecbed-0.2.1 → fakecbed-0.3.0}/.github/workflows/test_library.yml +0 -0
  11. {fakecbed-0.2.1 → fakecbed-0.3.0}/.gitignore +0 -0
  12. {fakecbed-0.2.1 → fakecbed-0.3.0}/LICENSE +0 -0
  13. {fakecbed-0.2.1 → fakecbed-0.3.0}/README.md +0 -0
  14. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/INSTALL.rst +0 -0
  15. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/Makefile +0 -0
  16. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/_static/readthedocs_custom.css +0 -0
  17. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/_templates/custom_class_template.rst +0 -0
  18. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/_templates/custom_module_template.rst +0 -0
  19. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/_templates/versions.html +0 -0
  20. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/api.rst +0 -0
  21. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/build_docs.py +0 -0
  22. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/conf.py +0 -0
  23. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/examples.rst +0 -0
  24. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/index.rst +0 -0
  25. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/license.rst +0 -0
  26. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/literature.rst +0 -0
  27. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/make.bat +0 -0
  28. {fakecbed-0.2.1 → fakecbed-0.3.0}/docs/private_members_to_publish_to_docs.rst +0 -0
  29. {fakecbed-0.2.1 → fakecbed-0.3.0}/examples/basic_usage.ipynb +0 -0
  30. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed/__init__.py +0 -0
  31. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed/shapes.py +0 -0
  32. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed/tds.py +0 -0
  33. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed.egg-info/SOURCES.txt +0 -0
  34. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed.egg-info/dependency_links.txt +0 -0
  35. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed.egg-info/requires.txt +0 -0
  36. {fakecbed-0.2.1 → fakecbed-0.3.0}/fakecbed.egg-info/top_level.txt +0 -0
  37. {fakecbed-0.2.1 → fakecbed-0.3.0}/pyproject.toml +0 -0
  38. {fakecbed-0.2.1 → fakecbed-0.3.0}/setup.cfg +0 -0
  39. {fakecbed-0.2.1 → fakecbed-0.3.0}/setup.py +0 -0
  40. {fakecbed-0.2.1 → fakecbed-0.3.0}/tests/test_shapes.py +0 -0
  41. {fakecbed-0.2.1 → fakecbed-0.3.0}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: fakecbed
3
- Version: 0.2.1
3
+ Version: 0.3.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
@@ -412,6 +412,41 @@ def _de_pre_serialize_apply_shot_noise(serializable_rep):
412
412
 
413
413
 
414
414
 
415
+ def _check_and_convert_rng_seed(params):
416
+ obj_name = "rng_seed"
417
+ obj = params[obj_name]
418
+
419
+ current_func_name = "_check_and_convert_rng_seed"
420
+
421
+ if obj is not None:
422
+ kwargs = {"obj": obj, "obj_name": obj_name}
423
+ try:
424
+ rng_seed = czekitout.convert.to_nonnegative_int(**kwargs)
425
+ except:
426
+ err_msg = globals()[current_func_name+"_err_msg_1"]
427
+ raise TypeError(err_msg)
428
+ else:
429
+ rng_seed = obj
430
+
431
+ return rng_seed
432
+
433
+
434
+
435
+ def _pre_serialize_rng_seed(rng_seed):
436
+ obj_to_pre_serialize = rng_seed
437
+ serializable_rep = obj_to_pre_serialize
438
+
439
+ return serializable_rep
440
+
441
+
442
+
443
+ def _de_pre_serialize_rng_seed(serializable_rep):
444
+ rng_seed = serializable_rep
445
+
446
+ return rng_seed
447
+
448
+
449
+
415
450
  def _check_and_convert_detector_partition_width_in_pixels(params):
416
451
  obj_name = "detector_partition_width_in_pixels"
417
452
  func_alias = czekitout.convert.to_nonnegative_int
@@ -562,6 +597,8 @@ _default_num_pixels_across_pattern = \
562
597
  512
563
598
  _default_apply_shot_noise = \
564
599
  False
600
+ _default_rng_seed = \
601
+ None
565
602
  _default_detector_partition_width_in_pixels = \
566
603
  0
567
604
  _default_cold_pixels = \
@@ -1035,6 +1072,9 @@ class CBEDPattern(fancytypes.PreSerializableAndUpdatable):
1035
1072
  If ``apply_shot_noise`` is set to ``True``, then shot noise is applied
1036
1073
  to the image of the fake CBED pattern. Otherwise, no shot noise is
1037
1074
  applied.
1075
+ rng_seed : `int` | `None`, optional
1076
+ ``rng_seed`` specifies the seed used in the random number generator used
1077
+ to apply shot noise.
1038
1078
  detector_partition_width_in_pixels : `int`, optional
1039
1079
  The detector partition width in units of pixels,
1040
1080
  :math:`N_{\text{DPW}}`. Must be nonnegative.
@@ -1057,6 +1097,7 @@ class CBEDPattern(fancytypes.PreSerializableAndUpdatable):
1057
1097
  "num_pixels_across_pattern",
1058
1098
  "distortion_model",
1059
1099
  "apply_shot_noise",
1100
+ "rng_seed",
1060
1101
  "detector_partition_width_in_pixels",
1061
1102
  "cold_pixels",
1062
1103
  "mask_frame")
@@ -1091,6 +1132,8 @@ class CBEDPattern(fancytypes.PreSerializableAndUpdatable):
1091
1132
  _default_distortion_model,
1092
1133
  apply_shot_noise=\
1093
1134
  _default_apply_shot_noise,
1135
+ rng_seed=\
1136
+ _default_rng_seed,
1094
1137
  detector_partition_width_in_pixels=\
1095
1138
  _default_detector_partition_width_in_pixels,
1096
1139
  cold_pixels=\
@@ -1657,7 +1700,11 @@ class CBEDPattern(fancytypes.PreSerializableAndUpdatable):
1657
1700
  image = method_alias(u_x, u_y)
1658
1701
 
1659
1702
  apply_shot_noise = self._apply_shot_noise
1660
- image = torch.poisson(image) if (apply_shot_noise == True) else image
1703
+ if apply_shot_noise == True:
1704
+ np_rng = np.random.default_rng(self._rng_seed)
1705
+ torch_rng_seed = np_rng.integers(low=0, high=2**32-1).item()
1706
+ torch_rng = torch.Generator().manual_seed(torch_rng_seed)
1707
+ image = torch.poisson(image, torch_rng)
1661
1708
 
1662
1709
  image = self._apply_detector_partition_inpainting(input_image=image)
1663
1710
 
@@ -2522,6 +2569,10 @@ _check_and_convert_distortion_model_err_msg_1 = \
2522
2569
  "grid, specified by the object ``distortion_model``, must be divisible "
2523
2570
  "by the object ``num_pixels_across_pattern``.")
2524
2571
 
2572
+ _check_and_convert_rng_seed_err_msg_1 = \
2573
+ ("The object ``rng_seed`` must be either a nonnegative integer or of the "
2574
+ "type `NoneType`.")
2575
+
2525
2576
  _check_and_convert_cold_pixels_err_msg_1 = \
2526
2577
  ("The object ``cold_pixels`` must be a sequence of integer pairs, where "
2527
2578
  "each integer pair specifies valid pixel coordinates (i.e. row and column "
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.2.1'
16
- __version_tuple__ = version_tuple = (0, 2, 1)
15
+ __version__ = version = '0.3.0'
16
+ __version_tuple__ = version_tuple = (0, 3, 0)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: fakecbed
3
- Version: 0.2.1
3
+ Version: 0.3.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
@@ -85,6 +85,8 @@ def generate_cbed_pattern_ctor_params():
85
85
  distortion_model,
86
86
  "apply_shot_noise": \
87
87
  True,
88
+ "rng_seed": \
89
+ 5,
88
90
  "detector_partition_width_in_pixels": \
89
91
  4,
90
92
  "cold_pixels": \
@@ -630,6 +632,33 @@ def test_7_of_CBEDPattern():
630
632
 
631
633
 
632
634
 
635
+ def test_8_of_CBEDPattern():
636
+ cbed_pattern_1 = generate_cbed_pattern()
637
+ cbed_pattern_2 = generate_cbed_pattern()
638
+
639
+ signal_1 = cbed_pattern_1.signal
640
+ signal_2 = cbed_pattern_2.signal
641
+
642
+ assert np.all(signal_1.data == signal_2.data)
643
+
644
+ new_core_attr_subset_candidate = {"rng_seed": None}
645
+ cbed_pattern_1.update(new_core_attr_subset_candidate)
646
+
647
+ cbed_pattern_1.signal
648
+
649
+ with pytest.raises(TypeError) as err_info:
650
+ new_core_attr_subset_candidate = {"rng_seed": -1}
651
+ cbed_pattern_1.update(new_core_attr_subset_candidate)
652
+
653
+ new_core_attr_subset_candidate = {"apply_shot_noise": False}
654
+ cbed_pattern_1.update(new_core_attr_subset_candidate)
655
+
656
+ cbed_pattern_1.signal
657
+
658
+ return None
659
+
660
+
661
+
633
662
  ###########################
634
663
  ## Define error messages ##
635
664
  ###########################
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes