Skip to content

Write ISTP BIN_LOCATION attributes as CDF_REAL4#330

Merged
bryan-harter merged 1 commit into
lasp:mainfrom
davidt0x:fix/istp-bin-location-real4
May 6, 2026
Merged

Write ISTP BIN_LOCATION attributes as CDF_REAL4#330
bryan-harter merged 1 commit into
lasp:mainfrom
davidt0x:fix/istp-bin-location-real4

Conversation

@davidt0x
Copy link
Copy Markdown
Contributor

@davidt0x davidt0x commented May 1, 2026

Summary

Write ISTP BIN_LOCATION variable attributes as CDF_REAL4 when using xarray_to_cdf(..., istp=True).

SPDF ISTP validation expects BIN_LOCATION to be stored as REAL*4 / CDF_REAL4. Previously, cdflib relied on generic attribute type inference, so values like 0 were written as CDF_INT8 and values like 0.5 were written as CDF_DOUBLE.

That produced SPDF validation errors such as:

Bin_location has a data type of CDF_INT8. It should be CDF_REAL4.
Bin_location has a data type of CDF_DOUBLE. It should be CDF_REAL4.

Details

BIN_LOCATION is an ISTP variable attribute describing where a timestamp falls within a measurement bin. The SPDF ISTP guide defines it as a REAL*4 attribute:

https://spdf.gsfc.nasa.gov/istp_guide/vattributes.html#BIN_LOCATION

This PR adds a narrow ISTP-mode special case in xarray_to_cdf so BIN_LOCATION is serialized as:

[np.float32(value), "CDF_REAL4"]

The behavior only applies when istp=True. Non-ISTP writes continue to use the existing inferred attribute type behavior.

Validation

Added regression tests for:

  • Integer BIN_LOCATION values written as CDF_REAL4 in ISTP mode.
  • Fractional BIN_LOCATION values written as CDF_REAL4 in ISTP mode.
  • Non-ISTP writes preserving existing type inference.

Targeted test run:

pytest tests/test_xarray_reader_writer.py -k 'bin_location or compression_skip_vars or skips_epoch_compression'

Result:

4 passed

Validated against a real IMAP CDF that previously triggered the SPDF checker error. Before rewriting:

epoch BIN_LOCATION:    CDF_INT8
latitude BIN_LOCATION: CDF_DOUBLE

After rewriting through this branch:

epoch BIN_LOCATION:    CDF_REAL4
latitude BIN_LOCATION: CDF_REAL4

The SPDF Java checker no longer reports the Bin_location has a data type ... should be CDF_REAL4 errors on the rewritten file.

Related IMAP validation context:

IMAP-Science-Operations-Center/imap_processing#2577

SPDF ISTP validation expects BIN_LOCATION variable attributes to be
stored as REAL*4/CDF_REAL4. xarray_to_cdf previously relied on generic
attribute type inference, which wrote integer values such as 0 as
CDF_INT8 and floating-point values such as 0.5 as CDF_DOUBLE.

This caused SPDF validation errors like:

    Bin_location has a data type of CDF_INT8. It should be CDF_REAL4.
    Bin_location has a data type of CDF_DOUBLE. It should be CDF_REAL4.

When writing with istp=True, explicitly serialize BIN_LOCATION as
[np.float32(value), "CDF_REAL4"]. Preserve the existing inferred
attribute typing behavior for non-ISTP writes.

Add regression tests covering ISTP BIN_LOCATION output for integer and
fractional values, and non-ISTP behavior.
@bryan-harter bryan-harter merged commit cf5ae1f into lasp:main May 6, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants