imap-processing 0.19.0__py3-none-any.whl → 0.19.3__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.

Potentially problematic release.


This version of imap-processing might be problematic. Click here for more details.

Files changed (73) hide show
  1. imap_processing/_version.py +2 -2
  2. imap_processing/cdf/config/imap_codice_global_cdf_attrs.yaml +6 -0
  3. imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml +31 -894
  4. imap_processing/cdf/config/imap_codice_l1b_variable_attrs.yaml +279 -255
  5. imap_processing/cdf/config/imap_enamaps_l2-common_variable_attrs.yaml +55 -0
  6. imap_processing/cdf/config/imap_enamaps_l2-healpix_variable_attrs.yaml +29 -0
  7. imap_processing/cdf/config/imap_enamaps_l2-rectangular_variable_attrs.yaml +32 -0
  8. imap_processing/cdf/config/imap_glows_l1b_variable_attrs.yaml +3 -1
  9. imap_processing/cdf/config/imap_lo_global_cdf_attrs.yaml +5 -4
  10. imap_processing/cdf/config/imap_ultra_global_cdf_attrs.yaml +28 -16
  11. imap_processing/cdf/config/imap_ultra_l1b_variable_attrs.yaml +33 -31
  12. imap_processing/cdf/config/imap_ultra_l1c_variable_attrs.yaml +61 -1
  13. imap_processing/cli.py +62 -71
  14. imap_processing/codice/codice_l0.py +2 -1
  15. imap_processing/codice/codice_l1a.py +47 -49
  16. imap_processing/codice/codice_l1b.py +42 -32
  17. imap_processing/codice/codice_l2.py +105 -7
  18. imap_processing/codice/constants.py +50 -8
  19. imap_processing/codice/data/lo_stepping_values.csv +1 -1
  20. imap_processing/ena_maps/ena_maps.py +39 -18
  21. imap_processing/ena_maps/utils/corrections.py +291 -0
  22. imap_processing/ena_maps/utils/map_utils.py +20 -4
  23. imap_processing/glows/l1b/glows_l1b.py +38 -23
  24. imap_processing/glows/l1b/glows_l1b_data.py +10 -11
  25. imap_processing/hi/hi_l1c.py +4 -109
  26. imap_processing/hi/hi_l2.py +34 -23
  27. imap_processing/hi/utils.py +109 -0
  28. imap_processing/ialirt/l0/ialirt_spice.py +1 -1
  29. imap_processing/ialirt/l0/parse_mag.py +18 -4
  30. imap_processing/ialirt/l0/process_hit.py +9 -4
  31. imap_processing/ialirt/l0/process_swapi.py +9 -4
  32. imap_processing/ialirt/l0/process_swe.py +9 -4
  33. imap_processing/ialirt/utils/create_xarray.py +1 -1
  34. imap_processing/lo/ancillary_data/imap_lo_hydrogen-geometric-factor_v001.csv +75 -0
  35. imap_processing/lo/ancillary_data/imap_lo_oxygen-geometric-factor_v001.csv +75 -0
  36. imap_processing/lo/l1b/lo_l1b.py +90 -16
  37. imap_processing/lo/l1c/lo_l1c.py +164 -50
  38. imap_processing/lo/l2/lo_l2.py +941 -127
  39. imap_processing/mag/l1d/mag_l1d_data.py +36 -3
  40. imap_processing/mag/l2/mag_l2.py +2 -0
  41. imap_processing/mag/l2/mag_l2_data.py +4 -3
  42. imap_processing/quality_flags.py +14 -0
  43. imap_processing/spice/geometry.py +13 -8
  44. imap_processing/spice/pointing_frame.py +4 -2
  45. imap_processing/spice/repoint.py +49 -0
  46. imap_processing/ultra/constants.py +29 -0
  47. imap_processing/ultra/l0/decom_tools.py +58 -46
  48. imap_processing/ultra/l0/decom_ultra.py +21 -9
  49. imap_processing/ultra/l0/ultra_utils.py +4 -4
  50. imap_processing/ultra/l1b/badtimes.py +35 -11
  51. imap_processing/ultra/l1b/de.py +15 -9
  52. imap_processing/ultra/l1b/extendedspin.py +24 -12
  53. imap_processing/ultra/l1b/goodtimes.py +112 -0
  54. imap_processing/ultra/l1b/lookup_utils.py +1 -1
  55. imap_processing/ultra/l1b/ultra_l1b.py +7 -7
  56. imap_processing/ultra/l1b/ultra_l1b_culling.py +8 -4
  57. imap_processing/ultra/l1b/ultra_l1b_extended.py +79 -43
  58. imap_processing/ultra/l1c/helio_pset.py +68 -39
  59. imap_processing/ultra/l1c/l1c_lookup_utils.py +45 -12
  60. imap_processing/ultra/l1c/spacecraft_pset.py +81 -37
  61. imap_processing/ultra/l1c/ultra_l1c.py +27 -22
  62. imap_processing/ultra/l1c/ultra_l1c_culling.py +7 -0
  63. imap_processing/ultra/l1c/ultra_l1c_pset_bins.py +41 -41
  64. imap_processing/ultra/l2/ultra_l2.py +75 -18
  65. imap_processing/ultra/utils/ultra_l1_utils.py +10 -5
  66. {imap_processing-0.19.0.dist-info → imap_processing-0.19.3.dist-info}/METADATA +2 -2
  67. {imap_processing-0.19.0.dist-info → imap_processing-0.19.3.dist-info}/RECORD +71 -69
  68. imap_processing/ultra/l1b/cullingmask.py +0 -90
  69. imap_processing/ultra/l1c/histogram.py +0 -36
  70. /imap_processing/glows/ancillary/{imap_glows_pipeline_settings_20250923_v002.json → imap_glows_pipeline-settings_20250923_v002.json} +0 -0
  71. {imap_processing-0.19.0.dist-info → imap_processing-0.19.3.dist-info}/LICENSE +0 -0
  72. {imap_processing-0.19.0.dist-info → imap_processing-0.19.3.dist-info}/WHEEL +0 -0
  73. {imap_processing-0.19.0.dist-info → imap_processing-0.19.3.dist-info}/entry_points.txt +0 -0
@@ -133,7 +133,7 @@ def transform_instrument_vectors_to_inertial(
133
133
  spin_phase: NDArray,
134
134
  sc_inertial_right: NDArray,
135
135
  sc_inertial_decline: NDArray,
136
- instrument_frame: SpiceFrame = SpiceFrame.IMAP_MAG,
136
+ instrument_frame: SpiceFrame,
137
137
  spacecraft_frame: SpiceFrame = SpiceFrame.IMAP_SPACECRAFT,
138
138
  ) -> NDArray:
