Skip to content

Commit

Permalink
MNT/STY: upgrade and style a few python files I missed
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed Apr 24, 2024
1 parent 04832a2 commit 46b7662
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 57 deletions.
3 changes: 2 additions & 1 deletion scripts/BLmotors
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 23 additions & 17 deletions scripts/elog_par_post
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -51,5 +56,6 @@ def main():

postRunTable(args.file, args.experiment, args.run)


if __name__ == '__main__':
main()
7 changes: 4 additions & 3 deletions scripts/epicsArchChecker
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
41 changes: 22 additions & 19 deletions scripts/epix_gains
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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
11 changes: 2 additions & 9 deletions scripts/evrStatus
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 9 additions & 8 deletions scripts/image_saver
Original file line number Diff line number Diff line change
@@ -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=""):
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 46b7662

Please sign in to comment.