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

Expose streamlines #480

Merged
merged 14 commits into from
Sep 20, 2023
Merged

Expose streamlines #480

merged 14 commits into from
Sep 20, 2023

Conversation

PProfizi
Copy link
Contributor

@PProfizi PProfizi commented Sep 7, 2023

Create the ansys.dpf.post.tools package, with the ansys.dpf.post.tools.streamlines module.
Add the plot_streamlines helper to provide a first way of plotting streamlines based on a DataFrame.
Add a first test in test_streamlines.py.

Initial mock-up:
image

@PProfizi PProfizi added the enhancement New feature or request label Sep 7, 2023
@PProfizi PProfizi added this to the v0.5.1 milestone Sep 7, 2023
@PProfizi PProfizi requested a review from cbellot000 September 7, 2023 10:29
@PProfizi PProfizi self-assigned this Sep 7, 2023
@codecov
Copy link

codecov bot commented Sep 7, 2023

Codecov Report

Merging #480 (d67a405) into master (a713af2) will increase coverage by 0.27%.
Report is 1 commits behind head on master.
The diff coverage is 69.76%.

@@            Coverage Diff             @@
##           master     #480      +/-   ##
==========================================
+ Coverage   83.49%   83.77%   +0.27%     
==========================================
  Files          45       47       +2     
  Lines        5041     5072      +31     
==========================================
+ Hits         4209     4249      +40     
+ Misses        832      823       -9     

Copy link
Contributor

@rafacanton rafacanton left a comment

Choose a reason for hiding this comment

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

@PProfizi Just made a couple of suggestions to avoid referring to velocity. This is way more general and applies to all vector fields. For example, when we support EMag data, the same method could be used to plot the magnetic field lines

src/ansys/dpf/post/tools/streamlines.py Outdated Show resolved Hide resolved
src/ansys/dpf/post/tools/streamlines.py Outdated Show resolved Hide resolved
src/ansys/dpf/post/tools/streamlines.py Outdated Show resolved Hide resolved
src/ansys/dpf/post/tools/streamlines.py Outdated Show resolved Hide resolved
if mesh:
meshed_region = mesh._meshed_region
else:
meshed_region = dataframe._fc[0].meshed_region
Copy link
Contributor

Choose a reason for hiding this comment

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

we will eventually need a public method in the dataframe to get the mesh, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbellot000 sure, but again it will need a label logic to select which field's meshed_region is of interest, or else I guess return a MeshesContainer as a Meshes

