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

Plotting responsiveness - optimizing from_region()? #234

Open
johnomotani opened this issue Mar 12, 2022 · 3 comments
Open

Plotting responsiveness - optimizing from_region()? #234

johnomotani opened this issue Mar 12, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@johnomotani
Copy link
Collaborator

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

    xBOUT/xbout/region.py

    Lines 1738 to 1745 in 12c0088

    # get inner x-guard cells for result from the global array
    result = _concat_inner_guards(result, ds_or_da, mxg)
    # get outer x-guard cells for result from the global array
    result = _concat_outer_guards(result, ds_or_da, mxg)
    # get lower y-guard cells from the global array
    result = _concat_lower_guards(result, ds_or_da, mxg, myg)
    # get upper y-guard cells from the global array
    result = _concat_upper_guards(result, ds_or_da, mxg, myg)
  • optionally change the coords and compat arguments to xr.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.
@johnomotani johnomotani added the enhancement New feature or request label Mar 12, 2022
@johnomotani
Copy link
Collaborator Author

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.

@mikekryjak
Copy link
Collaborator

I only just spotted this issue. Making a note that this is partially resolved by #280

@johnomotani
Copy link
Collaborator Author

Would be interesting to see if this is improved by the latest xarray release - pydata/xarray#7824 may help things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants