xBOUT
xBOUT copied to clipboard
Plotting responsiveness - optimizing `from_region()`?
Some operations, such as poloidal-plane plots/animations, can be annoyingly slow. This can happen even when a plot on the x-theta logical grid is fast, in which case the slow-down probably comes from the from_region()
operation.
Slow down is probably due to combining coordinates (as in #220). In plotting functions, no Dataset/DataArray is returned, so most of the coordinates are not needed or used.
Responsiveness (e.g. of poloidal-plane plots/animations) might be significantly improved by:
- dropping unused coordinates somewhere before the concatenation operations here https://github.com/boutproject/xBOUT/blob/12c0088a27d9554b01a4f0ac4e2658b65329b9d0/xbout/region.py#L1738-L1745
- optionally change the
coords
andcompat
arguments toxr.concat()
to less-safe but faster settings. A good method might be to add an argument to various functions to switch between the current settings and 'fast'/'unsafe' settings; this argument could then be passed from within plotting methods, etc.
Another option could be to load the Rxy_corners
and Zxy_corners
from the grid file (now that hypnotoad saves them). With the corner positions, the plotting could be done without guard cells and adjacent regions would line up perfectly without the need for guard cells: avoiding guard cells would mean no need to concatenate, which should speed everything up.
There would probably be a bit of initial overhead, because we'd probably need to convert the Rxy_corners
and Zxy_corners
which give the 'lower left' corner position into separate arrays for all four corners of a cell (i.e. getting some values from adjacent regions just once at start-up time, and ideally without concatenating any arrays).
Implementing this suggestion would probably also have the bonus of making the plots look a bit nicer, and line up with the divertor targets better.
I only just spotted this issue. Making a note that this is partially resolved by https://github.com/boutproject/xBOUT/pull/280
Would be interesting to see if this is improved by the latest xarray release - https://github.com/pydata/xarray/pull/7824 may help things.