139
139
  """
@@ -268,6 +268,9 @@ def calculate_l1b(
268
268
  retrieve_matrix_from_single_l1b_calibration(calibration_dataset, is_mago=False)
269
269
  )
270
270
 
271
+ logger.info(f"calibration_matrix_mago shape: {calibration_matrix_mago.shape}.")
272
+ logger.info(f"calibration_matrix_magi shape: {calibration_matrix_magi.shape}.")
273
+
271
274
  # Get time values for each group.
272
275
  time_data = get_time(
273
276
  grouped_data, group, pkt_counter, time_shift_mago, time_shift_magi
@@ -392,6 +395,7 @@ def transform_to_inertial(
392
395
  attitude_time: np.ndarray,
393
396
  target_time: float,
394
397
  mag_vector: np.ndarray,
398
+ instrument_frame: SpiceFrame,
395
399
  ) -> np.ndarray:
396
400
  """
397
401
  Transform vector to ECLIPJ2000.
@@ -415,6 +419,8 @@ def transform_to_inertial(
415
419
  Example: time_data['primary_epoch'].
416
420
  mag_vector : numpy.ndarray
417
421
  Vector, shape (3).
422
+ instrument_frame : SpiceFrame
423
+ SPICE frame of the instrument.
418
424
 
419
425
  Returns
420
426
  -------
@@ -478,6 +484,7 @@ def transform_to_inertial(
478
484
  np.array([spin_phase_deg]),
479
485
  np.array([ra_deg]),
480
486
  np.array([dec_deg]),
487
+ instrument_frame,
481
488
  )[0]
482
489
 
483
490
  return inertial_vector
@@ -570,6 +577,7 @@ def process_packet(
570
577
  mago_times_all = []
571
578
  magi_vectors_all = []
572
579
  magi_times_all = []
580
+ incomplete_groups = []
573
581
 
574
582
  for group in unique_groups:
575
583
  # Get status values for each group.
@@ -581,10 +589,7 @@ def process_packet(
581
589
  ]
582
590
 
583
591
  if not np.array_equal(pkt_counter, np.arange(4)):
584
- logger.info(
585
- f"Group {group} does not contain all values from 0 to "
586
- f"3 without duplicates."
587
- )
592
+ incomplete_groups.append(group)
588
593
  continue
589
594
 
590
595
  # Get decoded status data.
@@ -648,6 +653,7 @@ def process_packet(
648
653
  attitude_time,
649
654
  time_data["primary_epoch"],
650
655
  mago_out,
656
+ SpiceFrame.IMAP_MAG_O,
651
657
  )
652
658
  magi_inertial_vector = transform_to_inertial(
653
659
  sc_spin_phase_rad.values,
@@ -656,6 +662,7 @@ def process_packet(
656
662
  attitude_time,
657
663
  time_data["secondary_epoch"],
658
664
  magi_out,
665
+ SpiceFrame.IMAP_MAG_I,
659
666
  )
660
667
 
661
668
  met = grouped_data["met"][(grouped_data["group"] == group).values]
@@ -665,6 +672,13 @@ def process_packet(
665
672
  magi_vectors_all.append(magi_inertial_vector)
666
673
  magi_times_all.append(time_data["secondary_epoch"])
667
674
 
675
+ if incomplete_groups:
676
+ logger.info(
677
+ f"The following mag groups were skipped due to "
678
+ f"missing or duplicate pkt_counter values: "
679
+ f"{incomplete_groups}"
680
+ )
681
+
668
682
  mago_corrected, magnitude = apply_gradiometry_correction(
669
683
  np.array(mago_vectors_all),
670
684
  np.array(mago_times_all),
@@ -127,6 +127,7 @@ def process_hit(xarray_data: xr.Dataset) -> list[dict]:
127
127
  Dictionary final data product.
128
128
  """
129
129
  hit_data = []
130
+ incomplete_groups = []
130
131
 
131
132
  # Subsecond time conversion specified in 7516-9054 GSW-FSW ICD.
132
133
  # Value of SCLK subseconds, unsigned, (LSB = 1/256 sec)
@@ -148,10 +149,7 @@ def process_hit(xarray_data: xr.Dataset) -> list[dict]:
148
149
 
149
150
  # Ensure no duplicates and all values from 0 to 59 are present
150
151
  if not np.array_equal(subcom_values, np.arange(60)):
151
- logger.warning(
152
- f"Group {group} does not contain all values from 0 to "
153
- f"59 without duplicates."
154
- )
152
+ incomplete_groups.append(group)
155
153
  continue
156
154
 
157
155
  fast_rate_1 = grouped_data["hit_fast_rate_1"][
@@ -187,4 +185,11 @@ def process_hit(xarray_data: xr.Dataset) -> list[dict]:
187
185
  }
188
186
  )
189
187
 
188
+ if incomplete_groups:
189
+ logger.info(
190
+ f"The following hit groups were skipped due to "
191
+ f"missing or duplicate pkt_counter values: "
192
+ f"{incomplete_groups}"
193
+ )
194
+
190
195
  return hit_data
@@ -158,6 +158,7 @@ def process_swapi_ialirt(
158
158
  # Add required parameters.
159
159
  sci_dataset["met"] = met
160
160
  met_values = []
161
+ incomplete_groups = []
161
162
 
162
163
  grouped_dataset = find_groups(sci_dataset, (0, 11), "swapi_seq_number", "met")
163
164
 
@@ -179,12 +180,16 @@ def process_swapi_ialirt(
179
180
 
180
181
  # Ensure no duplicates and all values from 0 to 11 are present
181
182
  if not np.array_equal(seq_values.astype(int), np.arange(12)):
182
- logger.info(
183
- f"SWAPI group {group} does not contain all sequence values from 0 to "
184
- f"11 without duplicates."
185
- )
183
+ incomplete_groups.append(group)
186
184
  continue
187
185
 
186
+ if incomplete_groups:
187
+ logger.info(
188
+ f"The following swapi groups were skipped due to "
189
+ f"missing or duplicate pkt_counter values: "
190
+ f"{incomplete_groups}"
191
+ )
192
+
188
193
  raw_coin_count = process_sweep_data(grouped_dataset, "swapi_coin_cnt")
189
194
  raw_coin_rate = raw_coin_count / SWAPI_LIVETIME
190
195
  count_rate_error = np.sqrt(raw_coin_count) / SWAPI_LIVETIME
@@ -478,6 +478,7 @@ def process_swe(accumulated_data: xr.Dataset, in_flight_cal_files: list) -> list
478
478
  grouped_data = find_groups(accumulated_data, (0, 59), "swe_seq", "time_seconds")
479
479
  unique_groups = np.unique(grouped_data["group"])
480
480
  swe_data: list[dict] = []
481
+ incomplete_groups = []
481
482
 
482
483
  for group in unique_groups:
483
484
  # Sequence values for the group should be 0-59 with no duplicates.
@@ -485,10 +486,7 @@ def process_swe(accumulated_data: xr.Dataset, in_flight_cal_files: list) -> list
485
486
 
486
487
  # Ensure no duplicates and all values from 0 to 59 are present
487
488
  if not np.array_equal(seq_values, np.arange(60)):
488
- logger.info(
489
- f"Group {group} does not contain all values from 0 to "
490
- f"59 without duplicates."
491
- )
489
+ incomplete_groups.append(group)
492
490
  continue
493
491
  # Prepare raw counts array just for this group
494
492
  # (8 energy steps, 7 CEMs, 30 phi bins)
@@ -570,4 +568,11 @@ def process_swe(accumulated_data: xr.Dataset, in_flight_cal_files: list) -> list
570
568
  },
571
569
  )
572
570
 
571
+ if incomplete_groups:
572
+ logger.info(
573
+ f"The following swe groups were skipped due to "
574
+ f"missing or duplicate pkt_counter values: "
575
+ f"{incomplete_groups}"
576
+ )
577
+
573
578
  return swe_data
@@ -144,7 +144,7 @@ def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0
144
144
  # Populate the dataset variables
145
145
  for i, record in enumerate(records):
146
146
  for key, val in record.items():
147
- if key in ["apid", "met", "met_in_utc", "ttj2000ns"]:
147
+ if key in ["apid", "met", "met_in_utc", "ttj2000ns", "last_modified"]:
148
148
  continue
149
149
  elif key in ["mag_B_GSE", "mag_B_GSM", "mag_B_RTN"]:
150
150
  dataset[key].data[i, :] = val
@@ -0,0 +1,75 @@
1
+ incident_E-Step,Observed_E-Step,Cntr_E,Cntr_E_unc,GF_Dbl_all,GF_Dbl_all_unc,GF_Trpl_all,GF_Trpl_all_unc,GF_Dbl_H,GF_Dbl_H_unc,GF_Trpl_H,GF_Trpl_H_unc
2
+ Hi_Res,,[keV],[keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV]
3
+ 1,1,0.015,0.00135,5.35E-05,4.82E-06,2.20E-05,1.87E-06,5.32E-05,4.26E-06,2.19E-05,1.86E-06
4
+ 2,1,0.015,0.00135,3.10E-05,2.79E-06,1.25E-05,1.06E-06,3.09E-05,2.47E-06,1.27E-05,1.08E-06
5
+ 2,2,0.029,0.00261,1.04E-04,9.36E-06,4.27E-05,3.63E-06,1.03E-04,8.26E-06,4.24E-05,3.61E-06
6
+ 3,1,0.015,0.00135,4.13E-05,3.72E-06,1.68E-05,1.43E-06,4.16E-05,3.33E-06,1.71E-05,1.45E-06
7
+ 3,2,0.029,0.00261,1.28E-04,1.15E-05,5.02E-05,4.26E-06,1.30E-04,1.04E-05,5.35E-05,4.55E-06
8
+ 3,3,0.055,0.00495,1.59E-04,1.43E-05,6.54E-05,5.56E-06,1.59E-04,1.27E-05,6.51E-05,5.54E-06
9
+ 4,1,0.015,0.00135,9.85E-06,8.86E-07,3.73E-06,3.17E-07,7.97E-06,6.38E-07,3.28E-06,2.79E-07
10
+ 4,2,0.029,0.00261,1.71E-05,1.54E-06,6.54E-06,5.56E-07,1.68E-05,1.34E-06,6.89E-06,5.86E-07
11
+ 4,3,0.055,0.00495,6.72E-05,6.05E-06,2.58E-05,2.19E-06,6.92E-05,5.53E-06,2.84E-05,2.42E-06
12
+ 4,4,0.11,0.0099,1.79E-04,1.61E-05,7.36E-05,6.25E-06,1.78E-04,1.42E-05,7.30E-05,6.20E-06
13
+ 5,1,0.015,0.00135,1.62E-05,1.46E-06,5.05E-06,4.29E-07,7.86E-06,6.29E-07,3.23E-06,2.75E-07
14
+ 5,2,0.029,0.00261,1.57E-05,1.41E-06,5.16E-06,4.39E-07,9.72E-06,7.77E-07,3.99E-06,3.39E-07
15
+ 5,3,0.055,0.00495,1.45E-05,1.31E-06,4.98E-06,4.24E-07,1.49E-05,1.20E-06,6.14E-06,5.22E-07
16
+ 5,4,0.11,0.0099,5.81E-05,5.23E-06,2.15E-05,1.83E-06,6.00E-05,4.80E-06,2.47E-05,2.10E-06
17
+ 5,5,0.209,0.01881,1.77E-04,1.59E-05,7.26E-05,6.17E-06,1.76E-04,1.41E-05,7.22E-05,6.14E-06
18
+ 6,1,0.015,0.00135,1.34E-05,1.21E-06,4.33E-06,3.68E-07,9.40E-06,7.52E-07,3.86E-06,3.28E-07
19
+ 6,2,0.029,0.00261,1.61E-05,1.45E-06,4.64E-06,3.94E-07,1.11E-05,8.92E-07,4.58E-06,3.89E-07
20
+ 6,3,0.055,0.00495,1.74E-05,1.57E-06,5.02E-06,4.27E-07,1.42E-05,1.14E-06,5.84E-06,4.96E-07
21
+ 6,4,0.11,0.0099,1.45E-05,1.30E-06,4.28E-06,3.64E-07,1.56E-05,1.25E-06,6.40E-06,5.44E-07
22
+ 6,5,0.209,0.01881,5.81E-05,5.23E-06,2.06E-05,1.75E-06,6.01E-05,4.81E-06,2.47E-05,2.10E-06
23
+ 6,6,0.439,0.03951,2.06E-04,1.85E-05,8.46E-05,7.19E-06,2.06E-04,1.64E-05,8.45E-05,7.18E-06
24
+ 7,1,0.015,0.00135,5.32E-06,4.79E-07,1.51E-06,1.29E-07,5.05E-06,4.04E-07,2.08E-06,1.76E-07
25
+ 7,2,0.029,0.00261,1.61E-05,1.45E-06,5.15E-06,4.38E-07,1.39E-05,1.11E-06,5.70E-06,4.85E-07
26
+ 7,3,0.055,0.00495,1.96E-05,1.77E-06,6.10E-06,5.19E-07,1.42E-05,1.14E-06,5.84E-06,4.96E-07
27
+ 7,4,0.11,0.0099,2.08E-05,1.87E-06,6.43E-06,5.46E-07,1.65E-05,1.32E-06,6.78E-06,5.77E-07
28
+ 7,5,0.209,0.01881,2.52E-05,2.27E-06,8.69E-06,7.39E-07,2.61E-05,2.09E-06,1.07E-05,9.11E-07
29
+ 7,6,0.439,0.03951,1.93E-04,1.74E-05,6.94E-05,5.90E-06,1.98E-04,1.59E-05,8.15E-05,6.93E-06
30
+ 7,7,0.872,0.07848,3.82E-04,3.44E-05,1.57E-04,1.33E-05,3.82E-04,3.05E-05,1.57E-04,1.33E-05
31
+ 8,1,0.015,0.00135,5.28E-05,4.75E-06,2.25E-05,1.91E-06,4.10E-05,3.28E-06,1.68E-05,1.43E-06
32
+ 8,2,0.029,0.00261,6.14E-06,5.53E-07,1.96E-06,1.66E-07,5.25E-06,4.20E-07,2.16E-06,1.83E-07
33
+ 8,3,0.055,0.00495,1.13E-05,1.02E-06,3.39E-06,2.88E-07,9.37E-06,7.50E-07,3.85E-06,3.27E-07
34
+ 8,4,0.11,0.0099,1.16E-05,1.04E-06,3.83E-06,3.25E-07,8.69E-06,6.95E-07,3.57E-06,3.03E-07
35
+ 8,5,0.209,0.01881,1.09E-05,9.78E-07,3.55E-06,3.02E-07,8.41E-06,6.73E-07,3.46E-06,2.94E-07
36
+ 8,6,0.439,0.03951,3.29E-05,2.96E-06,1.28E-05,1.08E-06,3.28E-05,2.62E-06,1.35E-05,1.15E-06
37
+ 8,7,0.872,0.07848,3.95E-04,3.56E-05,1.44E-04,1.23E-05,4.04E-04,3.23E-05,1.66E-04,1.41E-05
38
+ 8,8,1.821,0.16389,5.41E-04,4.87E-05,2.22E-04,1.89E-05,5.41E-04,4.33E-05,2.22E-04,1.89E-05
39
+ Hi_Thr,,,,,,,,,,,
40
+ 1,1,0.016,0.00144,8.92E-05,8.03E-06,3.67E-05,3.12E-06,8.87E-05,7.10E-06,3.65E-05,3.10E-06
41
+ 2,1,0.016,0.00144,5.16E-05,4.65E-06,2.08E-05,1.76E-06,5.15E-05,4.12E-06,2.12E-05,1.80E-06
42
+ 2,2,0.03,0.0027,1.73E-04,1.56E-05,7.12E-05,6.06E-06,1.72E-04,1.38E-05,7.07E-05,6.01E-06
43
+ 3,1,0.016,0.00144,6.88E-05,6.19E-06,2.80E-05,2.38E-06,6.94E-05,5.55E-06,2.85E-05,2.42E-06
44
+ 3,2,0.03,0.0027,2.13E-04,1.91E-05,8.36E-05,7.11E-06,2.17E-04,1.74E-05,8.92E-05,7.58E-06
45
+ 3,3,0.056,0.00504,2.65E-04,2.39E-05,1.09E-04,9.26E-06,2.64E-04,2.11E-05,1.09E-04,9.23E-06
46
+ 4,1,0.016,0.00144,1.64E-05,1.48E-06,6.22E-06,5.29E-07,1.33E-05,1.06E-06,5.46E-06,4.64E-07
47
+ 4,2,0.03,0.0027,2.84E-05,2.56E-06,1.09E-05,9.27E-07,2.80E-05,2.24E-06,1.15E-05,9.77E-07
48
+ 4,3,0.056,0.00504,1.12E-04,1.01E-05,4.30E-05,3.66E-06,1.15E-04,9.22E-06,4.74E-05,4.03E-06
49
+ 4,4,0.111,0.00999,2.98E-04,2.68E-05,1.23E-04,1.04E-05,2.96E-04,2.37E-05,1.22E-04,1.03E-05
50
+ 5,1,0.016,0.00144,2.70E-05,2.43E-06,8.42E-06,7.15E-07,1.31E-05,1.05E-06,5.38E-06,4.58E-07
51
+ 5,2,0.03,0.0027,2.61E-05,2.35E-06,8.61E-06,7.31E-07,1.62E-05,1.30E-06,6.65E-06,5.66E-07
52
+ 5,3,0.056,0.00504,2.42E-05,2.18E-06,8.30E-06,7.06E-07,2.49E-05,1.99E-06,1.02E-05,8.70E-07
53
+ 5,4,0.111,0.00999,9.69E-05,8.72E-06,3.58E-05,3.04E-06,1.00E-04,8.00E-06,4.11E-05,3.49E-06
54
+ 5,5,0.21,0.0189,2.94E-04,2.65E-05,1.21E-04,1.03E-05,2.93E-04,2.34E-05,1.20E-04,1.02E-05
55
+ 6,1,0.016,0.00144,2.24E-05,2.01E-06,7.22E-06,6.14E-07,1.57E-05,1.25E-06,6.44E-06,5.47E-07
56
+ 6,2,0.03,0.0027,2.68E-05,2.41E-06,7.73E-06,6.57E-07,1.86E-05,1.49E-06,7.64E-06,6.49E-07
57
+ 6,3,0.056,0.00504,2.91E-05,2.61E-06,8.37E-06,7.12E-07,2.37E-05,1.89E-06,9.73E-06,8.27E-07
58
+ 6,4,0.111,0.00999,2.41E-05,2.17E-06,7.13E-06,6.06E-07,2.60E-05,2.08E-06,1.07E-05,9.07E-07
59
+ 6,5,0.21,0.0189,9.68E-05,8.71E-06,3.44E-05,2.92E-06,1.00E-04,8.02E-06,4.12E-05,3.50E-06
60
+ 6,6,0.44,0.0396,3.43E-04,3.09E-05,1.41E-04,1.20E-05,3.43E-04,2.74E-05,1.41E-04,1.20E-05
61
+ 7,1,0.016,0.00144,8.87E-06,7.98E-07,2.52E-06,2.14E-07,8.42E-06,6.73E-07,3.46E-06,2.94E-07
62
+ 7,2,0.03,0.0027,2.68E-05,2.41E-06,8.59E-06,7.30E-07,2.31E-05,1.85E-06,9.50E-06,8.08E-07
63
+ 7,3,0.056,0.00504,3.27E-05,2.95E-06,1.02E-05,8.64E-07,2.37E-05,1.89E-06,9.73E-06,8.27E-07
64
+ 7,4,0.111,0.00999,3.47E-05,3.12E-06,1.07E-05,9.10E-07,2.75E-05,2.20E-06,1.13E-05,9.61E-07
65
+ 7,5,0.21,0.0189,4.20E-05,3.78E-06,1.45E-05,1.23E-06,4.35E-05,3.48E-06,1.79E-05,1.52E-06
66
+ 7,6,0.44,0.0396,3.21E-04,2.89E-05,1.16E-04,9.84E-06,3.31E-04,2.65E-05,1.36E-04,1.16E-05
67
+ 7,7,0.873,0.07857,6.36E-04,5.73E-05,2.61E-04,2.22E-05,6.36E-04,5.09E-05,2.61E-04,2.22E-05
68
+ 8,1,0.016,0.00144,8.79E-05,7.91E-06,3.75E-05,3.19E-06,6.83E-05,5.46E-06,2.81E-05,2.39E-06
69
+ 8,2,0.03,0.0027,1.02E-05,9.21E-07,3.26E-06,2.77E-07,8.75E-06,7.00E-07,3.60E-06,3.06E-07
70
+ 8,3,0.056,0.00504,1.88E-05,1.70E-06,5.65E-06,4.80E-07,1.56E-05,1.25E-06,6.42E-06,5.46E-07
71
+ 8,4,0.111,0.00999,1.93E-05,1.73E-06,6.38E-06,5.42E-07,1.45E-05,1.16E-06,5.95E-06,5.06E-07
72
+ 8,5,0.21,0.0189,1.81E-05,1.63E-06,5.92E-06,5.03E-07,1.40E-05,1.12E-06,5.76E-06,4.90E-07
73
+ 8,6,0.44,0.0396,5.48E-05,4.93E-06,2.13E-05,1.81E-06,5.46E-05,4.37E-06,2.25E-05,1.91E-06
74
+ 8,7,0.873,0.07857,6.59E-04,5.93E-05,2.40E-04,2.04E-05,6.74E-04,5.39E-05,2.77E-04,2.35E-05
75
+ 8,8,1.822,0.16398,9.01E-04,8.11E-05,3.70E-04,3.15E-05,9.01E-04,7.21E-05,3.70E-04,3.15E-05
@@ -0,0 +1,75 @@
1
+ incident_E-Step,Observed_E-Step,Cntr_E,Cntr_E_unc,GF_Dbl_all,GF_Dbl_all_unc,GF_Trpl_all,GF_Trpl_all_unc,GF_Dbl_O,GF_Dbl_O_unc,GF_Trpl_O,GF_Trpl_O_unc
2
+ Hi_Res,,[keV],[keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV],[cm^2sr keV/keV]
3
+ 1,1,0.016,0.00144,3.8700E-04,3.4400E-04,8.9100E-05,8.0200E-05,4.2600E-04,3.4100E-04,1.0600E-04,9.1500E-05
4
+ 2,1,0.016,0.00144,2.8700E-04,2.5600E-04,6.6100E-05,5.9500E-05,2.7700E-04,2.2100E-04,6.9200E-05,5.9500E-05
5
+ 2,2,0.032,0.00288,4.4800E-04,3.9900E-04,9.6700E-05,8.7000E-05,4.7800E-04,3.8200E-04,1.2000E-04,1.0300E-04
6
+ 3,1,0.016,0.00144,5.2900E-04,4.7100E-04,1.3200E-04,1.1900E-04,4.1800E-04,3.3400E-04,1.0400E-04,8.9800E-05
7
+ 3,2,0.032,0.00288,5.9300E-04,5.2800E-04,1.4100E-04,1.2700E-04,6.3000E-04,5.0400E-04,1.5800E-04,1.3600E-04
8
+ 3,3,0.065,0.00585,6.9900E-04,6.2200E-04,1.6600E-04,1.5000E-04,7.6400E-04,6.1100E-04,1.9100E-04,1.6400E-04
9
+ 4,1,0.016,0.00144,6.6400E-04,5.9100E-04,1.7700E-04,1.5900E-04,4.1600E-04,3.3300E-04,1.0400E-04,8.9400E-05
10
+ 4,2,0.032,0.00288,1.1500E-03,1.0200E-03,2.6900E-04,2.4200E-04,1.0900E-03,8.7300E-04,2.7300E-04,2.3500E-04
11
+ 4,3,0.065,0.00585,2.3600E-03,2.1000E-03,5.1700E-04,4.6500E-04,2.5200E-03,2.0100E-03,6.2900E-04,5.4100E-04
12
+ 4,4,0.135,0.01215,8.1500E-04,7.2600E-04,1.9100E-04,1.7200E-04,8.7400E-04,7.0000E-04,2.1900E-04,1.8800E-04
13
+ 5,1,0.016,0.00144,2.8100E-04,2.5000E-04,8.8400E-05,7.9600E-05,1.2500E-04,9.9900E-05,3.1200E-05,2.6800E-05
14
+ 5,2,0.032,0.00288,3.8100E-04,3.4000E-04,1.0800E-04,9.7300E-05,2.0800E-04,1.6600E-04,5.1900E-05,4.4600E-05
15
+ 5,3,0.065,0.00585,5.8000E-04,5.1600E-04,1.3800E-04,1.2400E-04,5.7100E-04,4.5700E-04,1.4300E-04,1.2300E-04
16
+ 5,4,0.135,0.01215,5.4100E-04,4.8100E-04,1.2100E-04,1.0800E-04,5.6900E-04,4.5500E-04,1.4200E-04,1.2200E-04
17
+ 5,5,0.279,0.02511,8.4100E-04,7.4900E-04,2.0500E-04,1.8500E-04,8.6900E-04,6.9500E-04,2.1700E-04,1.8700E-04
18
+ 6,1,0.016,0.00144,2.2100E-04,1.9700E-04,7.1000E-05,6.3900E-05,4.7600E-05,3.8100E-05,1.1900E-05,1.0200E-05
19
+ 6,2,0.032,0.00288,3.1900E-04,2.8400E-04,9.7800E-05,8.8000E-05,1.3800E-04,1.1100E-04,3.4600E-05,2.9800E-05
20
+ 6,3,0.065,0.00585,4.4900E-04,4.0000E-04,1.2400E-04,1.1100E-04,1.7000E-04,1.3600E-04,4.2500E-05,3.6500E-05
21
+ 6,4,0.135,0.01215,6.7700E-04,6.0300E-04,1.5400E-04,1.3800E-04,5.1000E-04,4.0800E-04,1.2700E-04,1.1000E-04
22
+ 6,5,0.279,0.02511,1.2800E-03,1.1400E-03,2.9100E-04,2.6200E-04,1.1700E-03,9.3300E-04,2.9100E-04,2.5100E-04
23
+ 6,6,0.601,0.05409,8.3600E-04,7.4400E-04,1.9800E-04,1.7800E-04,8.2700E-04,6.6100E-04,2.0700E-04,1.7800E-04
24
+ 7,1,0.016,0.00144,1.8500E-04,1.6500E-04,5.9600E-05,5.3700E-05,5.6700E-05,4.5400E-05,1.4200E-05,1.2200E-05
25
+ 7,2,0.032,0.00288,2.3400E-04,2.0800E-04,7.3700E-05,6.6300E-05,9.2100E-05,7.3700E-05,2.3000E-05,1.9800E-05
26
+ 7,3,0.065,0.00585,3.2000E-04,2.8500E-04,9.2000E-05,8.2800E-05,1.0600E-04,8.5000E-05,2.6600E-05,2.2800E-05
27
+ 7,4,0.135,0.01215,4.4900E-04,4.0000E-04,1.2000E-04,1.0800E-04,1.7800E-04,1.4200E-04,4.4400E-05,3.8200E-05
28
+ 7,5,0.279,0.02511,7.1800E-04,6.3900E-04,1.7600E-04,1.5800E-04,6.1600E-04,4.9300E-04,1.5400E-04,1.3200E-04
29
+ 7,6,0.601,0.05409,1.0300E-03,9.1800E-04,2.4500E-04,2.2000E-04,9.9900E-04,7.9900E-04,2.5000E-04,2.1500E-04
30
+ 7,7,1.206,0.10854,9.6000E-04,8.5400E-04,2.4400E-04,2.1900E-04,9.6100E-04,7.6900E-04,2.4000E-04,2.0700E-04
31
+ 8,1,0.016,0.00144,2.8900E-04,2.5800E-04,9.1800E-05,8.2700E-05,4.4800E-05,3.5800E-05,1.1200E-05,9.6300E-06
32
+ 8,2,0.032,0.00288,3.4200E-04,3.0500E-04,1.0500E-04,9.4300E-05,6.8300E-05,5.4600E-05,1.7100E-05,1.4700E-05
33
+ 8,3,0.065,0.00585,1.9300E-04,1.7200E-04,5.6900E-05,5.1200E-05,4.9700E-05,3.9800E-05,1.2400E-05,1.0700E-05
34
+ 8,4,0.135,0.01215,2.7000E-04,2.4000E-04,7.2300E-05,6.5000E-05,6.1300E-05,4.9000E-05,1.5300E-05,1.3200E-05
35
+ 8,5,0.279,0.02511,3.7600E-04,3.3500E-04,9.7400E-05,8.7700E-05,1.5500E-04,1.2400E-04,3.8800E-05,3.3300E-05
36
+ 8,6,0.601,0.05409,7.3600E-04,6.5500E-04,1.8400E-04,1.6600E-04,6.0000E-04,4.8000E-04,1.5000E-04,1.2900E-04
37
+ 8,7,1.206,0.10854,1.0600E-03,9.4100E-04,2.5600E-04,2.3100E-04,9.7300E-04,7.7900E-04,2.4300E-04,2.0900E-04
38
+ 8,8,2.361,0.21249,9.8400E-04,8.7500E-04,2.5500E-04,2.2900E-04,9.3600E-04,7.4900E-04,2.3400E-04,2.0100E-04
39
+ Hi_Thr,,,,,,,,,,,
40
+ 1,1,0.017,0.00153,6.4500E-04,5.7400E-04,1.4900E-04,1.3400E-04,7.1000E-04,5.6800E-04,1.7700E-04,1.5300E-04
41
+ 2,1,0.017,0.00153,4.7900E-04,4.2600E-04,1.1000E-04,9.9200E-05,4.6100E-04,3.6900E-04,1.1500E-04,9.9200E-05
42
+ 2,2,0.033,0.00297,7.4600E-04,6.6400E-04,1.6100E-04,1.4500E-04,7.9700E-04,6.3700E-04,1.9900E-04,1.7100E-04
43
+ 3,1,0.017,0.00153,8.8200E-04,7.8500E-04,2.2000E-04,1.9800E-04,6.9600E-04,5.5700E-04,1.7400E-04,1.5000E-04
44
+ 3,2,0.033,0.00297,9.8800E-04,8.7900E-04,2.3500E-04,2.1100E-04,1.0500E-03,8.4100E-04,2.6300E-04,2.2600E-04
45
+ 3,3,0.066,0.00594,1.1700E-03,1.0400E-03,2.7700E-04,2.4900E-04,1.2700E-03,1.0200E-03,3.1800E-04,2.7400E-04
46
+ 4,1,0.017,0.00153,1.1100E-03,9.8600E-04,2.9500E-04,2.6600E-04,6.9300E-04,5.5400E-04,1.7300E-04,1.4900E-04
47
+ 4,2,0.033,0.00297,1.9200E-03,1.7100E-03,4.4800E-04,4.0300E-04,1.8200E-03,1.4600E-03,4.5500E-04,3.9100E-04
48
+ 4,3,0.066,0.00594,3.9300E-03,3.4900E-03,8.6100E-04,7.7500E-04,4.1900E-03,3.3500E-03,1.0500E-03,9.0100E-04
49
+ 4,4,0.136,0.01224,1.3600E-03,1.2100E-03,3.1800E-04,2.8600E-04,1.4600E-03,1.1700E-03,3.6400E-04,3.1300E-04
50
+ 5,1,0.017,0.00153,4.6800E-04,4.1700E-04,1.4700E-04,1.3300E-04,2.0800E-04,1.6700E-04,5.2000E-05,4.4700E-05
51
+ 5,2,0.033,0.00297,6.3600E-04,5.6600E-04,1.8000E-04,1.6200E-04,3.4600E-04,2.7700E-04,8.6500E-05,7.4400E-05
52
+ 5,3,0.066,0.00594,9.6600E-04,8.6000E-04,2.3000E-04,2.0700E-04,9.5100E-04,7.6100E-04,2.3800E-04,2.0400E-04
53
+ 5,4,0.136,0.01224,9.0100E-04,8.0200E-04,2.0100E-04,1.8100E-04,9.4800E-04,7.5800E-04,2.3700E-04,2.0400E-04
54
+ 5,5,0.28,0.0252,1.4000E-03,1.2500E-03,3.4200E-04,3.0800E-04,1.4500E-03,1.1600E-03,3.6200E-04,3.1100E-04
55
+ 6,1,0.017,0.00153,3.6800E-04,3.2800E-04,1.1800E-04,1.0700E-04,7.9400E-05,6.3500E-05,1.9800E-05,1.7100E-05
56
+ 6,2,0.033,0.00297,5.3200E-04,4.7300E-04,1.6300E-04,1.4700E-04,2.3100E-04,1.8500E-04,5.7700E-05,4.9600E-05
57
+ 6,3,0.066,0.00594,7.4800E-04,6.6600E-04,2.0600E-04,1.8500E-04,2.8300E-04,2.2600E-04,7.0800E-05,6.0900E-05
58
+ 6,4,0.136,0.01224,1.1300E-03,1.0000E-03,2.5600E-04,2.3000E-04,8.4900E-04,6.8000E-04,2.1200E-04,1.8300E-04
59
+ 6,5,0.28,0.0252,2.1400E-03,1.9100E-03,4.8500E-04,4.3700E-04,1.9400E-03,1.5500E-03,4.8600E-04,4.1800E-04
60
+ 6,6,0.602,0.05418,1.3900E-03,1.2400E-03,3.3000E-04,2.9700E-04,1.3800E-03,1.1000E-03,3.4400E-04,2.9600E-04
61
+ 7,1,0.017,0.00153,3.0900E-04,2.7500E-04,9.9400E-05,8.9500E-05,9.4500E-05,7.5600E-05,2.3600E-05,2.0300E-05
62
+ 7,2,0.033,0.00297,3.9000E-04,3.4700E-04,1.2300E-04,1.1100E-04,1.5400E-04,1.2300E-04,3.8400E-05,3.3000E-05
63
+ 7,3,0.066,0.00594,5.3400E-04,4.7500E-04,1.5300E-04,1.3800E-04,1.7700E-04,1.4200E-04,4.4300E-05,3.8100E-05
64
+ 7,4,0.136,0.01224,7.4900E-04,6.6700E-04,2.0000E-04,1.8000E-04,2.9600E-04,2.3700E-04,7.4000E-05,6.3700E-05
65
+ 7,5,0.28,0.0252,1.2000E-03,1.0700E-03,2.9300E-04,2.6400E-04,1.0300E-03,8.2100E-04,2.5700E-04,2.2100E-04
66
+ 7,6,0.602,0.05418,1.7200E-03,1.5300E-03,4.0800E-04,3.6700E-04,1.6700E-03,1.3300E-03,4.1600E-04,3.5800E-04
67
+ 7,7,1.207,0.10863,1.6000E-03,1.4200E-03,4.0600E-04,3.6500E-04,1.6000E-03,1.2800E-03,4.0000E-04,3.4400E-04
68
+ 8,1,0.017,0.00153,4.8200E-04,4.2900E-04,1.5300E-04,1.3800E-04,7.4700E-05,5.9700E-05,1.8700E-05,1.6100E-05
69
+ 8,2,0.033,0.00297,5.7000E-04,5.0800E-04,1.7500E-04,1.5700E-04,1.1400E-04,9.1100E-05,2.8500E-05,2.4500E-05
70
+ 8,3,0.066,0.00594,3.2100E-04,2.8600E-04,9.4800E-05,8.5300E-05,8.2900E-05,6.6300E-05,2.0700E-05,1.7800E-05
71
+ 8,4,0.136,0.01224,4.5000E-04,4.0100E-04,1.2000E-04,1.0800E-04,1.0200E-04,8.1700E-05,2.5500E-05,2.2000E-05
72
+ 8,5,0.28,0.0252,6.2700E-04,5.5800E-04,1.6200E-04,1.4600E-04,2.5800E-04,2.0700E-04,6.4600E-05,5.5600E-05
73
+ 8,6,0.602,0.05418,1.2300E-03,1.0900E-03,3.0700E-04,2.7600E-04,1.0000E-03,8.0000E-04,2.5000E-04,2.1500E-04
74
+ 8,7,1.207,0.10863,1.7600E-03,1.5700E-03,4.2700E-04,3.8400E-04,1.6200E-03,1.3000E-03,4.0600E-04,3.4900E-04
75
+ 8,8,2.362,0.21258,1.6400E-03,1.4600E-03,4.2500E-04,3.8200E-04,1.5600E-03,1.2500E-03,3.9000E-04,3.3500E-04
@@ -9,6 +9,7 @@ import numpy as np
9
9
  import xarray as xr
10
10
 
11
11
  from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes
12
+ from imap_processing.lo import lo_ancillary
12
13
  from imap_processing.lo.l1b.tof_conversions import (
13
14
  TOF0_CONV,
14
15
  TOF1_CONV,
@@ -16,20 +17,24 @@ from imap_processing.lo.l1b.tof_conversions import (
16
17
  TOF3_CONV,
17
18
  )
18
19
  from imap_processing.spice.geometry import SpiceFrame, instrument_pointing
20
+ from imap_processing.spice.repoint import get_pointing_times
21
+ from imap_processing.spice.spin import get_spin_number
19
22
  from imap_processing.spice.time import met_to_ttj2000ns, ttj2000ns_to_et
20
23
 
21
24
  logger = logging.getLogger(__name__)
22
25
  logger.setLevel(logging.INFO)
23
26
 
24
27
 
25
- def lo_l1b(dependencies: dict) -> list[Path]:
28
+ def lo_l1b(sci_dependencies: dict, anc_dependencies: list) -> list[Path]:
26
29
  """
27
30
  Will process IMAP-Lo L1A data into L1B CDF data products.
28
31
 
29
32
  Parameters
30
33
  ----------
31
- dependencies : dict
34
+ sci_dependencies : dict
32
35
  Dictionary of datasets needed for L1B data product creation in xarray Datasets.
36
+ anc_dependencies : list
37
+ List of ancillary file paths needed for L1B data product creation.
33
38
 
34
39
  Returns
35
40
  -------
@@ -43,17 +48,20 @@ def lo_l1b(dependencies: dict) -> list[Path]:
43
48
  # create the attribute manager to access L1A fillval attributes
44
49
  attr_mgr_l1a = ImapCdfAttributes()
45
50
  attr_mgr_l1a.add_instrument_variable_attrs(instrument="lo", level="l1a")
46
- logger.info(f"\n Dependencies: {list(dependencies.keys())}\n")
51
+ logger.info(f"\n Dependencies: {list(sci_dependencies.keys())}\n")
47
52
  # if the dependencies are used to create Annotated Direct Events
48
- if "imap_lo_l1a_de" in dependencies and "imap_lo_l1a_spin" in dependencies:
53
+ if "imap_lo_l1a_de" in sci_dependencies and "imap_lo_l1a_spin" in sci_dependencies:
49
54
  logger.info("\nProcessing IMAP-Lo L1B Direct Events...")
50
55
  logical_source = "imap_lo_l1b_de"
51
56
  # get the dependency dataset for l1b direct events
52
- l1a_de = dependencies["imap_lo_l1a_de"]
53
- spin_data = dependencies["imap_lo_l1a_spin"]
57
+ l1a_de = sci_dependencies["imap_lo_l1a_de"]
58
+ spin_data = sci_dependencies["imap_lo_l1a_spin"]
54
59
 
55
60
  # Initialize the L1B DE dataset
56
61
  l1b_de = initialize_l1b_de(l1a_de, attr_mgr_l1b, logical_source)
62
+ pointing_start_met, pointing_end_met = get_pointing_times(
63
+ l1a_de["met"].values[0].item()
64
+ )
57
65
  # Get the start and end times for each spin epoch
58
66
  acq_start, acq_end = convert_start_end_acq_times(spin_data)
59
67
  # Get the average spin durations for each epoch
@@ -66,7 +74,7 @@ def lo_l1b(dependencies: dict) -> list[Path]:
66
74
  # spin bins are 0 - 60 bins
67
75
  l1b_de = set_spin_bin(l1b_de, spin_angle)
68
76
  # set the spin cycle for each direct event
69
- l1b_de = set_spin_cycle(l1a_de, l1b_de)
77
+ l1b_de = set_spin_cycle(pointing_start_met, l1a_de, l1b_de)
70
78
  # get spin start times for each event
71
79
  spin_start_time = get_spin_start_times(l1a_de, l1b_de, spin_data, acq_end)
72
80
  # get the absolute met for each event
@@ -75,6 +83,10 @@ def lo_l1b(dependencies: dict) -> list[Path]:
75
83
  )
76
84
  # set the epoch for each event
77
85
  l1b_de = set_each_event_epoch(l1b_de)
86
+ # Set the ESA mode for each direct event
87
+ l1b_de = set_esa_mode(
88
+ pointing_start_met, pointing_end_met, anc_dependencies, l1b_de
89
+ )
78
90
  # Set the average spin duration for each direct event
79
91
  l1b_de = set_avg_spin_durations_per_event(
80
92
  l1a_de, l1b_de, avg_spin_durations_per_cycle
@@ -133,7 +145,7 @@ def initialize_l1b_de(
133
145
  # TODO: Add pos to YAML file
134
146
  # attrs=attr_mgr.get_variable_attributes("pos"),
135
147
  )
136
- l1b_de["mode"] = xr.DataArray(
148
+ l1b_de["mode_bit"] = xr.DataArray(
137
149
  l1a_de["mode"].values,
138
150
  dims=["epoch"],
139
151
  # TODO: Add mode to YAML file
@@ -155,6 +167,65 @@ def initialize_l1b_de(
155
167
  return l1b_de
156
168
 
157
169
 
170
+ def set_esa_mode(
171
+ pointing_start_met: float,
172
+ pointing_end_met: float,
173
+ anc_dependencies: list,
174
+ l1b_de: xr.Dataset,
175
+ ) -> xr.Dataset:
176
+ """
177
+ Set the ESA mode for each direct event.
178
+
179
+ The ESA mode is determined from the sweep table for the time period of the pointing.
180
+
181
+ Parameters
182
+ ----------
183
+ pointing_start_met : float
184
+ Start time for the pointing in MET seconds.
185
+ pointing_end_met : float
186
+ End time for the pointing in MET seconds.
187
+ anc_dependencies : list
188
+ List of ancillary file paths.
189
+ l1b_de : xarray.Dataset
190
+ The L1B DE dataset.
191
+
192
+ Returns
193
+ -------
194
+ l1b_de : xr.Dataset
195
+ The L1B DE dataset with the ESA mode added.
196
+ """
197
+ # Read the sweep table from the ancillary files
198
+ sweep_df = lo_ancillary.read_ancillary_file(
199
+ next(str(s) for s in anc_dependencies if "sweep-table" in str(s))
200
+ )
201
+
202
+ # Get the sweep table rows that correspond to the time period of the pointing
203
+ pointing_sweep_df = sweep_df[
204
+ (sweep_df["GoodTime_start"] >= pointing_start_met)
205
+ & (sweep_df["GoodTime_start"] <= pointing_end_met)
206
+ ]
207
+
208
+ # Check that there is only one ESA mode in the sweep table for the pointing
209
+ if len(pointing_sweep_df["ESA_Mode"].unique()) == 1:
210
+ # Update the ESA mode strings to be 0 for HiRes and 1 for HiThr
211
+ sweep_df["esa_mode"] = sweep_df["ESA_Mode"].map({"HiRes": 0, "HiThr": 1})
212
+ # Get the ESA mode for the pointing
213
+ esa_mode = sweep_df["esa_mode"].values[0]
214
+ # Repeat the ESA mode for each direct event in the pointing
215
+ esa_mode_array = np.repeat(esa_mode, len(l1b_de["epoch"]))
216
+ else:
217
+ raise ValueError("Multiple ESA modes found in sweep table for pointing.")
218
+
219
+ l1b_de["esa_mode"] = xr.DataArray(
220
+ esa_mode_array,
221
+ dims=["epoch"],
222
+ # TODO: Add esa_mode to YAML file
223
+ # attrs=attr_mgr.get_variable_attributes("esa_mode"),
224
+ )
225
+
226
+ return l1b_de
227
+
228
+
158
229
  def convert_start_end_acq_times(
159
230
  spin_data: xr.Dataset,
160
231
  ) -> tuple[xr.DataArray, xr.DataArray]:
@@ -252,7 +323,9 @@ def set_spin_bin(l1b_de: xr.Dataset, spin_angle: np.ndarray) -> xr.Dataset:
252
323
  return l1b_de
253
324
 
254
325
 
255
- def set_spin_cycle(l1a_de: xr.Dataset, l1b_de: xr.Dataset) -> xr.Dataset:
326
+ def set_spin_cycle(
327
+ pointing_start_met: float, l1a_de: xr.Dataset, l1b_de: xr.Dataset
328
+ ) -> xr.Dataset:
256
329
  """
257
330
  Set the spin cycle for each direct event.
258
331
 
@@ -265,6 +338,8 @@ def set_spin_cycle(l1a_de: xr.Dataset, l1b_de: xr.Dataset) -> xr.Dataset:
265
338
 
266
339
  Parameters
267
340
  ----------
341
+ pointing_start_met : float
342
+ The start time of the pointing in MET seconds.
268
343
  l1a_de : xarray.Dataset
269
344
  The L1A DE dataset.
270
345
  l1b_de : xarray.Dataset
@@ -275,19 +350,18 @@ def set_spin_cycle(l1a_de: xr.Dataset, l1b_de: xr.Dataset) -> xr.Dataset:
275
350
  l1b_de : xarray.Dataset
276
351
  The L1B DE dataset with the spin cycle added for each direct event.
277
352
  """
353
+ spin_start_num = get_spin_number(pointing_start_met)
278
354
  counts = l1a_de["de_count"].values
279
355
  # split the esa_steps into ASC groups
280
356
  de_asc_groups = np.split(l1a_de["esa_step"].values, np.cumsum(counts)[:-1])
281
357
  spin_cycle = []
282
- for i, esa_asc_group in enumerate(de_asc_groups):
283
- # TODO: Spin Number does not reset for each pointing. Need to figure out
284
- # how to retain this information across days
285
- # increment the spin_start by 28 after each aggregated science cycle
286
- spin_start = i * 28
358
+ for esa_asc_group in de_asc_groups:
287
359
  # calculate the spin cycle for each DE in the ASC group
288
360
  # TODO: Add equation number in algorithm document when new version is
289
- # available. Add to docstring as well
290
- spin_cycle.extend(spin_start + 7 + (esa_asc_group - 1) * 2)
361
+ # available. Add to docstring as well
362
+ spin_cycle.extend(spin_start_num + 7 + (esa_asc_group - 1) * 2)
363
+ # increment the spin start number by 28 for the next ASC
364
+ spin_start_num += 28
291
365
 
292
366
  l1b_de["spin_cycle"] = xr.DataArray(
293
367
  spin_cycle,