Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix in case 'dz' was actually 0-dimensional #310

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

johnomotani
Copy link
Collaborator

Fixes f49585e "Changes required to load output from a grid-free BOUT.0.nc file, necessary for MMS tests of the differential operators." in case dz was actually zero dimensional, rather than 2-dimensional.

Sorry, I missed that the tests failed on #309, because the final commit by the linter didn't run all the tests, so they weren't listed in the box, and I forgot for a minute that we have lots of pytest tests that should have been there. This PR should fix the test failures.

Fixes f49585e "Changes required to load
output from a grid-free BOUT.0.nc file, necessary for MMS tests of the
differential operators." in case dz was actually zero dimensional,
rather than 2-dimensional.
@johnomotani johnomotani added the bugfix Fix for a bug label Jan 15, 2025
@johnomotani
Copy link
Collaborator Author

There seem to be test failures unrelated to #309. Is anyone working on these? For example:

>       n_highres = n.bout.interpolate_parallel("core", n=res_factor)

xbout/tests/test_boutdataarray.py:668: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
xbout/boutdataarray.py:313: in interpolate_parallel
    da = da.bout.from_region(region.name, with_guards={xcoord: 0, ycoord: 2})
xbout/boutdataarray.py:218: in from_region
    return _from_region(self.data, name, with_guards)
xbout/region.py:1744: in _from_region
    result = _concat_lower_guards(result, ds_or_da, mxg, myg)
xbout/region.py:1566: in _concat_lower_guards
    da_lower = da_lower.reset_index(xcoord).set_xindex(xcoord)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <xarray.DataArray 'n' (t: 2, x: 3, theta: 2, zeta: 3)>
array([[[[-2.03570987, -2.03570987, -2.03570987],
         [-1....     None
    regions:        {'core': <xbout.region.Region>\n\tname\tcore\n\txinner_in...
    geometry:       toroidal
name = 'set_xindex'

    def __getattr__(self, name: str) -> Any:
        if name not in {"__dict__", "__setstate__"}:
            # this avoids an infinite loop when pickle looks for the
            # __setstate__ attribute before the xarray object is initialized
            for source in self._attr_sources:
                with suppress(KeyError):
                    return source[name]
>       raise AttributeError(
            f"{type(self).__name__!r} object has no attribute {name!r}"
        )
E       AttributeError: 'DataArray' object has no attribute 'set_xindex'

../../../miniforge3/envs/gen/lib/python3.10/site-packages/xarray/core/common.py:256: AttributeError

@mrhardman
Copy link
Collaborator

mrhardman commented Jan 17, 2025

I also have noticed new errors testing Hermes-3, it seems like my attempt to slice dz.data was too simple a fix.

$ ctest --rerun-failed --output-on-failure
Test project /home/mrhardman/hermes-3-work/hermes-3/build-debug-nonorthogonal
    Start  9: drift-wave
1/2 Test  #9: drift-wave .......................***Failed   21.95 sec
ln: failed to create symbolic link 'hermes-3': File exists
Running B = 0.1
getmpirun: using the default mpirun -np
Traceback (most recent call last):
  File "/home/mrhardman/hermes-3-work/hermes-3/build-debug-nonorthogonal/tests/integrated/drift-wave/runtest", line 42, in <module>
    result = analysis.extract_data("data")
  File "/home/mrhardman/hermes-3-work/hermes-3/build-debug-nonorthogonal/tests/integrated/drift-wave/analysis.py", line 6, in extract_data
    bd = xhermes.open(path)
  File "/home/mrhardman/hermes-3-work/xhermes/xhermes/load.py", line 421, in open
    return open_hermesdataset(
        datapath=os.path.join(path, "BOUT.dmp.*.nc"),
        inputfilepath=os.path.join(path, "BOUT.settings"),
        **kwargs,
    )
  File "/home/mrhardman/hermes-3-work/xhermes/xhermes/load.py", line 31, in open_hermesdataset
    ds = open_boutdataset(
        datapath=datapath,
    ...<4 lines>...
        **kwargs,
    )
  File "/home/mrhardman/hermes-3-work/xBOUT/xbout/load.py", line 361, in open_boutdataset
    ds = geometries.apply_geometry(ds, geometry, grid=grid)
  File "/home/mrhardman/hermes-3-work/xBOUT/xbout/geometries.py", line 217, in apply_geometry
    z1 = z0 + nz * dz.data[0,0]
                   ~~~~~~~^^^^^
  File "/home/mrhardman/hermes-3-work/python3.13.0-hermes-venv/lib/python3.13/site-packages/dask/array/core.py", line 1991, in __getitem__
    index2 = normalize_index(index, self.shape)
  File "/home/mrhardman/hermes-3-work/python3.13.0-hermes-venv/lib/python3.13/site-packages/dask/array/slicing.py", line 826, in normalize_index
    raise IndexError("Too many indices for array")
IndexError: Too many indices for array

@johnomotani
Copy link
Collaborator Author

@mrhardman this PR should fix that error.

@mrhardman
Copy link
Collaborator

I confirm that this fix works for me for the Hermes ctest and for the python post processing.

@bendudson bendudson merged commit 64408ea into master Jan 17, 2025
10 of 13 checks passed
@bendudson bendudson deleted the fix-fix-gridless-loading branch January 17, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fix for a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants