From 46b7662c5f5502f3c04e299fd9dc3f531662e14a Mon Sep 17 00:00:00 2001 From: tangkong Date: Wed, 24 Apr 2024 16:21:50 -0700 Subject: [PATCH] MNT/STY: upgrade and style a few python files I missed --- scripts/BLmotors | 3 ++- scripts/elog_par_post | 40 ++++++++++++++++++++++----------------- scripts/epicsArchChecker | 7 ++++--- scripts/epix_gains | 41 +++++++++++++++++++++------------------- scripts/evrStatus | 11 ++--------- scripts/image_saver | 17 +++++++++-------- 6 files changed, 62 insertions(+), 57 deletions(-) diff --git a/scripts/BLmotors b/scripts/BLmotors index 264f6109..38c3ec27 100755 --- a/scripts/BLmotors +++ b/scripts/BLmotors @@ -13,8 +13,9 @@ The script will generate a report for: 3. If the current configuration matches or not with the appropriate values. """ -import os import argparse +import os + import ophyd.signal from pmgr import pmgrAPI from prettytable import PrettyTable diff --git a/scripts/elog_par_post b/scripts/elog_par_post index 15a918ba..a58a843c 100755 --- a/scripts/elog_par_post +++ b/scripts/elog_par_post @@ -1,45 +1,50 @@ #!/usr/bin/env python -import requests -from requests.auth import HTTPBasicAuth import argparse import socket +import requests +from requests.auth import HTTPBasicAuth + + def readRunTable(fname): - runTableData={} + runTableData = {} with open(fname) as reader: lines = reader.readlines() for line in lines: try: print(line) - runTableData[line.split()[0]]=line.split()[1] - except: + runTableData[line.split()[0]] = line.split()[1] + except Exception: pass return runTableData + def postRunTableDict(runtable_data, experiment, run): - args_url="https://pswww.slac.stanford.edu/ws-auth/lgbk/" + args_url = "https://pswww.slac.stanford.edu/ws-auth/lgbk/" ws_url = args_url + "/run_control/{0}/ws/add_run_params".format(experiment) - print('URL:',ws_url) - user=experiment[:3]+'opr' - elogPostFile='/cds/home/opr/%s/forElogPost.txt'%user - hostname=socket.gethostname() - if hostname.find('sdf')>=0: - elogPostFile='/sdf/group/lcls/ds/tools/forElogPost.txt' - with open(elogPostFile,'r') as reader: + print('URL:', ws_url) + user = experiment[:3] + 'opr' + elogPostFile = '/cds/home/opr/%s/forElogPost.txt' % user + hostname = socket.gethostname() + if hostname.find('sdf') >= 0: + elogPostFile = '/sdf/group/lcls/ds/tools/forElogPost.txt' + with open(elogPostFile, 'r') as reader: answer = reader.readline() - r = requests.post(ws_url, params={"run_num": run}, json=runtable_data, \ - auth=HTTPBasicAuth(experiment[:3]+'opr', answer[:-1])) + r = requests.post(ws_url, params={"run_num": run}, json=runtable_data, + auth=HTTPBasicAuth(experiment[:3] + 'opr', answer[:-1])) print(r) + def postRunTable(fname, experiment, run): print(fname, experiment, run) - if fname=='pedestal': - dataDict={'pedestal':'done'} + if fname == 'pedestal': + dataDict = {'pedestal': 'done'} else: dataDict = readRunTable(fname) print(dataDict) postRunTableDict(dataDict, experiment, run) + def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-r', '--run', help='run number', @@ -51,5 +56,6 @@ def main(): postRunTable(args.file, args.experiment, args.run) + if __name__ == '__main__': main() diff --git a/scripts/epicsArchChecker b/scripts/epicsArchChecker index f1823845..c00a0154 100755 --- a/scripts/epicsArchChecker +++ b/scripts/epicsArchChecker @@ -9,8 +9,9 @@ of reports: 3. PVs no connected. 4. Files that do not exist. """ -import os import argparse +import os + import ophyd.signal from prettytable import PrettyTable @@ -119,7 +120,7 @@ def create_Lists(entries): myPVs.append(entry[1]) myFiles.append(entry[2]) lineNumbers.append('№ ' + str(entry[3])) - return(myKeys, myPVs, myFiles, lineNumbers) + return (myKeys, myPVs, myFiles, lineNumbers) def find_index(myKeys, myPVs, myFiles): @@ -146,7 +147,7 @@ def find_index(myKeys, myPVs, myFiles): if dmyPVs[dpv] == myPVs[pv]: indPVs.append(pv) - return(indKeys, indPVs) + return (indKeys, indPVs) def report_duplicates(indKeys, indPVs, myKeys, myPVs, myFiles, numLines): diff --git a/scripts/epix_gains b/scripts/epix_gains index 55ee8f3f..f245320d 100755 --- a/scripts/epix_gains +++ b/scripts/epix_gains @@ -1,29 +1,30 @@ #!/usr/bin/env python -import psana -from Detector.UtilsEpix10ka import find_gain_mode -from Detector.UtilsEpix10ka import info_pixel_gain_mode_statistics_for_raw -import sys import argparse +import sys + +import psana +from Detector.UtilsEpix10ka import (find_gain_mode, + info_pixel_gain_mode_statistics_for_raw) parser = argparse.ArgumentParser() parser.add_argument('--run', help='run', type=str) parser.add_argument('--experiment', help='experiment name', type=str) args = parser.parse_args() -exprun = 'exp=%s:run=%s'%(args.experiment,args.run) +exprun = 'exp=%s:run=%s' % (args.experiment, args.run) ds = psana.DataSource(exprun+':smd') aliases = [] for dn in psana.DetNames(): - if dn[1]!='': + if dn[1] != '': alias = dn[1] else: alias = dn[0] - if alias.find('10k')>0: + if alias.find('10k') > 0: aliases.append(alias) -if len(alias)==0: +if len(alias) == 0: print('did not find an epix10k, quit.') sys.exit() @@ -33,29 +34,31 @@ for ialias, alias in enumerate(aliases): epixs.append(psana.Detector(alias)) for run in ds.runs(): - print 'run loop' - for nstep,step in enumerate(run.steps()): + print('run loop') + for nstep, step in enumerate(run.steps()): for epix in epixs: - print '*** config gain mode: %s \t'%epix.name, find_gain_mode(det=epix) + print('*** config gain mode: %s \t' % epix.name, find_gain_mode(det=epix)) pvList = cd().pvLabels() for pv in pvList: - print 'Step',nstep,'name/value:',pv.name(),pv.value() + print('Step', nstep, 'name/value:', pv.name(), pv.value()) found = False nbad = 0 - raws=[] + raws = [] for epix in epixs: raws.append(None) - for nevt,evt in enumerate(step.events()): + for nevt, evt in enumerate(step.events()): if not found: - for iepix,epix in enumerate(epixs): + for iepix, epix in enumerate(epixs): found = True if epix.raw(evt) is None: nbad += 1 - raws[iepix]=None + raws[iepix] = None found = False else: - raws[iepix]=epix.raw(evt) + raws[iepix] = epix.raw(evt) if found: - for iepix,epix in enumerate(epixs): - print '--- event gain mode for %s \t'%epix.name,find_gain_mode(det=epix,data=raws[iepix]),info_pixel_gain_mode_statistics_for_raw(epix, raws[iepix]) + for iepix, epix in enumerate(epixs): + print('--- event gain mode for %s \t' % epix.name, + find_gain_mode(det=epix, data=raws[iepix]), + info_pixel_gain_mode_statistics_for_raw(epix, raws[iepix])) pass diff --git a/scripts/evrStatus b/scripts/evrStatus index 0846569b..8ebe1d16 100755 --- a/scripts/evrStatus +++ b/scripts/evrStatus @@ -6,15 +6,8 @@ from sys import stdin from pydm.widgets import PyDMPushButton from pydm.widgets.label import PyDMLabel from qtpy import QtCore -from qtpy.QtWidgets import ( - QApplication, - QGridLayout, - QHBoxLayout, - QHeaderView, - QLabel, - QTableWidget, - QWidget, -) +from qtpy.QtWidgets import (QApplication, QGridLayout, QHBoxLayout, + QHeaderView, QLabel, QTableWidget, QWidget) class Expert(QWidget): diff --git a/scripts/image_saver b/scripts/image_saver index edafb8ae..a80720f1 100755 --- a/scripts/image_saver +++ b/scripts/image_saver @@ -1,11 +1,12 @@ #!/usr/bin/env python -from argparse import ArgumentParser -from subprocess import getoutput -from time import time, sleep import os -from hutch_python.cam_load import interpret_lines, build_cam +from argparse import ArgumentParser from functools import partial +from subprocess import getoutput +from time import sleep, time + from hdf5_to_gif import convert +from hutch_python.cam_load import build_cam, interpret_lines def take_images(camera, num_images, path, filename, output_gif=""): @@ -161,11 +162,11 @@ def button_gui(cameras, num_images, path, filenames, hutch, filename_prefix, Path to which hdf5 images taken will be converted to gifs and stored in. If empty, no gifs will be made. """ - from qtpy.QtWidgets import (QApplication, QWidget, QGridLayout, - QPushButton, QLineEdit, QLabel, QHBoxLayout, - QInputDialog) - from qtpy.QtGui import QIntValidator from qtpy.QtCore import Qt + from qtpy.QtGui import QIntValidator + from qtpy.QtWidgets import (QApplication, QGridLayout, QHBoxLayout, + QInputDialog, QLabel, QLineEdit, QPushButton, + QWidget) app = QApplication([]) window = QWidget() window.setWindowTitle("Imager")