Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aperture and new capabilities for linking controls. #19

Closed
wants to merge 12 commits into from

Conversation

Brow71189
Copy link
Collaborator

Most important cahnges:

  • Add aperture that can be moved and "distorted" (i.e. dipole and quadropole effect simulation)
  • Add functions to 'Instrument' that facilitate adding new inputs to existing controls
  • Allow input weights for controls to be controls in addition to float
  • Add option to attach a python expression as control input (only one expression per control can be set, but it can be arbitrarily complex)

This might fix #11 and #17 (or at least work towards fixing them)

@Brow71189
Copy link
Collaborator Author

Forgot one item:

  • Changed meaning of convergence angle to reflect its real meaning (in the simulator it only controls the size of the aperture on the ronchigram camera, the effect on the scan is not simulated yet)

@cmeyer
Copy link
Contributor

cmeyer commented Dec 5, 2019

This looks good so far. Is it still a work in progress? (if so, change title to have [WIP] at the end)

Also, any affect on performance for the regular acquisition cases?

@cmeyer
Copy link
Contributor

cmeyer commented Dec 5, 2019

Also: can you update the CHANGES file?

@Brow71189
Copy link
Collaborator Author

Also: can you update the CHANGES file?

Done.

@Brow71189
Copy link
Collaborator Author

This looks good so far. Is it still a work in progress? (if so, change title to have [WIP] at the end)

Also, any affect on performance for the regular acquisition cases?

I didn't measure it but also don't see any immediate effects. Adding the aperture will add a little bit of computational time, but that happens only when you actually "insert" it. And still it is probably negligible compared to the overall simlation time.
Making the simulator (especially for the amorphous sample) faster would be nice thing though. Maybe I'll work on that sometimes in the near future.

@cmeyer
Copy link
Contributor

cmeyer commented Dec 6, 2019

How about this to make the flake look the same:

diff --git a/nionswift_plugin/usim/InstrumentDevice.py b/nionswift_plugin/usim/InstrumentDevice.py
index adf85cc..0308606 100755
--- a/nionswift_plugin/usim/InstrumentDevice.py
+++ b/nionswift_plugin/usim/InstrumentDevice.py
@@ -350,13 +350,15 @@ class Instrument(stem_controller.STEMController):
         self.instrument_id = instrument_id
         self.property_changed_event = Event.Event()
         self.__camera_frame_event = threading.Event()
-        self.__samples = [SampleSimulator.RectangleFlakeSample(), SampleSimulator.AmorphousSample()]
-        self.__sample_index = 1
 
         # define the STEM geometry limits
         self.stage_size_nm = 1000
         self.max_defocus = 5000 / 1E9
 
+        # define the samples
+        self.__samples = [SampleSimulator.RectangleFlakeSample(self.stage_size_nm), SampleSimulator.AmorphousSample()]
+        self.__sample_index = 0
+
         self.__stage_position_m = Geometry.FloatPoint()
         self.__slit_in = False
         self.__energy_per_channel_eV = 0.5
diff --git a/nionswift_plugin/usim/SampleSimulator.py b/nionswift_plugin/usim/SampleSimulator.py
index 6444312..8be0e9e 100644
--- a/nionswift_plugin/usim/SampleSimulator.py
+++ b/nionswift_plugin/usim/SampleSimulator.py
@@ -84,9 +84,9 @@ class Sample(abc.ABC):
 
 class RectangleFlakeSample:
 
-    def __init__(self):
+    def __init__(self, stage_size_nm: float):
         self.__features = list()
-        sample_size_m = Geometry.FloatSize(height=20, width=20) / 1E9
+        sample_size_m = Geometry.FloatSize(height=20 * stage_size_nm / 100, width=20 * stage_size_nm / 100) / 1E9
         feature_percentage = 0.3
         random_state = random.getstate()
         random.seed(1)
diff --git a/nionswift_plugin/usim/ScanDevice.py b/nionswift_plugin/usim/ScanDevice.py
index d77b628..4c04935 100644
--- a/nionswift_plugin/usim/ScanDevice.py
+++ b/nionswift_plugin/usim/ScanDevice.py
@@ -68,9 +68,9 @@ class Device:
         # profiles.append(scan_base.ScanFrameParameters({"size": (512, 512), "pixel_time_us": 0.2}))
         # profiles.append(scan_base.ScanFrameParameters({"size": (1024, 1024), "pixel_time_us": 0.2}))
         # profiles.append(scan_base.ScanFrameParameters({"size": (2048, 2048), "pixel_time_us": 2.5}))
