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

Test geometries #58

Merged
merged 12 commits into from
Dec 3, 2019
Merged

Test geometries #58

merged 12 commits into from
Dec 3, 2019

Conversation

johnomotani
Copy link
Collaborator

@johnomotani johnomotani commented Oct 25, 2019

Builds on #55, so merging into fix-test-against-collect.

Adds unit tests for loading datasets with 'toroidal' or 's-alpha' geometries. These show the need to be able to pass a grid file to get psixy, Rxy, Zxy, hthe variables, which are not needed by BOUT++ so are never loaded or saved to the dump files. Therefore reinstates the option to pass a gridfilepath, but now the grid file can be opened with just open_boutdataset 🎉

Also includes a work-around to tell Travis to exclude xarray-0.14.0, which fixes the Travis tests.

Resolves #17.

TomNicholas and others added 7 commits October 24, 2019 11:41
Implement 1D animations, and refactor generation of test data
Previously the return statement was missing, leading to a bug.
May be needed to provide some variables that are not saved by default to
BOUT++'s output files, e.g. psixy, Rxy, Zxy.
Need to add hthe before getting toroidal coordinates, as dimension names
are changed only in the Dataset, not in the _grid member variable.

'r' coordinate is created as 1d, so selecting 'theta=0' part is an
error.
@pep8speaks
Copy link

pep8speaks commented Oct 25, 2019

Hello @johnomotani! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-10-28 20:40:07 UTC

xbout/load.py Outdated

if gridfilepath is not None:
print('here in load', ds.attrs)
ds.attrs["_grid"] = open_boutdataset(gridfilepath, chunks=chunks,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we store the grid data in the attrs like this then the dataset won't be serializable to netcdf. If the grid variables are just normal variables then it would be fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _grid is possibly only needed temporarily - the current use is that some variables are read from it and put into the dataset in add_toroidal_geometry_coords() and add_s_alpha_geometry_coords(). I'm inclined to leave it available once it's added in case we want to get other info out of it later, but for the way it's being used here we could happily just drop/ignore the _grid dataset when saving to netcdf, as any needed variables have been copied to the main dataset.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...so the way I've implemented so far isn't a good idea, as @TomNicholas says. Suggestions for a replacement welcome!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed this problem by making the _grid dataset a member of the BoutDataset accessor, rather than being in attrs, and added saving to netCDF to the tests of 'toroidal' and 's-alpha' geometries.

I found a problem, which might well be an issue to address later: a variable that's added as a 'coordinate' shouldn't have metadata, or when saving to netCDF there will be an error because of not being able to save a dict to netCDF. Adding the variable as a coordinate is the only thing I currently need to do with the variables read from the grid file, so I've used _open_grid instead of open_boutdataset to open the grid without adding metadata. That's OK, but what if:

  1. we want to use a variable from the grid file as something other than a coordinate
    • could be useful to have a bout.addVariable method, that adds metadata to the variable as well as adding it?
  2. we want to use a variable from, or calculated from, the dataset as a coordinates
    • do we need an addCoordinates() method that would strip metadata and then call set_coords()?

@TomNicholas TomNicholas mentioned this pull request Oct 25, 2019
@codecov-io
Copy link

codecov-io commented Oct 25, 2019

Codecov Report

❗ No coverage uploaded for pull request base (fix-test-against-collect@212f913). Click here to learn what that means.
The diff coverage is 55.55%.

Impacted file tree graph

@@                     Coverage Diff                     @@
##             fix-test-against-collect      #58   +/-   ##
===========================================================
  Coverage                            ?   69.14%           
===========================================================
  Files                               ?        8           
  Lines                               ?      444           
  Branches                            ?       93           
===========================================================
  Hits                                ?      307           
  Misses                              ?       85           
  Partials                            ?       52
Impacted Files Coverage Δ
xbout/boutdataset.py 46.87% <ø> (ø)
xbout/load.py 77.65% <100%> (ø)
xbout/geometries.py 75.64% <46.66%> (ø)

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 212f913...3fc4f02. Read the comment docs.

Doing this prevented the dataset being saved to netCDF file.

Also use _open_grid instead of open_boutdataset to open the grid file so
that the grid dataset does not have metadata added to the DataArray
variables. These variables are added as coordinates and become members
of the DataArrays representing simulation variables; if they have a
metadata dict, it is not possible to save them to netCDF.
...when hthe is loaded from the grid file. Variables from the grid file
do not have all the correct metadata, so cause errors when trying to
save to netCDF.
Depedency has been made optional by an update to boututils.
@johnomotani johnomotani added the testing Involves writing or running unit, integrated, or regression tests label Oct 31, 2019
@johnomotani johnomotani merged commit 5047941 into fix-test-against-collect Dec 3, 2019
@johnomotani johnomotani deleted the test-geometries branch December 3, 2019 13:30
johnomotani added a commit that referenced this pull request Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Involves writing or running unit, integrated, or regression tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants