Skip to content

Preserve complex values in nonsparse EPOCH16 writes - #347

Open
vera-rubin wants to merge 1 commit into
lasp:mainfrom
vera-rubin:fix/epoch16-records
Open

vera-rubin wants to merge 1 commit into
lasp:mainfrom
vera-rubin:fix/epoch16-records

Conversation

@vera-rubin

Copy link
Copy Markdown

When we write one CDF_EPOCH16 timestamp to a nonsparse variable, it becomes two records with zero picoseconds. For complex(63871286400, 123456789012), we get [63871286400+0j, 123456789012+0j] and Last_Rec=1, instead of one complex value and Last_Rec=0, as the documented representation requires.

from cdflib import CDF, cdfwrite

with cdfwrite.CDF("epoch16.cdf") as writer:
    writer.write_var(
        {"Variable": "Epoch", "Data_Type": writer.CDF_EPOCH16,
         "Num_Elements": 1, "Rec_Vary": True, "Dim_Sizes": []},
        var_data=[complex(63871286400, 123456789012)],
    )
with CDF("epoch16.cdf") as reader:
    print(reader.varget("Epoch"), reader.varinq("Epoch").Last_Rec)

We now pass EPOCH16 values directly to the shared converter, as sparse writes already do, preserving both components and the record count.

We added a regression test and ran the existing reader/writer tests.

— ChipLab

This branch has not been deployed

No deployments
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.

1 participant