GLOWS fix L1B error#2893
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes GLOWS L1B failures when ingesting updated ancillary “map-of-excluded-regions” files by handling the case where the excluded-regions .dat file is empty.
Changes:
- Add an early return that produces an empty
xr.Datasetwhennp.loadtxt()yields no data for an excluded-regions file.
Comments suppressed due to low confidence (2)
imap_processing/ancillary/ancillary_dataset_combiner.py:384
np.loadtxt()returns a 1D array when the file contains exactly one longitude/latitude pair (shape(2,)), sodata[:, 0]/data[:, 1]will still raise an IndexError. Consider normalizing withdata = np.atleast_2d(data)(ornp.loadtxt(..., ndmin=2)if supported) before indexing, and then keep the empty-file guard for the(0, 2)case.
if "excluded-regions" in filename:
# Handle excluded regions (2 columns: longitude, latitude)
data = np.loadtxt(filepath, comments="#")
if data.size == 0:
return xr.Dataset(
{
"ecliptic_longitude_deg": (
["region"],
np.array([], dtype=float),
),
"ecliptic_latitude_deg": (
["region"],
np.array([], dtype=float),
),
}
)
return xr.Dataset(
{
"ecliptic_longitude_deg": (["region"], data[:, 0]),
"ecliptic_latitude_deg": (["region"], data[:, 1]),
}
imap_processing/ancillary/ancillary_dataset_combiner.py:385
- Returning a zero-length dataset here can break
_combine_input_datasets()when multiple excluded-regions files are provided: the combiner allocates output arrays using the first input dataset’s shape, and later assignment will fail if another version has a different number of regions (including 0). If excluded-regions file counts can vary across versions, the combiner needs to either (a) treat an empty file as “no update” and skip filling, or (b) change the combine strategy to support variable-length region lists (e.g., keep per-day objects or pad to a max length).
if data.size == 0:
return xr.Dataset(
{
"ecliptic_longitude_deg": (
["region"],
np.array([], dtype=float),
),
"ecliptic_latitude_deg": (
["region"],
np.array([], dtype=float),
),
}
)
return xr.Dataset(
{
"ecliptic_longitude_deg": (["region"], data[:, 0]),
"ecliptic_latitude_deg": (["region"], data[:, 1]),
}
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if data.size == 0: | ||
| return xr.Dataset( | ||
| { | ||
| "ecliptic_longitude_deg": ( | ||
| ["region"], | ||
| np.array([], dtype=float), | ||
| ), | ||
| "ecliptic_latitude_deg": ( | ||
| ["region"], | ||
| np.array([], dtype=float), | ||
| ), | ||
| } | ||
| ) |
There was a problem hiding this comment.
This new empty-file branch is not covered by tests. There are existing unit tests for GlowsAncillaryCombiner.convert_file_to_dataset(); please add a test that writes an empty (or comment-only) map-of-excluded-regions file and asserts the returned dataset has the expected variables and zero-length region dimension.
b0f1dc4
into
IMAP-Science-Operations-Center:dev
Change Summary
This change fixes the L1B error we saw with new ancillary files.
Basically, the new file is empty, and the code did not gracefully handle this case.