Skip to content

GLOWS fix L1B error#2893

Merged
maxinelasp merged 6 commits intoIMAP-Science-Operations-Center:devfrom
maxinelasp:glows-2878-anc-file-rename
Mar 31, 2026
Merged

GLOWS fix L1B error#2893
maxinelasp merged 6 commits intoIMAP-Science-Operations-Center:devfrom
maxinelasp:glows-2878-anc-file-rename

Conversation

@maxinelasp
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Dataset when np.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,)), so data[:, 0] / data[:, 1] will still raise an IndexError. Consider normalizing with data = np.atleast_2d(data) (or np.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.

Comment on lines +367 to +379
if data.size == 0:
return xr.Dataset(
{
"ecliptic_longitude_deg": (
["region"],
np.array([], dtype=float),
),
"ecliptic_latitude_deg": (
["region"],
np.array([], dtype=float),
),
}
)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@tech3371 tech3371 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maxinelasp maxinelasp merged commit b0f1dc4 into IMAP-Science-Operations-Center:dev Mar 31, 2026
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.

3 participants