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

Define Regions and add method to get BoutDataArrays in a region #107

Merged
merged 72 commits into from
Jul 29, 2020

Conversation

johnomotani
Copy link
Collaborator

It will be useful to operate on or plot variables in a region, within which the grid is contiguous. This PR provides a Region class to define regions (indices of their boundaries, connections to neighbouring regions). It also adds a method BoutDataArray.fromRegion() to get a variable in a region, including guard cells correctly filled from the connections of the region (not the adjacent points in the global array).

Includes #106, because it uses the join argument to xr.concat.

This is a fairly big PR, but only 835 of the lines added are 'code', the rest are for the tests.

Including a method of BoutDataArray to get data for a single region.
Guard cells taken from a neighbouring region may have coordinates that
are not continuous with the coordinates of the region they are being
added to. Work around this by replacing the coordinate values of the
guard cells being added with the coordinate values of the adjacent
couple of points in the global grid (which have values continuous with
those in the region being added to).

Adds some utility methods to Region to get slices to select the values
to fill the guard cells with.
Allows BoutDataArray methods to use the regions.
Required keyword arguments are clearer than having many positional
arguments. Rename the xinner/xouter/ylower/yupper arguments with a
suffix _ind as they are indices and will add coordinate values as well.
Now that there are 'regions' elsewhere in the code, it is better to
change the variable name to make clear that the members of da_regions
are the parts of the DataArray in each region (not the regions
themselves).
Also re-order arguments to Region constructor.
Also store regions in OrderedDict instead of dict.
This is the appropriate place, as regions do not necessarily exist for
all geometries.
Combinations like jyseps1_2==ny_inner-1 and similar are not supported.
jyseps1_2 should be <=jyseps2_2.
OrderedDicts cannot be saved to netCDF. Regions can be reconstructed
from metadata anyway.
Just use the index values as the coordinate values. Having a global
coordinate is useful for remembering positions and combining regions.
s-alpha adds an 'r' coordinate for the x-dimension. Remove the global
'x' coordinate added by add_toroidal_geometry_coords in this case so
that we can rename the 'x' dimension to 'r'. 'r' provides a global
coordinate, so we do not need the global 'x' coordinate.
xarray.DataArray.transpose() gives a FutureWarning about transposing
coordinates. Can silence this by passing 'transpose_coords=True', which
means we use the future default behaviour.
'Different topologies' means setting up ixseps*, jyseps*, ny_inner.
Useful for testing regions, etc.
'core' and 'limiter' topologies may not have neighbouring points to get
guard cell coordinates from if the Dataset was opened with
keep_yboundaries=False. Raise an informative exception if this occurs.
Need to not count extra points in the global grid for the upper target
boundary cells if there is no upper target.
Should not have been changed to exclude boundary points.
Avoids name conflict with 'region' local variable.
...to follow PEP8 naming convention.
Equivalent to self.* except it has to create a new accessor instance.
...to follow PEP8 naming convention.
...to follow PEP8 naming convention.
There was previously a lot of logic to do with getting guard cells
around a region in BoutDataArray.from_region(). Moving this into
separate utility functions in region.py makes from_region() clearer and
collects the region logic into the same file.
xbout/region.py Outdated Show resolved Hide resolved
Makes BoutDataArray.from_region cleaner.
Add _x and _y in the names of connection_* members of Region, to be
clearer about which direction they belong to. Also rename the
constructor arguments from connect_* to connection_*.
If a Dataset with a geometry applied was saved, it already has
coordinates created, and only needs regions re-creating, so handle
specially in add_toroidal_geometry_coords() and
add_s_alpha_geometry_coords().
Needed for tests on Datasets with Region attributes.
@johnomotani
Copy link
Collaborator Author

@TomNicholas I think this PR is ready for review/merge now.

@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2020

Codecov Report

Merging #107 into master will increase coverage by 17.06%.
The diff coverage is 80.69%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #107       +/-   ##
===========================================
+ Coverage   53.16%   70.22%   +17.06%     
===========================================
  Files          11       12        +1     
  Lines        1217     1488      +271     
  Branches      246      299       +53     
===========================================
+ Hits          647     1045      +398     
+ Misses        496      353      -143     
- Partials       74       90       +16     
Impacted Files Coverage Δ
xbout/plotting/plotfuncs.py 6.54% <0.00%> (-0.61%) ⬇️
xbout/plotting/utils.py 16.66% <0.00%> (+9.75%) ⬆️
xbout/plotting/animate.py 42.02% <28.57%> (ø)
xbout/geometries.py 74.10% <76.92%> (-0.16%) ⬇️
xbout/region.py 90.81% <90.81%> (ø)
xbout/boutdataarray.py 80.00% <100.00%> (+5.26%) ⬆️
xbout/boutdataset.py 77.90% <100.00%> (+0.88%) ⬆️
xbout/load.py 81.66% <100.00%> (+4.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21ca594...ab4f52a. Read the comment docs.

@johnomotani johnomotani merged commit a89feb6 into master Jul 29, 2020
@johnomotani johnomotani deleted the regions branch July 29, 2020 14:51
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

Successfully merging this pull request may close these issues.

6 participants