-
Notifications
You must be signed in to change notification settings - Fork 8
/
instrumentconfig.vue
394 lines (389 loc) · 14.1 KB
/
instrumentconfig.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<template>
<panel :show="show"
title="Instrument Configuration"
icon="fas fa-camera-retro"
:id="'instrumentconfig' + $parent.$parent.$parent.index + $parent.index + index"
:index="index"
:errors="errors"
:canremove="this.index > 0"
:cancopy="true"
@remove="$emit('remove')"
@copy="$emit('copy')"
@show="show = $event"
>
<customalert
v-for="error in topLevelErrors"
:key="error"
alertclass="danger"
:dismissible="false"
>
{{ error }}
</customalert>
<b-container class="p-0">
<b-row>
<b-col md="6" v-show="show">
<ul>
<li>
Try the
<a href=" https://exposure-time-calculator.lco.global/" target="_blank">
online Exposure Time Calculator.
</a>
</li>
</ul>
</b-col>
<b-col :md="show ? 6 : 12">
<b-form>
<customfield
v-model="instrumentconfig.exposure_count"
label="Exposure Count"
field="exposure_count"
type="number"
:errors="errors.exposure_count"
desc="Clicking the 'Fill' button will set the exposure count to the number of
exposures (including overheads) that will fit in the largest observing window.
This button is disabled until the entire observation request has passed validation."
@input="update"
>
<b-input-group-append slot="inline-input">
<b-button
@click="instrumentConfigurationfillWindow"
:disabled="duration_data.duration > 0 ? false : true"
>
Fill
</b-button>
</b-input-group-append>
</customfield>
<customfield
v-model="instrumentconfig.exposure_time"
label="Exposure Time"
field="exposure_time"
:errors="errors.exposure_time"
desc="Seconds"
@input="update"
>
<div
slot="extra-help-text"
v-if="suggestedLampFlatSlitExposureTime"
>
Suggested exposure time for a Lamp Flat with
slit {{ instrumentconfig.optical_elements.slit }} and readout mode {{ instrumentconfig.mode }}
is <strong>{{ suggestedLampFlatSlitExposureTime }} seconds</strong>
</div>
<div
slot="extra-help-text"
v-else-if="suggestedArcExposureTime"
>
Suggested exposure time for an Arc is <strong>{{ suggestedArcExposureTime }} seconds</strong>
</div>
</customfield>
<customselect
v-if="readoutModeOptions.length > 1"
v-model="instrumentconfig.mode"
label="Readout Mode"
field="readout_mode"
:options="readoutModeOptions"
:errors="errors.mode"
@input="update"
/>
<div
v-for="opticalElementGroup in availableOpticalElementGroups"
:key="opticalElementGroup.type"
>
<customselect
v-model="instrumentconfig.optical_elements[opticalElementGroup.type]"
:label="opticalElementGroup.label"
:field="opticalElementGroup.type"
:options="opticalElementGroup.options"
:lowerOptions="true"
:errors="{}"
@input="updateOpticalElement"
/>
</div>
<div v-if="rotatorModeOptions.length > 0">
<customselect
v-model="instrumentconfig.rotator_mode"
label="Rotator Mode"
desc="The slit position. At the parallactic slit angle, atmospheric dispersion is along the slit."
:errors="errors.rotator_mode"
:options="rotatorModeOptions"
@input="update"
/>
<!-- TODO: Validate required field values -->
<customfield
v-for="field in requiredRotatorModeFields"
:key="field"
v-model="instrumentconfig.extra_params[field]"
:label="field | formatField"
:errors="null"
:desc="field | getFieldDescription"
@input="updateInstrumentConfigExtraParam($event, field)"
/>
</div>
<!-- TODO: Validate to make sure this is a floating point number -->
<customfield
v-if="datatype == 'IMAGE' && !simple_interface"
v-model="defocus"
label="Defocus"
field="defocus"
:errors="null"
desc="Observations may be defocused to prevent the CCD from saturating on bright targets. This
term describes the offset (in mm) of the secondary mirror from its default (focused)
position. The limits are ± 3mm."
@input="update"
/>
</b-form>
</b-col>
</b-row>
</b-container>
</panel>
</template>
<script>
import _ from 'lodash';
import {
collapseMixin,
lampFlatDefaultExposureTime,
arcDefaultExposureTime,
extractTopLevelErrors
} from '../utils.js';
import customfield from './util/customfield.vue';
import customselect from './util/customselect.vue';
import panel from './util/panel.vue';
import customalert from './util/customalert.vue';
export default {
props: [
'errors',
'index',
'simple_interface',
'available_instruments',
'selectedinstrument',
'datatype',
'configurationType',
'instrumentconfig',
'show',
'duration_data'
],
components: {
customfield,
customselect,
panel,
customalert
},
mixins: [
collapseMixin
],
data: function() {
return {
defocus: 0,
opticalElementUpdates: 0
}
},
mounted: function() {
// If a draft is loaded in that has a defocus set in the extra_params, update the defocus
// here since extra_params is not reactive and cannot be watched
if (this.instrumentconfig.extra_params.defocus) {
this.defocus = this.instrumentconfig.extra_params.defocus;
}
},
computed: {
topLevelErrors: function() {
return extractTopLevelErrors(this.errors);
},
instrumentHasRotatorModes: function() {
return this.available_instruments[this.selectedinstrument] && 'rotator' in this.available_instruments[this.selectedinstrument].modes;
},
instrumentHasReadoutModes: function() {
return this.available_instruments[this.selectedinstrument] && 'readout' in this.available_instruments[this.selectedinstrument].modes;
},
readoutModeOptions: function() {
if (this.selectedinstrument in this.available_instruments && this.instrumentHasReadoutModes) {
let readoutModes = [];
for (let rm in this.available_instruments[this.selectedinstrument].modes.readout.modes) {
readoutModes.push({
text: this.available_instruments[this.selectedinstrument].modes.readout.modes[rm].name,
value: this.available_instruments[this.selectedinstrument].modes.readout.modes[rm].code,
binning: this.available_instruments[this.selectedinstrument].modes.readout.modes[rm].params.binning
});
}
return readoutModes;
} else {
return [];
}
},
availableOpticalElementGroups: function() {
if (this.simple_interface) {
return {
filters: {
type: 'filter',
label: 'Filter',
options: [
{value: 'b', text: 'Blue'},
{value: 'v', text: 'Green'},
{value: 'rp', text: 'Red'}
]
}
}
} else if (this.selectedinstrument in this.available_instruments) {
let oe_groups = {};
for (let oe_group_type in this.available_instruments[this.selectedinstrument].optical_elements) {
// Each optical element group type has an 's' on the end, but the optical element that is
// submitted in the optical_elements should have a key that is the same as a group, without the 's'
let oe_type = oe_group_type.substring(0, oe_group_type.length - 1);
oe_groups[oe_type] = {};
oe_groups[oe_type]['type'] = oe_type;
oe_groups[oe_type]['label'] = _.capitalize(oe_type);
let elements = [];
for (let element in this.available_instruments[this.selectedinstrument].optical_elements[oe_group_type]) {
if (this.available_instruments[this.selectedinstrument].optical_elements[oe_group_type][element].schedulable) {
elements.push({
value: this.available_instruments[this.selectedinstrument].optical_elements[oe_group_type][element].code,
text: this.available_instruments[this.selectedinstrument].optical_elements[oe_group_type][element].name
});
}
}
oe_groups[oe_type]['options'] = _.sortBy(elements, 'text');
}
return oe_groups;
} else {
return [];
}
},
rotatorModeOptions: function() {
let options = [];
let requiredModeFields = [];
if (this.instrumentHasRotatorModes) {
let modes = this.available_instruments[this.selectedinstrument].modes.rotator.modes;
for (let i in modes) {
requiredModeFields = [];
if ('required_fields' in modes[i].params) {
for (let j in modes[i].params.required_fields) {
requiredModeFields.push(
modes[i].params.required_fields[j]
)
}
}
options.push({
value: modes[i].code,
text: modes[i].name,
requiredFields: requiredModeFields
});
}
}
return options;
},
requiredRotatorModeFields: function() {
for (let i in this.rotatorModeOptions) {
if (this.rotatorModeOptions[i].value == this.instrumentconfig.rotator_mode) {
return this.rotatorModeOptions[i].requiredFields;
}
}
return [];
},
suggestedLampFlatSlitExposureTime: function() {
// Update on optical element updates
this.opticalElementUpdates;
let slitWidth = this.instrumentconfig.optical_elements.slit;
let readoutMode = this.instrumentconfig.mode;
if (this.configurationType === 'LAMP_FLAT' && slitWidth && readoutMode && this.selectedinstrument) {
return lampFlatDefaultExposureTime(slitWidth, this.selectedinstrument, readoutMode);
} else {
return undefined;
}
},
suggestedArcExposureTime: function() {
if (this.configurationType === 'ARC' && this.selectedinstrument) {
return arcDefaultExposureTime(this.selectedinstrument);
} else {
return undefined;
}
}
},
methods: {
update: function() {
this.$emit('instrumentconfigupdate');
},
updateInstrumentConfigExtraParam: function(value, field) {
if (value === '') {
// Remove the field if an empty value is entered because the validation
// for required extra params only check if the field exists
this.instrumentconfig.extra_params[field] = undefined;
}
this.update();
},
updateOpticalElement: function() {
// The optical element fields are not reactive as they change/ are deleted/ don't exist on start.
// Increment this reactive variable to watch for changed to the optical elements
this.opticalElementUpdates += 1;
this.update();
},
updateBinning: function() {
for (let mode in this.readoutModeOptions) {
if (this.instrumentconfig.mode === this.readoutModeOptions[mode].value) {
this.instrumentconfig.bin_x = this.readoutModeOptions[mode].binning;
this.instrumentconfig.bin_y = this.readoutModeOptions[mode].binning;
this.update();
return;
}
}
},
instrumentConfigurationfillWindow: function() {
this.$emit('instrumentconfigurationfillwindow', this.index);
}
},
watch: {
'instrumentconfig.mode': function() {
this.updateBinning();
},
rotatorModeOptions: function() {
if (this.instrumentHasRotatorModes) {
this.instrumentconfig.rotator_mode = this.available_instruments[this.selectedinstrument].modes.rotator.default;
} else {
this.instrumentconfig.rotator_mode = '';
}
this.update();
},
requiredRotatorModeFields: function(newValue, oldValue) {
// TODO: Implement rotator mode and required rotator mode fields history
const defaultRequiredFieldValue = 0;
for (let idx in oldValue) {
this.instrumentconfig.extra_params[oldValue[idx]] = undefined;
}
for (let idx in newValue) {
this.instrumentconfig.extra_params[newValue[idx]] = defaultRequiredFieldValue;
}
this.update();
},
readoutModeOptions: function() {
// TODO: Implement history
this.instrumentconfig.mode = this.available_instruments[this.selectedinstrument].modes.readout.default;
this.updateBinning();
this.update();
},
availableOpticalElementGroups: function(value) {
// TODO: Implement optical element history
this.instrumentconfig.optical_elements = {};
if (this.simple_interface) {
this.instrumentconfig.optical_elements.filter = 'b';
} else {
for (let oe_type in value) {
if (value[oe_type]['options'].length > 0) {
this.instrumentconfig.optical_elements[oe_type] = value[oe_type]['options'][0].value;
}
}
}
this.updateOpticalElement();
},
defocus: function(value) {
this.instrumentconfig.extra_params.defocus = value || undefined;
this.update();
},
datatype: function(value) {
if (value === 'IMAGE') {
this.instrumentconfig.extra_params.defocus = this.defocus;
} else {
this.instrumentconfig.extra_params.defocus = undefined;
}
this.update();
}
}
}
</script>