Exemplo n.º 1
0
def MidasSetVar(varPath, varValue):
    """
    Wrapper for pythonmidas.setvar(key,val).
    Deals with some special cases in in ODB.
    """

    varValue = ConvertValueToString(varValue)
    print varValue
    try:
        Midas.varset(varPath, varValue)
    except Midas.FailedCommand as e:
        Midas.sendmessage('pythonrc', e.value)
        raise Exception
    except Midas.KeyNotFound as e:
        Midas.sendmessage('pythonrc', e.value)
        raise Exception
Exemplo n.º 2
0
def MidasSetVar(varPath, varValue):
    """
    Wrapper for pythonmidas.setvar(key,val).
    Deals with some special cases in in ODB.
    """

    varValue = ConvertValueToString(varValue)
    print varValue
    try:
        Midas.varset(varPath, varValue)
    except Midas.FailedCommand as e:
        Midas.sendmessage('pythonrc', e.value)
        raise Exception
    except Midas.KeyNotFound as e:
        Midas.sendmessage('pythonrc', e.value)
        raise Exception
Exemplo n.º 3
0
def LogScanStop():
    """
    Write iformation to the PerlRC.log file at the end of a scan.
    """

    CurrentScan = int(Midas.varget(RunControlPath + "RCCurrentRun"))
    NRuns = int(Midas.varget(RunControlPath + "RCTotalRuns"))

    if CurrentScan == NRuns:
        with open(LogFile, 'a') as myfile:
            myfile.write("===             Finished PerlRC scan" + "===\n")
            myfile.write("====================================" +
                         "================\n")

        # Deactivate the Scans
        Midas.varset(RCActive, 'n')
Exemplo n.º 4
0
def LogScanStop():
    """
    Write iformation to the PerlRC.log file at the end of a scan.
    """

    CurrentScan = int(Midas.varget(RunControlPath + "RCCurrentRun"))
    NRuns = int(Midas.varget(RunControlPath + "RCTotalRuns"))

    if CurrentScan == NRuns:
        with open(LogFile, 'a') as myfile:
            myfile.write("===             Finished PerlRC scan" +
                         "===\n")
            myfile.write("====================================" +
                         "================\n")

        # Deactivate the Scans
        Midas.varset(RCActive, 'n')
Exemplo n.º 5
0
    def test_varset(self, mock_odbcommand):
        mock_odbcommand.return_value = "ans"

        key = "/path/to/key"
        value = "value"

        result = Midas.varset(key, value)

        self.assertEqual(result, None)
        mock_odbcommand.assert_called_once_with("set", key, value)
Exemplo n.º 6
0
    def test_varset(self, mock_odbcommand):
        mock_odbcommand.return_value = "ans"

        key = "/path/to/key"
        value = "value"

        result = Midas.varset(key, value)

        self.assertEqual(result, None)
        mock_odbcommand.assert_called_once_with("set", key, value)
    def calcRFAmplitude(self):
        ExTime = self.getExcitationTime()
        calExTime = float(Midas.varget(self.varCalExTime))
        calVoltage = float(Midas.varget(self.varCalVolatage))
        takeUser = Midas.varget(self.varTakeUser)

        if takeUser == "y":
            RFAmpCalc = float(Midas.varget(self.varRFUserAmp))
        else:
            RFAmpCalc = calVoltage * calExTime / ExTime

        # Ensure RF amplitude is at least the minimum, and less than 2.0V
        if RFAmpCalc < self.minRFAmp:
            RFAmpCalc = self.minRFAmp
        elif RFAmpCalc > self.maxRFAmp:
            RFAmpCalc = self.maxRFAmp

        # Update RF amplitude in ODB with the calculated value
        Midas.varset(self.varRFUserAmp, str(RFAmpCalc))

        return RFAmpCalc
Exemplo n.º 8
0
def TuneSwitch():
    """
    TuneSwitch() switches bewteen the listed tunes.
    """
    RunN = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Runcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    Runcurrn += 1
    if Runcurrn > RunN:
        Runcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Runcurrn)

    #Tunes, currn, CurrentTune = zip(*Midas.dirlist(TuneSwitchPath))[1]
    Tunes = Midas.varget(TuneSwitchPath + "TunesList")
    currn = Midas.varget(TuneSwitchPath + "CurrentTuneIndex")
    #CurrentTune = Midas.varget(TuneSwitchPath + "CurrentTuneName")

    currn = int(currn)
    Tunes = StringToList(Tunes)

    currn += 1
    if currn > len(Tunes):
        currn = 1
    Midas.varset(TuneSwitchPath + "CurrentTuneIndex", currn)
    currn -= 1

    ChangeTune(Tunes[currn])
    Midas.varset(TuneSwitchPath + "CurrentTuneName", Tunes[currn])
    return "Tune is \"" + Tunes[currn] + "\""
Exemplo n.º 9
0
def TuneSwitch():
    """
    TuneSwitch() switches bewteen the listed tunes.
    """
    RunN = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Runcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    Runcurrn += 1
    if Runcurrn > RunN:
        Runcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Runcurrn)

    #Tunes, currn, CurrentTune = zip(*Midas.dirlist(TuneSwitchPath))[1]
    Tunes = Midas.varget(TuneSwitchPath + "TunesList")
    currn = Midas.varget(TuneSwitchPath + "CurrentTuneIndex")
    #CurrentTune = Midas.varget(TuneSwitchPath + "CurrentTuneName")

    currn = int(currn)
    Tunes = StringToList(Tunes)

    currn += 1
    if currn > len(Tunes):
        currn = 1
    Midas.varset(TuneSwitchPath + "CurrentTuneIndex", currn)
    currn -= 1

    ChangeTune(Tunes[currn])
    Midas.varset(TuneSwitchPath + "CurrentTuneName", Tunes[currn])
    return "Tune is \"" + Tunes[currn] + "\""
Exemplo n.º 10
0
def Scan1D():
    """
    Scan1D() does a 1D scan
    """
    Scan1Dn = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Scan1Dcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    # Update the current scan number in the RunControlPath
    Scan1Dcurrn += 1
    if Scan1Dcurrn > Scan1Dn:
        Scan1Dcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Scan1Dcurrn)
    Scan1Dcurrn -= 1  # To get the right scan range.

    # Get the varibales to be scanned, and the start and stop values
    Variables = Midas.varget(Scan1DPath + "Variables")
    Start = Midas.varget(Scan1DPath + "VarStart")
    Stop = Midas.varget(Scan1DPath + "VarStop")
    # Don't need the totalsteps or currentstep for 1D scan
    #n = Midas.varget(Scan2DPath + "VarSteps")
    #currn = Midas.varget(Scan2DPath + "VarCurrentStep")

    print Variables

    Variables, Start, Stop = map(StringToList, [Variables, Start, Stop])
    Start, Stop = map(StringListToFloatList, [Start, Stop])

    NextVariableStep = map(
        lambda x, y: NextVariableSetPoint(x, y, Scan1Dn, Scan1Dcurrn), Start,
        Stop)

    returnstr = ""
    for var, val in zip(Variables, NextVariableStep):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    return returnstr
Exemplo n.º 11
0
def Scan1D():
    """
    Scan1D() does a 1D scan
    """
    Scan1Dn = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Scan1Dcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    # Update the current scan number in the RunControlPath
    Scan1Dcurrn += 1
    if Scan1Dcurrn > Scan1Dn:
        Scan1Dcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Scan1Dcurrn)
    Scan1Dcurrn -= 1  # To get the right scan range.

    # Get the varibales to be scanned, and the start and stop values
    Variables = Midas.varget(Scan1DPath + "Variables")
    Start = Midas.varget(Scan1DPath + "VarStart")
    Stop = Midas.varget(Scan1DPath + "VarStop")
    # Don't need the totalsteps or currentstep for 1D scan
    #n = Midas.varget(Scan2DPath + "VarSteps")
    #currn = Midas.varget(Scan2DPath + "VarCurrentStep")

    print Variables

    Variables, Start, Stop = map(StringToList, [Variables, Start, Stop])
    Start, Stop = map(StringListToFloatList, [Start, Stop])

    NextVariableStep = map(lambda x, y:
                           NextVariableSetPoint(x, y, Scan1Dn, Scan1Dcurrn),
                           Start, Stop)

    returnstr = ""
    for var, val in zip(Variables, NextVariableStep):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    return returnstr
Exemplo n.º 12
0
def main():
    StartScan = Midas.varget(RCActive)
    try:  # If called from the command line parse the arguements
        print sys.argv
        if len(sys.argv) == 2:
            # Start a PerlRC scan
            if sys.argv[1] == "start":
                Midas.varset(RCActive, 'y')
                StartScan = 'y'
            # Stop a PerlRC scan
            if sys.argv[1] == "stop":
                Midas.varset(RCActive, 'n')
                StartScan = 'n'
        # Change to a tune
        elif len(sys.argv) == 3 and sys.argv[1] == "tune":
            try:
                ChangeTune(sys.argv[2])
                LogSwitchedTune(sys.argv[2])
            except:
                LogSwitchedTune(sys.argv[2], True)
    except:  # calling it as a module, so ignore the stuff above
        pass

    # If we're doing a PerlRC scan, do what's in the ODB.
    if StartScan == 'y':
        ScanFuncs = {
            "SCAN1D": Scan1D,
            "SCAN2D": Scan2D,
            "TUNESWITCH": TuneSwitch
        }

        # Get the scan type and convert to uppercase
        ScanType = Midas.varget(RunControlPath + "RCType").upper()
        try:
            # call scan function based on the ScanType
            scanoutput = ScanFuncs[ScanType]()
            # Write some info to the log file
            # LogScanStart and LogScanStop only write something
            # if it's the beginning or end of a PerlRC scan.
            LogScanStart()
            LogScanVarStep(scanoutput)
            LogScanStop()

            # Sleep for a second so that scepics can update
            # the values
            time.sleep(1)
            Midas.startrun()
        except:
            # Error occurred. Stop future runs, and write an error message
            Midas.varset(RCActive, 'n')
            LogScanError()
            Midas.sendmessage(
                "pythonrc", "There was a problem. " +
                "Please check input variables and values, " +
                "and the message log for more info.")
Exemplo n.º 13
0
def main():
    StartScan = Midas.varget(RCActive)
    try:  # If called from the command line parse the arguements
        print sys.argv
        if len(sys.argv) == 2:
            # Start a PerlRC scan
            if sys.argv[1] == "start":
                Midas.varset(RCActive, 'y')
                StartScan = 'y'
            # Stop a PerlRC scan
            if sys.argv[1] == "stop":
                Midas.varset(RCActive, 'n')
                StartScan = 'n'
        # Change to a tune
        elif len(sys.argv) == 3 and sys.argv[1] == "tune":
            try:
                ChangeTune(sys.argv[2])
                LogSwitchedTune(sys.argv[2])
            except:
                LogSwitchedTune(sys.argv[2], True)
    except:  # calling it as a module, so ignore the stuff above
        pass

    # If we're doing a PerlRC scan, do what's in the ODB.
    if StartScan == 'y':
        ScanFuncs = {"SCAN1D": Scan1D,
                     "SCAN2D": Scan2D,
                     "TUNESWITCH": TuneSwitch}

        # Get the scan type and convert to uppercase
        ScanType = Midas.varget(RunControlPath + "RCType").upper()
        try:
            # call scan function based on the ScanType
            scanoutput = ScanFuncs[ScanType]()
            # Write some info to the log file
            # LogScanStart and LogScanStop only write something
            # if it's the beginning or end of a PerlRC scan.
            LogScanStart()
            LogScanVarStep(scanoutput)
            LogScanStop()

            # Sleep for a second so that scepics can update
            # the values
            time.sleep(1)
            Midas.startrun()
        except:
            # Error occurred. Stop future runs, and write an error message
            Midas.varset(RCActive, 'n')
            LogScanError()
            Midas.sendmessage("pythonrc", "There was a problem. " +
                              "Please check input variables and values, " +
                              "and the message log for more info.")
Exemplo n.º 14
0
    def genFreqList(self):
        """
        Given a semi-colon delimited list of center frequencies and
        modulations from the odb generate a frequency list.

        The number of points defined in the odb should be a multiple
        of the number of frequencies.  If not the 'extra' points are
        included in the last frequency to be scanned.

        If the frequency modulation list is shorter than the center
        frequency list then the last modulation listed is repeated
        until the lists are the same length.

        If the Frequency Modulation list is longer than the center
        frequency list then the 'extra' elements are ignored.
        """
        self.freqlist = []  # reset freqlist
        self.getFrequencyCentre()
        self.getFrequencyModulation()
        self.getNumberOfPoints()

        while(len(self.FreqMod) < len(self.FreqC)):
            self.FreqMod.append(self.FreqMod[-1])
            print self.FreqMod

        n = [self.NumberPoints / len(self.FreqC)
             for x in range(len(self.FreqC))]
        # Add the left-overs to the last element
        n[-1] += self.NumberPoints % n[0]
        print n

        for i in range(len(self.FreqC)):
            fstart = self.FreqC[i] - self.FreqMod[i]
            df = 2. * self.FreqMod[i] / float(n[i] - 1)
            for j in range(n[i]):
                self.freqlist.append(str((fstart + j * df) / 1000000.) + "E06")

        # Update the start and end frequencies in the odb
        Midas.varset(self.varStartFreq, (float(self.freqlist[0]) / 1000000.))
        Midas.varset(self.varStopFreq, (float(self.freqlist[-1]) / 1000000.))

        print self.freqlist
        fltemp = map(lambda x, y, z: "(" + str(x) + ", "
                     + str(y) + ", " + str(z) + ")",
                     self.FreqC, self.FreqMod, n)
        fltemp = "; ".join(fltemp)
        Midas.varset(self.varFreqList, fltemp)

        return self.freqlist
Exemplo n.º 15
0
#!/usr/bin/python
# A.A. Kwiatkowski October 2014
# stop TIS FIL, based off stopRFQ.py

import pythonmidas.pythonmidas as Midas

Midas.sendmessage("Alarm:", "TIS:IG1 pressure too high: Kill TIS1 FIL")

print Midas.varget("/Equipment/Beamline/Variables/Measured[129]")

# The Demand isn't set again if it is the same value as previously used.
print Midas.varset("/Equipment/Beamline/Variables/Demand[129]", 1)
print Midas.varset("/Equipment/Beamline/Variables/Demand[129]", 0)
Exemplo n.º 16
0
        print "Element in input", name, "does not exist in AME table."
        #passes = False
        Midas.sendmessage("DipoleCalculator", "Element in input " + name +
                          " does not exist in AME table.")

    return passes


#####################
# Start the program
#####################

if __name__ == "__main__":
    #args = sys.argv

    #if len(args) > 1 and args[1] == "dipole":
        names = Midas.varget("/Experiment/Variables/Contaminants/" +
                             "Contaminant List")

        reducedCyclotron = CF.dipole_frequencies(names)
        cyclotron = CF.cyclotron_frequencies(names)
        freqerrs = CF.calc_freqerr(names)

        Midas.varset("/Experiment/Variables/Contaminants/Contaminant FreqPlus",
                     ", ".join(["%0.3f" % x for x in reducedCyclotron]))
        Midas.varset("/Experiment/Variables/Contaminants/Contaminant FreqC",
                     ", ".join(["%0.3f" % x for x in cyclotron]))
        Midas.varset("/Experiment/Variables/Contaminants/" +
                     "Contaminant FreqC Error",
                     ", ".join(["%0.3f" % x for x in freqerrs]))
