def gainscan(idx):
    gainnum = 1
    #where_i_was=acsc.getRPosition(hcomm,0)
    acsc.toPoint(hcomm, None, 0, gain_z_out_of_beam)
    # while(abs(acsc.getFVelocity(hcomm, 0))>wait_ms):
    # 1+1
    while (not acsc.getMotorState(hcomm, 0)['in position']
           ):  #check for stop event using other API call?
        time.sleep(.1)
    while (gainnum < num_gain_per_scan):
        mmc.snapImage()
        image_npy = mmc.getImage()
        image_itk = sitk.GetImageFromArray(image_npy)
        sitk.WriteImage(
            image_itk, output_dir + "\\gain\\gain_" + str(idx) + "_" +
            str(gainnum) + ".tiff"
        )  #Change this to Gainscan_"+str(idx)+".tiff" if you would rather sort by time and not filename
        dt = datetime.now()
        micro = dt.microsecond
        time_temp = time.strftime("%Y%m%d-%H%M%S") + ":" + str(micro)
        file_output.write("gain_%d\t%f\t%f\t%f\t%s\t%s\t%d\n" %
                          (idx, 0, acsc.getRPosition(hcomm, 1),
                           acsc.getFPosition(hcomm, 1), time_temp,
                           (datetime.now() - startTime), exposure_inpt))
        gainnum = gainnum + 1
    acsc.toPoint(hcomm, None, 0, where_i_was)
    # while(abs(acsc.getFVelocity(hcomm, 0))>wait_ms):
    # 1+1
    while (not acsc.getMotorState(hcomm, 0)['in position']
           ):  #check for stop event using other API call?
        time.sleep(.1)
Пример #2
0
    def on_timer_fast(self):
        if self.hcomm == acsc.INVALID:
            self.close()
        self.ui.tabWidgetMode.setEnabled(self.axis_enabled)
        self.ui.dock_jog.setEnabled(self.axis_enabled)
        self.ui.pbJogPendant.setEnabled(self.axis_enabled)
        self.ui.toolBar_Jog.setEnabled(self.axis_enabled)

        if self.homecounter > 0 or self.override == True:
            self.ui.rbAbsolute.setEnabled(True)
            self.ui.rbAbsolute_baf.setEnabled(True)
            if self.homecounter > 0:
                self.ui.groupBox_shortcuts.setEnabled(True)
                self.hlabel.setText("Homed ")

        if self.jogmode == True:
            self.ui.pbJogPendant.setChecked(True)
            self.ui.actionJogPendant.setChecked(True)
        else:
            self.ui.pbJogPendant.setChecked(False)
            self.ui.actionJogPendant.setChecked(False)

        # Get and display reference position and velocity
        self.rpos = acsc.getRPosition(self.hcomm, self.axis)
        self.rvel = acsc.getRVelocity(self.hcomm, self.axis)
        self.poslabel.setText("Pos. (m): %.3f " % self.rpos)
        self.vellabel.setText("Vel. (m/s): %.2f " % self.rvel)
Пример #3
0
def test_upload_prg():
    """Test that a program can be uploaded and run in the simulator."""
    hc = acsc.openCommDirect()
    txt = "enable 0\nVEL(0) = 1333\nptp 0, 1.33\nSTOP"
    acsc.loadBuffer(hc, 19, txt, 64)
    acsc.runBuffer(hc, 19)
    time.sleep(0.2)
    vel = acsc.getVelocity(hc, 0)
    pos = acsc.getRPosition(hc, 0)
    print("Position:", pos)
    print("Velocity:", vel)
    assert vel == 1333.0
    assert pos == 1.33
    acsc.closeComm(hc)
Пример #4
0
 def rpos(self, axis):
     if axis in self.axisdefs:
         axis = self.axisdefs[axis]
     return acsc.getRPosition(self.hc, axis)
Пример #5
0
then uploading it to the controller and running it.
"""

from __future__ import division, print_function
from acspy import acsc
import time

#file = open("test/test.prg", "w+")

acs_prg = """
ENABLE 1""" + \
"""
VEL(1) = 1000
PTP/r 1, -900
STOP
"""

#file.write(acs_prg)
#file.close()

print(acs_prg)
hc = acsc.openCommDirect()
acsc.loadBuffer(hc, 0, acs_prg, 512)
acsc.enable(hc, 0)
#acsc.LoadBuffersFromFile(hc, "test/test.prg")
acsc.runBuffer(hc, 0)
time.sleep(1)
print(acsc.getRPosition(hc, 1))
print(acsc.getMotorState(hc, 1))
acsc.closeComm(hc)
Пример #6
0
            image_npy = mmc.getImage()
        proj_32bit_filler = proj_32bit_filler + image_npy
    return proj_32bit_filler


##################
####stage calls###
##################
if load_stages:
    #initiate connection
    hcomm = acsc.openCommEthernetTCP(address="10.0.0.100", port=701)
    if scan_gain:
        acsc.enable(hcomm, 0)  #z
        # acsc.toPoint(hcomm, None,0,110) #YIFU CHECK THIS
        acsc.setVelocity(hcomm, 0, 5)  #velocity in mm/sec
        r_pos_0 = acsc.getRPosition(hcomm, 0)
        f_pos_0 = acsc.getFPosition(hcomm, 0)

    acsc.enable(hcomm, 1)  #theta
    acsc.setVelocity(hcomm, 1, 5)  #velocity in degrees/sec
    r_pos_1 = acsc.getRPosition(hcomm, 1)
    f_pos_1 = acsc.getFPosition(hcomm, 1)
    # acsc.toPoint(hcomm, None,1,0)
    print("z-stage F pos: %f \n z-stage R pos: %f" % (f_pos_0, r_pos_0))
    print("theta-stage F pos: %f \n theta-stage R pos: %f" %
          (f_pos_1, r_pos_1))
    where_i_was = r_pos_0

##################
###camera calls###
##################
Пример #7
0
 def rpos(self):
     return acsc.getRPosition(self.controller.hc, self.axisno)
Пример #8
0
 def getPosition2(self):
     return (acsc.getRPosition(self.hc, 4), acsc.getRPosition(self.hc, 5),
             acsc.getRPosition(self.hc, 6))
Пример #9
0
 def getPosition_all(self):
     return (acsc.getRPosition(self.hc, 0), acsc.getRPosition(self.hc, 1),
             acsc.getRPosition(self.hc, 2), acsc.getRPosition(self.hc, 4),
             acsc.getRPosition(self.hc, 5), acsc.getRPosition(self.hc, 6))
Пример #10
0
 def getPosition(self):
     return (acsc.getRPosition(self.hc, 0), acsc.getRPosition(self.hc, 1))
Пример #11
0
 def rpos(self):
     return acsc.getRPosition(self.controller.hc, self.axisno)
Пример #12
0
def take_photo(deg, idx):
    #test image
    if scan_gain:
        if idx in gainarray:
            gainscan(idx)

    q = time.time()
    for projnum in range(num_exposures_per_projection):
        print("Projection average %d out of %d" %
              (projnum + 1, num_exposures_per_projection))
        if load_camera10k:
            print("Projection %d out of %d" %
                  (projnum + 1, num_exposures_per_projection))
            # image_npy,channel_temp=GrabOneImage(channel)
            s2 = datetime.now()
            MC.SetParamStr(channel, 'ChannelState', 'ACTIVE')
            gotEndOfChannelActivity = False
            gotAcquisitionFailure = False

            while not gotEndOfChannelActivity:
                signalInfo = MC.WaitSignal(
                    channel, MC.SIG_ANY, 15000
                )  #Attempt to make this call shorter (1.5 second overhead as written....)
                # signalInfo = MC.WaitSignal(channel, MC.SIG_ANY, 1000)
                if signalInfo.Signal == MC.SIG_END_CHANNEL_ACTIVITY:
                    gotEndOfChannelActivity = True
                elif signalInfo.Signal == MC.SIG_ACQUISITION_FAILURE:
                    gotAcquisitionFailure = True
                elif signalInfo.Signal == MC.SIG_SURFACE_PROCESSING:
                    MC.SetParamStr(signalInfo.SignalInfo, 'SurfaceState',
                                   'FREE')
                else:
                    raise MC.MultiCamError('Unexpected signal: %d' %
                                           signalInfo.Signal)
                # MC.SetParamStr(channel, "ForceTrig", "TRIG");
            if gotAcquisitionFailure:
                raise MC.MultiCamError('Acquisition failure!')

            surface = MC.GetParamInst(channel, 'Cluster:0')
            width = MC.GetParamInt(surface, 'SurfaceSizeX')
            height = MC.GetParamInt(surface, 'SurfaceSizeY')
            # image = ConvertSurfaceIntoImage(surface)
            surfaceAddress = MC.GetParamPtr(surface,
                                            'SurfaceAddr:%d' % planeIndex)
            surfaceSize = MC.GetParamInt(surface,
                                         'SurfaceSize:%d' % planeIndex)
            imageBuffer = ctypes.string_at(surfaceAddress, surfaceSize)
            MC.SetParamStr(channel, 'ChannelState', 'READY')
            data = np.fromstring(imageBuffer, np.uint16)
            image_npy = np.reshape(data, (height, width))
            # image = ConvertBufferIntoImage(width, height, imageBuffer)
            # print(image.shape)
            # print(image[0].shape)
            # channel_temp=channel
            print(str(datetime.now() - s2) + " single proj")

        else:
            mmc.snapImage()
            image_npy = mmc.getImage()
        projection_fill[projnum] = image_npy
    proj = np.mean(projection_fill, axis=0)
    # image_itk = sitk.GetImageFromArray(proj)
    #sitk.WriteImage(image_itk, output_dir+"/Projection_"+str(idx)+".tiff")
    if idx == 0:
        dx.write_tiff(
            proj,
            output_dir +
            "//Drift_Projections_at_0deg/Correction_Projection_from_" +
            str(int(deg)) + "_deg" + ".tiff",
            dtype=np.uint16)
    dx.write_tiff(proj,
                  output_dir + "//Raw_Projections/Projection_" + str(idx) +
                  ".tiff",
                  dtype=np.uint16)
    #Projection\tZ\tTheta\trTheta\tTime\tdTime\tExposure(ms)\r\n
    dt = datetime.now()
    micro = dt.microsecond
    time_temp = time.strftime("%Y%m%d-%H%M%S") + ":" + str(micro)
    file_output.write("%d\t%f\t%f\t%f\t%s\t%s\t%d\n" %
                      (idx, 0, acsc.getRPosition(
                          hcomm, 1), acsc.getFPosition(hcomm, 1), time_temp,
                       (datetime.now() - startTime), exposure_inpt))
    print("Projection " + str(idx + 1) + " out of " + str(total_projections) +
          " Acquired")
Пример #13
0
"""
This is a test for generating an ACSPL+ program
then uploading it to the controller and running it.
"""
from acspy import acsc
import time

#file = open("test/test.prg", "w+")

acs_prg = """
ENABLE 1""" + \
"""
VEL(1) = 1000
PTP/r 1, -900
STOP
"""

#file.write(acs_prg)
#file.close()

print acs_prg
hc = acsc.openCommDirect()
acsc.loadBuffer(hc, 0, acs_prg, 512)
acsc.enable(hc, 0)
#acsc.LoadBuffersFromFile(hc, "test/test.prg")
acsc.runBuffer(hc, 0)
time.sleep(1)
print acsc.getRPosition(hc, 1)
print acsc.getMotorState(hc, 1)
acsc.closeComm(hc)