boutproject / xBOUT

Collects BOUT++ data from parallelized simulations into xarray.
https://xbout.readthedocs.io/en/latest/
Apache License 2.0
22 stars 10 forks source link

KeyError: 'dz' in open_boutdataset #206

Closed ZedThree closed 3 years ago

ZedThree commented 3 years ago

Using BOUT++ current next (b19674) and xBOUT 0.2.5 from pip, running the BOUT++ conduction example, I get the following exception:

In [2]: df = xbout.open_boutdataset("data/BOUT.dmp.*.nc", inputfilepath="data/BOUT.inp")
/home/peter/.local/lib/python3.9/site-packages/xbout/load.py:278: UserWarning: No geometry type found, no physical coordinates will be added
  warn("No geometry type found, no physical coordinates will be added")
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-2-f31aaaaee55d> in <module>
----> 1 df = xbout.open_boutdataset("data/BOUT.dmp.*.nc", inputfilepath="data/BOUT.inp")

~/.local/lib/python3.9/site-packages/xbout/load.py in open_boutdataset(datapath, inputfilepath, geometry, gridfilepath, chunks, keep_xboundaries, keep_yboundaries, run_name, info, **kwargs)
    279 
    280     # Update coordinates to match particular geometry of grid
--> 281     ds = geometries.apply_geometry(ds, geometry, grid=grid)
    282 
    283     if remove_yboundaries:

~/.local/lib/python3.9/site-packages/xbout/geometries.py in apply_geometry(***failed resolving arguments***)
    182         nz = updated_ds.dims[zcoord]
    183         z0 = 2 * np.pi * updated_ds.metadata["ZMIN"]
--> 184         z1 = z0 + nz * updated_ds.metadata["dz"]
    185         if not np.isclose(
    186             z1, 2.0 * np.pi * updated_ds.metadata["ZMAX"], rtol=1.0e-15, atol=0.0

KeyError: 'dz'

dz is definitely in the netCDF file. We have recently merged the 3D metrics branch, so dz is now a Field2D -- might be related?

Is there a way to just not apply geometry? This example has nx=nz=1, so there's no need to do anything with Z

johnomotani commented 3 years ago

197 should fix this, but could do with having tests added.

ZedThree commented 3 years ago

Thanks! I'll see if I can get some on there next week, it would be good to get that in

johnomotani commented 3 years ago

Fixed by #197.