dkist-processing-visp 2.20.14__py3-none-any.whl → 5.1.1__py3-none-any.whl

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.
Files changed (73) hide show
  1. dkist_processing_visp/__init__.py +1 -0
  2. dkist_processing_visp/config.py +1 -0
  3. dkist_processing_visp/models/constants.py +61 -20
  4. dkist_processing_visp/models/fits_access.py +20 -0
  5. dkist_processing_visp/models/metric_code.py +10 -0
  6. dkist_processing_visp/models/parameters.py +129 -24
  7. dkist_processing_visp/models/tags.py +22 -1
  8. dkist_processing_visp/models/task_name.py +1 -0
  9. dkist_processing_visp/parsers/map_repeats.py +1 -0
  10. dkist_processing_visp/parsers/modulator_states.py +1 -0
  11. dkist_processing_visp/parsers/polarimeter_mode.py +4 -2
  12. dkist_processing_visp/parsers/raster_step.py +4 -1
  13. dkist_processing_visp/parsers/spectrograph_configuration.py +75 -0
  14. dkist_processing_visp/parsers/time.py +24 -14
  15. dkist_processing_visp/parsers/visp_l0_fits_access.py +19 -8
  16. dkist_processing_visp/parsers/visp_l1_fits_access.py +1 -0
  17. dkist_processing_visp/tasks/__init__.py +1 -0
  18. dkist_processing_visp/tasks/assemble_movie.py +1 -0
  19. dkist_processing_visp/tasks/background_light.py +2 -1
  20. dkist_processing_visp/tasks/dark.py +5 -4
  21. dkist_processing_visp/tasks/geometric.py +132 -20
  22. dkist_processing_visp/tasks/instrument_polarization.py +128 -18
  23. dkist_processing_visp/tasks/l1_output_data.py +203 -0
  24. dkist_processing_visp/tasks/lamp.py +53 -93
  25. dkist_processing_visp/tasks/make_movie_frames.py +8 -6
  26. dkist_processing_visp/tasks/mixin/beam_access.py +1 -0
  27. dkist_processing_visp/tasks/mixin/corrections.py +54 -4
  28. dkist_processing_visp/tasks/mixin/downsample.py +1 -0
  29. dkist_processing_visp/tasks/parse.py +50 -17
  30. dkist_processing_visp/tasks/quality_metrics.py +5 -4
  31. dkist_processing_visp/tasks/science.py +126 -46
  32. dkist_processing_visp/tasks/solar.py +896 -456
  33. dkist_processing_visp/tasks/visp_base.py +4 -3
  34. dkist_processing_visp/tasks/write_l1.py +38 -10
  35. dkist_processing_visp/tests/conftest.py +145 -47
  36. dkist_processing_visp/tests/header_models.py +157 -20
  37. dkist_processing_visp/tests/local_trial_workflows/l0_cals_only.py +21 -78
  38. dkist_processing_visp/tests/local_trial_workflows/l0_polcals_as_science.py +421 -0
  39. dkist_processing_visp/tests/local_trial_workflows/l0_solar_gain_as_science.py +387 -0
  40. dkist_processing_visp/tests/local_trial_workflows/l0_to_l1.py +18 -75
  41. dkist_processing_visp/tests/local_trial_workflows/local_trial_helpers.py +346 -14
  42. dkist_processing_visp/tests/test_assemble_movie.py +2 -3
  43. dkist_processing_visp/tests/test_assemble_quality.py +89 -4
  44. dkist_processing_visp/tests/test_background_light.py +51 -44
  45. dkist_processing_visp/tests/test_dark.py +4 -3
  46. dkist_processing_visp/tests/test_downsample.py +1 -0
  47. dkist_processing_visp/tests/test_fits_access.py +43 -0
  48. dkist_processing_visp/tests/test_geometric.py +45 -4
  49. dkist_processing_visp/tests/test_instrument_polarization.py +72 -9
  50. dkist_processing_visp/tests/test_lamp.py +22 -26
  51. dkist_processing_visp/tests/test_make_movie_frames.py +4 -4
  52. dkist_processing_visp/tests/test_map_repeats.py +3 -1
  53. dkist_processing_visp/tests/test_parameters.py +122 -21
  54. dkist_processing_visp/tests/test_parse.py +164 -18
  55. dkist_processing_visp/tests/test_quality.py +3 -4
  56. dkist_processing_visp/tests/test_science.py +113 -15
  57. dkist_processing_visp/tests/test_solar.py +318 -99
  58. dkist_processing_visp/tests/test_visp_constants.py +38 -8
  59. dkist_processing_visp/tests/test_workflows.py +1 -0
  60. dkist_processing_visp/tests/test_write_l1.py +22 -3
  61. dkist_processing_visp/workflows/__init__.py +1 -0
  62. dkist_processing_visp/workflows/l0_processing.py +10 -3
  63. dkist_processing_visp/workflows/trial_workflows.py +8 -2
  64. dkist_processing_visp-5.1.1.dist-info/METADATA +552 -0
  65. dkist_processing_visp-5.1.1.dist-info/RECORD +94 -0
  66. {dkist_processing_visp-2.20.14.dist-info → dkist_processing_visp-5.1.1.dist-info}/WHEEL +1 -1
  67. docs/conf.py +5 -1
  68. docs/gain_correction.rst +52 -44
  69. docs/science_calibration.rst +7 -0
  70. dkist_processing_visp/tasks/mixin/line_zones.py +0 -115
  71. dkist_processing_visp-2.20.14.dist-info/METADATA +0 -196
  72. dkist_processing_visp-2.20.14.dist-info/RECORD +0 -89
  73. {dkist_processing_visp-2.20.14.dist-info → dkist_processing_visp-5.1.1.dist-info}/top_level.txt +0 -0
