-
Notifications
You must be signed in to change notification settings - Fork 55
implementing interpolation option for plot_field
method
#1964
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
Conversation
Hi @FilipeFcp Thanks for this! In xarray there is a convenient way to grab every >>> import xarray as xr
>>> da = xr.DataArray([1, 2, 3], [("x", [0, 1, 2])])
>>> da.isel(x=slice(None, None, 2))
<xarray.DataArray (x: 2)> Size: 16B
array([1, 3])
Coordinates:
* x (x) int64 16B 0 2 perhaps we could instead allow the user to input the Just a thought let me know how you think that would work or if you prefer the interpolation approach |
What I had in mind was a way to add more data points, making it easier to create smoother visualizations. For example, moving from this: To this: I understand that the slice option is useful for quickly plotting a large dataset, but could it be used to generate a smoother image? However, if users are most likely looking to downsample datasets before plotting rather than generating more points for visualization purposes, the slice option would make more sense. |
ah ok, I misunderstood. Maybe in the same sprit, it could be nice if the The only thing about the current approach I think is not ideal is that it requires the hardcoding of these values (200x200) whereas the data might have a different aspect ratio, so it could lead to weird results. Are there other examples of interpolation in plotting and what do they do? Also, could you include a changelog item under Added for the final PR? thanks |
0352ec0
to
f2b2141
Compare
Hi @tylerflex, your float approach is actually way better. Ideally, the user could be able to pass the |
looks like they could also try this? |
Oh... I saw this comment, but I tried with infer_interval = True not False. Yes, it works with False. I think we can pass the shading argument through - plot_field -> plot_field_monitor_data -> plot_scalar_array -> field_data.plot. Or create a **args in plot_scalar_array and input it into field_data.plot. |
Great
yea I think either a shading argument or just exploring all of the **kwargs for xarray would work. I dont have a strong preference. what do you think is better? will this be used often you think? |
Hi @FilipeFcp sorry I let this slide, what's the current status of it? I would say that the current implementation looks pretty good, but we should also add one test, just to make sure calling this with a value of, say 2, will work? and also adding a CHANGLOG item mentioning the new feature Thanks again! |
Hi @tylerflex, It was my bad. I had a lot of meetings and other tasks when Tom was in China, and I forgot about this for a while. If you don't mind, I’ve pushed a different version that passes the shading argument. It seems simpler, though we lost the option to reduce the data for plotting. It was ready a month ago, just pending a review and push. Let me know which implementation you think is better, and I’ll add it to the changelog. Thank you. |
No worries at all. I also forgeot.
Yea this seems great I like it better since it's more simple and adds less complication.
That would be great when you get around to it, thanks! |
3dc5cc8
to
1de577c
Compare
Ok, I think is done. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please modify a test showing the new shading option passed to plot_field
. You can see some examples here
https://github.com/flexcompute/tidy3d/blob/develop/tests/test_data/test_sim_data.py#L139-L145
CHANGELOG.md
Outdated
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
## [Unreleased] | |||
|
|||
### Added | |||
- Users can pass the `shading` argument in the `SimulationData.plot_field` to `Xarray.plot` method. When shading='gouraud', the image is interpolated, producing a smoother visualization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you put shading='gouraud'
into the backslash quotes?
1de577c
to
afc04b8
Compare
Thanks @FilipeFcp ! |
Hi @tylerflex,
I’ve implemented the interpolation option. Here's how I approached it:
The default is set to False, so it generates a regular plot.
If set to
True
, it interpolates with 200 x 200 points.If a
tuple (a, b)
is provided, it interpolates with a x b points.If an
int a
is provided, it interpolates with a x a points.I added an assertion to prevent users from interpolating more than 1000 points in any dimension to avoid potential notebook crashes due to memory limitations.
Let me know if this approach is too complex; I can simplify it if needed, like just True or False.
Fixes #1952