Skip to content

Commit c2cdc9d

Browse files
authored
1 parent f5ebc7b commit c2cdc9d

5 files changed

Lines changed: 74 additions & 41 deletions

File tree

imap_processing/cdf/config/imap_ialirt_l1_variable_attrs.yaml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ codice_hi_energy_plus:
209209
dtype: float32
210210
LABLAXIS: Energy upper delta
211211

212-
codice_hi_elevation:
213-
CATDESC: Elevation Angle
214-
FIELDNAM: Elevation Angle
215-
LABLAXIS: Elevation Angle
212+
codice_hi_polar:
213+
CATDESC: Polar Angle
214+
FIELDNAM: Polar Angle
215+
LABLAXIS: Polar Angle
216216
SCALETYP: linear
217217
UNITS: degrees
218218
VALIDMIN: 0.0
@@ -222,9 +222,9 @@ codice_hi_elevation:
222222
FORMAT: F12.6
223223
dtype: float32
224224

225-
codice_hi_elevation_labels:
226-
CATDESC: CoDICE-Hi elevation labels
227-
FIELDNAM: CoDICE-Hi elevation labels
225+
codice_hi_polar_labels:
226+
CATDESC: CoDICE-Hi polar labels
227+
FIELDNAM: CoDICE-Hi polar labels
228228
FORMAT: A12
229229
VAR_TYPE: metadata
230230
UNITS: " "
@@ -262,7 +262,7 @@ swe_electron_energy:
262262
# Variables
263263
codice_hi_h:
264264
<<: *default_float32
265-
CATDESC: Proton flux from CoDICE-Hi in 15 energy bins between 0.02 to 3.62 MeV over 4 spin sectors and 4 azimuth bins
265+
CATDESC: Proton flux from CoDICE-Hi in 15 energy bins between 0.02 to 3.62 MeV over 4 spin sectors and 4 polar angle bins
266266
FIELDNAM: H+ intensity
267267
LABLAXIS: H+ intensity
268268
DEPEND_0: codice_hi_epoch
@@ -271,9 +271,9 @@ codice_hi_h:
271271
VALIDMAX: 100000000.0
272272
DEPEND_1: codice_hi_energy_center
273273
DEPEND_2: codice_hi_spin_sector
274-
DEPEND_3: codice_hi_elevation
274+
DEPEND_3: codice_hi_polar
275275
DISPLAY_TYPE: no_plot
276-
FORMAT: F6.1
276+
FORMAT: F11.1
277277
VAR_NOTES: Energy ranges (MeV) are 0.0200 to 0.0283, 0.0283 to 0.0400, 0.0400 to 0.0566, 0.0566 to 0.0800, 0.0800 to 0.113, 0.113 to 0.160, 0.160 to 0.226, 0.226 to 0.320, 0.320 to 0.453, 0.453 to 0.640, 0.640 to 0.905, 0.905 to 1.28, 1.28 to 1.81, 1.81 to 2.56, 2.56 to 3.62.
278278

279279
codice_lo_c_over_o_abundance:
@@ -362,6 +362,7 @@ hit_e_a_side_med_en:
362362
UNITS: counts per second
363363
VALIDMIN: 0
364364
VALIDMAX: 1000000000.0
365+
FORMAT: F17.6
365366
VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction.
366367

367368
hit_e_a_side_high_en:
@@ -395,6 +396,7 @@ hit_e_b_side_med_en:
395396
UNITS: counts per second
396397
VALIDMIN: 0
397398
VALIDMAX: 1000000000.0
399+
FORMAT: F17.6
398400
VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction.
399401

400402
hit_e_b_side_high_en:
@@ -417,6 +419,7 @@ hit_h_omni_low_en:
417419
UNITS: counts per second
418420
VALIDMIN: 0
419421
VALIDMAX: 1000000000.0
422+
FORMAT: F17.6
420423
VAR_NOTES: Omni indicates the sum of the number of particles divided by the area of the full sky.
421424

422425
hit_h_omni_med_en:
@@ -428,6 +431,7 @@ hit_h_omni_med_en:
428431
UNITS: counts per second
429432
VALIDMIN: 0
430433
VALIDMAX: 1000000000.0
434+
FORMAT: F17.6
431435
VAR_NOTES: Omni indicates the sum of the number of particles divided by the area of the full sky.
432436

433437
hit_h_a_side_high_en:
@@ -461,6 +465,7 @@ hit_he_omni_low_en:
461465
UNITS: counts per second
462466
VALIDMIN: 0
463467
VALIDMAX: 1000000000.0
468+
FORMAT: F17.6
464469
VAR_NOTES: Omni indicates the sum of the number of particles divided by the area of the full sky.
465470

466471
hit_he_omni_high_en:
@@ -472,6 +477,7 @@ hit_he_omni_high_en:
472477
UNITS: counts per second
473478
VALIDMIN: 0
474479
VALIDMAX: 1000000000.0
480+
FORMAT: F17.6
475481
VAR_NOTES: Omni indicates the sum of the number of particles divided by the area of the full sky.
476482

477483
mag_B_magnitude:

imap_processing/ialirt/calculate_ingest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def format_ingest_data(last_filename: str, log_lines: list) -> dict:
107107
last_timestamp_str = last_timestamp_str.replace("_", ":")
108108
end_of_time = datetime.strptime(last_timestamp_str, "%Y-%jT%H:%M:%S")
109109

110-
# File is created every 5 minutes.
110+
# File creation time of last file minus 48 hrs.
111111
start_of_time = datetime.strptime(last_timestamp_str, "%Y-%jT%H:%M:%S") - timedelta(
112-
minutes=5
112+
hours=48
113113
)
114114

115115
# Parse file.

imap_processing/ialirt/utils/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"codice_hi_epoch",
1313
"codice_hi_energy_center",
1414
"codice_hi_spin_sector",
15-
"codice_hi_elevation",
15+
"codice_hi_polar",
1616
],
1717
# C/O abundance ratio
1818
"codice_lo_c_over_o_abundance": ["codice_lo_epoch"],

imap_processing/ialirt/utils/create_xarray.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Creates xarray based on structure of queried DynamoDB."""
22

33
from collections import defaultdict
4+
from datetime import datetime, timedelta
45

56
import numpy as np
67
import xarray as xr
@@ -18,6 +19,7 @@
1819
hit_restricted_fields,
1920
swe_energy,
2021
)
22+
from imap_processing.spice.time import et_to_ttj2000ns, str_to_et
2123

2224

2325
def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0912
@@ -44,6 +46,19 @@ def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0
4446
epochs: dict[str, list[int]] = {inst: [] for inst in (one_epoch | multi_epoch)}
4547
by_inst: dict[str, list[dict]] = defaultdict(list)
4648

49+
# Get the start and end ttj2000ns.
50+
date = records[0]["time_utc"] # e.g. "2025-06-20T08:00:00Z"
51+
52+
# Parse as UTC
53+
dt = datetime.fromisoformat(date)
54+
55+
# Start and end of that UTC day
56+
start_str = dt.date().isoformat() + "T00:00:00Z"
57+
end_str = (dt.date() + timedelta(days=1)).isoformat() + "T00:00:00Z"
58+
59+
start_ttj2000 = et_to_ttj2000ns(str_to_et(start_str))
60+
end_ttj2000 = et_to_ttj2000ns(str_to_et(end_str))
61+
4762
for record in records:
4863
inst = record.get("instrument")
4964
by_inst[record["instrument"]].append(record)
@@ -162,21 +177,21 @@ def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0
162177
),
163178
)
164179

165-
elevation = xr.DataArray(
180+
polar = xr.DataArray(
166181
HI_IALIRT_ELEVATION_ANGLE,
167-
name="codice_hi_elevation",
168-
dims=["codice_hi_elevation"],
182+
name="codice_hi_polar",
183+
dims=["codice_hi_polar"],
169184
attrs=cdf_manager.get_variable_attributes(
170-
"codice_hi_elevation", check_schema=False
185+
"codice_hi_polar", check_schema=False
171186
),
172187
)
173188

174-
elevation_labels = xr.DataArray(
175-
[f"{float(v):.1f}deg" for v in elevation.values],
176-
name="codice_hi_elevation_labels",
177-
dims=["codice_hi_elevation"],
189+
polar_labels = xr.DataArray(
190+
[f"{float(v):.1f}deg" for v in polar.values],
191+
name="codice_hi_polar_labels",
192+
dims=["codice_hi_polar"],
178193
attrs=cdf_manager.get_variable_attributes(
179-
"codice_hi_elevation_labels", check_schema=False
194+
"codice_hi_polar_labels", check_schema=False
180195
),
181196
)
182197

@@ -221,8 +236,8 @@ def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0
221236
"codice_hi_energy_center": codice_hi_energy_centers,
222237
"codice_hi_energy_minus": codice_energy_minus,
223238
"codice_hi_energy_plus": codice_energy_plus,
224-
"codice_hi_elevation": elevation,
225-
"codice_hi_elevation_labels": elevation_labels,
239+
"codice_hi_polar": polar,
240+
"codice_hi_polar_labels": polar_labels,
226241
"codice_hi_spin_sector": spin_sector,
227242
"codice_hi_spin_sector_labels": spin_sector_labels,
228243
"swe_electron_energy": swe_electron_energy,
@@ -305,4 +320,16 @@ def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0
305320
if key.startswith("sc_"):
306321
dataset[key].data[i, :] = np.asarray(record[key], dtype=np.float32)
307322

323+
# Trim data that does not fit within the UTC day.
324+
for inst in epochs.keys():
325+
if inst == "spacecraft":
326+
dim = "ephemeris_epoch"
327+
else:
328+
dim = f"{inst}_epoch"
329+
330+
if dim in dataset.coords:
331+
dataset = dataset.sel(
332+
{dim: (dataset[dim] >= start_ttj2000) & (dataset[dim] < end_ttj2000)}
333+
)
334+
308335
return dataset

imap_processing/tests/ialirt/unit/test_create_xarray.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def test_create_dataset():
1616
{
1717
"instrument": "mag",
1818
"time_utc": "2025-06-20T08:00:00",
19-
"ttj2000ns": 123456789000001,
20-
"mag_epoch": 123456789000001,
19+
"ttj2000ns": 803692869184000000,
20+
"mag_epoch": 803692869184000000,
2121
"mag_B_GSE": [Decimal("5.0"), Decimal("-3.2"), Decimal("1.1")],
2222
"mag_B_GSM": [Decimal("4.8"), Decimal("-3.0"), Decimal("1.0")],
2323
"mag_B_RTN": [Decimal("5.1"), Decimal("-3.3"), Decimal("1.2")],
@@ -30,12 +30,12 @@ def test_create_dataset():
3030
{
3131
"instrument": "codice_hi",
3232
"time_utc": "2025-06-20T08:00:00",
33-
"ttj2000ns": 123456789000000,
33+
"ttj2000ns": 803692869184000000,
3434
"codice_hi_epoch": [
35-
123456789000000,
36-
123456789000000,
37-
123456789000000,
38-
123456789000000,
35+
803692869184000000,
36+
803692869184000000,
37+
803692869184000000,
38+
803692869184000000,
3939
],
4040
"codice_hi_h": [
4141
[
@@ -48,8 +48,8 @@ def test_create_dataset():
4848
{
4949
"instrument": "codice_lo",
5050
"time_utc": "2025-06-20T08:00:00",
51-
"ttj2000ns": 123456789000000,
52-
"codice_lo_epoch": 123456789000000,
51+
"ttj2000ns": 803692869184000000,
52+
"codice_lo_epoch": 803692869184000000,
5353
"codice_lo_c_over_o_abundance": Decimal("0.5"),
5454
"codice_lo_mg_over_o_abundance": Decimal("0.3"),
5555
"codice_lo_fe_over_o_abundance": Decimal("0.2"),
@@ -60,8 +60,8 @@ def test_create_dataset():
6060
{
6161
"instrument": "hit",
6262
"time_utc": "2025-06-20T08:00:00",
63-
"ttj2000ns": 123456789000002,
64-
"hit_epoch": 123456789000002,
63+
"ttj2000ns": 803692869184000000,
64+
"hit_epoch": 803692869184000000,
6565
"hit_e_a_side_low_en": Decimal("0.0"),
6666
"hit_e_a_side_med_en": Decimal("0.0"),
6767
"hit_e_a_side_high_en": Decimal("0.0"),
@@ -78,17 +78,17 @@ def test_create_dataset():
7878
{
7979
"instrument": "swapi",
8080
"time_utc": "2025-06-20T08:00:00",
81-
"ttj2000ns": 123456789000002,
82-
"swapi_epoch": 123456789000002,
81+
"ttj2000ns": 803692869184000000,
82+
"swapi_epoch": 803692869184000000,
8383
"swapi_pseudo_proton_speed": Decimal("400.0"),
8484
"swapi_pseudo_proton_density": Decimal("5.0"),
8585
"swapi_pseudo_proton_temperature": Decimal("100000.0"),
8686
},
8787
{
8888
"instrument": "swe",
8989
"time_utc": "2025-06-20T08:00:00",
90-
"ttj2000ns": 123456789000002,
91-
"swe_epoch": 123456789000002,
90+
"ttj2000ns": 803692869184000000,
91+
"swe_epoch": 803692869184000000,
9292
"swe_normalized_counts": [Decimal("0.0") for _ in range(8)],
9393
"swe_counterstreaming_electrons": Decimal("1.0"),
9494
},
@@ -140,7 +140,7 @@ def test_create_dataset():
140140
np.zeros(8, dtype=np.uint32),
141141
)
142142
np.testing.assert_allclose(
143-
dataset["mag_B_GSE"].sel(mag_epoch=123456789000001).values,
143+
dataset["mag_B_GSE"].sel(mag_epoch=803692869184000000).values,
144144
[5.0, -3.2, 1.1],
145145
)
146146

@@ -155,7 +155,7 @@ def test_create_dataset():
155155
"codice_hi_epoch",
156156
"codice_hi_energy_center",
157157
"codice_hi_spin_sector",
158-
"codice_hi_elevation",
158+
"codice_hi_polar",
159159
)
160160

161161
# Tests that you can write to a cdf.

0 commit comments

Comments
 (0)