meshed_region = mesh._meshed_region
else:
meshed_region = dataframe._fc[0].meshed_region
field = dataframe._fc[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

why the first field? what if you have a single time, but different label (like "elshape") in your data frame?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbellot000 talked it out and it seems the only use-case is merging the fields labeled by zone, as well as selecting a set.
I updated the PR accordingly.

@PProfizi
Copy link
Contributor Author

PProfizi commented Sep 14, 2023

@rafacanton @cbellot000 @anslpa

Just realized we cannot actually create a ansys.dpf.post.tools sub-package with ansys.dpf.post.tools.streamlines module (ansys/dpf/post/tools/streamlines.py) as we already have a ansys.dpf.post.tools module (ansys/dpf/post/tools.py).
Four solutions:

  • rename the new sub-package from tools to helpers. This is the current solution implemented, so now the new method is in ansys.dpf.post.helpers.streamlines. This is also what was done in ansys-dpf-core which makes both libraries coherent.
  • Move the streamlines.py module directly in ansys/dpf/post
  • Move the streamlines helpers in the tools.py module, which would mean no streamlines-specific module and a direct call to from ansys.dpf.post.tools import plot_streamlines.
  • Remove the tools.py module and move its methods in a new module in the tools sub-package. This would mean makign sure that the old imports would still work. Not sure we can cover all edge-cases.

I think the first solution is the best.

What do you think?

@rafacanton
Copy link
Contributor

@rafacanton @cbellot000 @anslpa

Just realized we cannot actually create a ansys.dpf.post.tools sub-package with ansys.dpf.post.tools.streamlines module (ansys/dpf/post/tools/streamlines.py) as we already have a ansys.dpf.post.tools module (ansys/dpf/post/tools.py). Four solutions:

  • rename the new sub-package from tools to helpers. This is the current solution implemented, so now the new method is in ansys.dpf.post.helpers.streamlines. This is also what was done in ansys-dpf-core which makes both libraries coherent.
  • Move the streamlines.py module directly in ansys/dpf/post
  • Move the streamlines helpers in the tools.py module, which would mean no streamlines-specific module and a direct call to from ansys.dpf.post.tools import plot_streamlines.
  • Remove the tools.py module and move its methods in a new module in the tools sub-package. This would mean makign sure that the old imports would still work. Not sure we can cover all edge-cases.

I think the first solution is the best.

What do you think?

@PProfizi I agree, I think it is right to have both libraries with a similar structure. Thanks!

@PProfizi
Copy link
Contributor Author

@rafacanton @cbellot000 @anslpa
Just realized we cannot actually create a ansys.dpf.post.tools sub-package with ansys.dpf.post.tools.streamlines module (ansys/dpf/post/tools/streamlines.py) as we already have a ansys.dpf.post.tools module (ansys/dpf/post/tools.py). Four solutions:

  • rename the new sub-package from tools to helpers. This is the current solution implemented, so now the new method is in ansys.dpf.post.helpers.streamlines. This is also what was done in ansys-dpf-core which makes both libraries coherent.
  • Move the streamlines.py module directly in ansys/dpf/post
  • Move the streamlines helpers in the tools.py module, which would mean no streamlines-specific module and a direct call to from ansys.dpf.post.tools import plot_streamlines.
  • Remove the tools.py module and move its methods in a new module in the tools sub-package. This would mean makign sure that the old imports would still work. Not sure we can cover all edge-cases.

I think the first solution is the best.
What do you think?

@PProfizi I agree, I think it is right to have both libraries with a similar structure. Thanks!

What I ended-up doing:

  • add a new ansys.dpf.post.helpers sub-package
  • add a new ansys.dpf.post.helpers.streamlines module
  • add a new ansys.dpf.post.helpers.selections module
  • moved the ansys.dpf.post.tools.select method to the ansys.dpf.post.helpers.selections module
  • made an import to it in ansys.dpf.post.tools to ensure retro-compatibility
  • updated the dosctring in ansys.dpf.post.tools to mention the move to ansys.dpf.post.helpers

@PProfizi PProfizi requested a review from cbellot000 September 18, 2023 13:53
@@ -0,0 +1,6 @@
"""Tools package.

Tools
Copy link
Contributor

Choose a reason for hiding this comment

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

Helpers?

Copy link
Contributor

Choose a reason for hiding this comment

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

The only problem I see is naming. For me "helpers" means wrapping already existing capabilities in another way to make them easier to be used

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a plan for follow up PR adding an example for streamlines?

Copy link
Contributor Author

@PProfizi PProfizi Sep 19, 2023

Choose a reason for hiding this comment

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

The only problem I see is naming. For me "helpers" means wrapping already existing capabilities in another way to make them easier to be used

IMO this is what this method is? The end-goal is to have a much more thorough streamlines manipulation capability, this method being a quick way to plot the streamlines given a Dataframe.

Is there a plan for follow up PR adding an example for streamlines?

Yes of course, I initially wanted this merged before last Friday's deadline, but if the deadline is not an issue anymore, I can add an example within this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only problem I see is naming. For me "helpers" means wrapping already existing capabilities in another way to make them easier to be used

@cbellot000 What I can do though is rename helpers as tools, but that will require deleting the tools.py module, which I think can be done without retro-compatibility issues if I import the select method from within the __init__.py file of the new tools sub-package, yet I may have missed a case where it breaks.

Copy link
Contributor

Choose a reason for hiding this comment

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

@PProfizi no, it's okay, your justification makes sense

@@ -0,0 +1,6 @@
"""Tools package.

Tools
Copy link
Contributor

Choose a reason for hiding this comment

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

@PProfizi no, it's okay, your justification makes sense

@PProfizi PProfizi merged commit f7dc485 into master Sep 20, 2023
21 of 23 checks passed
@PProfizi PProfizi deleted the feat/expose_streamlines branch September 20, 2023 14:17
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.

3 participants