@@ -8,6 +8,7 @@ values.
8
8
  This is very nice, but it's important to understand that the kwargs matter beyond just setting header values; they
9
9
  actually control the output of the generators themselves.
10
10
  """
11
+
11
12
  import uuid
12
13
  from random import choice
13
14
  from random import random
@@ -30,6 +31,12 @@ class VispHeaders(Spec122Dataset):
30
31
  num_modstates_header_value: int = 2,
31
32
  instrument: str = "visp",
32
33
  polarimeter_mode: str = "observe_polarimetric",
34
+ arm_id: int = 1,
35
+ ip_start_time: str = "2022-11-28T13:00:00",
36
+ ip_end_time: str = "2022-11-28T13:00:00",
37
+ grating_constant: float = 316.0,
38
+ grating_angle: float = -69.9,
39
+ arm_position: float = -4.0,
33
40
  **kwargs,
34
41
  ):
35
42
  super().__init__(
@@ -39,14 +46,32 @@ class VispHeaders(Spec122Dataset):
39
46
  instrument=instrument,
40
47
  **kwargs,
41
48
  )
49
+ self.add_constant_key("VISP_001", arm_id)
42
50
  self.add_constant_key("WAVELNTH", 656.30)
43
51
  self.add_constant_key("VISP_010", num_modstates_header_value)
44
52
  self.add_constant_key("ID___013", "TEST_PROPOSAL_ID")
45
53
  self.add_constant_key("VISP_006", polarimeter_mode)
46
54
  self.add_constant_key("PAC__005", "0")
47
55
  self.add_constant_key("PAC__007", "10")
56
+ self.add_constant_key("DKIST011", ip_start_time)
57
+ self.add_constant_key("DKIST012", ip_end_time)
48
58
  self.add_constant_key("FILE_ID", uuid.uuid4().hex)
59
+
60
+ self.add_constant_key("VISP_002", arm_position)
61
+ self.add_constant_key("VISP_013", grating_constant)
62
+ self.add_constant_key("VISP_015", grating_angle)
63
+
49
64
  self.num_modstates_header_value = num_modstates_header_value
65
+ self.add_constant_key("CAM__001", "camera_id")
66
+ self.add_constant_key("CAM__002", "camera_name")
67
+ self.add_constant_key("CAM__003", 1)
68
+ self.add_constant_key("CAM__009", 1)
69
+ self.add_constant_key("CAM__010", 1)
70
+ self.add_constant_key("CAM__011", 1)
71
+ self.add_constant_key("CAM__012", 1)
72
+ self.add_constant_key("ID___014", "v1")
73
+ self.add_constant_key("TELTRACK", "Fixed Solar Rotation Tracking")
74
+ self.add_constant_key("TTBLTRCK", "fixed angle on sun")
50
75
 
51
76
  @key_function("VISP_011")
52
77
  def current_modstate(self, key: str):
@@ -72,6 +97,8 @@ class VispHeadersInputDarkFrames(VispHeaders):
72
97
  num_modstates: int,
73
98
  exp_time: float = 1.0,
74
99
  readout_exp_time: float = 2.0,
100
+ ip_start_time="2022-11-28T13:44:00",
101
+ ip_end_time="2022-11-28T13:45:00",
75
102
  **kwargs,
76
103
  ):
77
104
  ################################################
@@ -84,13 +111,13 @@ class VispHeadersInputDarkFrames(VispHeaders):
84
111
  array_shape,
85
112
  time_delta,
86
113
  num_modstates_header_value=num_modstates,
114
+ ip_start_time=ip_start_time,
115
+ ip_end_time=ip_end_time,
87
116
  **kwargs,
88
117
  )
89
118
  self.add_constant_key("DKIST004", TaskName.dark.value.lower())
90
119
  self.add_constant_key("DKIST008", 1)
91
120
  self.add_constant_key("DKIST009", 1)
92
- self.add_constant_key("DKIST011", "2022-11-28T13:44:00")
93
- self.add_constant_key("DKIST012", "2022-11-28T13:45:00")
94
121
  self.add_constant_key("VISP_019", 1) # Num raster steps
95
122
  self.add_constant_key("VISP_020", 1) # Current raster step
96
123
  self.add_constant_key("ID___004")
@@ -100,6 +127,12 @@ class VispHeadersInputDarkFrames(VispHeaders):
100
127
  self.add_constant_key("CAM__004", exp_time)
101
128
  self.add_constant_key("CAM__005", readout_exp_time)
102
129
  self.add_constant_key("CAM__014", 10) # Num frames per FPA
130
+ self.add_constant_key("TELSCAN", "Raster")
131
+ self.add_constant_key("PAC__002", "lamp")
132
+ self.add_constant_key("PAC__003", "on")
133
+ self.add_constant_key("PAC__004", "Sapphire Polarizer")
134
+ self.add_constant_key("PAC__006", "SiO2 OC")
135
+ self.add_constant_key("PAC__008", "FieldStop (5arcmin)")
103
136
 
104
137
  @key_function("VISP_011")
105
138
  def current_modstate(self, key: str) -> int:
@@ -114,6 +147,8 @@ class VispHeadersInputLampGainFrames(VispHeaders):
114
147
  num_modstates: int,
115
148
  exp_time: float = 10.0,
116
149
  readout_exp_time: float = 20.0,
150
+ ip_start_time="2022-11-28T13:46:00",
151
+ ip_end_time="2022-11-28T13:47:00",
117
152
  **kwargs,
118
153
  ):
119
154
  ################################################
@@ -126,14 +161,14 @@ class VispHeadersInputLampGainFrames(VispHeaders):
126
161
  array_shape,
127
162
  time_delta,
128
163
  num_modstates_header_value=num_modstates,
164
+ ip_start_time=ip_start_time,
165
+ ip_end_time=ip_end_time,
129
166
  **kwargs,
130
167
  )
131
168
  self.add_constant_key("DKIST004", TaskName.gain.value.lower())
132
169
  self.add_constant_key("PAC__002", "lamp")
133
170
  self.add_constant_key("DKIST008", 1)
134
171
  self.add_constant_key("DKIST009", 1)
135
- self.add_constant_key("DKIST011", "2022-11-28T13:46:00")
136
- self.add_constant_key("DKIST012", "2022-11-28T13:47:00")
137
172
  self.add_constant_key("VISP_019", 1)
138
173
  self.add_constant_key("VISP_020", 1)
139
174
  self.add_constant_key("PAC__003", "on")
@@ -155,6 +190,8 @@ class VispHeadersInputSolarGainFrames(VispHeaders):
155
190
  num_modstates: int,
156
191
  exp_time: float = 20.0,
157
192
  readout_exp_time: float = 40.0,
193
+ ip_start_time="2022-11-28T13:48:00",
194
+ ip_end_time="2022-11-28T13:49:00",
158
195
  **kwargs,
159
196
  ):
160
197
  ################################################
@@ -167,16 +204,20 @@ class VispHeadersInputSolarGainFrames(VispHeaders):
167
204
  array_shape,
168
205
  time_delta,
169
206
  num_modstates_header_value=num_modstates,
207
+ ip_start_time=ip_start_time,
208
+ ip_end_time=ip_end_time,
170
209
  **kwargs,
171
210
  )
172
211
  self.add_constant_key("DKIST004", TaskName.gain.value.lower())
173
212
  self.add_constant_key("DKIST008", 1)
174
213
  self.add_constant_key("DKIST009", 1)
175
- self.add_constant_key("DKIST011", "2022-11-28T13:48:00")
176
- self.add_constant_key("DKIST012", "2022-11-28T13:49:00")
177
214
  self.add_constant_key("VISP_019", 1)
178
215
  self.add_constant_key("VISP_020", 1)
179
216
  self.add_constant_key("PAC__002", "clear")
217
+ self.add_constant_key("PAC__003", "off")
218
+ self.add_constant_key("PAC__004", "clear")
219
+ self.add_constant_key("PAC__006", "clear")
220
+ self.add_constant_key("PAC__008", "FieldStop (5arcmin)")
180
221
  self.add_constant_key("TELSCAN", "Raster")
181
222
  self.add_constant_key("ID___004")
182
223
  self.add_constant_key("CAM__004", exp_time)
@@ -197,6 +238,8 @@ class VispHeadersInputPolcalFrames(VispHeaders):
197
238
  num_cs_steps: int = 1,
198
239
  exp_time: float = 0.01,
199
240
  readout_exp_time: float = 0.02,
241
+ ip_start_time="2022-11-28T13:50:00",
242
+ ip_end_time="2022-11-28T13:51:00",
200
243
  **kwargs,
201
244
  ):
202
245
  ################################################
@@ -209,31 +252,36 @@ class VispHeadersInputPolcalFrames(VispHeaders):
209
252
  array_shape,
210
253
  time_delta,
211
254
  num_modstates_header_value=num_modstates,
255
+ ip_start_time=ip_start_time,
256
+ ip_end_time=ip_end_time,
212
257
  **kwargs,
213
258
  )
214
259
  self.index_to_modstate = list(range(1, num_modstates + 1)) * num_cs_steps
215
260
  self.index_to_cs_step = sum([[c] * num_modstates for c in range(num_cs_steps)], [])
216
261
  self.polarizer_choices = ["Sapphire Polarizer", "clear"]
217
- self.retarder_choices = ["SiO2 SAR", "clear"]
262
+ self.retarder_choices = ["SiO2 OC", "clear"]
218
263
 
219
264
  self.add_constant_key("DKIST004", TaskName.polcal.value.lower())
220
265
  self.add_constant_key("DKIST008", 1)
221
266
  self.add_constant_key("DKIST009", 1)
222
- self.add_constant_key("DKIST011", "2022-11-28T13:50:00")
223
- self.add_constant_key("DKIST012", "2022-11-28T13:51:00")
224
267
  self.add_constant_key("VISP_019", 1)
225
268
  self.add_constant_key("VISP_020", 1)
226
269
  self.add_constant_key("TELSCAN", "Raster")
227
270
  self.add_constant_key("ID___004")
228
271
  self.add_constant_key("PAC__004", "Sapphire Polarizer")
229
272
  self.add_constant_key("PAC__005", "60.")
230
- self.add_constant_key("PAC__006", "clear")
231
273
  self.add_constant_key("PAC__007", "0.0")
232
274
  self.add_constant_key("PAC__008", "FieldStop (5arcmin)")
233
275
  self.add_constant_key("CAM__004", exp_time)
234
276
  self.add_constant_key("CAM__005", readout_exp_time)
235
277
  self.add_constant_key("CAM__014", 10)
236
278
 
279
+ @key_function("PAC__006")
280
+ def retarder_name(self, key: str) -> str:
281
+ if self.index % 2:
282
+ return self.retarder_choices[1]
283
+ return self.retarder_choices[0]
284
+
237
285
  @property
238
286
  def current_cs_step(self) -> int:
239
287
  # There is no header value for CS step; this property is used to help data generator fixtures with tagging
@@ -251,15 +299,89 @@ class VispHeadersInputPolcalFrames(VispHeaders):
251
299
  def pol_angle(self, key: str) -> float:
252
300
  return random() * 120.0
253
301
 
254
- @key_function("PAC__006")
255
- def retarder(self, key: str) -> str:
256
- return choice(self.retarder_choices)
257
-
258
302
  @key_function("PAC__007")
259
303
  def ret_angle(self, key: str) -> float:
260
304
  return random() * 120.0
261
305
 
262
306
 
307
+ class VispHeadersInputPolcalDarkFrames(VispHeaders):
308
+ def __init__(
309
+ self,
310
+ array_shape: tuple[int, ...],
311
+ time_delta: float,
312
+ num_modstates: int,
313
+ exp_time: float = 0.01,
314
+ readout_exp_time: float = 0.02,
315
+ ip_start_time="2022-11-28T13:50:00",
316
+ ip_end_time="2022-11-28T13:51:00",
317
+ **kwargs,
318
+ ):
319
+ num_frames = num_modstates
320
+ dataset_shape = (num_frames, *array_shape[-2:])
321
+ super().__init__(
322
+ dataset_shape,
323
+ array_shape,
324
+ time_delta,
325
+ ip_start_time=ip_start_time,
326
+ ip_end_time=ip_end_time,
327
+ **kwargs,
328
+ )
329
+ self.add_constant_key("DKIST004", TaskName.polcal.value.lower())
330
+ self.add_constant_key("DKIST008", 1)
331
+ self.add_constant_key("DKIST009", 1)
332
+ self.add_constant_key("VISP_019", 1)
333
+ self.add_constant_key("VISP_020", 1)
334
+ self.add_constant_key("TELSCAN", "Raster")
335
+ self.add_constant_key("ID___004")
336
+ self.add_constant_key("PAC__004", "clear")
337
+ self.add_constant_key("PAC__005", "60.")
338
+ self.add_constant_key("PAC__006", "clear")
339
+ self.add_constant_key("PAC__007", "0.0")
340
+ self.add_constant_key("PAC__008", "DarkShutter")
341
+ self.add_constant_key("CAM__004", exp_time)
342
+ self.add_constant_key("CAM__005", readout_exp_time)
343
+ self.add_constant_key("CAM__014", 10)
344
+
345
+
346
+ class VispHeadersInputPolcalGainFrames(VispHeaders):
347
+ def __init__(
348
+ self,
349
+ array_shape: tuple[int, ...],
350
+ time_delta: float,
351
+ num_modstates: int,
352
+ exp_time: float = 0.01,
353
+ readout_exp_time: float = 0.02,
354
+ ip_start_time="2022-11-28T13:50:00",
355
+ ip_end_time="2022-11-28T13:51:00",
356
+ **kwargs,
357
+ ):
358
+ num_frames = num_modstates
359
+ dataset_shape = (num_frames, *array_shape[-2:])
360
+ super().__init__(
361
+ dataset_shape,
362
+ array_shape,
363
+ time_delta,
364
+ ip_start_time=ip_start_time,
365
+ ip_end_time=ip_end_time,
366
+ **kwargs,
367
+ )
368
+ self.add_constant_key("DKIST004", TaskName.polcal.value.lower())
369
+ self.add_constant_key("DKIST008", 1)
370
+ self.add_constant_key("DKIST009", 1)
371
+ self.add_constant_key("VISP_019", 1)
372
+ self.add_constant_key("VISP_020", 1)
373
+ self.add_constant_key("TELSCAN", "Raster")
374
+ self.add_constant_key("ID___004")
375
+ self.add_constant_key("PAC__004", "clear")
376
+ self.add_constant_key("PAC__005", "60.")
377
+ self.add_constant_key("PAC__006", "clear")
378
+ self.add_constant_key("PAC__007", "0.0")
379
+ self.add_constant_key("PAC__008", "FieldStop (5arcmin)")
380
+ self.add_constant_key("CAM__004", exp_time)
381
+ self.add_constant_key("CAM__005", readout_exp_time)
382
+ self.add_constant_key("CAM__014", 10)
383
+
384
+
263
385
  class VispHeadersValidObserveFrames(VispHeaders):
264
386
  def __init__(
265
387
  self,
@@ -271,6 +393,9 @@ class VispHeadersValidObserveFrames(VispHeaders):
271
393
  exp_time: float = 15.0,
272
394
  readout_exp_time: float = 30.0,
273
395
  abort_last_step: bool = False,
396
+ ip_start_time="2022-11-28T13:55:00",
397
+ ip_end_time="2022-11-28T13:56:00",
398
+ grating_constant=316,
274
399
  **kwargs,
275
400
  ):
276
401
  ################################################
@@ -284,7 +409,15 @@ class VispHeadersValidObserveFrames(VispHeaders):
284
409
  num_frames -= num_dropped_frames
285
410
 
286
411
  dataset_shape = (num_frames, *array_shape[-2:])
287
- super().__init__(dataset_shape, array_shape, time_delta, **kwargs)
412
+ super().__init__(
413
+ dataset_shape,
414
+ array_shape,
415
+ time_delta,
416
+ ip_start_time=ip_start_time,
417
+ ip_end_time=ip_end_time,
418
+ grating_constant=grating_constant,
419
+ **kwargs,
420
+ )
288
421
 
289
422
  self.index_to_map = sum(
290
423
  [[map_num + 1] * num_modstates * num_raster_steps for map_num in range(num_maps)], []
@@ -305,8 +438,6 @@ class VispHeadersValidObserveFrames(VispHeaders):
305
438
 
306
439
  self.num_raster_steps = num_raster_steps
307
440
  self.add_constant_key("DKIST004", TaskName.observe.value.lower())
308
- self.add_constant_key("DKIST011", "2022-11-28T13:55:00") # IP start time
309
- self.add_constant_key("DKIST012", "2022-11-28T13:56:00") # IP end time
310
441
  self.add_constant_key("ID___004")
311
442
  self.add_constant_key("WAVELNTH", 656.28)
312
443
  self.add_constant_key("EXPER_ID", "EXPERIMENT ID")
@@ -353,6 +484,8 @@ class VispHeadersValidCalibratedFrames(VispHeaders):
353
484
  exp_time: float = 15.0,
354
485
  readout_exp_time: float = 30.0,
355
486
  wcs_axis_names: tuple[str, str] | None = None,
487
+ ip_start_time="2022-11-28T13:55:00",
488
+ ip_end_time="2022-11-28T13:56:00",
356
489
  **kwargs,
357
490
  ):
358
491
  ################################################
@@ -366,7 +499,13 @@ class VispHeadersValidCalibratedFrames(VispHeaders):
366
499
  num_frames = num_maps * num_raster_steps * num_stokes
367
500
  dataset_shape = (num_frames, *array_shape[-2:])
368
501
  super().__init__(
369
- dataset_shape, array_shape, time_delta, polarimeter_mode=polarimeter_mode, **kwargs
502
+ dataset_shape,
503
+ array_shape,
504
+ time_delta,
505
+ polarimeter_mode=polarimeter_mode,
506
+ ip_start_time=ip_start_time,
507
+ ip_end_time=ip_end_time,
508
+ **kwargs,
370
509
  )
371
510
 
372
511
  stokes_list = ["I", "Q", "U", "V"][:num_stokes]
@@ -380,8 +519,6 @@ class VispHeadersValidCalibratedFrames(VispHeaders):
380
519
 
381
520
  self.num_raster_steps = num_raster_steps
382
521
  self.add_constant_key("DKIST004", TaskName.observe.value.lower())
383
- self.add_constant_key("DKIST011", "2022-11-28T13:55:00") # IP start time
384
- self.add_constant_key("DKIST012", "2022-11-28T13:56:00") # IP end time
385
522
  self.add_constant_key("ID___004")
386
523
  self.add_constant_key("WAVELNTH", 656.28)
387
524
  self.add_constant_key("EXPER_ID", "EXPERIMENT ID")
@@ -4,12 +4,11 @@ import os
4
4
  import sys
5
5
  from dataclasses import asdict
6
6
  from datetime import datetime
7
- from pathlib import Path
8
7
  from random import randint
9
8
 
10
- from astropy.io import fits
11
- from dkist_header_validator import spec122_validator
9
+ from dkist_processing_common.codecs.basemodel import basemodel_encoder
12
10
  from dkist_processing_common.manual import ManualProcessing
11
+ from dkist_processing_common.models.input_dataset import InputDatasetPartDocumentList
13
12
  from dkist_processing_common.tasks import WorkflowTaskBase
14
13
  from dkist_service_configuration.logging import logger
15
14
 
@@ -38,15 +37,19 @@ from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers impor
38
37
  from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import SaveInstPolCal
39
38
  from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import SaveLampCal
40
39
  from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import SaveSolarCal
41
- from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import (
42
- set_observe_wavelength_task,
43
- )
44
40
  from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import SetNumModstates
45
41
  from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import SetObserveExpTime
46
42
  from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import (
47
43
  SetObserveIpStartTime,
48
44
  )
49
45
  from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import SetPolarimeterMode
46
+ from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import (
47
+ set_observe_wavelength_task,
48
+ )
49
+ from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import tag_inputs_task
50
+ from dkist_processing_visp.tests.local_trial_workflows.local_trial_helpers import (
51
+ translate_122_to_214l0_task,
52
+ )
50
53
 
51
54
 
52
55
  class DatetimeEncoder(json.JSONEncoder):
@@ -61,43 +64,19 @@ class DatetimeEncoder(json.JSONEncoder):
61
64
  return super().default(obj)
62
65
 
63
66
 
64
- class Translate122To214L0(WorkflowTaskBase):
65
- def run(self) -> None:
66
- raw_dir = Path(self.scratch.scratch_base_path) / f"VISP{self.recipe_run_id:03n}"
67
- if not os.path.exists(self.scratch.workflow_base_path):
68
- os.makedirs(self.scratch.workflow_base_path)
69
-
70
- if not raw_dir.exists():
71
- raise FileNotFoundError(
72
- f"Expected to find a raw VISP{{run_id:03n}} folder in {self.scratch.scratch_base_path}"
73
- )
74
-
75
- for file in raw_dir.glob("*.FITS"):
76
- translated_file_name = Path(self.scratch.workflow_base_path) / os.path.basename(file)
77
- logger.info(f"Translating {file} -> {translated_file_name}")
78
- hdl = fits.open(file)
79
-
80
- header = spec122_validator.validate_and_translate_to_214_l0(
81
- hdl[0].header, return_type=fits.HDUList
82
- )[0].header
83
-
84
- comp_hdu = fits.CompImageHDU(header=header, data=hdl[0].data)
85
- comp_hdl = fits.HDUList([fits.PrimaryHDU(), comp_hdu])
86
- comp_hdl.writeto(translated_file_name, overwrite=True)
87
-
88
- hdl.close()
89
- del hdl
90
- comp_hdl.close()
91
- del comp_hdl
92
-
93
-
94
67
  class CreateInputDatasetParameterDocument(WorkflowTaskBase):
95
68
  def run(self) -> None:
96
- doc_path = self.scratch.workflow_base_path / "input_dataset_parameters.json"
97
- with open(doc_path, "w") as f:
98
- f.write(json.dumps(self.input_dataset_document_simple_parameters_part))
99
- self.tag(doc_path, VispTag.input_dataset_parameters())
100
- logger.info(f"Wrote input dataset doc to {doc_path}")
69
+ relative_path = "input_dataset_parameters.json"
70
+ self.write(
71
+ data=InputDatasetPartDocumentList(
72
+ doc_list=self.input_dataset_document_simple_parameters_part
73
+ ),
74
+ relative_path=relative_path,
75
+ tags=VispTag.input_dataset_parameters(),
76
+ encoder=basemodel_encoder,
77
+ overwrite=True,
78
+ )
79
+ logger.info(f"Wrote input dataset parameter doc to {relative_path}")
101
80
 
102
81
  @property
103
82
  def input_dataset_document_simple_parameters_part(self):
@@ -121,37 +100,6 @@ class CreateInputDatasetParameterDocument(WorkflowTaskBase):
121
100
  return parameters_list
122
101
 
123
102
 
124
- def tag_inputs_task(suffix: str):
125
- class TagInputs(WorkflowTaskBase):
126
- def run(self) -> None:
127
- logger.info(f"Looking in {os.path.abspath(self.scratch.workflow_base_path)}")
128
- input_file_list = list(self.scratch.workflow_base_path.glob(f"*.{suffix}"))
129
- if len(input_file_list) == 0:
130
- raise FileNotFoundError(
131
- f"Did not find any files matching '*.{suffix}' in {self.scratch.workflow_base_path}"
132
- )
133
- for file in input_file_list:
134
- logger.info(f"Found {file}")
135
- self.tag(path=file, tags=[VispTag.input(), VispTag.frame()])
136
-
137
- return TagInputs
138
-
139
-
140
- def setup_APM_config() -> None:
141
- mesh_config = {
142
- "system-monitoring-log-apm": {
143
- "mesh_address": "system-monitoring-log-apm.service.sim.consul",
144
- "mesh_port": 8200,
145
- },
146
- "automated-processing-scratch-inventory": {"mesh_address": "localhost", "mesh_port": 6379},
147
- "internal-api-gateway": {"mesh_address": "localhost", "mesh_port": 80},
148
- }
149
- apm_options = {"TRANSACTION_MAX_SPANS": 10000}
150
- os.environ["MESH_CONFIG"] = json.dumps(mesh_config)
151
- os.environ["ELASTIC_APM_ENABLED"] = "true"
152
- os.environ["ELASTIC_APM_OTHER_OPTIONS"] = json.dumps(apm_options)
153
-
154
-
155
103
  def main(
156
104
  scratch_path: str,
157
105
  suffix: str = "FITS",
@@ -165,11 +113,8 @@ def main(
165
113
  load_geometric: bool = False,
166
114
  load_solar: bool = False,
167
115
  load_inst_pol: bool = False,
168
- use_apm: bool = False,
169
116
  dummy_wavelength: float = 630.0,
170
117
  ):
171
- if use_apm:
172
- setup_APM_config()
173
118
  with ManualProcessing(
174
119
  workflow_path=scratch_path,
175
120
  recipe_run_id=recipe_run_id,
@@ -178,7 +123,7 @@ def main(
178
123
  workflow_version="GROGU",
179
124
  ) as manual_processing_run:
180
125
  if not skip_translation:
181
- manual_processing_run.run_task(task=Translate122To214L0)
126
+ manual_processing_run.run_task(task=translate_122_to_214l0_task(suffix=suffix))
182
127
  if only_translate:
183
128
  return
184
129
  manual_processing_run.run_task(task=CreateInputDatasetParameterDocument)
@@ -302,7 +247,6 @@ if __name__ == "__main__":
302
247
  help="Load instrument polarization calibration from previously saved run",
303
248
  action="store_true",
304
249
  )
305
- parser.add_argument("-A", "--use-apm", help="Send APM spans to SIM", action="store_true")
306
250
  args = parser.parse_args()
307
251
  sys.exit(
308
252
  main(
@@ -318,6 +262,5 @@ if __name__ == "__main__":
318
262
  load_geometric=args.load_geometric,
319
263
  load_solar=args.load_solar,
320
264
  load_inst_pol=args.load_inst_pol,
321
- use_apm=args.use_apm,
322
265
  )
323
266
  )