from __future__ import print_function import sys sys.path.append('/Users/jmilli/Documents/p2/API/') import p2api # connect to API passing environment = 'demo' | 'production', username, password # Set trailing boolean parameter to True for debug output api = p2api.ApiConnection('demo', '52052', 'tutorial', False) # get the run and read its containerId containerId = 1318488 # create OB ob, obVersion = api.createOB(containerId, 'Julien') obId = ob['obId'] print ('Created OB', obId) # change OB parameters ob, obVersion = api.getOB(obId) ob['userPriority'] = 42 ob['target']['name'] = 'M 32 -- Interacting Galaxies' ob['target']['ra'] = '00:42:41.825' ob['target']['dec'] = '-60:51:54.610' ob['target']['properMotionRa'] = 1 ob['target']['properMotionDec'] = 2 ob['constraints']['name'] = 'My hardest constraints ever' ob['constraints']['airmass'] = 1.3 ob['constraints']['skyTransparency'] = 'Variable, thin cirrus' ob['constraints']['fli'] = 0.1 ob['constraints']['seeing'] = 2.0 ob, obVersion = api.saveOB(ob, obVersion) print ('Saved OB properties') # attach acquisition template tpl, tplVersion = api.createTemplate(obId, 'UVES_dic1_acq_slit') templateId = tpl["templateId"] print('Created acquisition template', templateId) # set some acquisition template parameters tpl, tplVersion = api.getTemplate(obId, templateId) tpl, tplVersion = api.setTemplateParams(obId, tpl, { 'TEL.GS1.ALPHA': '11:22:33.000', 'INS.FILT1.NAME': 'ND1', 'INS.DPOL.MODE': 'ON' }, tplVersion) print('Updated parameters for acquisition template', tpl['templateName']) # create science template tpl, tplVersion = api.createTemplate(obId, 'UVES_blue_obs_exp') templateId = tpl["templateId"] print('Created science template', templateId) # set some science template parameters tpl, tplVersion = api.getTemplate(obId, templateId) tpl, tplVersion = api.setTemplateParams(obId, tpl, { 'DET1.READ.SPEED' : '50kHz,2x2,high', 'INS.SLIT2.WID' : 0.15 }, tplVersion) print('Updated parameters for science template', tpl['templateName']) # verify OB response, _ = api.verifyOB(obId, True, obVersion) if response['observable']: print('*** Congratulations. Your OB' , obId, ob['name'], 'is observable! ***') else: print('OB', obId, 'is >>not observable<<. See messages below.') print(' ', '\n '.join(response['messages'])) # fetch OB again to confirm its status change ob, obVersion = api.getOB(obId) print('Status of verified OB', obId, 'is now', ob['obStatus'])