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

Add a phase parameter to frequency-domain monitor data. #1261

Closed
e-g-melo opened this issue Nov 20, 2023 · 10 comments
Closed

Add a phase parameter to frequency-domain monitor data. #1261

e-g-melo opened this issue Nov 20, 2023 · 10 comments
Assignees

Comments

@e-g-melo
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
In our meetings with professors interested in the teaching program, they frequently ask how to create field animations using Tidy3d.

Describe the solution you'd like
Currently, we have the FieldTimeMonitor, which allows us to create time-domain animations easily. However, animating the frequency-domain fields would be nice and less memory-intensive for teaching purposes. For example, to show how the waves propagate from a point-dipole source, we could animate the field phase, like below:

dip_anim

Describe alternatives you've considered
It is possible to get the field components from the FieldData object, change the phase, and create an animation. However, a built-in feature would help Tidy3D beginners.

Additional context
Other field animation example from mode data:
mode_anim

@momchil-flex
Copy link
Collaborator

I am a bit confused by the title of this issue vs. what it's asking for. Are you suggesting a convenience method to create the entire animation, like a FieldData.animate(...)? Or what do you mean by "add a phase parameter"?

@momchil-flex
Copy link
Collaborator

Assigning @tylerflex so that someone is on this, but feel free to reassign if you want.

@e-g-melo
Copy link
Collaborator Author

Both should work for the purpose of creating the animations, but I think adding the phase parameter would be more general, allowing the user to choose how to create the animations or plot a single field snapshot using a different phase.

@tylerflex
Copy link
Collaborator

@e-g-melo could you explain what the API should look like for adding a phase parameter? like

field_data = field_data.apply_phase(phase)

or something directly stored in the field data? like FieldData(..., phase=1.0) that we can modify with updated_copy()?

@e-g-melo
Copy link
Collaborator Author

We could include a phase parameter in the plot_field function for both FDTD and ModeSolver data, like below:

sim_data.plot_field("field", "Ex", "real", y=0.0, f=200e12, eps_alpha=0.2, phase=phase)
mode_solver.plot_field("Ex", "real", mode_index=0, f=freq0, ax=ax, phase=phase)

And include a function like the apply_phase(phase) as well to allow for custom plots or whatever the user wants to do.

mode_data_1 = mode_data.apply_phase(phase)
mode_data_1.Ex.isel(mode_index=0, f=freq0)).real.plot(x="x", y="z", ax=ax, cmap="RdBu")
field_data_1 = field_data.apply_phase(phase)
Ez_data = field_data_1.Ez.isel(y=0).interp(f=freq0)
Ez_data.real.plot(x="x", y="z", cmap="bwr", ax=ax)

@tylerflex
Copy link
Collaborator

@e-g-melo I made a solution here, please give it a test when you get a chance thanks.
#1271

@e-g-melo
Copy link
Collaborator Author

Wow! That was fast!

I will try it. Thanks!

@tylerflex
Copy link
Collaborator

actually need to fix one thing, give me a sec

@tylerflex
Copy link
Collaborator

should be working now

@tylerflex
Copy link
Collaborator

Fixed by #1271

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

No branches or pull requests

3 participants