-        profiles.append(scan_base.ScanFrameParameters({"size": (256, 256), "pixel_time_us": 1, "fov_nm": 10}))
-        profiles.append(scan_base.ScanFrameParameters({"size": (512, 512), "pixel_time_us": 1, "fov_nm": 40}))
-        profiles.append(scan_base.ScanFrameParameters({"size": (1024, 1024), "pixel_time_us": 1, "fov_nm": 100}))
+        profiles.append(scan_base.ScanFrameParameters({"size": (256, 256), "pixel_time_us": 1, "fov_nm": self.__instrument.stage_size_nm * 0.1}))
+        profiles.append(scan_base.ScanFrameParameters({"size": (512, 512), "pixel_time_us": 1, "fov_nm": self.__instrument.stage_size_nm * 0.4}))
+        profiles.append(scan_base.ScanFrameParameters({"size": (1024, 1024), "pixel_time_us": 1, "fov_nm": self.__instrument.stage_size_nm * 1.0}))
         return profiles
 
     @property

@Brow71189
Copy link
Collaborator Author

How about this to make the flake look the same:

diff --git a/nionswift_plugin/usim/InstrumentDevice.py b/nionswift_plugin/usim/InstrumentDevice.py
index adf85cc..0308606 100755
--- a/nionswift_plugin/usim/InstrumentDevice.py
+++ b/nionswift_plugin/usim/InstrumentDevice.py
@@ -350,13 +350,15 @@ class Instrument(stem_controller.STEMController):
         self.instrument_id = instrument_id
         self.property_changed_event = Event.Event()
         self.__camera_frame_event = threading.Event()
-        self.__samples = [SampleSimulator.RectangleFlakeSample(), SampleSimulator.AmorphousSample()]
-        self.__sample_index = 1
 
         # define the STEM geometry limits
         self.stage_size_nm = 1000
         self.max_defocus = 5000 / 1E9
 
+        # define the samples
+        self.__samples = [SampleSimulator.RectangleFlakeSample(self.stage_size_nm), SampleSimulator.AmorphousSample()]
+        self.__sample_index = 0
+
         self.__stage_position_m = Geometry.FloatPoint()
         self.__slit_in = False
         self.__energy_per_channel_eV = 0.5
diff --git a/nionswift_plugin/usim/SampleSimulator.py b/nionswift_plugin/usim/SampleSimulator.py
index 6444312..8be0e9e 100644
--- a/nionswift_plugin/usim/SampleSimulator.py
+++ b/nionswift_plugin/usim/SampleSimulator.py
@@ -84,9 +84,9 @@ class Sample(abc.ABC):
 
 class RectangleFlakeSample:
 
-    def __init__(self):
+    def __init__(self, stage_size_nm: float):
         self.__features = list()
-        sample_size_m = Geometry.FloatSize(height=20, width=20) / 1E9
+        sample_size_m = Geometry.FloatSize(height=20 * stage_size_nm / 100, width=20 * stage_size_nm / 100) / 1E9
         feature_percentage = 0.3
         random_state = random.getstate()
         random.seed(1)
diff --git a/nionswift_plugin/usim/ScanDevice.py b/nionswift_plugin/usim/ScanDevice.py
index d77b628..4c04935 100644
--- a/nionswift_plugin/usim/ScanDevice.py
+++ b/nionswift_plugin/usim/ScanDevice.py
@@ -68,9 +68,9 @@ class Device:
         # profiles.append(scan_base.ScanFrameParameters({"size": (512, 512), "pixel_time_us": 0.2}))
         # profiles.append(scan_base.ScanFrameParameters({"size": (1024, 1024), "pixel_time_us": 0.2}))
         # profiles.append(scan_base.ScanFrameParameters({"size": (2048, 2048), "pixel_time_us": 2.5}))
-        profiles.append(scan_base.ScanFrameParameters({"size": (256, 256), "pixel_time_us": 1, "fov_nm": 10}))
-        profiles.append(scan_base.ScanFrameParameters({"size": (512, 512), "pixel_time_us": 1, "fov_nm": 40}))
-        profiles.append(scan_base.ScanFrameParameters({"size": (1024, 1024), "pixel_time_us": 1, "fov_nm": 100}))
+        profiles.append(scan_base.ScanFrameParameters({"size": (256, 256), "pixel_time_us": 1, "fov_nm": self.__instrument.stage_size_nm * 0.1}))
+        profiles.append(scan_base.ScanFrameParameters({"size": (512, 512), "pixel_time_us": 1, "fov_nm": self.__instrument.stage_size_nm * 0.4}))
+        profiles.append(scan_base.ScanFrameParameters({"size": (1024, 1024), "pixel_time_us": 1, "fov_nm": self.__instrument.stage_size_nm * 1.0}))
         return profiles
 
     @property

Looks good.

@cmeyer
Copy link
Contributor

cmeyer commented Dec 11, 2019

Merged e5ef7f9..d00d1b2

@cmeyer cmeyer closed this Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for arbitrary control dependencies, useful for testing or better sim
3 participants