p2api 1.0.4__tar.gz → 1.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- p2api-1.0.6/.gitignore +4 -0
- p2api-1.0.6/PKG-INFO +61 -0
- {p2api-1.0.4 → p2api-1.0.6}/README.md +7 -1
- p2api-1.0.6/p2api/__about__.py +1 -0
- {p2api-1.0.4 → p2api-1.0.6}/p2api/p2api.py +9 -3
- p2api-1.0.6/p2api/utils/add_absolute_time_intervals.py +399 -0
- {p2api-1.0.4/p2api/generate_finding_charts → p2api-1.0.6/p2api/utils}/generate_finding_charts.py +8 -199
- p2api-1.0.6/p2api/utils/p2api_utils.py +304 -0
- p2api-1.0.6/pyproject.toml +58 -0
- p2api-1.0.4/MANIFEST.in +0 -4
- p2api-1.0.4/PKG-INFO +0 -30
- p2api-1.0.4/p2api.egg-info/PKG-INFO +0 -30
- p2api-1.0.4/p2api.egg-info/SOURCES.txt +0 -15
- p2api-1.0.4/p2api.egg-info/dependency_links.txt +0 -1
- p2api-1.0.4/p2api.egg-info/entry_points.txt +0 -3
- p2api-1.0.4/p2api.egg-info/requires.txt +0 -2
- p2api-1.0.4/p2api.egg-info/top_level.txt +0 -2
- p2api-1.0.4/setup.cfg +0 -4
- p2api-1.0.4/setup.py +0 -92
- {p2api-1.0.4 → p2api-1.0.6}/LICENSE +0 -0
- {p2api-1.0.4 → p2api-1.0.6}/p2api/__init__.py +0 -0
- {p2api-1.0.4/p2api/generate_finding_charts → p2api-1.0.6/p2api/utils}/__init__.py +0 -0
p2api-1.0.6/.gitignore
ADDED
p2api-1.0.6/PKG-INFO
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: p2api
|
|
3
|
+
Version: 1.0.6
|
|
4
|
+
Summary: Binding for the ESO phase 2 programmatic API
|
|
5
|
+
Project-URL: Homepage, https://www.eso.org/copdemo/apidoc/index.html
|
|
6
|
+
Author-email: Thomas Bierwirth <thomas.bierwirth@eso.org>, John Pritchard <john.pritchard@eso.org>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2018-present Thomas Bierwirth and other contributors
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Keywords: API,ESO,Observation,Phase2,Preparation,Programmatic
|
|
30
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
31
|
+
Classifier: Intended Audience :: Developers
|
|
32
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
+
Classifier: Programming Language :: Python :: 3
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.4
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
43
|
+
Requires-Dist: astroplan
|
|
44
|
+
Requires-Dist: astropy
|
|
45
|
+
Requires-Dist: keyring
|
|
46
|
+
Requires-Dist: requests
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+
# p2api
|
|
50
|
+
|
|
51
|
+
The [ESO](https://www.eso.org/public/) [Phase 2](https://www.eso.org/sci/observing/phase2.html) Application Programming Interface (API) uses the lightweight [JSON](<https://en.wikipedia.org/wiki/JSON>) standard as data format to exchange information between your application and the Phase 2 server at ESO. In order to program more conveniently against the API, it is helpful to create small, [language-specific bindings](<https://en.wikipedia.org/wiki/Language_binding>) to the API. We provide a simple example binding for Python, i.e. p2api.
|
|
52
|
+
|
|
53
|
+
As of version 1.0.6: Added script p2api_add_absolute_time_intervals.
|
|
54
|
+
|
|
55
|
+
As of version 1.0.3: support for \<url\>,\<access_token\> constructor.
|
|
56
|
+
|
|
57
|
+
As of version 0.97.2: support for La Silla.
|
|
58
|
+
|
|
59
|
+
Please see the [ESO-USD p2api](<http://eso.org/sci/observing/phase2/p2intro/Phase2API.html>) page for more details.
|
|
60
|
+
|
|
61
|
+
Phase 2 programmatic API documentation can be found [here](<https://www.eso.org/copdemo/apidoc/>).
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
# p2api
|
|
2
|
+
|
|
1
3
|
The [ESO](https://www.eso.org/public/) [Phase 2](https://www.eso.org/sci/observing/phase2.html) Application Programming Interface (API) uses the lightweight [JSON](<https://en.wikipedia.org/wiki/JSON>) standard as data format to exchange information between your application and the Phase 2 server at ESO. In order to program more conveniently against the API, it is helpful to create small, [language-specific bindings](<https://en.wikipedia.org/wiki/Language_binding>) to the API. We provide a simple example binding for Python, i.e. p2api.
|
|
2
4
|
|
|
5
|
+
As of version 1.0.6: Added script p2api_add_absolute_time_intervals.
|
|
6
|
+
|
|
3
7
|
As of version 1.0.3: support for \<url\>,\<access_token\> constructor.
|
|
4
8
|
|
|
5
9
|
As of version 0.97.2: support for La Silla.
|
|
6
10
|
|
|
7
|
-
Please see the [ESO-USD p2api](<http://eso.org/sci/observing/phase2/p2intro/Phase2API.html>) page for more details.
|
|
11
|
+
Please see the [ESO-USD p2api](<http://eso.org/sci/observing/phase2/p2intro/Phase2API.html>) page for more details.
|
|
12
|
+
|
|
13
|
+
Phase 2 programmatic API documentation can be found [here](<https://www.eso.org/copdemo/apidoc/>).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.6"
|
|
@@ -35,14 +35,20 @@ SOFTWARE.
|
|
|
35
35
|
"""
|
|
36
36
|
from __future__ import print_function
|
|
37
37
|
import os
|
|
38
|
+
import io
|
|
38
39
|
import json
|
|
39
40
|
import requests
|
|
40
41
|
import re
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
__version__
|
|
43
|
+
## The hatchling way...
|
|
44
|
+
try:
|
|
45
|
+
from p2api.__about__ import __version__
|
|
46
|
+
except:
|
|
47
|
+
# Need this construct to run in VSCode
|
|
48
|
+
from __about__ import __version__
|
|
49
|
+
P2_API_VERSION = __version__
|
|
45
50
|
|
|
51
|
+
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
46
52
|
API_URL = {
|
|
47
53
|
'production' : 'https://www.eso.org/cop/api/v1',
|
|
48
54
|
'production_lasilla': 'https://www.eso.org/copls/api/v1',
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
#! /usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# $Id: generate_finding_charts.py 267033 2021-09-16 11:08:57Z jpritcha $
|
|
4
|
+
from __future__ import print_function
|
|
5
|
+
|
|
6
|
+
_VERSION_ = "$Revision: 267033 $"
|
|
7
|
+
|
|
8
|
+
import sys # interaction with Python interpreter
|
|
9
|
+
from optparse import OptionParser # for parsing command line arguments
|
|
10
|
+
from optparse import OptionGroup
|
|
11
|
+
|
|
12
|
+
import logging
|
|
13
|
+
|
|
14
|
+
import keyring
|
|
15
|
+
import datetime
|
|
16
|
+
import re
|
|
17
|
+
|
|
18
|
+
import p2api
|
|
19
|
+
import p2api.utils.p2api_utils as p2api_utils
|
|
20
|
+
|
|
21
|
+
from astropy.time import Time
|
|
22
|
+
import numpy as np
|
|
23
|
+
from astroplan import Observer
|
|
24
|
+
import astropy.units as u
|
|
25
|
+
|
|
26
|
+
################################################################################
|
|
27
|
+
default_eso_period=p2api_utils.current_ESO_period()+1
|
|
28
|
+
min_ATI_length=1.*u.hr
|
|
29
|
+
################################################################################
|
|
30
|
+
class get_options:
|
|
31
|
+
"get command line options"
|
|
32
|
+
|
|
33
|
+
def __init__(self, vers="0.0"):
|
|
34
|
+
# define options and arguments
|
|
35
|
+
parser = OptionParser(version="%prog "+vers, formatter=p2api_utils.IndentedHelpFormatterWithNL())
|
|
36
|
+
|
|
37
|
+
group = OptionGroup(parser, "Input OB(s)")
|
|
38
|
+
group.add_option(
|
|
39
|
+
"-i", "--ids",
|
|
40
|
+
dest="ids",
|
|
41
|
+
help="""\
|
|
42
|
+
List of run, container, folder, and/or OB IDs. \
|
|
43
|
+
Note that the ATCs will be applied to all OBs recursively when a \
|
|
44
|
+
run, container or folder is specified.
|
|
45
|
+
[required]\
|
|
46
|
+
""",
|
|
47
|
+
default=None
|
|
48
|
+
)
|
|
49
|
+
parser.add_option_group(group)
|
|
50
|
+
|
|
51
|
+
group = OptionGroup(parser, "Specify the Absolute Time Intervals explicity.")
|
|
52
|
+
group.add_option(
|
|
53
|
+
"--ATCs", dest="ATCs",
|
|
54
|
+
help="""\
|
|
55
|
+
Underscore separated list of comma separated Absolute Time Constraints \
|
|
56
|
+
e.g. yyyy-mm-ddThh:mm,yyyy-mm-ddThh:mm_yyyy-mm-ddThh:mm,yyyy-mm-ddThh:mm{_...}
|
|
57
|
+
[optional]\
|
|
58
|
+
""",
|
|
59
|
+
default=None
|
|
60
|
+
)
|
|
61
|
+
group.add_option("-f", "--file", dest="file", help="A file with one ATC per line [optional]", default=None)
|
|
62
|
+
parser.add_option_group(group)
|
|
63
|
+
|
|
64
|
+
group = OptionGroup(parser, "Specify the Absolute Time Intervals using an orbital ephemeris. This functionality is EXPERIMENTAL, please check carefully!!!")
|
|
65
|
+
group.add_option("-E", "--ephem", dest="ephem", metavar="T0,PERIOD", help="Comma separated list of orbital T0[JD] and period[days] [optional]", default=None)
|
|
66
|
+
group.add_option("--phase_intervals", dest="phase_intervals", help="Comma separated list of phase intervals e.g. 0.1-0.2,0.305-0.375 [optional]", default=None)
|
|
67
|
+
group.add_option("--phase_target", dest="phase_target", help="Comma separated list of target phase, start_before [mins], min_start_before [mins] e.g. 0.01,120,30 [optional]", default=None)
|
|
68
|
+
group.add_option("--periods", dest="periods", help=f"Comma separated list of periods, default={default_eso_period} [optional]", default=str(default_eso_period))
|
|
69
|
+
parser.add_option_group(group)
|
|
70
|
+
|
|
71
|
+
group = OptionGroup(parser, "p2 server selection, options and password management")
|
|
72
|
+
group.add_option("--env", dest="env", help="Use the %s environment [optional], default = production" %("|".join(p2api.API_URL.keys())), default='production')
|
|
73
|
+
group.add_option("-u", "--user", dest="user", metavar="USER", help="the User Portal account of the user to use, e.g. ASMITHSONIAN [required for production (not required for demo)]", default=None)
|
|
74
|
+
group.add_option("-S", "--PWstore", dest="pwstore", metavar="PWSTORE", help="Store the password in the keyring, default=False", action="store_true", default=False)
|
|
75
|
+
group.add_option("-R", "--PWreenter", dest="pwreenter", metavar="PWREENTER", help="Reenter the password, thus overriding any PW in the keyring, default=False", action="store_true", default=False)
|
|
76
|
+
group.add_option("-Z", "--PWremove", dest="pwremove", metavar="PWREMOVE", help="Remove any password from the keyring, default=False", action="store_true", default=False)
|
|
77
|
+
parser.add_option_group(group)
|
|
78
|
+
|
|
79
|
+
group = OptionGroup(parser, "Verbosity...",
|
|
80
|
+
"All optional")
|
|
81
|
+
group.add_option("-n", "--dryRun", dest="dryrun", help="Do everything but make any changes to tickets [optional]", action="store_true", default=False)
|
|
82
|
+
group.add_option("-D", "--debug", dest="debug", help="Write out debugging info [optional]", action="store_true", default=False)
|
|
83
|
+
#group.add_option("-v", "--verbose", dest="vbose", help="Write out verbose info [optional]", action="store_true", default=False)
|
|
84
|
+
group.add_option("-q", "--quiet", dest="quiet", help="Write out minimal info [optional]", action="store_true", default=False)
|
|
85
|
+
parser.add_option_group(group)
|
|
86
|
+
|
|
87
|
+
# parse arguments
|
|
88
|
+
(options, args) = parser.parse_args()
|
|
89
|
+
|
|
90
|
+
if options.ids is None or (
|
|
91
|
+
(
|
|
92
|
+
options.ATCs is None
|
|
93
|
+
and
|
|
94
|
+
options.file is None
|
|
95
|
+
and
|
|
96
|
+
(
|
|
97
|
+
options.ephem is None
|
|
98
|
+
or
|
|
99
|
+
options.periods is None
|
|
100
|
+
or
|
|
101
|
+
options.phase_intervals is None
|
|
102
|
+
)
|
|
103
|
+
and
|
|
104
|
+
(
|
|
105
|
+
options.ephem is None
|
|
106
|
+
or
|
|
107
|
+
options.periods is None
|
|
108
|
+
or
|
|
109
|
+
options.phase_target is None
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
) :
|
|
113
|
+
parser.print_help()
|
|
114
|
+
sys.exit(2)
|
|
115
|
+
|
|
116
|
+
self.ids = options.ids
|
|
117
|
+
self.periods = options.periods
|
|
118
|
+
self.ATCs = options.ATCs
|
|
119
|
+
self.file = options.file
|
|
120
|
+
self.ephem = options.ephem
|
|
121
|
+
self.phase_intervals = options.phase_intervals
|
|
122
|
+
self.phase_target = options.phase_target
|
|
123
|
+
|
|
124
|
+
self.user = options.user
|
|
125
|
+
self.env = options.env
|
|
126
|
+
self.pwstore = options.pwstore
|
|
127
|
+
self.pwreenter = options.pwreenter
|
|
128
|
+
self.pwremove = options.pwremove
|
|
129
|
+
|
|
130
|
+
self.debug = options.debug
|
|
131
|
+
self.dryrun = options.dryrun
|
|
132
|
+
self.quiet = options.quiet
|
|
133
|
+
|
|
134
|
+
logFMT = "%(asctime)s %(module)15s[%(process)5d] [%(levelname)s] %(message)s"
|
|
135
|
+
logLVL=logging.INFO
|
|
136
|
+
if options.debug:
|
|
137
|
+
logLVL=logging.DEBUG
|
|
138
|
+
if options.quiet:
|
|
139
|
+
logLVL=logging.WARN
|
|
140
|
+
logging.basicConfig(level=logLVL, format=logFMT)
|
|
141
|
+
|
|
142
|
+
options = get_options(_VERSION_)
|
|
143
|
+
|
|
144
|
+
# ------------------------------------------------------------------------------
|
|
145
|
+
def get_ob_ATCs(telescope=None, ob_info=None, run_info=None) :
|
|
146
|
+
ob_ATCs=[]
|
|
147
|
+
ATCs=None
|
|
148
|
+
check_ATCs=False
|
|
149
|
+
if options.ATCs is not None :
|
|
150
|
+
ATCs=[
|
|
151
|
+
[p2api_utils.decode_datetime(x.split(',')[0]),p2api_utils.decode_datetime(x.split(',')[1])]
|
|
152
|
+
for x in options.ATCs.splt('_')
|
|
153
|
+
]
|
|
154
|
+
|
|
155
|
+
elif options.file is not None :
|
|
156
|
+
with open(options.file) as file:
|
|
157
|
+
lines = file.readlines()
|
|
158
|
+
lines = [line.rstrip().lstrip().split(',') for line in lines]
|
|
159
|
+
ATCs=[
|
|
160
|
+
[
|
|
161
|
+
p2api_utils.decode_datetime(x[0])+datetime.timedelta(seconds=30), # rounding to 1min
|
|
162
|
+
p2api_utils.decode_datetime(x[1])+datetime.timedelta(seconds=30), # rounding to 1min
|
|
163
|
+
] for x in lines
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
elif options.ephem is not None :
|
|
167
|
+
ob_exec_time=ob_info['executionTime']
|
|
168
|
+
T0,P=(float(x) for x in options.ephem.split(','))
|
|
169
|
+
periods=[
|
|
170
|
+
item for sublist in
|
|
171
|
+
[[y for y in range(int(x.split('-')[0]),int(x.split('-')[-1])+1)] for x in options.periods.split(',')]
|
|
172
|
+
for item in sublist
|
|
173
|
+
]
|
|
174
|
+
periods.sort()
|
|
175
|
+
period_range=[periods[0],]
|
|
176
|
+
period_ranges=[]
|
|
177
|
+
_pp=periods[0]
|
|
178
|
+
sf_jds=[]
|
|
179
|
+
for _p in periods[1:] :
|
|
180
|
+
if _p > _pp+1 :
|
|
181
|
+
period_range+=[_pp,]
|
|
182
|
+
sf_jd=Time([p2api_utils.ESO_period_start_end_datetimes(ESO_P) for ESO_P in period_range]).jd
|
|
183
|
+
sf_jds+=[[sf_jd[0][0],sf_jd[1][1]],]
|
|
184
|
+
period_ranges+=[period_range,]
|
|
185
|
+
period_range=[_p,]
|
|
186
|
+
_pp=_p
|
|
187
|
+
period_range+=[_pp,]
|
|
188
|
+
sf_jd=Time([p2api_utils.ESO_period_start_end_datetimes(ESO_P) for ESO_P in period_range]).jd
|
|
189
|
+
sf_jds+=[[sf_jd[0][0],sf_jd[1][1]],]
|
|
190
|
+
period_ranges+=[period_range,]
|
|
191
|
+
|
|
192
|
+
post_ob_exec_time=0.
|
|
193
|
+
if options.phase_intervals is not None :
|
|
194
|
+
phase_intervals=[[float(y) for y in x.split('-')] for x in options.phase_intervals.split(',')]
|
|
195
|
+
min_start_before=0.
|
|
196
|
+
elif options.phase_target is not None :
|
|
197
|
+
phase_target,start_before,min_start_before=(float(x) for x in options.phase_target.split(','))
|
|
198
|
+
phase_intervals=[[phase_target-start_before/P/24./60.,phase_target],]
|
|
199
|
+
post_ob_exec_time=ob_exec_time
|
|
200
|
+
ob_exec_time=0.
|
|
201
|
+
else :
|
|
202
|
+
logging.error('No means to calculate phase intervals specified.')
|
|
203
|
+
|
|
204
|
+
checked_phase_intervals=[]
|
|
205
|
+
for p_int in phase_intervals :
|
|
206
|
+
if p_int[1] < p_int[0] :
|
|
207
|
+
p_int[0]=p_int[0]-1.
|
|
208
|
+
p_int_in_sec=(p_int[1]-p_int[0])*P*24.*60.*60.
|
|
209
|
+
if (
|
|
210
|
+
ob_exec_time < p_int_in_sec
|
|
211
|
+
and
|
|
212
|
+
p_int_in_sec > min_ATI_length.to_value(u.second)
|
|
213
|
+
) :
|
|
214
|
+
checked_phase_intervals+=[p_int,]
|
|
215
|
+
else :
|
|
216
|
+
if ob_exec_time < p_int_in_sec :
|
|
217
|
+
logging.warning(f'Phase interval {p_int[0]}--{p_int[1]} == {p_int_in_sec:3.1f}sec is too short to start and finish this OB with execution time of {ob_exec_time}secs.')
|
|
218
|
+
if p_int_in_sec > min_ATI_length.to_value(u.second) :
|
|
219
|
+
logging.warning(f'Phase interval {p_int[0]}--{p_int[1]} == {p_int_in_sec:3.1f}sec is shorter than the minimum ATI length time of {min_ATI_length.to_value(u.second)}secs.')
|
|
220
|
+
|
|
221
|
+
sf_ints=[]
|
|
222
|
+
for sf_jd in sf_jds :
|
|
223
|
+
orbits=(np.array(sf_jd)-T0)//P
|
|
224
|
+
for o in range(int(orbits[0])-1,int(orbits[1])+1) :
|
|
225
|
+
for p_int in checked_phase_intervals :
|
|
226
|
+
sf_int=[
|
|
227
|
+
T0+(o+p_int[0])*P,
|
|
228
|
+
T0+(o+p_int[1])*P-ob_exec_time/24./60./60.,
|
|
229
|
+
]
|
|
230
|
+
if (
|
|
231
|
+
( sf_int[0] > sf_jd[0] and sf_int[0] < sf_jd[1] )
|
|
232
|
+
or
|
|
233
|
+
( sf_int[1] > sf_jd[0] and sf_int[1] < sf_jd[1] )
|
|
234
|
+
) :
|
|
235
|
+
# Interval is within the time range of the specified period(s)...
|
|
236
|
+
original_sf_int=sf_int
|
|
237
|
+
int_spans_nighttime=True
|
|
238
|
+
if sf_int[1] - sf_int[0] < 1. :
|
|
239
|
+
sssr=[]
|
|
240
|
+
# Check that some part of the interval occurs during nighttime...
|
|
241
|
+
int_spans_nighttime=False
|
|
242
|
+
for which in ['previous','next',] :
|
|
243
|
+
sun_set_time=telescope.sun_set_time(Time(sf_int[0], format='jd'), which=which)
|
|
244
|
+
sun_rise_time=telescope.sun_rise_time(sun_set_time, which='next')
|
|
245
|
+
sssr+=[[sun_set_time,sun_rise_time],]
|
|
246
|
+
if (
|
|
247
|
+
(sf_int[0] > sun_set_time.jd and sf_int[0] < sun_rise_time.jd-ob_exec_time/24./60./60. )
|
|
248
|
+
or
|
|
249
|
+
(sf_int[1] > sun_set_time.jd and sf_int[1] < sun_rise_time.jd-ob_exec_time/24./60./60. )
|
|
250
|
+
or
|
|
251
|
+
(sf_int[0] < sun_set_time.jd and sf_int[1] > sun_rise_time.jd-ob_exec_time/24./60./60. )
|
|
252
|
+
) :
|
|
253
|
+
sf_int=[
|
|
254
|
+
np.max([sf_int[0],sun_set_time.jd]),
|
|
255
|
+
np.min([sf_int[1],sun_rise_time.jd-ob_exec_time/24./60./60.,sun_rise_time.jd-post_ob_exec_time/24./60./60.]),
|
|
256
|
+
]
|
|
257
|
+
if sf_int[1] > sf_int[0]+min_start_before/24./60. :
|
|
258
|
+
int_spans_nighttime=True
|
|
259
|
+
break
|
|
260
|
+
if (
|
|
261
|
+
int_spans_nighttime
|
|
262
|
+
and
|
|
263
|
+
((sf_int[1]-sf_int[0])*24*60.*60. > ob_exec_time)
|
|
264
|
+
and
|
|
265
|
+
(sf_int[1]-sf_int[0])*24*60.*60. > min_ATI_length.to_value(u.second)
|
|
266
|
+
) :
|
|
267
|
+
sf_ints+=[sf_int,]
|
|
268
|
+
else :
|
|
269
|
+
if not int_spans_nighttime :
|
|
270
|
+
logging.debug(f'Interval does not span any part of the night, original interval = {original_sf_int}, SSSR of previous and next nights {sssr[0][0].jd}--{sssr[0][1].jd} and {sssr[1][0].jd}--{sssr[1][1].jd}')
|
|
271
|
+
if ((sf_int[1]-sf_int[0])*24*60.*60. < ob_exec_time) :
|
|
272
|
+
logging.debug(f'Checked Interval shorter [{(sf_int[1]-sf_int[0])*24*60.*60.:3.1f}sec] than OB execution time [{ob_exec_time:3.1f}sec], original interval = {original_sf_int}, checked interval = {sf_int}')
|
|
273
|
+
if ((sf_int[1]-sf_int[0])*24*60.*60. < min_ATI_length.to_value(u.second)) :
|
|
274
|
+
logging.debug(f'Checked Interval shorter [{(sf_int[1]-sf_int[0])*24*60.*60.:3.1f}sec] than minimum ATI length time [{min_ATI_length.to_value(u.second):3.1f}sec], original interval = {original_sf_int}, checked interval = {sf_int}')
|
|
275
|
+
pass
|
|
276
|
+
ATCs=[Time(sf_int, format='jd') for sf_int in sf_ints]
|
|
277
|
+
check_ATCs=True
|
|
278
|
+
else :
|
|
279
|
+
raise "Don't know how to compute Absolute Time Constraints."
|
|
280
|
+
|
|
281
|
+
ob_ATCs=[]
|
|
282
|
+
for i,ATC in enumerate(ATCs) :
|
|
283
|
+
t=Time(ATC)
|
|
284
|
+
t.format = 'isot'
|
|
285
|
+
t.out_subfmt = 'date_hm'
|
|
286
|
+
ob_ATCs+=[{
|
|
287
|
+
'from': t[0].isot,
|
|
288
|
+
'to': t[1].isot,
|
|
289
|
+
},]
|
|
290
|
+
if check_ATCs :
|
|
291
|
+
phase_range=''
|
|
292
|
+
if options.ephem is not None :
|
|
293
|
+
phase_range=f" [Phases: {(((t[0]-Time(T0,format='jd'))/P).to_value(u.day)%1):5.3f} -- {(((t[1]-Time(T0,format='jd'))/P).to_value(u.day)%1):5.3f}]"
|
|
294
|
+
print(f"{i+1:3d} {ob_ATCs[-1]['from']} -- {ob_ATCs[-1]['to']} [duration={((t[1]-t[0]).to_datetime())}]{phase_range}")
|
|
295
|
+
if check_ATCs :
|
|
296
|
+
'''
|
|
297
|
+
logging.warning("****************************************************************************************")
|
|
298
|
+
logging.warning("****************************************************************************************")
|
|
299
|
+
logging.warning("****************************************************************************************")
|
|
300
|
+
logging.warning("Intervals via Orbital Ephemeris functionality is EXPERIMENTAL")
|
|
301
|
+
logging.warning("Please check the above intervals carefully and only continue if you are sure they are what YOU require.")
|
|
302
|
+
logging.warning("YOU, and YOU ALONE are responsible for the accuracy of these inetervals.")
|
|
303
|
+
'''
|
|
304
|
+
print("****************************************************************************************")
|
|
305
|
+
print("****************************************************************************************")
|
|
306
|
+
print("****************************************************************************************")
|
|
307
|
+
print("Intervals via Orbital Ephemeris functionality is EXPERIMENTAL")
|
|
308
|
+
print("Please check the above intervals carefully and only continue if you are sure they are what YOU require.")
|
|
309
|
+
print("YOU, and YOU ALONE are responsible for the accuracy of these intervals.")
|
|
310
|
+
yorn = input("Continue [y/N] ")
|
|
311
|
+
if yorn.lower() not in ['y',] :
|
|
312
|
+
print("Please contact ESO User Support via a ticket at https://support.eso.org/tickets")
|
|
313
|
+
print("to report/discuss the errors/problems in the above calculations.")
|
|
314
|
+
print("Please include in the description the EXACT command line used to run the script.")
|
|
315
|
+
sys.exit(0)
|
|
316
|
+
#raise Exception(f"Aborted.")
|
|
317
|
+
return ob_ATCs
|
|
318
|
+
# ------------------------------------------------------------------------------
|
|
319
|
+
def oneOB( api, obId ) :
|
|
320
|
+
try :
|
|
321
|
+
OB, _ = api.getOB(obId)
|
|
322
|
+
except p2api.P2Error as e :
|
|
323
|
+
## Looks like this ID is not an OB...
|
|
324
|
+
logging.error('OB %d could not be found...' %(obId))
|
|
325
|
+
return
|
|
326
|
+
except:
|
|
327
|
+
raise
|
|
328
|
+
ob_info = api.executionTime(obId)
|
|
329
|
+
run_info,_=api.getRun(OB['runId'])
|
|
330
|
+
|
|
331
|
+
telescope = Observer(location=p2api_utils.telescope_locations[run_info['telescope']])
|
|
332
|
+
|
|
333
|
+
if OB['itemType'] not in ['OB',] :
|
|
334
|
+
logging.warning('OB %d is not a science OB' %(obId))
|
|
335
|
+
return
|
|
336
|
+
|
|
337
|
+
if OB['obStatus'] not in ['P','-'] :
|
|
338
|
+
logging.warning('OB status is %s, OB not modifiable' %(OB['obstatus']))
|
|
339
|
+
return
|
|
340
|
+
|
|
341
|
+
runId, _ = api.getRun(OB['runId'])
|
|
342
|
+
ob_url=api.apiUrl+'/obsBlocks/'+str(obId)
|
|
343
|
+
oneOB_sdt=datetime.datetime.now()
|
|
344
|
+
## For the moment only setting is supported,
|
|
345
|
+
## ToDo: implement support for adding to...
|
|
346
|
+
logging.info("Setting Absolute Time Intervals for OBid = %d, OBname = '%s' @ %s..." % (OB['obId'],OB['name'],OB['instrument']))
|
|
347
|
+
absTCs, atcVersion = api.getAbsoluteTimeConstraints(obId)
|
|
348
|
+
|
|
349
|
+
ob_ATCs=get_ob_ATCs(
|
|
350
|
+
telescope=telescope,
|
|
351
|
+
ob_info=ob_info,
|
|
352
|
+
run_info=run_info,
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
if not options.dryrun :
|
|
356
|
+
api.saveAbsoluteTimeConstraints(
|
|
357
|
+
obId,
|
|
358
|
+
ob_ATCs,
|
|
359
|
+
atcVersion,
|
|
360
|
+
)
|
|
361
|
+
oneOB_edt=datetime.datetime.now()
|
|
362
|
+
logging.info(
|
|
363
|
+
"Added %d Absolute Time Intervals for OBid = %d, OBname = '%s' @ %s done in %s."
|
|
364
|
+
%(
|
|
365
|
+
len(ob_ATCs), obId, OB['name'], OB['instrument'], str(oneOB_edt-oneOB_sdt)
|
|
366
|
+
)
|
|
367
|
+
)
|
|
368
|
+
# ------------------------------------------------------------------------------
|
|
369
|
+
|
|
370
|
+
# ------------------------------------------------------------------------------
|
|
371
|
+
# ------------------------------------------------------------------------------
|
|
372
|
+
# ------------------------------------------------------------------------------
|
|
373
|
+
|
|
374
|
+
def main():
|
|
375
|
+
|
|
376
|
+
################################################################################
|
|
377
|
+
# remove password from keyring...
|
|
378
|
+
if options.pwremove and options.user is not None :
|
|
379
|
+
keyring.delete_password('usd_p2api_interactive:www.eso.org', options.user)
|
|
380
|
+
sys.exit(0)
|
|
381
|
+
|
|
382
|
+
api=p2api_utils.get_api(options)
|
|
383
|
+
obIds=p2api_utils.r_get_all_OBIds( api, options.ids.split(',') )
|
|
384
|
+
|
|
385
|
+
if len(obIds) > 0 :
|
|
386
|
+
if len(obIds) > 1 :
|
|
387
|
+
sdt=datetime.datetime.now()
|
|
388
|
+
logging.warning('Adding Absolute Time Constraints to %d OBs...' %( len(obIds) ))
|
|
389
|
+
for obId in obIds :
|
|
390
|
+
oneOB(api, obId, )
|
|
391
|
+
if len(obIds) > 1 :
|
|
392
|
+
edt=datetime.datetime.now()
|
|
393
|
+
logging.info('Total elapsed time to process %d finding charts %s...' %(len(obIds),str(edt-sdt)))
|
|
394
|
+
else :
|
|
395
|
+
logging.error('No OBs found.')
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
if __name__ == '__main__' :
|
|
399
|
+
main()
|