Exemplo n.º 17
0
#!/usr/bin/python
# A.A. Kwiatkowski February 2013
# stop RFQ PSD, based off A.T. Gallant's test.py

import pythonmidas.pythonmidas as Midas

#print "\nTesting sendmessage: name=test msg=test message"
Midas.sendmessage("Alarm:", "An ISAC Exhaust Fan has failed: Kill RFQ PSD")

print Midas.varget("/Equipment/Beamline/Variables/Measured[124]")

# The Demand isn't set again if it is the same value as previously used.
Midas.varset("/Equipment/Beamline/Variables/Demand[124]", 1)
Midas.varset("/Equipment/Beamline/Variables/Demand[124]", 0)
Exemplo n.º 18
0
def Scan2D():
    """
    Scan2D() does a 2D scan
    """
    Scan2Dn = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Scan2Dcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    Scan2Dcurrn += 1
    if Scan2Dcurrn > Scan2Dn:
        Scan2Dcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Scan2Dcurrn)

    # Lots of variables in a 2D scan, so list them:
    dirKeys = ["Variables1", "Var1Start", "Var1Stop", "Var1Steps",
               "Var1CurrentStep", "Variables2", "Var2Start", "Var2Stop",
               "Var2Steps", "Var2CurrentStep"]
    # Get the values of the variables:
    Variables1, Start1, Stop1, n1, currn1, \
        Variables2, Start2, Stop2, n2, currn2 = \
        [Midas.varget(Scan2DPath + x) for x in dirKeys]
    # Convert into a list
    Variables1, Start1, Stop1, Variables2, Start2, Stop2 = \
        map(StringToList, [Variables1, Start1,
                           Stop1, Variables2, Start2, Stop2])
    # Convert into floats
    Start1, Stop1, Start2, Stop2 = \
        map(StringListToFloatList, [Start1, Stop1, Start2, Stop2])

    # Check that currn's are correct
    currn1 = int(currn1)
    n1 = int(n1)
    currn2 = int(currn2)
    n2 = int(n2)

    # Update the 2D scan counters.
    # Ensure that if either currn1 or currn2 are at their max values that
    # they are reset back to 1.
    currn2 += 1
    if currn2 > n2:
        currn2 = 1

        currn1 += 1
        if currn1 > n1:
            currn1 = 1
    Midas.varset(Scan2DPath + "Var1CurrentStep", currn1)
    Midas.varset(Scan2DPath + "Var2CurrentStep", currn2)
    # de-increment to calculate the scan value
    currn1 -= 1
    currn2 -= 1

    NextVariableStep1 = map(lambda x, y:
                            NextVariableSetPoint(x, y, n1, currn1),
                            Start1, Stop1)
    NextVariableStep2 = map(lambda x, y:
                            NextVariableSetPoint(x, y, n2, currn2),
                            Start2, Stop2)

    # Write out the list of variables
    # Each variable is separated by a ';', while the 2D scans
    # are separated by ';;'
    returnstr = ""
    for var, val in zip(Variables1, NextVariableStep1):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    returnstr += ";"
    for var, val in zip(Variables2, NextVariableStep2):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    return returnstr
Exemplo n.º 19
0
 def afgOff(self):
     self.afgWrite("OUTP OFF")
     Midas.varset(self.afgOnPath, "n")
Exemplo n.º 20
0
 def afgOn(self):
     self.afgWrite("OUTP ON")
     Midas.varset(self.afgOnPath, "y")
