Single-element arrays are read back as scalars from NetCDF files
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
Research direction
Start by reading read_from_netcdf, which the issue identifies as returning values[0] for every variable of size 1. Trace how load_events and load_lcurve use its result, then run the NetCDF round-trip examples in the issue. Done means a one-event time remains an array and a one-bin light curve loads successfully.
Written by the indexing model from the issue text.
Description
Describe the bug
A NetCDF file (.nc, the default format) cannot hold a one-element array apart from a scalar: read_from_netcdf returns values[0] for every variable of size 1. So an event list with a single event comes back with time as a scalar, and a light curve with a single bin cannot be loaded at all. The pickle and HDF5 formats round-trip both correctly.
To Reproduce
from stingray import EventList, Lightcurve
from hendrics.io import save_events, load_events, save_lcurve, load_lcurve
save_events(EventList(time=[1.0], gti=[[0, 5]], mjdref=55000.0), "one_ev.nc")
print(load_events("one_ev.nc").time) # 1.0 (a scalar); with "one_ev.p" it is [1.]
lc = Lightcurve([0.5], [3.0], dt=1, gti=[[0, 1]], mjdref=55000.0)
save_lcurve(lc, "one_lc.nc")
load_lcurve("one_lc.nc") # ValueError: time array must be at least 1D
Expected behavior
[1.] and a one-bin light curve, as with the other formats.
Desktop
- OS: macOS
- Python version 3.12
- HENDRICS Version: development from github (main)
- Dominant language
- Jupyter Notebook
- Stars
- 26
- Forks
- 18
- Avg merge
- 1h 26m
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from StingraySoftware/HENDRICS
-
memmapped_arange ignores the start value and drops the last point above the memmap thresholdPossibly taken @prathameshfuke claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
StingraySoftware/HENDRICS#213 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 48/100
StingraySoftware/HENDRICS#198 ·
-
HEN2xspec cannot handle Lomb-Scargle spectraMay be free again @aviralgarg05 claimed this 26 days ago, and no pull request is open. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
StingraySoftware/HENDRICS#197 · 1 comment ·
-
tmp filesOpen
Difficulty 3/5 1-2 days Newbie friendliness 35/100
StingraySoftware/HENDRICS#174 · 1 comment ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 20/100
StingraySoftware/HENDRICS#155 ·
All issues in StingraySoftware/HENDRICS
Similar issues
-
country:US rating:6 request-theme type:TV SHOW
Difficulty 1/5 Under an hour Newbie friendliness 65/100
LizardByte/ThemerrDB#10501 · 1 comment ·
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
agentscope-ai/agentscope#4563 ·
Maintainers usually reply within 2 days
-
Split part lines show the bare category name, ordinary booking lines show the full category pathOpenbugfix
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
GiroCrab/GiroCrab#2528 · 1 comment ·
Maintainers usually reply within 1 day
-
approved correction metadata
Difficulty 1/5 Under an hour Newbie friendliness 80/100
acl-org/acl-anthology#11237 · 1 comment ·
Maintainers usually reply within 1 day
-
#1643 unrecoverable split: 1 digest with a 403 — two earlier captures of the same URL are real 200sOpen
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Robin-IA/Congressional-Letters-Dev#1684 ·
Maintainers usually reply within 1 day