diff --git a/configs/lr_iviscan.json b/configs/lr_iviscan.json index 827cd0e3abbe141499131627846155b75c97757b..637179bbe96583d4049ab027fa9678fa6221e143 100644 --- a/configs/lr_iviscan.json +++ b/configs/lr_iviscan.json @@ -5,11 +5,11 @@ { "name": "HV", "initial_voltage": 0, - "final_voltage": 1000, - "step_size": 50, + "final_voltage": -150, + "step_size": -5, "measurements_per_step": 3, - "sleeping_time_per_step_s": 4, - "current_protection": 0.000001 + "sleeping_time_per_step_s": 10, + "current_protection": 0.0001 }, "passive_channels": [ @@ -24,19 +24,14 @@ "name": "LV", "initial_current": 4.4, "final_current": 0, - "step_size": -0.2, - "measurements_per_step": 5, - "sleeping_time_per_step_s": 1, - "voltage_protection": 1.8, - "setting_voltage": 2.2 + "step_size": -0.1, + "measurements_per_step": 3, + "sleeping_time_per_step_s": 2, + "voltage_protection": 2.0, + "setting_voltage": 1.9 }, "passive_channels": [ - { - "name": "fan", - "voltage": 5, - "current": 0.35 - } ] } } \ No newline at end of file diff --git a/libDCS/iviscan.py b/libDCS/iviscan.py index dc7db0bc4969fa08be2a692064ef03c2d337f123..66b7f0086b7ac775224b619c5815996cbd475637 100644 --- a/libDCS/iviscan.py +++ b/libDCS/iviscan.py @@ -7,16 +7,14 @@ import time import getpass from influxdb import InfluxDBClient, exceptions - +# LR stuff +LABREMOTE = 1 try: - import labRemote + import _labRemote as labRemote except: - print("Couldn't find the labRemote Python libraries. Make sure to add them to your $PYTHONPATH first by doing") - print() - print(" export PYTHONPATH=/path/to/labRemote/build/lib:$PYTHONPATH") - print() - print("And make sure also that you have previously built labRemote enabling the Python bindings (cmake3 -DUSE_PYTHON=on)") - exit(1) + LABREMOTE = 0 + + def sigint_handler(sig, frame): print('[ info ][ ivi ] Received SIGINT. Exiting!') @@ -64,7 +62,7 @@ def powerPassiveChannels(config, key, what): ps.turnOn() -def doivi(config, w, dbSink): +def doivi(config, w, dbSink=""): if w == "iv": key = "sensor_iv" @@ -102,8 +100,8 @@ def doivi(config, w, dbSink): ps.setCurrentProtect(ch["current_protection"]) elif w == "vi": - ps.setVoltageLevel(ch["setting_voltage"]) ps.setVoltageProtect(ch["voltage_protection"]) + ps.setVoltageLevel(ch["setting_voltage"]) start = time.time() @@ -131,13 +129,22 @@ def doivi(config, w, dbSink): # Output to the terminal # > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > colWidths = "{0:8}{1:17}{2:20}{3:20}{4:20}{5:20}" - print(colWidths.format("time", xVarName + "_Level", xVarName + "_SenseMean", xVarName + "_SenseStd", yVarName + "_SenseMean", yVarName + "_SenseStd")) + print(colWidths.format("# time", xVarName + "_Level", xVarName + "_SenseMean", xVarName + "_SenseStd", yVarName + "_SenseMean", yVarName + "_SenseStd")) # < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < - xVar = ch["initial_" + xVarName] step = ch["step_size"] - while xVar * step/abs(step) <= ch["final_" + xVarName]: + + startX = measXvar() + + # Go to the starting point + steps = np.linspace(startX, xVar, 10) + for e in steps: + setXvar(e) + time.sleep(1) + + + while (xVar - ch["final_" + xVarName])* step/abs(step) <= 0: setXvar(xVar) ps.turnOn() @@ -173,34 +180,43 @@ def doivi(config, w, dbSink): data[outputKey][-1][yKeyOutName+"_sigma"] = yVarStd # Terminal output - print(colWidths.format("%.2g" % elapsedTime, "%.2g" % xVar, "%.2g" % xVarMean, "%.2g" % xVarStd, "%.2g" % yVarMean, "%.2g" % yVarStd)) + print(colWidths.format("%.2g" % elapsedTime, "%.3g" % xVar, "%.3g" % xVarMean, "%.3g" % xVarStd, "%.3g" % yVarMean, "%.3g" % yVarStd)) # Output to InfluxDB # > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > - point = { - "measurement": dbSink["measurement"], - "fields": { - "x_" + xVarName + "Setting": xVar, - "x_" + xVarName + "SenseMean": xVarMean, - "x_" + xVarName + "SenseStd": xVarStd, - "y_" + yVarName + "SenseMean": yVarMean, - "y_" + yVarName + "SenseStd": yVarStd - }, - "tags": { - "user": getpass.getuser() + if dbSink != "": + point = { + "measurement": dbSink["measurement"], + "fields": { + "x_" + xVarName + "Setting": xVar, + "x_" + xVarName + "SenseMean": xVarMean, + "x_" + xVarName + "SenseStd": xVarStd, + "y_" + yVarName + "SenseMean": yVarMean, + "y_" + yVarName + "SenseStd": yVarStd + }, + "tags": { + "user": getpass.getuser() + } } - } - toInfluxDB([point], dbSink) + toInfluxDB([point], dbSink) # < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < xVar += step # turn everything off (power-cycle the PS) - ps.turnOff() + #ps.turnOff() continue break + + # Go back to the point before the scans + steps = np.linspace(measXvar(), startX, 10) + for e in steps: + setXvar(e) + time.sleep(1) + + powerPassiveChannels(config, key, "turnOff") with open("output_"+w+".json", "w") as f: @@ -306,7 +322,34 @@ if __name__ == "__main__": with open(args.equip) as g: psConfig = json.load(g) - dbSink = psConfig["influxdb_cfg"] + + if LABREMOTE == 0: + + with open(args.equip) as f: + lrLibPath = json.load(f)["LR_lib_path"] + + sys.path.append(lrLibPath) + + try: + import _labRemote as labRemote + except: + print("Couldn't find the labRemote Python libraries. Make sure to add them to your $PYTHONPATH first by either doing") + print() + print(" export PYTHONPATH=/path/to/labRemote/build/lib:$PYTHONPATH") + print() + print(" or writing \"/path/to/labRemote/build/lib\" in \"" + args.equip + "\"") + print() + print("And make sure also that you have previously built labRemote enabling the Python bindings (cmake3 -DUSE_PYTHON=on)") + exit(1) + + + uploadToInflux = False + if uploadToInflux: + #dbSink = psConfig["influxdb_cfg"] + pass + else: + dbSink = "" + hw = labRemote.ec.EquipConf() diff --git a/libDCS/qaqc.py b/libDCS/qaqc.py index 386a95e4d5923f064d5cb65cef3d37d1925e84fa..b2fe0bf253040d0244fbc2d4a054194b5845f4f7 100644 --- a/libDCS/qaqc.py +++ b/libDCS/qaqc.py @@ -46,7 +46,7 @@ dpColumnName = "Dew Point (ch.Carrier in) [C]" # LR stuff LABREMOTE = 1 try: - import labRemote + import _labRemote as labRemote except: LABREMOTE = 0 @@ -92,6 +92,12 @@ def power_on(hw, ps, args): def power_off(hw, ps, args): + if (args.force): + ps.turnOff() + print("[ info ][ps] ps off") + return + + t = getFromInflux(temperatureSink, "select last(" + tColumnName + ") from " + temperatureSink["measurement"]) dp = getFromInflux(dewpointSink, "select last(\"" + dpColumnName + "\") from " + dewpointSink["measurement"]) @@ -118,7 +124,7 @@ def power_off(hw, ps, args): diff = t - dp if diff < maxDiffBetweenTandDPtoTurnTheHVoff: - print("[ warn ][ps] T - DP = {:.2f}, which is smaller than {}. Cannot power off the PS in these conditions".format(diff, maxDiffBetweenTandDPtoTurnTheHVoff)) + print("[ warn ][ps] (T - DP) = {:.2f}, which is smaller than {}. Cannot power off the PS in these conditions".format(diff, maxDiffBetweenTandDPtoTurnTheHVoff)) else: ps.turnOff() print("[ info ][ps] ps off") @@ -264,7 +270,12 @@ if __name__ == "__main__": action='store_true', help="Measure and Post until the end of the universe (or until killed)", ) - + parser.add_argument( + "-f", + "--force", + action='store_true', + help="Force power-off", + ) subparsers = parser.add_subparsers(help="command action") parser_set_current = subparsers.add_parser( "set-current", help="Set current [A] with maximum voltage [V]" @@ -345,7 +356,7 @@ if __name__ == "__main__": sys.path.append(lrLibPath) try: - import labRemote + import _labRemote as labRemote except: print("Couldn't find the labRemote Python libraries. Make sure to add them to your $PYTHONPATH first by either doing") print()