Skip to content

Commit

Permalink
Merge pull request #15 from decarlof/master
Browse files Browse the repository at this point in the history
update to use the new APS scheduling system REST API
  • Loading branch information
decarlof committed Mar 29, 2024
2 parents 7f3d09b + 62ab760 commit b3f0463
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 146 deletions.
16 changes: 16 additions & 0 deletions .readthedocs.yml
@@ -0,0 +1,16 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
version: 2
sphinx:
configuration: doc/conf.py
# Set the version of Python and other tools you might need
python:
install:
- requirements: envs/requirements-doc.txt
submodules:
recursive: false
build:
os: ubuntu-22.04
tools:
python: "3"
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.0.3
0.0.4
2 changes: 2 additions & 0 deletions dmagic/__init__.py
Expand Up @@ -47,3 +47,5 @@
# #########################################################################

from dmagic.scheduling import *
from dmagic.pv import *
from dmagic.util import *
4 changes: 2 additions & 2 deletions bin/dmagic → dmagic/__main__.py
Expand Up @@ -60,7 +60,7 @@
import datetime as dt

from dmagic import scheduling
from dmagic import pv_update
from dmagic import pv
from dmagic import log
from dmagic import config

Expand All @@ -82,7 +82,7 @@ def tag(args):
# set the experiment date
now = datetime.datetime.today()
log.info("Today's date: %s" % now)
args = pv_update.pv_daemon(args, now)
args = pv.update(args, now)


def main():
Expand Down
6 changes: 5 additions & 1 deletion dmagic/config.py
Expand Up @@ -27,7 +27,7 @@
'beamline' : {
'default' : '7-BM-B',
'type': str,
'help': "beam line"},
'help': "beamline ID as stored in the APS scheduling system, e.g. 2-BM-A,B or 7-BM-B or 32-ID-B,C"},
'tomoscan-prefix':{
'default': '7bmb1:',
'type': str,
Expand All @@ -36,6 +36,10 @@
'type': float,
'default': 0,
'help': "Number of +/- number days for the current date. Used for setting user info for past/future user groups"},
'url':{
'default': 'https://mis7.aps.anl.gov:7004',
'type': str,
'help': "URL address of the scheduling system REST API' "},
}


Expand Down
55 changes: 40 additions & 15 deletions dmagic/pv_update.py → dmagic/pv.py
Expand Up @@ -53,8 +53,9 @@
import pytz
from epics import PV

from dmagic import scheduling
from dmagic import log
from dmagic import utils
from dmagic import scheduling

__author__ = "Francesco De Carlo"
__copyright__ = "Copyright (c) 2015-2016, UChicago Argonne, LLC."
Expand All @@ -77,32 +78,56 @@ def init_PVs(args):
return user_pvs


def pv_daemon(args, date=None):
user_pvs = init_PVs(args)
# set iso format time
central = pytz.timezone('US/Central')
local_time = central.localize(date)
local_time_iso = local_time.isoformat()
def update(args, date=None):

user_pvs['user_info_update_time'].put(local_time_iso)
log.info("User/Experiment PV update")
auth = scheduling.authorize()
run = scheduling.current_run(auth, args)
proposals = scheduling.beamtime_requests(run, auth, args)

proposal = scheduling.get_current_proposal(args)
if not proposals:
log.error('No valid current experiment')
return None
try:
log.error(proposals['message'])
return None
except:
pass

proposal = scheduling.get_current_proposal(proposals, args)
if not proposal:
log.warning('No valid current proposal')
return

# get PI information
pi = scheduling.get_current_pi(args)
pi = scheduling.get_current_pi(proposal)

user_pvs = init_PVs(args)

log.info("User/Experiment PV update")
user_pvs['user_name'].put(pi['firstName'])
log.info('Updated EPICS PV with: %s' % pi['firstName'])
user_pvs['user_last_name'].put(pi['lastName'])
log.info('Updated EPICS PV with: %s' % pi['lastName'])
user_pvs['user_affiliation'].put(pi['institution'])
log.info('Updated EPICS PV with: %s' % pi['institution'])
user_pvs['user_email'].put(pi['email'])
log.info('Updated EPICS PV with: %s' % pi['email'])
user_pvs['user_badge'].put(pi['badge'])
log.info('Updated EPICS PV with: %s' % pi['badge'])

# set iso format time
central = pytz.timezone('US/Central')
local_time = central.localize(date)
local_time_iso = local_time.isoformat()
user_pvs['user_info_update_time'].put(local_time_iso)
log.info('Updated EPICS PV with: %s' % local_time_iso)

# get experiment information
user_pvs['proposal_number'].put(scheduling.get_current_proposal_id(args))
user_pvs['proposal_title'].put(scheduling.get_current_proposal_title(args))
user_pvs['proposal_number'].put(scheduling.get_current_proposal_id(proposal))
log.info('Updated EPICS PV with: %s' % scheduling.get_current_proposal_id(proposal))
user_pvs['proposal_title'].put(scheduling.get_current_proposal_title(proposal))
log.info('Updated EPICS PV with: %s' % scheduling.get_current_proposal_title(proposal))
#Make the start date of the experiment into a year - month
start_datetime = datetime.datetime.strptime(proposal['startTime'],'%Y-%m-%d %H:%M:%S%z')
start_datetime = datetime.datetime.strptime(utils.fix_iso(proposal['startTime']),'%Y-%m-%dT%H:%M:%S%z')
user_pvs['experiment_date'].put(start_datetime.strftime('%Y-%m'))
log.info('Updated EPICS PV with: %s' % start_datetime.strftime('%Y-%m'))

0 comments on commit b3f0463

Please sign in to comment.