Skip to content

Commit eb156ea

Browse files
committed
Merge branch '703-feedback-on-tom-swift-module-from-swift-operations-team' into dev
2 parents f73a801 + 01c965b commit eb156ea

File tree

8 files changed

+933
-825
lines changed

8 files changed

+933
-825
lines changed

.github/workflows/run-tests.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ jobs:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-python@v2
1111
with:
12-
python-version: '3.x'
12+
python-version: '3.11'
1313
- name: Install dependencies
1414
run: |
1515
python -m pip install --upgrade pip
1616
python -m pip install poetry
17-
poetry install
18-
pip install -I flake8
17+
poetry install --with lint
1918
- name: Style Checks
20-
run: flake8 tom_* --exclude=*/migrations/* --max-line-length=120
19+
run: poetry run flake8 tom_* --exclude=*/migrations/* --max-line-length=120
2120

2221
run_tests:
2322
runs-on: ubuntu-latest
2423
strategy:
2524
matrix:
26-
python-version: ["3.8", "3.9", "3.10"]
25+
python-version: ["3.8", "3.9", "3.10", "3.11"]
2726
os: [ubuntu-latest]
2827
steps:
2928
- uses: actions/checkout@v2
@@ -36,4 +35,4 @@ jobs:
3635
python -m pip install poetry
3736
poetry install
3837
- name: Run tests
39-
run: echo "write tests!"
38+
run: poetry run python -m unittest discover -v

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# tom_swift
2-
_Note: This repository is under active development. It is currently in alpha-release stage. Feedback is welcome._
3-
42
[Neil Gehrels Swift Observatory](https://swift.gsfc.nasa.gov/index.html) facility module for TOM Toolkit. This module uses the
53
[Swift TOO API](https://www.swift.psu.edu/too_api/) for all its interactions with the _Swift_ Observatory. When installed and
64
configured, your TOM can query target visibility, submit TOO observation requests to Swift, and check TOO observation status.

poetry.lock

Lines changed: 695 additions & 745 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ readme = "README.md"
99
packages = [{include = "tom_swift"}]
1010

1111
[tool.poetry.dependencies]
12-
python = ">=3.8,<3.12"
13-
tomtoolkit = "^2.14"
14-
BatAnalysis = "^1.0"
12+
python = ">=3.8.1,<3.12"
13+
tomtoolkit = ">=2.15"
14+
swifttools = "<4"
1515

16+
[tool.poetry.group.lint.dependencies]
17+
flake8 = "~6.0"
1618

1719
[tool.poetry-dynamic-versioning]
1820
enable = true

tom_swift/swift.py

Lines changed: 119 additions & 57 deletions
Large diffs are not rendered by default.

tom_swift/swift_api.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def resolve_target(self, target: Target):
7272
return resolved_target
7373

7474

75+
# define OTHER_CHOICE so it can be used consistently and tested against
76+
SWIFT_OTHER_CHOICE = 'Other (please specify)'
77+
7578
#
7679
# Urgency
7780
#
@@ -93,7 +96,7 @@ def resolve_target(self, target: Target):
9396
('Supernova', 'Supernova'),
9497
('Tidal Disruption Event', 'Tidal Disruption Event'),
9598
('X-Ray Transient', 'X-Ray Transient'),
96-
('Other (please specify)', 'Other (please specify)'),
99+
(SWIFT_OTHER_CHOICE, SWIFT_OTHER_CHOICE),
97100
]
98101

99102

@@ -103,6 +106,7 @@ def resolve_target(self, target: Target):
103106
# Note that:
104107
# >>> TOO().obs_types
105108
# ['Spectroscopy', 'Light Curve', 'Position', 'Timing']
109+
#
106110
def get_observation_type_choices():
107111
"""Returns a list of tuples for the observation type choices.
108112
@@ -119,12 +123,35 @@ def get_observation_type_choices():
119123
#
120124
# Instruments
121125
#
126+
# could also use TOO().instruments, which is [ 'XRT', 'BAT', 'UVOT']
127+
# but that doesn't include the full names
122128
SWIFT_INSTRUMENT_CHOICES = [
123129
('UVOT', 'UV/Optical Telescope (UVOT)'),
124130
('XRT', 'X-ray Telescope (XRT)'),
125131
('BAT', 'Burst Alert Telescope (BAT)'),
126132
]
127133

134+
#
135+
# GRB Detectors
136+
#
137+
138+
139+
def get_grb_detector_choices():
140+
"""Returns a list of tuples for the GRB detector choices.
141+
142+
Since the TOO() object has property describing the valid GRB detectors,
143+
use that to create the choices list of tuples (e.g. [('Swift/BAT', 'Swift/BAT'), ('Fermi/LAT',
144+
'Fermi/LAT'), ...]).
145+
"""
146+
grb_detector_choices = []
147+
for mission in TOO().mission_names:
148+
if mission != 'ANTARES':
149+
grb_detector_choices.append((mission, mission))
150+
151+
# add the SWIFT_OTHER_CHOICE
152+
grb_detector_choices.append((SWIFT_OTHER_CHOICE, SWIFT_OTHER_CHOICE))
153+
return grb_detector_choices
154+
128155

129156
#
130157
# XRT Modes
@@ -160,6 +187,26 @@ def get_observation_type_choices():
160187
# Any string will validate:
161188
# >>> too.uvot_mode = "I think I want all UV filters for this, whatever the UVOT team recommends."
162189

190+
SWIFT_UVOT_FILTER_MODE_CHOICES = [
191+
(0x015a, 'uvm2 (0x015a)'),
192+
(0x011e, 'uvw2 (0x011e)'),
193+
(0x01aa, 'u (0x01aa)'),
194+
(0x018c, 'uvw1 (0x018c)'),
195+
(0x2016, 'B (0x2016)'),
196+
(0x2005, 'V (0x2005)'),
197+
(0x2019, 'white (0x2019)'),
198+
(0x209a, 'three optical filters (0x209a)'),
199+
(0x308f, 'three NUV filters (0x308f)'),
200+
(0x30d5, 'four UV/NUV filters (0x30d5)'),
201+
(0x30ed, 'standard six-filter blue-weighted mode (0x30ed)'),
202+
(0x223f, 'heavily weighted six-filter mode; for supernovae and very red objects (0x223f)'),
203+
(0x2241, 'all seven optical/UV filters (0x2241)'),
204+
(0x0270, ('unscaled six-filter mode to get 6 broadband filters in AT observations with'
205+
' snapshot lengths > 1000s (0x0270)')),
206+
(0x9999, 'Filter of the Day (0x9999)'),
207+
(SWIFT_OTHER_CHOICE, SWIFT_OTHER_CHOICE),
208+
]
209+
163210

164211
#
165212
# Monitoring
@@ -172,5 +219,5 @@ def get_monitoring_unit_choices():
172219
"""
173220
monitoring_unit_choices = []
174221
for unit in TOO().monitoring_units:
175-
monitoring_unit_choices.append((unit, unit))
222+
monitoring_unit_choices.append((unit, f'{unit}(s)'))
176223
return monitoring_unit_choices

tom_swift/templates/tom_swift/observation_form.html

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,35 @@
1111
function showHideTargetClassificationFields() {
1212
const target_classification = document.getElementById('id_target_classification_choices').options[document.getElementById('id_target_classification_choices').selectedIndex].value;
1313
switch (target_classification) {
14-
case 'Other (please specify)':
14+
case 'Other (please specify)': // define as SWIFT_OTHER_CHOICE in swift_api.py
1515
// in this case show the target_classification CharField
1616
document.getElementById('div_id_target_classification').style.display = '';
1717
// and hide the grb_detector and grb_triggertime fields
18+
document.getElementById('div_id_grb_detector_choices').style.display = 'none';
1819
document.getElementById('div_id_grb_detector').style.display = 'none';
1920
document.getElementById('div_id_grb_triggertime').style.display = 'none';
2021
break;
2122
case 'GRB':
2223
// in this case show the grb_detector and grb_triggertime fields
23-
document.getElementById('div_id_grb_detector').style.display = '';
24+
document.getElementById('div_id_grb_detector_choices').style.display = '';
25+
// we do the other-please-specify dance if they want an Other GRB Detector
26+
const grb_detector_choice = document.getElementById('id_grb_detector_choices').options[document.getElementById('id_grb_detector_choices').selectedIndex].value;
27+
if (grb_detector_choice == 'Other (please specify)') {
28+
// in this case show the grb_detector CharField
29+
document.getElementById('div_id_grb_detector').style.display = '';
30+
} else {
31+
// in this case hide the grb_detector CharField
32+
document.getElementById('div_id_grb_detector').style.display = 'none';
33+
}
34+
2435
document.getElementById('div_id_grb_triggertime').style.display = '';
2536
// and hide the target_classification CharField
2637
document.getElementById('div_id_target_classification').style.display = 'none';
2738
break;
2839
default:
2940
// in this case hide all the extra fields
3041
document.getElementById('div_id_target_classification').style.display = 'none';
42+
document.getElementById('div_id_grb_detector_choices').style.display = 'none';
3143
document.getElementById('div_id_grb_detector').style.display = 'none';
3244
document.getElementById('div_id_grb_triggertime').style.display = 'none';
3345
break;
@@ -57,12 +69,19 @@
5769
// show the xrt_mode field; hide the UVOT fields
5870
document.getElementById('div_id_xrt_mode').style.display = '';
5971
document.getElementById('div_id_uvot_mode').style.display = 'none';
72+
document.getElementById('div_id_uvot_mode_choices').style.display = 'none';
6073
document.getElementById('div_id_uvot_just').style.display = 'none';
6174
break;
6275
case 'UVOT':
6376
console.log('UVOT instrument selected');
6477
// show the uvot_mode and uvot_just fields; hide the xrt_mode fields
65-
document.getElementById('div_id_uvot_mode').style.display = '';
78+
const uvot_mode = document.getElementById('id_uvot_mode_choices').options[document.getElementById('id_uvot_mode_choices').selectedIndex].value;
79+
if (uvot_mode == 'Other (please specify)') {
80+
document.getElementById('div_id_uvot_mode').style.display = '';
81+
} else {
82+
document.getElementById('div_id_uvot_mode').style.display = 'none';
83+
}
84+
document.getElementById('div_id_uvot_mode_choices').style.display = '';
6685
document.getElementById('div_id_uvot_just').style.display = '';
6786
document.getElementById('div_id_xrt_mode').style.display = 'none';
6887
break;
@@ -71,6 +90,7 @@
7190
// not sure what to show or hide here (hide everything?)
7291
document.getElementById('div_id_xrt_mode').style.display = 'none';
7392
document.getElementById('div_id_uvot_mode').style.display = 'none';
93+
document.getElementById('div_id_uvot_mode_choices').style.display = 'none';
7494
document.getElementById('div_id_uvot_just').style.display = 'none';
7595
break;
7696
}
@@ -108,6 +128,10 @@
108128
}
109129
};
110130

131+
function showExposureAccordianOnError() {
132+
const exposureAccordion = document.getElementById('exposure-visit-information');
133+
exposureAccordion.classList.add('show');
134+
}
111135
</script>
112136

113137
<script type="text/javascript">
@@ -120,7 +144,7 @@
120144
<!-- see also script element at end of file -->
121145

122146
{{ form|as_crispy_errors }}
123-
<h1>Submit Request to Neil Gehrels Swift Observatory</h1>
147+
<h1>Submit Request to Neil Gehrels Swift Observatory for <a href="{% url 'targets:detail' pk=target.id %}">{{target.name}}</a></h1>
124148

125149

126150
{% if target.type == 'SIDEREAL' %}
@@ -150,7 +174,7 @@ <h4>Resolved Target Information ({{ resolver }})</h4>
150174
</dl>
151175
<hr>
152176
<!-- display tom_swift Facility version -->
153-
<p><em>TOM Toolit Facility (<a href="https://github.com/TOMToolkit/tom_swift">tom_swift</a>) version {{ version }}</em></p>
177+
<p><em>TOM Toolkit Facility (<a target="_blank" href="https://github.com/TOMToolkit/tom_swift">tom_swift</a>) version {{ version }}</em></p>
154178
</div>
155179
<!-- Column 2 -->
156180
<div class="col-md-6">
@@ -180,19 +204,32 @@ <h4>Resolved Target Information ({{ resolver }})</h4>
180204
-->
181205
<script type="text/javascript">
182206
var el1 = document.getElementById("div_id_target_classification_choices");
183-
el1.addEventListener("click", showHideTargetClassificationFields);
207+
el1.addEventListener("change", showHideTargetClassificationFields);
184208

185209
var el2 = document.getElementById("div_id_instrument");
186-
el2.addEventListener("click", showHideInstrumentModeFields);
210+
el2.addEventListener("change", showHideInstrumentModeFields);
211+
212+
var el7 = document.getElementById("div_id_uvot_mode_choices");
213+
el7.addEventListener("change", showHideInstrumentModeFields);
187214

188215
var el3 = document.getElementById("div_id_num_of_visits");
189-
el3.addEventListener("click", showHideMonitoringFields);
216+
el3.addEventListener("change", showHideMonitoringFields);
190217

191218
var el4 = document.getElementById("div_id_tiling");
192-
el4.addEventListener("click", showHideTilingFields);
219+
el4.addEventListener("change", showHideTilingFields);
193220

194221
var el5 = document.getElementById("div_id_proposal");
195-
el5.addEventListener("click", showHideSwiftGIProposalFields);
222+
el5.addEventListener("change", showHideSwiftGIProposalFields);
223+
224+
var el6 = document.getElementById("div_id_grb_detector_choices");
225+
//el6.addEventListener("click", showHideGRBDetectionFields);
226+
el6.addEventListener("change", showHideTargetClassificationFields);
227+
228+
var el7 = document.getElementById("id_exposure");
229+
el7.addEventListener("invalid", showExposureAccordianOnError);
230+
231+
var el8 = document.getElementById("id_exp_time_just");
232+
el8.addEventListener("invalid", showExposureAccordianOnError);
196233
</script>
197234

198235
{% endblock %}

tom_swift/test_swift.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import unittest
2+
3+
4+
class SwiftFacilityTest(unittest.TestCase):
5+
6+
def test_something(self):
7+
expected = True
8+
actual = True
9+
self.assertEqual(expected, actual)
10+
11+
12+
if __name__ == '__main__':
13+
unittest.main()

0 commit comments

Comments
 (0)