imap-processing 0.6.0__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 (398) hide show
  1. imap_processing/__init__.py +34 -0
  2. imap_processing/_version.py +3 -0
  3. imap_processing/ccsds/__init__.py +0 -0
  4. imap_processing/ccsds/ccsds_data.py +55 -0
  5. imap_processing/ccsds/excel_to_xtce.py +477 -0
  6. imap_processing/cdf/__init__.py +0 -0
  7. imap_processing/cdf/cdf_attribute_manager.py +322 -0
  8. imap_processing/cdf/config/imap_codice_global_cdf_attrs.yaml +212 -0
  9. imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml +1358 -0
  10. imap_processing/cdf/config/imap_codice_l1b_variable_attrs.yaml +391 -0
  11. imap_processing/cdf/config/imap_constant_attrs.yaml +33 -0
  12. imap_processing/cdf/config/imap_default_global_cdf_attrs.yaml +17 -0
  13. imap_processing/cdf/config/imap_glows_global_cdf_attrs.yaml +41 -0
  14. imap_processing/cdf/config/imap_glows_l1a_variable_attrs.yaml +499 -0
  15. imap_processing/cdf/config/imap_glows_l1b_variable_attrs.yaml +334 -0
  16. imap_processing/cdf/config/imap_hi_global_cdf_attrs.yaml +51 -0
  17. imap_processing/cdf/config/imap_hi_variable_attrs.yaml +435 -0
  18. imap_processing/cdf/config/imap_hit_global_cdf_attrs.yaml +27 -0
  19. imap_processing/cdf/config/imap_hit_l1a_variable_attrs.yaml +493 -0
  20. imap_processing/cdf/config/imap_hit_l1b_variable_attrs.yaml +564 -0
  21. imap_processing/cdf/config/imap_idex_global_cdf_attrs.yaml +24 -0
  22. imap_processing/cdf/config/imap_idex_l1a_variable_attrs.yaml +426 -0
  23. imap_processing/cdf/config/imap_lo_global_cdf_attrs.yaml +90 -0
  24. imap_processing/cdf/config/imap_lo_l1a_variable_attrs.yaml +487 -0
  25. imap_processing/cdf/config/imap_lo_l1b_variable_attrs.yaml +121 -0
  26. imap_processing/cdf/config/imap_lo_l1c_variable_attrs.yaml +179 -0
  27. imap_processing/cdf/config/imap_mag_global_cdf_attrs.yaml +97 -0
  28. imap_processing/cdf/config/imap_mag_l1_variable_attrs.yaml +201 -0
  29. imap_processing/cdf/config/imap_swapi_global_cdf_attrs.yaml +33 -0
  30. imap_processing/cdf/config/imap_swapi_variable_attrs.yaml +137 -0
  31. imap_processing/cdf/config/imap_swe_global_cdf_attrs.yaml +24 -0
  32. imap_processing/cdf/config/imap_swe_l1a_variable_attrs.yaml +234 -0
  33. imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml +273 -0
  34. imap_processing/cdf/config/imap_ultra_global_cdf_attrs.yaml +100 -0
  35. imap_processing/cdf/config/imap_ultra_l1a_variable_attrs.yaml +52 -0
  36. imap_processing/cdf/config/imap_ultra_l1b_variable_attrs.yaml +297 -0
  37. imap_processing/cdf/config/imap_ultra_l1c_variable_attrs.yaml +121 -0
  38. imap_processing/cdf/config/shared/default_global_cdf_attrs_schema.yaml +246 -0
  39. imap_processing/cdf/config/shared/default_variable_cdf_attrs_schema.yaml +466 -0
  40. imap_processing/cdf/imap_cdf_manager.py +64 -0
  41. imap_processing/cdf/utils.py +147 -0
  42. imap_processing/cli.py +863 -0
  43. imap_processing/codice/__init__.py +1 -0
  44. imap_processing/codice/codice_l0.py +54 -0
  45. imap_processing/codice/codice_l1a.py +558 -0
  46. imap_processing/codice/codice_l1b.py +194 -0
  47. imap_processing/codice/constants.py +986 -0
  48. imap_processing/codice/data/esa_sweep_values.csv +257 -0
  49. imap_processing/codice/data/lo_stepping_values.csv +129 -0
  50. imap_processing/codice/decompress.py +142 -0
  51. imap_processing/codice/packet_definitions/P_COD_NHK.xml +618 -0
  52. imap_processing/codice/packet_definitions/codice_packet_definition.xml +5073 -0
  53. imap_processing/codice/utils.py +95 -0
  54. imap_processing/decom.py +40 -0
  55. imap_processing/glows/__init__.py +1 -0
  56. imap_processing/glows/ancillary/l1b_conversion_table_v001.json +42 -0
  57. imap_processing/glows/l0/__init__.py +0 -0
  58. imap_processing/glows/l0/decom_glows.py +91 -0
  59. imap_processing/glows/l0/glows_l0_data.py +194 -0
  60. imap_processing/glows/l1a/glows_l1a.py +424 -0
  61. imap_processing/glows/l1a/glows_l1a_data.py +555 -0
  62. imap_processing/glows/l1b/glows_l1b.py +270 -0
  63. imap_processing/glows/l1b/glows_l1b_data.py +583 -0
  64. imap_processing/glows/packet_definitions/GLX_COMBINED.xml +254 -0
  65. imap_processing/glows/packet_definitions/P_GLX_TMSCDE.xml +97 -0
  66. imap_processing/glows/packet_definitions/P_GLX_TMSCHIST.xml +215 -0
  67. imap_processing/glows/utils/__init__.py +0 -0
  68. imap_processing/glows/utils/constants.py +105 -0
  69. imap_processing/hi/__init__.py +1 -0
  70. imap_processing/hi/l0/__init__.py +0 -0
  71. imap_processing/hi/l0/decom_hi.py +24 -0
  72. imap_processing/hi/l1a/__init__.py +0 -0
  73. imap_processing/hi/l1a/hi_l1a.py +73 -0
  74. imap_processing/hi/l1a/histogram.py +142 -0
  75. imap_processing/hi/l1a/housekeeping.py +27 -0
  76. imap_processing/hi/l1a/science_direct_event.py +341 -0
  77. imap_processing/hi/l1b/__init__.py +0 -0
  78. imap_processing/hi/l1b/hi_eng_unit_convert_table.csv +154 -0
  79. imap_processing/hi/l1b/hi_l1b.py +127 -0
  80. imap_processing/hi/l1c/__init__.py +0 -0
  81. imap_processing/hi/l1c/hi_l1c.py +228 -0
  82. imap_processing/hi/packet_definitions/__init__.py +0 -0
  83. imap_processing/hi/packet_definitions/hi_packet_definition.xml +482 -0
  84. imap_processing/hi/utils.py +27 -0
  85. imap_processing/hit/__init__.py +1 -0
  86. imap_processing/hit/l0/__init__.py +0 -0
  87. imap_processing/hit/l0/data_classes/housekeeping.py +240 -0
  88. imap_processing/hit/l0/data_classes/science_packet.py +259 -0
  89. imap_processing/hit/l0/decom_hit.py +467 -0
  90. imap_processing/hit/l0/utils/hit_base.py +57 -0
  91. imap_processing/hit/l1a/__init__.py +0 -0
  92. imap_processing/hit/l1a/hit_l1a.py +254 -0
  93. imap_processing/hit/l1b/hit_l1b.py +179 -0
  94. imap_processing/hit/packet_definitions/hit_packet_definitions.xml +1276 -0
  95. imap_processing/ialirt/__init__.py +0 -0
  96. imap_processing/ialirt/l0/__init__.py +0 -0
  97. imap_processing/ialirt/l0/process_hit.py +220 -0
  98. imap_processing/ialirt/packet_definitions/__init__.py +0 -0
  99. imap_processing/ialirt/packet_definitions/ialirt.xml +778 -0
  100. imap_processing/ialirt/packet_definitions/ialirt_hit.xml +186 -0
  101. imap_processing/idex/__init__.py +2 -0
  102. imap_processing/idex/idex_constants.py +27 -0
  103. imap_processing/idex/idex_l0.py +31 -0
  104. imap_processing/idex/idex_l1a.py +631 -0
  105. imap_processing/idex/packet_definitions/idex_packet_definition.xml +3162 -0
  106. imap_processing/lo/__init__.py +1 -0
  107. imap_processing/lo/l0/__init__.py +0 -0
  108. imap_processing/lo/l0/data_classes/science_direct_events.py +215 -0
  109. imap_processing/lo/l0/data_classes/star_sensor.py +98 -0
  110. imap_processing/lo/l0/decompression_tables/12_to_16_bit.csv +4097 -0
  111. imap_processing/lo/l0/decompression_tables/8_to_12_bit.csv +257 -0
  112. imap_processing/lo/l0/decompression_tables/8_to_16_bit.csv +257 -0
  113. imap_processing/lo/l0/decompression_tables/decompression_tables.py +75 -0
  114. imap_processing/lo/l0/lo_apid.py +15 -0
  115. imap_processing/lo/l0/lo_science.py +150 -0
  116. imap_processing/lo/l0/utils/binary_string.py +59 -0
  117. imap_processing/lo/l0/utils/bit_decompression.py +62 -0
  118. imap_processing/lo/l0/utils/lo_base.py +57 -0
  119. imap_processing/lo/l1a/__init__.py +0 -0
  120. imap_processing/lo/l1a/lo_l1a.py +157 -0
  121. imap_processing/lo/l1b/lo_l1b.py +160 -0
  122. imap_processing/lo/l1c/lo_l1c.py +180 -0
  123. imap_processing/lo/packet_definitions/lo_xtce.xml +3541 -0
  124. imap_processing/mag/__init__.py +2 -0
  125. imap_processing/mag/constants.py +108 -0
  126. imap_processing/mag/l0/decom_mag.py +170 -0
  127. imap_processing/mag/l0/mag_l0_data.py +118 -0
  128. imap_processing/mag/l1a/mag_l1a.py +317 -0
  129. imap_processing/mag/l1a/mag_l1a_data.py +1007 -0
  130. imap_processing/mag/l1b/__init__.py +0 -0
  131. imap_processing/mag/l1b/imap_calibration_mag_20240229_v01.cdf +0 -0
  132. imap_processing/mag/l1b/mag_l1b.py +125 -0
  133. imap_processing/mag/l1c/mag_l1c.py +57 -0
  134. imap_processing/mag/packet_definitions/MAG_SCI_COMBINED.xml +235 -0
  135. imap_processing/quality_flags.py +91 -0
  136. imap_processing/spice/__init__.py +1 -0
  137. imap_processing/spice/geometry.py +322 -0
  138. imap_processing/spice/kernels.py +459 -0
  139. imap_processing/spice/time.py +72 -0
  140. imap_processing/swapi/__init__.py +1 -0
  141. imap_processing/swapi/l1/__init__.py +0 -0
  142. imap_processing/swapi/l1/swapi_l1.py +685 -0
  143. imap_processing/swapi/l2/__init__.py +0 -0
  144. imap_processing/swapi/l2/swapi_l2.py +107 -0
  145. imap_processing/swapi/packet_definitions/__init__.py +0 -0
  146. imap_processing/swapi/packet_definitions/swapi_packet_definition.xml +708 -0
  147. imap_processing/swapi/swapi_utils.py +25 -0
  148. imap_processing/swe/__init__.py +1 -0
  149. imap_processing/swe/l1a/__init__.py +0 -0
  150. imap_processing/swe/l1a/swe_l1a.py +48 -0
  151. imap_processing/swe/l1a/swe_science.py +223 -0
  152. imap_processing/swe/l1b/engineering_unit_convert_table.csv +65 -0
  153. imap_processing/swe/l1b/swe_esa_lookup_table.csv +1441 -0
  154. imap_processing/swe/l1b/swe_l1b.py +49 -0
  155. imap_processing/swe/l1b/swe_l1b_science.py +557 -0
  156. imap_processing/swe/packet_definitions/__init__.py +0 -0
  157. imap_processing/swe/packet_definitions/swe_packet_definition.xml +303 -0
  158. imap_processing/swe/utils/__init__.py +0 -0
  159. imap_processing/swe/utils/swe_utils.py +9 -0
  160. imap_processing/tests/__init__.py +0 -0
  161. imap_processing/tests/ccsds/test_data/expected_output.xml +171 -0
  162. imap_processing/tests/ccsds/test_excel_to_xtce.py +285 -0
  163. imap_processing/tests/cdf/__init__.py +0 -0
  164. imap_processing/tests/cdf/imap_default_global_cdf_attrs.yaml +8 -0
  165. imap_processing/tests/cdf/shared/default_global_cdf_attrs_schema.yaml +246 -0
  166. imap_processing/tests/cdf/shared/default_variable_cdf_attrs_schema.yaml +466 -0
  167. imap_processing/tests/cdf/test_cdf_attribute_manager.py +353 -0
  168. imap_processing/tests/cdf/test_data/imap_default_global_test_cdf_attrs.yaml +7 -0
  169. imap_processing/tests/cdf/test_data/imap_instrument1_global_cdf_attrs.yaml +14 -0
  170. imap_processing/tests/cdf/test_data/imap_instrument1_level1_variable_attrs.yaml +23 -0
  171. imap_processing/tests/cdf/test_data/imap_instrument2_global_cdf_attrs.yaml +23 -0
  172. imap_processing/tests/cdf/test_data/imap_instrument2_level2_variable_attrs.yaml +30 -0
  173. imap_processing/tests/cdf/test_data/imap_test_global.yaml +26 -0
  174. imap_processing/tests/cdf/test_data/imap_test_variable.yaml +41 -0
  175. imap_processing/tests/cdf/test_imap_cdf_manager.py +62 -0
  176. imap_processing/tests/cdf/test_utils.py +109 -0
  177. imap_processing/tests/codice/__init__.py +0 -0
  178. imap_processing/tests/codice/conftest.py +56 -0
  179. imap_processing/tests/codice/data/eu_unit_lookup_table.csv +101 -0
  180. imap_processing/tests/codice/data/idle_export_eu.COD_NHK_20230822_122700 2.csv +100 -0
  181. imap_processing/tests/codice/data/idle_export_raw.COD_NHK_20230822_122700.csv +100 -0
  182. imap_processing/tests/codice/data/imap_codice_l0_hi-counters-aggregated_20240429_v001.pkts +0 -0
  183. imap_processing/tests/codice/data/imap_codice_l0_hi-counters-singles_20240429_v001.pkts +0 -0
  184. imap_processing/tests/codice/data/imap_codice_l0_hi-omni_20240429_v001.pkts +0 -0
  185. imap_processing/tests/codice/data/imap_codice_l0_hi-pha_20240429_v001.pkts +0 -0
  186. imap_processing/tests/codice/data/imap_codice_l0_hi-sectored_20240429_v001.pkts +0 -0
  187. imap_processing/tests/codice/data/imap_codice_l0_hskp_20100101_v001.pkts +0 -0
  188. imap_processing/tests/codice/data/imap_codice_l0_lo-counters-aggregated_20240429_v001.pkts +0 -0
  189. imap_processing/tests/codice/data/imap_codice_l0_lo-counters-singles_20240429_v001.pkts +0 -0
  190. imap_processing/tests/codice/data/imap_codice_l0_lo-nsw-angular_20240429_v001.pkts +0 -0
  191. imap_processing/tests/codice/data/imap_codice_l0_lo-nsw-priority_20240429_v001.pkts +0 -0
  192. imap_processing/tests/codice/data/imap_codice_l0_lo-nsw-species_20240429_v001.pkts +0 -0
  193. imap_processing/tests/codice/data/imap_codice_l0_lo-pha_20240429_v001.pkts +0 -0
  194. imap_processing/tests/codice/data/imap_codice_l0_lo-sw-angular_20240429_v001.pkts +0 -0
  195. imap_processing/tests/codice/data/imap_codice_l0_lo-sw-priority_20240429_v001.pkts +0 -0
  196. imap_processing/tests/codice/data/imap_codice_l0_lo-sw-species_20240429_v001.pkts +0 -0
  197. imap_processing/tests/codice/data/imap_codice_l1a_hi-counters-aggregated_20240429_v001.cdf +0 -0
  198. imap_processing/tests/codice/data/imap_codice_l1a_hi-counters-singles_20240429_v001.cdf +0 -0
  199. imap_processing/tests/codice/data/imap_codice_l1a_hi-omni_20240429_v001.cdf +0 -0
  200. imap_processing/tests/codice/data/imap_codice_l1a_hi-sectored_20240429_v001.cdf +0 -0
  201. imap_processing/tests/codice/data/imap_codice_l1a_hskp_20100101_v001.cdf +0 -0
  202. imap_processing/tests/codice/data/imap_codice_l1a_lo-counters-aggregated_20240429_v001.cdf +0 -0
  203. imap_processing/tests/codice/data/imap_codice_l1a_lo-counters-singles_20240429_v001.cdf +0 -0
  204. imap_processing/tests/codice/data/imap_codice_l1a_lo-nsw-angular_20240429_v001.cdf +0 -0
  205. imap_processing/tests/codice/data/imap_codice_l1a_lo-nsw-priority_20240429_v001.cdf +0 -0
  206. imap_processing/tests/codice/data/imap_codice_l1a_lo-nsw-species_20240429_v001.cdf +0 -0
  207. imap_processing/tests/codice/data/imap_codice_l1a_lo-sw-angular_20240429_v001.cdf +0 -0
  208. imap_processing/tests/codice/data/imap_codice_l1a_lo-sw-priority_20240429_v001.cdf +0 -0
  209. imap_processing/tests/codice/data/imap_codice_l1a_lo-sw-species_20240429_v001.cdf +0 -0
  210. imap_processing/tests/codice/data/imap_codice_l1b_hi-counters-aggregated_20240429_v001.cdf +0 -0
  211. imap_processing/tests/codice/data/imap_codice_l1b_hi-counters-singles_20240429_v001.cdf +0 -0
  212. imap_processing/tests/codice/data/imap_codice_l1b_hi-omni_20240429_v001.cdf +0 -0
  213. imap_processing/tests/codice/data/imap_codice_l1b_hi-sectored_20240429_v001.cdf +0 -0
  214. imap_processing/tests/codice/data/imap_codice_l1b_hskp_20100101_v001.cdf +0 -0
  215. imap_processing/tests/codice/data/imap_codice_l1b_lo-counters-aggregated_20240429_v001.cdf +0 -0
  216. imap_processing/tests/codice/data/imap_codice_l1b_lo-counters-singles_20240429_v001.cdf +0 -0
  217. imap_processing/tests/codice/data/imap_codice_l1b_lo-nsw-angular_20240429_v001.cdf +0 -0
  218. imap_processing/tests/codice/data/imap_codice_l1b_lo-nsw-priority_20240429_v001.cdf +0 -0
  219. imap_processing/tests/codice/data/imap_codice_l1b_lo-nsw-species_20240429_v001.cdf +0 -0
  220. imap_processing/tests/codice/data/imap_codice_l1b_lo-sw-angular_20240429_v001.cdf +0 -0
  221. imap_processing/tests/codice/data/imap_codice_l1b_lo-sw-priority_20240429_v001.cdf +0 -0
  222. imap_processing/tests/codice/data/imap_codice_l1b_lo-sw-species_20240429_v001.cdf +0 -0
  223. imap_processing/tests/codice/test_codice_l0.py +144 -0
  224. imap_processing/tests/codice/test_codice_l1a.py +187 -0
  225. imap_processing/tests/codice/test_codice_l1b.py +60 -0
  226. imap_processing/tests/codice/test_decompress.py +50 -0
  227. imap_processing/tests/conftest.py +372 -0
  228. imap_processing/tests/glows/direct_events_validation_data_l1a.csv +5704 -0
  229. imap_processing/tests/glows/glows_test_packet_20110921_v01.pkts +0 -0
  230. imap_processing/tests/glows/test_glows_decom.py +133 -0
  231. imap_processing/tests/glows/test_glows_l1a_cdf.py +85 -0
  232. imap_processing/tests/glows/test_glows_l1a_data.py +510 -0
  233. imap_processing/tests/glows/test_glows_l1b.py +348 -0
  234. imap_processing/tests/glows/test_glows_l1b_data.py +70 -0
  235. imap_processing/tests/hi/__init__.py +0 -0
  236. imap_processing/tests/hi/conftest.py +133 -0
  237. imap_processing/tests/hi/test_data/l0/20231030_H45_APP_NHK.bin +0 -0
  238. imap_processing/tests/hi/test_data/l0/20231030_H45_APP_NHK.csv +201 -0
  239. imap_processing/tests/hi/test_data/l0/20231030_H45_SCI_CNT.bin +0 -0
  240. imap_processing/tests/hi/test_data/l0/20231030_H45_SCI_DE.bin +0 -0
  241. imap_processing/tests/hi/test_data/l0/README.txt +54 -0
  242. imap_processing/tests/hi/test_decom.py +55 -0
  243. imap_processing/tests/hi/test_hi_l1b.py +31 -0
  244. imap_processing/tests/hi/test_hi_l1c.py +69 -0
  245. imap_processing/tests/hi/test_l1a.py +96 -0
  246. imap_processing/tests/hi/test_l1a_sci_de.py +72 -0
  247. imap_processing/tests/hi/test_utils.py +15 -0
  248. imap_processing/tests/hit/PREFLIGHT_raw_record_2023_256_15_59_04_apid1251.pkts +0 -0
  249. imap_processing/tests/hit/PREFLIGHT_raw_record_2023_256_15_59_04_apid1252.pkts +0 -0
  250. imap_processing/tests/hit/__init__.py +0 -0
  251. imap_processing/tests/hit/test_data/imap_hit_l0_hk_20100105_v001.pkts +0 -0
  252. imap_processing/tests/hit/test_data/sci_sample.ccsds +0 -0
  253. imap_processing/tests/hit/test_hit_decom.py +230 -0
  254. imap_processing/tests/hit/test_hit_l1a.py +224 -0
  255. imap_processing/tests/hit/test_hit_l1b.py +52 -0
  256. imap_processing/tests/hit/validation_data/hskp_sample_raw.csv +88 -0
  257. imap_processing/tests/ialirt/__init__.py +0 -0
  258. imap_processing/tests/ialirt/test_data/l0/IALiRT Raw Packet Telemetry.txt +33 -0
  259. imap_processing/tests/ialirt/test_data/l0/hit_ialirt_sample.ccsds +0 -0
  260. imap_processing/tests/ialirt/test_data/l0/hit_ialirt_sample.csv +1001 -0
  261. imap_processing/tests/ialirt/unit/__init__.py +0 -0
  262. imap_processing/tests/ialirt/unit/test_decom_ialirt.py +94 -0
  263. imap_processing/tests/ialirt/unit/test_process_hit.py +226 -0
  264. imap_processing/tests/idex/__init__.py +0 -0
  265. imap_processing/tests/idex/conftest.py +22 -0
  266. imap_processing/tests/idex/imap_idex_l0_raw_20230725_v001.pkts +0 -0
  267. imap_processing/tests/idex/impact_14_tof_high_data.txt +8189 -0
  268. imap_processing/tests/idex/test_idex_l0.py +45 -0
  269. imap_processing/tests/idex/test_idex_l1a.py +91 -0
  270. imap_processing/tests/lo/__init__.py +0 -0
  271. imap_processing/tests/lo/test_binary_string.py +21 -0
  272. imap_processing/tests/lo/test_bit_decompression.py +39 -0
  273. imap_processing/tests/lo/test_cdfs/imap_lo_l0_raw_20240627_v001.pkts +0 -0
  274. imap_processing/tests/lo/test_cdfs/imap_lo_l1a_de_20100101_v001.cdf +0 -0
  275. imap_processing/tests/lo/test_cdfs/imap_lo_l1a_spin_20100101_v001.cdf +0 -0
  276. imap_processing/tests/lo/test_cdfs/imap_lo_l1b_de_20100101_v001.cdf +0 -0
  277. imap_processing/tests/lo/test_lo_l1a.py +66 -0
  278. imap_processing/tests/lo/test_lo_l1b.py +74 -0
  279. imap_processing/tests/lo/test_lo_l1c.py +66 -0
  280. imap_processing/tests/lo/test_science_counts.py +41 -0
  281. imap_processing/tests/lo/test_science_direct_events.py +209 -0
  282. imap_processing/tests/lo/test_star_sensor.py +35 -0
  283. imap_processing/tests/mag/imap_mag_l1a_burst-magi_20231025_v001.cdf +0 -0
  284. imap_processing/tests/mag/mag_l0_test_data.pkts +0 -0
  285. imap_processing/tests/mag/mag_l0_test_output.csv +37 -0
  286. imap_processing/tests/mag/mag_l1_test_data.pkts +0 -0
  287. imap_processing/tests/mag/mag_l1a_test_output.csv +97 -0
  288. imap_processing/tests/mag/test_mag_decom.py +117 -0
  289. imap_processing/tests/mag/test_mag_l1a.py +856 -0
  290. imap_processing/tests/mag/test_mag_l1b.py +77 -0
  291. imap_processing/tests/mag/test_mag_l1c.py +40 -0
  292. imap_processing/tests/spice/__init__.py +0 -0
  293. imap_processing/tests/spice/test_data/imap_ena_sim_metakernel.template +4 -0
  294. imap_processing/tests/spice/test_data/imap_science_0001.tf +171 -0
  295. imap_processing/tests/spice/test_data/imap_sclk_0000.tsc +156 -0
  296. imap_processing/tests/spice/test_data/imap_sim_ck_2hr_2secsampling_with_nutation.bc +0 -0
  297. imap_processing/tests/spice/test_data/imap_simple_metakernel.template +3 -0
  298. imap_processing/tests/spice/test_data/imap_spk_demo.bsp +0 -0
  299. imap_processing/tests/spice/test_data/imap_wkcp.tf +1806 -0
  300. imap_processing/tests/spice/test_data/naif0012.tls +150 -0
  301. imap_processing/tests/spice/test_data/sim_1yr_imap_attitude.bc +0 -0
  302. imap_processing/tests/spice/test_data/sim_1yr_imap_pointing_frame.bc +0 -0
  303. imap_processing/tests/spice/test_geometry.py +214 -0
  304. imap_processing/tests/spice/test_kernels.py +272 -0
  305. imap_processing/tests/spice/test_time.py +35 -0
  306. imap_processing/tests/swapi/__init__.py +0 -0
  307. imap_processing/tests/swapi/conftest.py +16 -0
  308. imap_processing/tests/swapi/l0_data/__init__.py +0 -0
  309. imap_processing/tests/swapi/l0_data/imap_swapi_l0_raw_20231012_v001.pkts +0 -0
  310. imap_processing/tests/swapi/l0_validation_data/__init__.py +0 -0
  311. imap_processing/tests/swapi/l0_validation_data/idle_export_eu.SWP_AUT_20231012_125245.csv +124 -0
  312. imap_processing/tests/swapi/l0_validation_data/idle_export_eu.SWP_HK_20231012_125245.csv +98 -0
  313. imap_processing/tests/swapi/l0_validation_data/idle_export_eu.SWP_MG_20231012_125245.csv +9 -0
  314. imap_processing/tests/swapi/l0_validation_data/idle_export_eu.SWP_SCI_20231012_125245.csv +72 -0
  315. imap_processing/tests/swapi/l0_validation_data/idle_export_raw.SWP_AUT_20231012_125245.csv +124 -0
  316. imap_processing/tests/swapi/l0_validation_data/idle_export_raw.SWP_HK_20231012_125245.csv +98 -0
  317. imap_processing/tests/swapi/l0_validation_data/idle_export_raw.SWP_MG_20231012_125245.csv +9 -0
  318. imap_processing/tests/swapi/l0_validation_data/idle_export_raw.SWP_SCI_20231012_125245.csv +72 -0
  319. imap_processing/tests/swapi/test_swapi_decom.py +135 -0
  320. imap_processing/tests/swapi/test_swapi_l1.py +354 -0
  321. imap_processing/tests/swapi/test_swapi_l2.py +21 -0
  322. imap_processing/tests/swe/__init__.py +0 -0
  323. imap_processing/tests/swe/conftest.py +35 -0
  324. imap_processing/tests/swe/decompressed/20230927173238_4th_quarter_decompressed.csv +181 -0
  325. imap_processing/tests/swe/decompressed/20230927173253_1st_quarter_decompressed.csv +181 -0
  326. imap_processing/tests/swe/decompressed/20230927173308_2nd_quarter_decompressed.csv +181 -0
  327. imap_processing/tests/swe/decompressed/20230927173323_3rd_quarter_decompressed.csv +181 -0
  328. imap_processing/tests/swe/l0_data/2024051010_SWE_SCIENCE_packet.bin +0 -0
  329. imap_processing/tests/swe/l0_validation_data/idle_export_eu.SWE_SCIENCE_20240510_092742.csv +544 -0
  330. imap_processing/tests/swe/l0_validation_data/idle_export_raw.SWE_SCIENCE_20240510_092742.csv +363 -0
  331. imap_processing/tests/swe/test_swe_l1a.py +12 -0
  332. imap_processing/tests/swe/test_swe_l1a_science.py +129 -0
  333. imap_processing/tests/swe/test_swe_l1b.py +61 -0
  334. imap_processing/tests/swe/test_swe_l1b_science.py +65 -0
  335. imap_processing/tests/test_cli.py +229 -0
  336. imap_processing/tests/test_decom.py +66 -0
  337. imap_processing/tests/test_quality_flags.py +71 -0
  338. imap_processing/tests/test_utils.py +107 -0
  339. imap_processing/tests/ultra/__init__.py +0 -0
  340. imap_processing/tests/ultra/test_data/l0/FM45_40P_Phi28p5_BeamCal_LinearScan_phi28.50_theta-0.00_20240207T102740.CCSDS +0 -0
  341. imap_processing/tests/ultra/test_data/l0/FM45_7P_Phi0.0_BeamCal_LinearScan_phi0.04_theta-0.01_20230821T121304.CCSDS +0 -0
  342. imap_processing/tests/ultra/test_data/l0/FM45_TV_Cycle6_Hot_Ops_Front212_20240124T063837.CCSDS +0 -0
  343. imap_processing/tests/ultra/test_data/l0/Ultra45_EM_SwRI_Cal_Run7_ThetaScan_20220530T225054.CCSDS +0 -0
  344. imap_processing/tests/ultra/test_data/l0/ultra45_raw_sc_auxdata_Ultra45_EM_SwRI_Cal_Run7_ThetaScan_20220530T225054.csv +24 -0
  345. imap_processing/tests/ultra/test_data/l0/ultra45_raw_sc_enaphxtofhangimg_FM45_TV_Cycle6_Hot_Ops_Front212_20240124T063837.csv +105 -0
  346. imap_processing/tests/ultra/test_data/l0/ultra45_raw_sc_ultraimgrates_Ultra45_EM_SwRI_Cal_Run7_ThetaScan_20220530T225054.csv +24 -0
  347. imap_processing/tests/ultra/test_data/l0/ultra45_raw_sc_ultrarawimg_withFSWcalcs_FM45_40P_Phi28p5_BeamCal_LinearScan_phi2850_theta-000_20240207T102740.csv +3314 -0
  348. imap_processing/tests/ultra/test_data/l0/ultra45_raw_sc_ultrarawimgevent_FM45_7P_Phi00_BeamCal_LinearScan_phi004_theta-001_20230821T121304.csv +702 -0
  349. imap_processing/tests/ultra/unit/__init__.py +0 -0
  350. imap_processing/tests/ultra/unit/conftest.py +210 -0
  351. imap_processing/tests/ultra/unit/test_decom_apid_880.py +98 -0
  352. imap_processing/tests/ultra/unit/test_decom_apid_881.py +50 -0
  353. imap_processing/tests/ultra/unit/test_decom_apid_883.py +44 -0
  354. imap_processing/tests/ultra/unit/test_decom_apid_896.py +104 -0
  355. imap_processing/tests/ultra/unit/test_lookup_utils.py +68 -0
  356. imap_processing/tests/ultra/unit/test_ultra_l1a.py +338 -0
  357. imap_processing/tests/ultra/unit/test_ultra_l1b.py +122 -0
  358. imap_processing/tests/ultra/unit/test_ultra_l1b_annotated.py +57 -0
  359. imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py +342 -0
  360. imap_processing/tests/ultra/unit/test_ultra_l1c.py +104 -0
  361. imap_processing/tests/ultra/unit/test_ultra_l1c_pset_bins.py +35 -0
  362. imap_processing/ultra/__init__.py +1 -0
  363. imap_processing/ultra/constants.py +60 -0
  364. imap_processing/ultra/l0/__init__.py +0 -0
  365. imap_processing/ultra/l0/decom_tools.py +281 -0
  366. imap_processing/ultra/l0/decom_ultra.py +278 -0
  367. imap_processing/ultra/l0/ultra_utils.py +326 -0
  368. imap_processing/ultra/l1a/__init__.py +0 -0
  369. imap_processing/ultra/l1a/ultra_l1a.py +319 -0
  370. imap_processing/ultra/l1b/badtimes.py +26 -0
  371. imap_processing/ultra/l1b/cullingmask.py +26 -0
  372. imap_processing/ultra/l1b/de.py +59 -0
  373. imap_processing/ultra/l1b/extendedspin.py +45 -0
  374. imap_processing/ultra/l1b/lookup_utils.py +165 -0
  375. imap_processing/ultra/l1b/ultra_l1b.py +65 -0
  376. imap_processing/ultra/l1b/ultra_l1b_annotated.py +54 -0
  377. imap_processing/ultra/l1b/ultra_l1b_extended.py +764 -0
  378. imap_processing/ultra/l1c/histogram.py +36 -0
  379. imap_processing/ultra/l1c/pset.py +36 -0
  380. imap_processing/ultra/l1c/ultra_l1c.py +52 -0
  381. imap_processing/ultra/l1c/ultra_l1c_pset_bins.py +54 -0
  382. imap_processing/ultra/lookup_tables/EgyNorm.mem.csv +32769 -0
  383. imap_processing/ultra/lookup_tables/FM45_Startup1_ULTRA_IMGPARAMS_20240719.csv +2 -0
  384. imap_processing/ultra/lookup_tables/ultra45_back-pos-luts.csv +4097 -0
  385. imap_processing/ultra/lookup_tables/ultra45_tdc_norm.csv +2050 -0
  386. imap_processing/ultra/lookup_tables/ultra90_back-pos-luts.csv +4097 -0
  387. imap_processing/ultra/lookup_tables/ultra90_tdc_norm.csv +2050 -0
  388. imap_processing/ultra/lookup_tables/yadjust.csv +257 -0
  389. imap_processing/ultra/packet_definitions/ULTRA_SCI_COMBINED.xml +547 -0
  390. imap_processing/ultra/packet_definitions/__init__.py +0 -0
  391. imap_processing/ultra/utils/__init__.py +0 -0
  392. imap_processing/ultra/utils/ultra_l1_utils.py +50 -0
  393. imap_processing/utils.py +413 -0
  394. imap_processing-0.6.0.dist-info/LICENSE +21 -0
  395. imap_processing-0.6.0.dist-info/METADATA +107 -0
  396. imap_processing-0.6.0.dist-info/RECORD +398 -0
  397. imap_processing-0.6.0.dist-info/WHEEL +4 -0
  398. imap_processing-0.6.0.dist-info/entry_points.txt +4 -0
@@ -0,0 +1,856 @@
1
+ from pathlib import Path
2
+
3
+ import numpy as np
4
+ import pandas as pd
5
+ import pytest
6
+
7
+ from imap_processing.mag.l0.decom_mag import decom_packets
8
+ from imap_processing.mag.l1a.mag_l1a import mag_l1a, process_packets
9
+ from imap_processing.mag.l1a.mag_l1a_data import (
10
+ MAX_FINE_TIME,
11
+ MagL1a,
12
+ MagL1aPacketProperties,
13
+ TimeTuple,
14
+ )
15
+ from imap_processing.spice.time import met_to_j2000ns
16
+
17
+
18
+ @pytest.fixture()
19
+ def uncompressed_vector_bytearray():
20
+ input_data = np.array(
21
+ [
22
+ 2,
23
+ 4,
24
+ 8,
25
+ 16,
26
+ 16,
27
+ 32,
28
+ 192,
29
+ 129,
30
+ 194,
31
+ 7,
32
+ 68,
33
+ 14,
34
+ 176,
35
+ 32,
36
+ 160,
37
+ 130,
38
+ 161,
39
+ 5,
40
+ 76,
41
+ 8,
42
+ 52,
43
+ 32,
44
+ 220,
45
+ 65,
46
+ 191,
47
+ 2,
48
+ 17,
49
+ 8,
50
+ 68,
51
+ 16,
52
+ 137,
53
+ 192,
54
+ 133,
55
+ 2,
56
+ 20,
57
+ 132,
58
+ 41,
59
+ 48,
60
+ 33,
61
+ 112,
62
+ 133,
63
+ 241,
64
+ 11,
65
+ 236,
66
+ 8,
67
+ 108,
68
+ 33,
69
+ 176,
70
+ 67,
71
+ 99,
72
+ 2,
73
+ 30,
74
+ 8,
75
+ 121,
76
+ 16,
77
+ 243,
78
+ 192,
79
+ 136,
80
+ 66,
81
+ 33,
82
+ 132,
83
+ 67,
84
+ 112,
85
+ 34,
86
+ 64,
87
+ 137,
88
+ 49,
89
+ 18,
90
+ 124,
91
+ 8,
92
+ 160,
93
+ 34,
94
+ 132,
95
+ 69,
96
+ 11,
97
+ 2,
98
+ 43,
99
+ 8,
100
+ 174,
101
+ 17,
102
+ 92,
103
+ 192,
104
+ 139,
105
+ 130,
106
+ 46,
107
+ 196,
108
+ 93,
109
+ 176,
110
+ 35,
111
+ 32,
112
+ 140,
113
+ 129,
114
+ 25,
115
+ 28,
116
+ 8,
117
+ 212,
118
+ 35,
119
+ 84,
120
+ 70,
121
+ 175,
122
+ 2,
123
+ 3,
124
+ 8,
125
+ 15,
126
+ 16,
127
+ 31,
128
+ 192,
129
+ 129,
130
+ 194,
131
+ 7,
132
+ 4,
133
+ 14,
134
+ 112,
135
+ 32,
136
+ 160,
137
+ 130,
138
+ 161,
139
+ 5,
140
+ 76,
141
+ 8,
142
+ 52,
143
+ 32,
144
+ 220,
145
+ 65,
146
+ 187,
147
+ 2,
148
+ 17,
149
+ 8,
150
+ 68,
151
+ 16,
152
+ 136,
153
+ 192,
154
+ 133,
155
+ 2,
156
+ 20,
157
+ 68,
158
+ 40,
159
+ 240,
160
+ 33,
161
+ 112,
162
+ 133,
163
+ 225,
164
+ 11,
165
+ 220,
166
+ 8,
167
+ 104,
168
+ 33,
169
+ 172,
170
+ 67,
171
+ 95,
172
+ 2,
173
+ 30,
174
+ 8,
175
+ 121,
176
+ 16,
177
+ 242,
178
+ 192,
179
+ 136,
180
+ 66,
181
+ 33,
182
+ 132,
183
+ 67,
184
+ 48,
185
+ 34,
186
+ 64,
187
+ 137,
188
+ 49,
189
+ 18,
190
+ 124,
191
+ 8,
192
+ 160,
193
+ 34,
194
+ 128,
195
+ 69,
196
+ 7,
197
+ 2,
198
+ 43,
199
+ 8,
200
+ 173,
201
+ 17,
202
+ 91,
203
+ 192,
204
+ 139,
205
+ 130,
206
+ 46,
207
+ 196,
208
+ 93,
209
+ 176,
210
+ 35,
211
+ 32,
212
+ 140,
213
+ 129,
214
+ 25,
215
+ 12,
216
+ 8,
217
+ 212,
218
+ 35,
219
+ 84,
220
+ 70,
221
+ 171,
222
+ ],
223
+ dtype=np.uint32,
224
+ )
225
+ return input_data
226
+
227
+
228
+ @pytest.fixture()
229
+ def expected_vectors():
230
+ primary_expected = np.array(
231
+ [
232
+ [516, 2064, 4128, 3],
233
+ [519, 2077, 4154, 3],
234
+ [522, 2090, 4180, 3],
235
+ [525, 2103, 4207, 3],
236
+ [529, 2116, 4233, 3],
237
+ [532, 2130, 4260, 3],
238
+ [535, 2143, 4286, 3],
239
+ [539, 2156, 4312, 3],
240
+ [542, 2169, 4339, 3],
241
+ [545, 2182, 4365, 3],
242
+ [548, 2195, 4391, 3],
243
+ [552, 2209, 4418, 3],
244
+ [555, 2222, 4444, 3],
245
+ [558, 2235, 4470, 3],
246
+ [562, 2248, 4497, 3],
247
+ [565, 2261, 4523, 3],
248
+ ]
249
+ )
250
+
251
+ secondary_expected = np.array(
252
+ [
253
+ [515, 2063, 4127, 3],
254
+ [519, 2076, 4153, 3],
255
+ [522, 2090, 4180, 3],
256
+ [525, 2103, 4206, 3],
257
+ [529, 2116, 4232, 3],
258
+ [532, 2129, 4259, 3],
259
+ [535, 2142, 4285, 3],
260
+ [538, 2155, 4311, 3],
261
+ [542, 2169, 4338, 3],
262
+ [545, 2182, 4364, 3],
263
+ [548, 2195, 4391, 3],
264
+ [552, 2208, 4417, 3],
265
+ [555, 2221, 4443, 3],
266
+ [558, 2235, 4470, 3],
267
+ [562, 2248, 4496, 3],
268
+ [565, 2261, 4522, 3],
269
+ ]
270
+ )
271
+
272
+ return (primary_expected, secondary_expected)
273
+
274
+
275
+ @pytest.fixture()
276
+ def raw_compressed_vectors():
277
+ # compressed vectors, without the first starting uncompressed vector.
278
+ # 15 primary vectors and 15 secondary vectors, corresponding to most of
279
+ # the vectors in expected_vectors.
280
+ primary_compressed = (
281
+ "0101110010"
282
+ "011100101011010111001001110010101101011100100110000000011100"
283
+ "011100100111001010110101100001011000000001101011100100111001"
284
+ "010111000111001001110010101101011100100110000000011010111001"
285
+ "001110010101101011100100111001010111000110000101100000000110"
286
+ "101110010011100101011010111001001110010101110001110010011000"
287
+ "00000110101110010011100101011"
288
+ )
289
+
290
+ secondary_compressed = (
291
+ "10001110"
292
+ "0100111001010110101100001011000000001101011100100111001010"
293
+ "1110001110010011100101011010111001001100000000110101110010"
294
+ "0111001010110101110010011100101011100011000010110000000011"
295
+ "0101110010011100101011010111001001100000000111000111001001"
296
+ "1100101011010111001001110010101101011000010110000000011100"
297
+ "011100100111001010110101110010011100101011"
298
+ )
299
+ return primary_compressed, secondary_compressed
300
+
301
+
302
+ def test_different_vector_rates(
303
+ uncompressed_vector_bytearray, expected_vectors, raw_compressed_vectors
304
+ ):
305
+ current_directory = Path(__file__).parent
306
+ test_file = current_directory / "mag_l1_test_data.pkts"
307
+ # Test file contains only normal packets
308
+ l0 = decom_packets(test_file)["norm"][0]
309
+
310
+ # overwrite vectors and different vector rates
311
+
312
+ l0.PRI_VECSEC = 4 # twice as many primary vectors as secondary vectors - 32 vectors
313
+ l0.VECTORS = np.concatenate(
314
+ (
315
+ uncompressed_vector_bytearray[:100],
316
+ uncompressed_vector_bytearray[:100],
317
+ uncompressed_vector_bytearray[100:],
318
+ )
319
+ )
320
+ l1 = process_packets([l0])
321
+ expected_day = np.datetime64("2023-11-30")
322
+
323
+ assert len(l1["magi"][expected_day].vectors) == 16
324
+ assert len(l1["mago"][expected_day].vectors) == 32
325
+
326
+ assert np.array_equal(
327
+ l1["mago"][expected_day].vectors[:, :4],
328
+ np.concatenate((expected_vectors[0], expected_vectors[0])),
329
+ )
330
+ assert np.array_equal(l1["magi"][expected_day].vectors[:, :4], expected_vectors[1])
331
+
332
+ # compressed data
333
+ # Compression headers - indicating a 16 bit width and no range section
334
+ headers = "01000000"
335
+
336
+ # 50 bits each - 16 bits per vector value, 2 bits for range.
337
+ first_primary_vector = "00000010000001000000100000010000000100000010000011"
338
+ first_secondary_vector = "00000010000000110000100000001111000100000001111111"
339
+
340
+ primary_compressed = (
341
+ first_primary_vector + raw_compressed_vectors[0] + raw_compressed_vectors[0]
342
+ )
343
+ secondary_compressed = first_secondary_vector + raw_compressed_vectors[1]
344
+
345
+ input_data = np.array(
346
+ [int(i) for i in headers + primary_compressed + secondary_compressed],
347
+ dtype=np.uint8,
348
+ )
349
+
350
+ # Will be the input data format
351
+ input_data = np.packbits(input_data)
352
+
353
+ (primary, secondary) = MagL1a.process_compressed_vectors(input_data, 31, 16)
354
+
355
+ assert (primary > 0).all()
356
+ assert np.array_equal(primary[:16], expected_vectors[0])
357
+ assert np.array_equal(secondary, expected_vectors[1])
358
+
359
+
360
+ def test_padding_uncompressed(expected_vectors):
361
+ # Test if the padding falls directly on a byte boundary
362
+ headers = "01000000"
363
+
364
+ # 50 bits each - 16 bits per vector value, 2 bits for range.
365
+ first_primary_vector = "00000010000001000000100000010000000100000010000011"
366
+ first_secondary_vector = "00000010000000110000100000001111000100000001111111"
367
+
368
+ primary_vectors = "11111111111011"
369
+ secondary_vectors = "11111111111011"
370
+
371
+ last_vector = expected_vectors[0][0].copy()
372
+ last_vector[2] = last_vector[2] - 2
373
+
374
+ input_data = np.array(
375
+ [
376
+ int(i)
377
+ for i in headers
378
+ + first_primary_vector
379
+ + primary_vectors
380
+ + first_secondary_vector
381
+ + secondary_vectors
382
+ ],
383
+ dtype=np.uint8,
384
+ )
385
+
386
+ # Will be the input data format
387
+ input_data = np.packbits(input_data)
388
+
389
+ (primary, secondary) = MagL1a.process_compressed_vectors(input_data, 3, 3)
390
+
391
+ assert np.array_equal(primary[0], expected_vectors[0][0])
392
+ assert np.array_equal(primary[1], expected_vectors[0][0])
393
+ assert np.array_equal(primary[2], last_vector)
394
+
395
+ last_vector = expected_vectors[1][0].copy()
396
+ last_vector[2] = last_vector[2] - 2
397
+
398
+ assert np.array_equal(secondary[0], expected_vectors[1][0])
399
+ assert np.array_equal(secondary[1], expected_vectors[1][0])
400
+ assert np.array_equal(secondary[2], last_vector)
401
+
402
+
403
+ def test_compare_validation_data():
404
+ current_directory = Path(__file__).parent
405
+ test_file = current_directory / "mag_l1_test_data.pkts"
406
+ # Test file contains only normal packets
407
+ l0 = decom_packets(test_file)
408
+ l1 = process_packets(l0["norm"])
409
+ # Should have one day of data
410
+ expected_day = np.datetime64("2023-11-30")
411
+ l1_mago = l1["mago"][expected_day]
412
+ l1_magi = l1["magi"][expected_day]
413
+
414
+ assert len(l1_mago.vectors) == 96
415
+ assert len(l1_magi.vectors) == 96
416
+
417
+ validation_data = pd.read_csv(current_directory / "mag_l1a_test_output.csv")
418
+
419
+ # Validation data does not have differing timestamps
420
+ for index in validation_data.index:
421
+ # Sequence in validation data starts at 5
422
+ # Mago is primary, Magi is secondary in test data
423
+
424
+ assert l1_mago.vectors[index][0] == validation_data["x_pri"][index]
425
+ assert l1_mago.vectors[index][1] == validation_data["y_pri"][index]
426
+ assert l1_mago.vectors[index][2] == validation_data["z_pri"][index]
427
+ assert l1_mago.vectors[index][3] == validation_data["rng_pri"][index]
428
+
429
+ assert l1_magi.vectors[index][0] == validation_data["x_sec"][index]
430
+ assert l1_magi.vectors[index][1] == validation_data["y_sec"][index]
431
+ assert l1_magi.vectors[index][2] == validation_data["z_sec"][index]
432
+ assert l1_magi.vectors[index][3] == validation_data["rng_sec"][index]
433
+
434
+
435
+ def test_compressed_vector_data(expected_vectors, raw_compressed_vectors):
436
+ # Values from test packet
437
+ primary_expected = expected_vectors[0]
438
+ secondary_expected = expected_vectors[1]
439
+
440
+ # Compression headers - indicating a 16 bit width and no range section
441
+ headers = "01000000"
442
+
443
+ # 50 bits each - 16 bits per vector value, 2 bits for range.
444
+ first_primary_vector = "00000010000001000000100000010000000100000010000011"
445
+ first_secondary_vector = "00000010000000110000100000001111000100000001111111"
446
+
447
+ primary_compressed = first_primary_vector + raw_compressed_vectors[0]
448
+ secondary_compressed = first_secondary_vector + raw_compressed_vectors[1]
449
+
450
+ padding = "00000" # Pad to byte boundary
451
+ input_data = np.array(
452
+ [int(i) for i in headers + primary_compressed + secondary_compressed + padding],
453
+ dtype=np.uint8,
454
+ )
455
+
456
+ # Will be the input data format
457
+ input_data = np.packbits(input_data)
458
+
459
+ (primary, secondary) = MagL1a.process_compressed_vectors(input_data, 16, 16)
460
+
461
+ assert np.array_equal(primary[0], primary_expected[0])
462
+ assert np.array_equal(secondary[0], secondary_expected[0])
463
+
464
+ # There should be 16 vectors for both primary and secondary, with 4 values per
465
+ # vector.
466
+ assert primary.shape[0] == 16
467
+ assert secondary.shape[0] == 16
468
+
469
+ assert primary.shape[1] == 4
470
+ assert secondary.shape[1] == 4
471
+
472
+ assert np.array_equal(primary, primary_expected)
473
+ assert np.array_equal(secondary, secondary_expected)
474
+
475
+ # range data has 2 bits per vector, primary and then secondary in sequence.
476
+ # It excludes the first vector, making the length (primary_count - 1) * 2
477
+ range_primary = "000000000000000101101011111111"
478
+
479
+ # This includes the first range value and all the ranges from range_primary
480
+ expected_range_primary = [3, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3]
481
+ range_secondary = "000000000000000101101011111101"
482
+ expected_range_secondary = [3, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 1]
483
+ # 16 bit width with range section
484
+ headers = "01000010"
485
+ input_data = np.array(
486
+ [
487
+ int(i)
488
+ for i in headers
489
+ + primary_compressed
490
+ + secondary_compressed
491
+ + padding
492
+ + range_primary
493
+ + range_secondary
494
+ ],
495
+ dtype=np.uint8,
496
+ )
497
+
498
+ # In this step, input_data is automatically padded to a byte boundary by adding
499
+ # zeros to the end
500
+ input_data = np.packbits(input_data)
501
+
502
+ for i in range(len(expected_range_primary)):
503
+ primary_expected[i][3] = expected_range_primary[i]
504
+ secondary_expected[i][3] = expected_range_secondary[i]
505
+
506
+ (primary_with_range, secondary_with_range) = MagL1a.process_compressed_vectors(
507
+ input_data, 16, 16
508
+ )
509
+
510
+ assert primary_with_range.shape[0] == 16
511
+ assert secondary_with_range.shape[0] == 16
512
+
513
+ assert np.array_equal(primary_with_range, primary_expected)
514
+ assert np.array_equal(secondary_with_range, secondary_expected)
515
+
516
+
517
+ def test_switch_to_uncompressed_vector_data(
518
+ expected_vectors, uncompressed_vector_bytearray
519
+ ):
520
+ primary_compressed = (
521
+ "000000100000010000001000000100000001000000100000110101110010"
522
+ "011100101011010111001001110010101101011100100110000000011100"
523
+ "011100100111001010110101100001011000000001101011100100111001"
524
+ "010111000111001001110010101101011100100110000000011010111001"
525
+ "001110010101101011100100111001010111000110000101100000000110"
526
+ "101110010011100101011010111001001110010101110001110010011000"
527
+ "000001100000000000000000000010111000000000000000000000010011"
528
+ "000000000000000000000000100101011"
529
+ )
530
+
531
+ # 4 uncompressed vectors from uncompressed_vector_bytearray
532
+ uncompressed_bits = (
533
+ "000000100000010000001000000100000001000000100000"
534
+ "000000100000011100001000000111010001000000111010"
535
+ "000000100000101000001000001010100001000001010100"
536
+ "000000100000110100001000001101110001000001101111"
537
+ )
538
+
539
+ secondary_compressed = (
540
+ "0000001000000011000010000000111100010000000111111110001110"
541
+ "0100111001010110101100001011000000001101011100100111001010"
542
+ "1110001110010011100101011010111001001100000000110101110010"
543
+ "0111001010110101110010011100101011100011000010110000000011"
544
+ "0101110010011100101011010111001001100000000111000111001001"
545
+ "1100101011010111001001110010101101011000010110000000011100"
546
+ "0111001001110010101100000000000000101110000000000000000000"
547
+ "00010011100101000000000011"
548
+ )
549
+
550
+ uncompressed_expected_vectors = expected_vectors[0][:4]
551
+
552
+ headers = "01000000"
553
+
554
+ input_data = np.array(
555
+ [
556
+ int(i)
557
+ for i in headers
558
+ + primary_compressed
559
+ + uncompressed_bits
560
+ + secondary_compressed
561
+ + uncompressed_bits
562
+ ],
563
+ dtype=np.uint8,
564
+ )
565
+
566
+ input_data = np.packbits(input_data)
567
+ (primary, secondary) = MagL1a.process_compressed_vectors(input_data, 20, 20)
568
+
569
+ # The 16th compressed vector is bad because it needs to be >60 bits
570
+ assert np.array_equal(primary[:15], expected_vectors[0][:-1])
571
+ assert np.array_equal(primary[16:], uncompressed_expected_vectors)
572
+
573
+ assert np.array_equal(secondary[:15], expected_vectors[1][:-1])
574
+ assert np.array_equal(secondary[16:], uncompressed_expected_vectors)
575
+
576
+ # Test if first primary vector is too long
577
+ primary_first_vector = "00000010000001000000100000010000000100000010000011"
578
+ primary_long_second_vector = (
579
+ "0000000000000000000001011100000000000000000000001"
580
+ "0011000000000000000000000000100101011"
581
+ )
582
+
583
+ input_data = np.array(
584
+ [
585
+ int(i)
586
+ for i in headers
587
+ + primary_first_vector
588
+ + primary_long_second_vector
589
+ + uncompressed_bits
590
+ + secondary_compressed
591
+ ],
592
+ dtype=np.uint8,
593
+ )
594
+ input_data = np.packbits(input_data)
595
+
596
+ (primary, secondary) = MagL1a.process_compressed_vectors(input_data, 6, 16)
597
+ assert len(primary) == 6
598
+ assert np.array_equal(primary[0], expected_vectors[0][0])
599
+ assert np.array_equal(primary[2:], uncompressed_expected_vectors)
600
+
601
+
602
+ def test_different_compression_width(raw_compressed_vectors):
603
+ # Compression headers - indicating a 12 bit width and no range section
604
+ headers = "00110000"
605
+
606
+ first_primary_vector = "00100000010010000001000000000010000011"
607
+ first_secondary_vector = "00000001011000000000000011111111111101"
608
+
609
+ primary_compressed = raw_compressed_vectors[0]
610
+ secondary_compressed = raw_compressed_vectors[1]
611
+
612
+ expected_first_vector = [516, -2032, 32, 3]
613
+ expected_second_vector = [22, 0, -1, 1]
614
+
615
+ padding = "00000" # Pad to byte boundary
616
+
617
+ input_data = np.array(
618
+ [
619
+ int(i)
620
+ for i in headers
621
+ + first_primary_vector
622
+ + primary_compressed
623
+ + first_secondary_vector
624
+ + secondary_compressed
625
+ + padding
626
+ ],
627
+ dtype=np.uint8,
628
+ )
629
+
630
+ input_data = np.packbits(input_data)
631
+ (primary, secondary) = MagL1a.process_compressed_vectors(input_data, 16, 16)
632
+
633
+ assert np.array_equal(primary[0], expected_first_vector)
634
+ assert np.array_equal(secondary[0], expected_second_vector)
635
+
636
+ assert sum(primary[-1]) != 0
637
+ assert sum(secondary[-1]) != 0
638
+
639
+ assert len(primary) == 16
640
+ assert len(secondary) == 16
641
+
642
+
643
+ def test_real_uncompressed_vector_data(uncompressed_vector_bytearray, expected_vectors):
644
+ primary_expected = expected_vectors[0]
645
+ secondary_expected = expected_vectors[1]
646
+
647
+ (primary, secondary) = MagL1a.process_uncompressed_vectors(
648
+ uncompressed_vector_bytearray, 16, 16
649
+ )
650
+ assert np.array_equal(primary_expected, primary)
651
+ assert np.array_equal(secondary_expected, secondary)
652
+
653
+
654
+ def test_accumulate_vectors():
655
+ range = 4
656
+ start_vector = np.array([1, 2, 3, range], dtype=np.uint)
657
+
658
+ diff_vectors = [1, 1, 1, 3, 0, -3, -1, -10, 1]
659
+
660
+ expected_vectors = np.array(
661
+ [[1, 2, 3, range], [2, 3, 4, range], [5, 3, 1, range], [4, -7, 2, range]]
662
+ )
663
+
664
+ test_vectors = MagL1a.convert_diffs_to_vectors(start_vector, diff_vectors, 4)
665
+
666
+ assert np.array_equal(test_vectors, expected_vectors)
667
+
668
+
669
+ sixteen_bits = "00000010000001000000100000010000000100000010000011"
670
+ twelve_bits = "000000010110000000000000111111111111"
671
+ eighteenbits = "000000100000010010000010000001000011000100000010000001"
672
+ twentybits = "00000010000001000010000010000001000000000000000000100000000101"
673
+
674
+
675
+ @pytest.mark.parametrize(
676
+ "vector_string, expected_vectors, width, include_range",
677
+ [
678
+ (sixteen_bits, [516, 2064, 4128, 3], 16, 1),
679
+ (twelve_bits, [22, 0, -1, 0], 12, 0),
680
+ (eighteenbits, [2066, 8259, 16513, 0], 18, 0),
681
+ (twentybits, [8258, 33024, 513, 1], 20, 1),
682
+ ],
683
+ ids=["16bit", "12bit", "18bit", "20bit"],
684
+ )
685
+ def test_unpack_one_vector(
686
+ vector_string, expected_vectors, uncompressed_vector_bytearray, width, include_range
687
+ ):
688
+ test_vector = np.array([int(i) for i in vector_string], dtype=np.uint8)
689
+ test_output = MagL1a.unpack_one_vector(test_vector, width, include_range)
690
+ assert all(test_output == expected_vectors)
691
+
692
+
693
+ def test_twos_complement():
694
+ # -19 in binary
695
+ input_test = np.array([1, 1, 1, 0, 1, 1, 0, 1], dtype=np.uint8)
696
+ input_test_uint = np.packbits(input_test)
697
+
698
+ twos_complement = MagL1a.twos_complement(input_test_uint, 8)
699
+ assert twos_complement == -19
700
+ assert twos_complement.dtype == np.int32
701
+
702
+ # In 12 bits, the number is 237
703
+ twos_complement = MagL1a.twos_complement(input_test_uint, 12)
704
+ assert twos_complement == 237
705
+
706
+ # Higher bit number
707
+ # -19001 in 16 bits
708
+ input_test = np.array(
709
+ [1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1], dtype=np.uint8
710
+ )
711
+ input_test_uint = np.packbits(input_test)
712
+ twos_complement = MagL1a.twos_complement(input_test_uint, 16)
713
+
714
+ assert twos_complement == -19001
715
+
716
+
717
+ def test_decode_fib_zig_zag():
718
+ test_values = np.array([1, 0, 0, 1, 0, 0, 1, 1])
719
+ assert MagL1a.decode_fib_zig_zag(test_values) == 13
720
+
721
+ test_values = np.array([1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1])
722
+ assert MagL1a.decode_fib_zig_zag(test_values) == -138
723
+
724
+
725
+ def test_process_uncompressed_vector_data():
726
+ expected_vector_data = [[1001, 1002, -3001, 3], [2001, -2002, -3333, 1]]
727
+
728
+ # 100 bits, created by hand by appending all bits from expected_vector_data into one
729
+ # hex string, with range being 2 bits (so the second half is offset from the hex
730
+ # values)
731
+ hex_string = "03E903EAF447C1F47E0BBCBED0"
732
+ input_data = np.frombuffer(bytes.fromhex(hex_string), dtype=np.dtype(">b"))
733
+ total_primary_vectors = 1
734
+ total_secondary_vectors = 1
735
+
736
+ # 36 bytes
737
+ (primary_vectors, secondary_vectors) = MagL1a.process_vector_data(
738
+ input_data, total_primary_vectors, total_secondary_vectors, 0
739
+ )
740
+
741
+ assert primary_vectors[0][0] == expected_vector_data[0][0]
742
+ assert primary_vectors[0][1] == expected_vector_data[0][1]
743
+ assert primary_vectors[0][2] == expected_vector_data[0][2]
744
+ assert primary_vectors[0][3] == expected_vector_data[0][3]
745
+
746
+ assert secondary_vectors[0][0] == expected_vector_data[1][0]
747
+ assert secondary_vectors[0][1] == expected_vector_data[1][1]
748
+ assert secondary_vectors[0][2] == expected_vector_data[1][2]
749
+ assert secondary_vectors[0][3] == expected_vector_data[1][3]
750
+
751
+
752
+ def test_time_tuple():
753
+ example_time_tuple = TimeTuple(439067318, 64618)
754
+
755
+ test_add = example_time_tuple + 2
756
+
757
+ assert test_add == TimeTuple(439067320, 64618)
758
+
759
+ # 1 / MAX_FINE_TIME
760
+ test_add = example_time_tuple + 1 / MAX_FINE_TIME
761
+
762
+ assert test_add == TimeTuple(439067318, 64619)
763
+
764
+ test_add = example_time_tuple + (1000 / MAX_FINE_TIME)
765
+
766
+ assert test_add == TimeTuple(439067319, 83)
767
+
768
+
769
+ def test_calculate_vector_time():
770
+ test_vectors = np.array(
771
+ [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=np.uint
772
+ )
773
+ test_vecsec = 2
774
+ start_time = TimeTuple(10000, 0)
775
+
776
+ test_data = MagL1a.calculate_vector_time(test_vectors, test_vecsec, start_time)
777
+
778
+ converted_start_time_ns = met_to_j2000ns(start_time.to_seconds())
779
+
780
+ skips_ns = np.timedelta64(int(1 / test_vecsec * 1e9), "ns")
781
+ expected_data = np.array(
782
+ [
783
+ [1, 2, 3, int(converted_start_time_ns)],
784
+ [4, 5, 6, int(converted_start_time_ns + skips_ns)],
785
+ [7, 8, 9, int(converted_start_time_ns + skips_ns * 2)],
786
+ [10, 11, 12, int(converted_start_time_ns + skips_ns * 3)],
787
+ ]
788
+ )
789
+ assert (test_data == expected_data).all()
790
+
791
+
792
+ def test_mag_l1a_data():
793
+ test_vectors = np.array(
794
+ [
795
+ [1, 2, 3, 4, 10000],
796
+ [5, 6, 7, 8, 10050],
797
+ [9, 10, 11, 12, 10100],
798
+ [13, 13, 11, 12, 10150],
799
+ ],
800
+ dtype=np.uint,
801
+ )
802
+ test_vecsec = 2
803
+ start_time = TimeTuple(10000, 0)
804
+
805
+ packet_properties = MagL1aPacketProperties(
806
+ 435954628, start_time, test_vecsec, 1, 0, 0, 1
807
+ )
808
+ mag_l1a = MagL1a(True, True, 10000, test_vectors, packet_properties)
809
+
810
+ new_vectors = np.array(
811
+ [[13, 14, 15, 16, 10400], [16, 17, 18, 19, 10450]], dtype=np.uint
812
+ )
813
+
814
+ new_seq = 5
815
+ new_properties = MagL1aPacketProperties(
816
+ 435954628, TimeTuple(10400, 0), test_vecsec, 0, new_seq, 0, 1
817
+ )
818
+ mag_l1a.append_vectors(new_vectors, new_properties)
819
+
820
+ assert np.array_equal(
821
+ mag_l1a.vectors,
822
+ np.array(
823
+ [
824
+ [1, 2, 3, 4, 10000],
825
+ [5, 6, 7, 8, 10050],
826
+ [9, 10, 11, 12, 10100],
827
+ [13, 13, 11, 12, 10150],
828
+ [13, 14, 15, 16, 10400],
829
+ [16, 17, 18, 19, 10450],
830
+ ],
831
+ dtype=np.uint,
832
+ ),
833
+ )
834
+ assert mag_l1a.missing_sequences == [1, 2, 3, 4]
835
+
836
+
837
+ def test_mag_l1a():
838
+ current_directory = Path(__file__).parent
839
+ test_file = current_directory / "mag_l1_test_data.pkts"
840
+
841
+ output_data = mag_l1a(test_file, "v001")
842
+
843
+ # Test data is one day's worth of NORM data, so it should return one raw, one MAGO
844
+ # and one MAGI dataset
845
+ assert len(output_data) == 3
846
+ expected_logical_source = [
847
+ "imap_mag_l1a_norm-raw",
848
+ "imap_mag_l1a_norm-mago",
849
+ "imap_mag_l1a_norm-magi",
850
+ ]
851
+
852
+ for data_type in [data.attrs["Logical_source"] for data in output_data]:
853
+ assert data_type in expected_logical_source
854
+
855
+ for data in output_data:
856
+ assert data.attrs["Data_version"] == "v001"