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

Ensure separatrices, target plotted correctly if Dataset transposed #68

Merged
merged 1 commit into from
Dec 10, 2019

Conversation

johnomotani
Copy link
Collaborator

@johnomotani johnomotani commented Dec 4, 2019

Create coordinates called 'xdim', 'ydim' and 'zdim' that depend only on x, y and z respectively, before applying geometry and re-naming the dimensions. This means that in plot_separatrices() and plot_targets() we can find renamed dimensions corresponding to x and y even if the Dataset has been transposed so that we cannot rely on the order of the dimensions.

This isn't exactly a beautiful solution, but I think it makes things more robust, without restricting what users can do with the BoutDataset.

@TomNicholas
Copy link
Collaborator

I'm not really a fan of adding extra coordinates to the dataset if we don't need to, if only because it's going to be confusing for users.

So this is intended to solve the problem of not knowing which dimensions correspond to the radial and poloidal directions on a plot if the 'x' and 'y' dimensions have been renamed? To do this we have to store some kind of record of which dimensions are radial and poloidal. We could have an attribute dedicated to this which is then consulted, which defaults to:

ds.attrs['plot_dims'] = {'radial': 'x', 'poloidal': 'y'}

The downside of this approach compared to yours is that it would have to be manually updated if someone renames their dims, whereas your coordinate-approach will update the coordinate to match automatically. I'm not sure which approach would be less confusing for users?

@ZedThree
Copy link
Member

ZedThree commented Dec 9, 2019

I'm not completely up to speed on what problem is trying to be solved here, but just be careful that "radial" and "poloidal" do imply a particular coordinate system, or set of coordinate systems, and don't apply to all BOUT++ uses. For example, linear plasma devices might use "azimuthal" instead of "poloidal".

@johnomotani
Copy link
Collaborator Author

@TomNicholas good points. I guess the question is what is the expected use-case? Probably most people will use 'toroidal' geometry, or a few other types (e.g. linear device, FCI) that could be added to xBOUT and maintained here. So having to manually update a dictionary translating x,y,z to the current dimension/coordinate names should not be a problem. I can't think of a real reason to rename the coordinates again.

The place this is actually needed is in the plotting routines that support plots in the R-Z plane in toroidal geometry, which are probably allowed to fail in other geometries (although I guess a cylindrical linear device might be able to use some of them). So cases where users are re-naming coordinates interactively and don't create a plot_dims attribute probably just don't expect those methods to work anyway. I'll update this.

@pep8speaks
Copy link

pep8speaks commented Dec 9, 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-12-09 18:43:33 UTC

Create metadata variables called 'bout_tdim', 'bout_xdim', 'bout_ydim',
and 'bout_zdim' that record what 't', 'x', 'y', and 'z' respectively
were renamed to. This means that in plot_separatrices() and
plot_targets() we can find renamed dimensions corresponding to 'x' and
'y' even if the Dataset has been transposed so that we cannot rely on
the order of the dimensions.
@johnomotani
Copy link
Collaborator Author

I had to add the new stuff to metadata so that it can be accessed through the DataArrays, and had to add a few variables since netCDF doesn't like dicts, but now pretty much implemented as @TomNicholas suggested.

@codecov-io
Copy link

codecov-io commented Dec 9, 2019

Codecov Report

Merging #68 into master will increase coverage by 5.31%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #68      +/-   ##
==========================================
+ Coverage   44.74%   50.05%   +5.31%     
==========================================
  Files           8        8              
  Lines         789      877      +88     
  Branches      152      178      +26     
==========================================
+ Hits          353      439      +86     
- Misses        380      381       +1     
- Partials       56       57       +1
Impacted Files Coverage Δ
xbout/plotting/utils.py 4.91% <0%> (ø) ⬆️
xbout/geometries.py 74.44% <100%> (+1.82%) ⬆️
xbout/load.py 82.94% <0%> (+5.52%) ⬆️

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 f02e677...bc62e98. Read the comment docs.

Copy link
Collaborator

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

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

So cases where users are re-naming coordinates interactively and don't create a plot_dims attribute probably just don't expect those methods to work anyway.

Yes, exactly. If the user doesn't specify geometry='toroidal', they won't have 'R' and 'Z' coordinates, so the plotting method will fail with an appropriate error.

Thanks!

@TomNicholas TomNicholas merged commit 010274a into master Dec 10, 2019
@johnomotani johnomotani deleted the restore_transposes branch December 10, 2019 23:39
johnomotani pushed a commit that referenced this pull request Dec 11, 2019
Ensure separatrices, target plotted correctly if Dataset transposed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants