2525
2626import odemis
2727from odemis import model
28- from odemis .acq .move import (FM_IMAGING , GRID_1 ,MILLING , SEM_IMAGING , UNKNOWN , POSITION_NAMES ,
29- MeteorTFS3PostureManager )
28+ from odemis .acq .move import (FM_IMAGING , GRID_1 , MILLING , SEM_IMAGING , UNKNOWN , POSITION_NAMES ,
29+ MeteorTFS3PostureManager , LOADING )
3030from odemis .acq .move import MicroscopePostureManager
3131from odemis .util import testing
3232from odemis .util .driver import isNearPosition
@@ -62,12 +62,23 @@ def setUpClass(cls):
6262 cls .stage_grid_centers = cls .stage_md [model .MD_SAMPLE_CENTERS ]
6363 cls .stage_loading = cls .stage_md [model .MD_FAV_POS_DEACTIVE ]
6464
65- def test_switching_movements (self ):
66- """Test switching between different postures and check that the 3D transformations work as expected"""
65+ def setUp (self ):
66+ # reset stage-bare metadata, so that even if a test modifies it, the next test starts fresh
6767 if self .pm .current_posture .value == UNKNOWN :
68- f = self .stage_bare .moveAbs (self .stage_grid_centers [POSITION_NAMES [GRID_1 ]])
68+ logging .warning ("Test setup: posture is UNKNOWN, resetting to SEM_IMAGING" )
69+ # Reset to loading position before each test
70+ f = self .pm .cryoSwitchSamplePosition (LOADING )
71+ f .result ()
72+ # From loading, going to SEM IMAGING will use GRID 1 as base position
73+ f = self .pm .cryoSwitchSamplePosition (SEM_IMAGING )
6974 f .result ()
7075
76+ def test_switching_movements (self ):
77+ """Test switching between different postures and check that the 3D transformations work as expected"""
78+ # if self.pm.current_posture.value == UNKNOWN:
79+ # f = self.stage_bare.moveAbs(self.stage_grid_centers[POSITION_NAMES[GRID_1]])
80+ # f.result()
81+
7182 f = self .pm .cryoSwitchSamplePosition (SEM_IMAGING )
7283 f .result ()
7384
@@ -86,14 +97,14 @@ def test_switching_movements(self):
8697 def test_to_posture (self ):
8798 """Test that posture projection is the same as moving to the posture"""
8899
89- # first move back to grid-1 to make sure we are in a known position
90- f = self .stage_bare .moveAbs (self .stage_grid_centers [POSITION_NAMES [GRID_1 ]])
91- f .result ()
92-
93100 # move to SEM imaging posture
94101 f = self .pm .cryoSwitchSamplePosition (SEM_IMAGING )
95102 f .result ()
96103
104+ # first move back to grid-1 to make sure we are in a known position
105+ f = self .stage_bare .moveAbs (self .stage_grid_centers [POSITION_NAMES [GRID_1 ]])
106+ f .result ()
107+
97108 # Check that getCurrentPostureLabel() with a given stage-bare position returns the expected posture
98109 pos = self .stage_bare .position .value
99110 self .assertEqual (self .pm .getCurrentPostureLabel (pos ), SEM_IMAGING )
@@ -121,29 +132,30 @@ def test_to_posture(self):
121132
122133 def test_sample_stage_movement (self ):
123134 """Test sample stage movements in different postures match the expected movements"""
124-
135+ # move to SEM/GRID 1
136+ f = self .pm .cryoSwitchSamplePosition (SEM_IMAGING )
137+ f .result ()
125138 f = self .stage_bare .moveAbs (self .stage_grid_centers [POSITION_NAMES [GRID_1 ]])
126139 f .result ()
127140
128141 dx , dy = 50e-6 , 50e-6
129- self .pm .use_3d_transforms = True
130- for posture in [FM_IMAGING , SEM_IMAGING ]:
142+ for posture in [SEM_IMAGING , FM_IMAGING ]:
131143
132144 if self .pm .current_posture .value is not posture :
133145 f = self .pm .cryoSwitchSamplePosition (posture )
134146 f .result ()
135147
136148 f = self .pm .cryoSwitchSamplePosition (GRID_1 )
137149 f .result ()
138- time .sleep (2 ) # simulated stage moves too fast, needs time to update
150+ time .sleep (0.1 ) # simulated stage moves too fast, needs time to update
139151
140152 # test relative movement
141153 init_ss_pos = self .stage .position .value
142154 init_sb_pos = self .stage_bare .position .value
143155
144156 f = self .stage .moveRel ({"x" : dx , "y" : dy })
145157 f .result ()
146- time .sleep (2 )
158+ time .sleep (0.1 )
147159
148160 new_pos = self .stage .position .value
149161 new_sb_pos = self .stage_bare .position .value
@@ -155,15 +167,15 @@ def test_sample_stage_movement(self):
155167 # test absolute movement
156168 f = self .pm .cryoSwitchSamplePosition (GRID_1 )
157169 f .result ()
158- time .sleep (2 ) # simulated stage moves too fast, needs time to update
170+ time .sleep (0.1 ) # simulated stage moves too fast, needs time to update
159171
160172 abs_pos = init_ss_pos .copy ()
161173 abs_pos ["x" ] += dx
162174 abs_pos ["y" ] += dy
163175
164176 f = self .stage .moveAbs (abs_pos )
165177 f .result ()
166- time .sleep (2 )
178+ time .sleep (0.1 )
167179
168180 new_pos = self .stage .position .value
169181 new_sb_pos = self .stage_bare .position .value
@@ -216,7 +228,7 @@ def test_stage_to_chamber(self):
216228 # go to sem imaging
217229 f = self .pm .cryoSwitchSamplePosition (SEM_IMAGING )
218230 f .result ()
219- time .sleep (2 )
231+ time .sleep (0.1 )
220232
221233 # calculate the vertical shift in chamber coordinates
222234 shift = {"x" : 100e-6 , "z" : 50e-6 }
0 commit comments