Skip to content

fix attribute errors in healda script#762

Open
nbren12 wants to merge 3 commits intoNVIDIA:mainfrom
nbren12:fix-healda-example
Open

fix attribute errors in healda script#762
nbren12 wants to merge 3 commits intoNVIDIA:mainfrom
nbren12:fix-healda-example

Conversation

@nbren12
Copy link

@nbren12 nbren12 commented Mar 18, 2026

there were several errors like this:

[~/workspace/earth2studio/examples] main:a93583c0 :(
$ python3 22_healda.py
Traceback (most recent call last):
  File "/home/nbrenowitz/workspace/earth2studio/examples/22_healda.py", line 230, in <module>
    field = da.sel(variable=var).data[0].get()  # [nlat, nlon] cupy -> numpy
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'numpy.ndarray' object has no attribute 'get'

Earth2Studio Pull Request

Description

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.
  • The CHANGELOG.md is up to date with these changes.
  • An issue is linked to this pull request.
  • Assess and address Greptile feedback (AI code review bot for guidance; use discretion, addressing all feedback is not required).

Dependencies

there were several errors like this:

    [~/workspace/earth2studio/examples] main:a93583c0 :(
    $ python3 22_healda.py
    Traceback (most recent call last):
      File "/home/nbrenowitz/workspace/earth2studio/examples/22_healda.py", line 230, in <module>
        field = da.sel(variable=var).data[0].get()  # [nlat, nlon] cupy -> numpy
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AttributeError: 'numpy.ndarray' object has no attribute 'get'
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 18, 2026

Greptile Summary

This PR fixes a runtime AttributeError in the 22_healda.py example by replacing the CuPy-specific .data[0].get() pattern with xarray's .values[0] accessor, which transparently converts GPU (CuPy) or CPU (NumPy) arrays to NumPy — making the plotting and MAE computation code device-agnostic.

  • Three locations are updated: the analysis field plot loop (line 230), the MAE computation loop (lines 277–282), and the difference field plot loop (line 296–329).
  • The fix is correct and clean; .values is the idiomatic xarray way to obtain a NumPy array regardless of the underlying backend.
  • Two unchanged lines (280 and 300) still use .data[0] for era5_interp, which is inconsistent with the updated pattern and worth aligning for robustness.

Confidence Score: 4/5

  • Safe to merge — the fix is correct and resolves a real runtime error; only minor consistency improvements are suggested.
  • The change is narrowly scoped to an example script, corrects a documented and reproducible bug, and uses the idiomatic xarray API. The two remaining .data[0] calls for era5_interp are low-risk in practice but slightly inconsistent with the rest of the updated code.
  • No files require special attention beyond the minor .data[0] inconsistency on lines 280 and 300.

Important Files Changed

Filename Overview
examples/22_healda.py Fixes AttributeError by replacing .data[0].get() (CuPy-specific) with .values[0] (xarray, always returns NumPy); era5_interp still uses .data[0] on unchanged lines, which is a minor inconsistency.

Last reviewed commit: "fix attribute errors..."

nbren12 and others added 2 commits March 18, 2026 13:30
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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