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

Fix issues with RectilinearGrid instantiation #530

Merged
merged 4 commits into from
Jan 13, 2020
Merged

Conversation

banesullivan
Copy link
Member

These changes fix an issue where you couldn't update the coordinates of a RectilinearGrid after instantiating it.

The issue arose from how the dimensions have to be updated anytime the coordinates are changed. These changes make it so that the dimensions are automatically managed by PyVista and the user is unable to set them unless using the VTK method (.SetDimensions()). RectilinearGrids are technically implicitly defined, so it makes sense to only let the user update the x, y, and z coordinates for the mesh grid.

These changes also give users more options if wanting to create a 1D or 2D RectilinearGrid upon instantiation by allowing 1 or 2 coordinate arrays to be passed instead of 3. The __init__ method defaults to x first, then y, then z. If a user wants to have a 2D grid oriented on the yz plane, then they can set the coordinates after instantiating like so (this was previously not possible):

import pyvista as pv
import numpy as np
foo = pv.RectilinearGrid()
foo.y = np.array([3,4,5])
foo.z = np.array([6,7,8])
foo.plot(show_edges=True, show_bounds=True, lighting=False)

download


This also adds a convenient cast_to_structured_grid() method as RectilinearGrids can easily be represented by a StructuredGrid.

Testing is implemented.

@banesullivan banesullivan added bug-fix enhancement Changes that enhance the library labels Jan 13, 2020
@banesullivan
Copy link
Member Author

@pyvista/developers, anyone up for reviewing this?

Copy link
Member

@akaszynski akaszynski left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@banesullivan banesullivan self-assigned this Jan 13, 2020
@banesullivan banesullivan merged commit f668c2e into master Jan 13, 2020
@banesullivan banesullivan deleted the patch-rectilinear branch January 16, 2020 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Changes that enhance the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants