-
Notifications
You must be signed in to change notification settings - Fork 63
Fix for single frequency FieldMonitor #2697
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
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.
1 file reviewed, 1 comment
Regarding |
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
|
Either way, does it hurt to include the mode area under the same conditional? If it also works, I think it's the safer choice. |
It's probably a good idea to include a short test case with a single frequency to guarantee the problem doesn't happen again in the future… |
I just included the mode_area, it works well (not sure why I thought it wouldn’t in the first place). Anyway, the user added another frequency to the monitor and could load the file, but mentioned that “Tidy3D and Zemax have a 90-degree difference.” I’m not sure if this is a true rotation or just a transposition. Do you think transposing the data would fix it? e_x = self._tangential_fields["E" + dim1].T Or is this likely specific to this case? |
Thanks @FilipeFcp! It looks good, I agree with @lucas-flexcompute that it would be good to include a single frequency test case. The tests are here, let me know if you need any help.
By 90-degree difference do they mean the x and y coordinates are swapped? It might be case dependent but it's hard to tell without more context, would the user be able to share more information? |
Thanks @bzhangflex. I will ask the user for some more context and let you know. Hi is from Japan, so probably he will reply just on Monday. |
This is a good question, since we did not have the opportunity to test or compare this code at all so far! We should try to work with the user to find out more. |
Regarding the coordinate rotation I think I might see the issue, here instead of I think it might need to be If that's the case then One test is if the user sets different values for |
Hi @bzhangflex and @lucas-flexcompute. I have added the tests, and also implemented the option to pass the argument for the flatten order to 'A' or 'F', which hopefully can help us to debug it in the future. @tomflexcompute, this is the PR I mentioned today |
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.
Is this flatten_order
something that we need to make available? My understanding was that, once we confirmed the expected ordering in Zenmax, we could just set it here and not have the user worrying about it…
6cbed0e
to
d025074
Compare
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.
Thank you @FilipeFcp! Looks great to me. @lucas-flexcompute would you like to have a quick look as well?
I think it looks good as well! |
d025074
to
ead7345
Compare
I just added an
if
condition to not interpolate the coordinates if it is a single frequency monitor to avoid interpolation data.This issue was reported by a user today.
Greptile Summary
This PR fixes a bug in the ZBF export functionality for single-frequency FieldMonitor data. The issue occurs in the
to_zbf_file
method withinmonitor_data.py
where xarray'sinterp()
method produces NaN values when interpolating single-frequency datasets.The change adds a conditional check
if len(e_x.f) > 1:
before interpolating the E-field components (e_x
ande_y
) to a specific frequency. This prevents unnecessary interpolation when only one frequency point exists, since the data already exists at the target frequency. The fix specifically addresses lines 1169-1171 where E-field interpolation occurs.This change integrates with the existing ZBF export pipeline, which is used to convert Tidy3D field monitor data into the ZBF (Zemax Beam File) format for interoperability with Zemax optical design software. The ZBF export functionality is part of the monitor data processing workflow that handles various electromagnetic field data types.
Confidence score: 4/5
• This is a safe, targeted bugfix that resolves a specific interpolation issue without affecting other functionality
• The fix follows sound logic by avoiding unnecessary operations that introduce numerical artifacts, though there's a potential inconsistency with
mode_area
interpolation handling• The
mode_area
interpolation on line 1166 should be reviewed for consistency, as it lacks the same conditional check