Exemplo n.º 21
0
def Scan2D():
    """
    Scan2D() does a 2D scan
    """
    Scan2Dn = int(Midas.varget(RunControlPath + "RCTotalRuns"))
    Scan2Dcurrn = int(Midas.varget(RunControlPath + "RCCurrentRun"))

    Scan2Dcurrn += 1
    if Scan2Dcurrn > Scan2Dn:
        Scan2Dcurrn = 1
    Midas.varset(RunControlPath + "RCCurrentRun", Scan2Dcurrn)

    # Lots of variables in a 2D scan, so list them:
    dirKeys = [
        "Variables1", "Var1Start", "Var1Stop", "Var1Steps", "Var1CurrentStep",
        "Variables2", "Var2Start", "Var2Stop", "Var2Steps", "Var2CurrentStep"
    ]
    # Get the values of the variables:
    Variables1, Start1, Stop1, n1, currn1, \
        Variables2, Start2, Stop2, n2, currn2 = \
        [Midas.varget(Scan2DPath + x) for x in dirKeys]
    # Convert into a list
    Variables1, Start1, Stop1, Variables2, Start2, Stop2 = \
        map(StringToList, [Variables1, Start1,
                           Stop1, Variables2, Start2, Stop2])
    # Convert into floats
    Start1, Stop1, Start2, Stop2 = \
        map(StringListToFloatList, [Start1, Stop1, Start2, Stop2])

    # Check that currn's are correct
    currn1 = int(currn1)
    n1 = int(n1)
    currn2 = int(currn2)
    n2 = int(n2)

    # Update the 2D scan counters.
    # Ensure that if either currn1 or currn2 are at their max values that
    # they are reset back to 1.
    currn2 += 1
    if currn2 > n2:
        currn2 = 1

        currn1 += 1
        if currn1 > n1:
            currn1 = 1
    Midas.varset(Scan2DPath + "Var1CurrentStep", currn1)
    Midas.varset(Scan2DPath + "Var2CurrentStep", currn2)
    # de-increment to calculate the scan value
    currn1 -= 1
    currn2 -= 1

    NextVariableStep1 = map(
        lambda x, y: NextVariableSetPoint(x, y, n1, currn1), Start1, Stop1)
    NextVariableStep2 = map(
        lambda x, y: NextVariableSetPoint(x, y, n2, currn2), Start2, Stop2)

    # Write out the list of variables
    # Each variable is separated by a ';', while the 2D scans
    # are separated by ';;'
    returnstr = ""
    for var, val in zip(Variables1, NextVariableStep1):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    returnstr += ";"
    for var, val in zip(Variables2, NextVariableStep2):
        print var, val
        MidasSetVar(GetVarName(var), val)
        returnstr += var + "=" + ConvertValueToString(val) + ";"

    return returnstr
Exemplo n.º 22
0
        #passes = False
        Midas.sendmessage(
            "DipoleCalculator",
            "Element in input " + name + " does not exist in AME table.")

    return passes


#####################
# Start the program
#####################

if __name__ == "__main__":
    #args = sys.argv

    #if len(args) > 1 and args[1] == "dipole":
    names = Midas.varget("/Experiment/Variables/Contaminants/" +
                         "Contaminant List")

    reducedCyclotron = CF.dipole_frequencies(names)
    cyclotron = CF.cyclotron_frequencies(names)
    freqerrs = CF.calc_freqerr(names)

    Midas.varset("/Experiment/Variables/Contaminants/Contaminant FreqPlus",
                 ", ".join(["%0.3f" % x for x in reducedCyclotron]))
    Midas.varset("/Experiment/Variables/Contaminants/Contaminant FreqC",
                 ", ".join(["%0.3f" % x for x in cyclotron]))
    Midas.varset(
        "/Experiment/Variables/Contaminants/" + "Contaminant FreqC Error",
        ", ".join(["%0.3f" % x for x in freqerrs]))