-
Notifications
You must be signed in to change notification settings - Fork 69
fix: Handling of zero values when using plot_fields with scale=dB #3130
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: Handling of zero values when using plot_fields with scale=dB #3130
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.
3 files reviewed, 4 comments
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
|
16865b5 to
fcc3743
Compare
fcc3743 to
dd065ae
Compare
|
@greptile Check the latest version of this PR and provide a new confidence score. |
|
@greptileai Check the latest version of this PR and provide a new confidence score. |
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
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.
No files reviewed, no comments
damiano-flex
left a comment
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.
The PR looks OK 👍 I will make another one to fix the log scale which has the same issue.
dd065ae to
d7b64f5
Compare
I went ahead and added the fix to the TCAD plot_field as well |
|
Ah I see now, I'll revert and let you fix the unstructured data set issues! |
d7b64f5 to
5ca813e
Compare
Warnings were being emitted by xarray/numpy when plotting with
scale=dB.Note
Prevents divide-by-zero warnings when plotting fields with
scale='dB'by safely handling zeros.AbstractSimulationData._apply_log_scale()to replace zeros (respecting optionalvmin) and apply log10 with appropriatedb_factorplot_field_monitor_datato use the new helper for dB scalingvminto ensure no warningsCHANGELOG.mdunder FixedWritten by Cursor Bugbot for commit 5ca813e. This will update automatically on new commits. Configure here.
Greptile Overview
Greptile Overview
Greptile Summary
This PR fixes divide-by-zero warnings when plotting field data with
scale=dBby replacing zero values before applyinglog10. The implementation correctly handles both the case wherevminis specified (zeros map to the floor value) and when it's not (zeros map to NaN). The mathematical logic is sound: whenvminis provided,fill_val = 10 ** (vmin / db_factor)ensures that zeros ultimately map to exactlyvmindB after the log transformation.Key Changes:
plot_field_monitor_datato usexarray.where()to replace zeros while preserving NaN valuesvmin=Noneandvmin=-50casesObservations:
np.isnan(field_data)works properly with xarray DataArrayswarnings.filterwarnings("error")to ensure no divide-by-zero warnings are raisedConfidence Score: 5/5
is not Nonechecks. Test coverage validates the fix prevents warnings in both scenarios (with and without vmin).Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant User participant SimulationData participant plot_field_monitor_data participant _field_component_value participant numpy participant xarray User->>SimulationData: plot_field(scale="dB") SimulationData->>plot_field_monitor_data: call with field_data plot_field_monitor_data->>_field_component_value: get field values (val="abs") _field_component_value->>numpy: np.abs(field_component) numpy-->>_field_component_value: absolute values _field_component_value-->>plot_field_monitor_data: field_data (xarray) alt scale == "dB" plot_field_monitor_data->>plot_field_monitor_data: determine db_factor alt vmin is not None plot_field_monitor_data->>plot_field_monitor_data: fill_val = 10 ** (vmin / db_factor) else vmin is None plot_field_monitor_data->>plot_field_monitor_data: fill_val = np.nan end plot_field_monitor_data->>numpy: np.abs(field_data) numpy-->>plot_field_monitor_data: absolute values plot_field_monitor_data->>xarray: field_data.where((field_data > 0) | np.isnan(field_data), fill_val) Note over xarray: Replace zeros with fill_val,<br/>preserve NaN values xarray-->>plot_field_monitor_data: field_data with zeros replaced plot_field_monitor_data->>numpy: db_factor * np.log10(field_data) Note over numpy: No divide-by-zero warnings<br/>because zeros were replaced numpy-->>plot_field_monitor_data: dB values end plot_field_monitor_data-->>User: plot with dB scaleImportant Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant User participant SimulationData participant plot_field_monitor_data participant _field_component_value participant numpy participant xarray User->>SimulationData: plot_field(scale="dB") SimulationData->>plot_field_monitor_data: call with field_data plot_field_monitor_data->>_field_component_value: get field values (val="abs") _field_component_value->>numpy: np.abs(field_component) numpy-->>_field_component_value: absolute values _field_component_value-->>plot_field_monitor_data: field_data (xarray) alt scale == "dB" plot_field_monitor_data->>plot_field_monitor_data: determine db_factor alt vmin is not None plot_field_monitor_data->>plot_field_monitor_data: fill_val = 10 ** (vmin / db_factor) else vmin is None plot_field_monitor_data->>plot_field_monitor_data: fill_val = np.nan end plot_field_monitor_data->>numpy: np.abs(field_data) numpy-->>plot_field_monitor_data: absolute values plot_field_monitor_data->>xarray: field_data.where((field_data > 0) | np.isnan(field_data), fill_val) Note over xarray: Replace zeros with fill_val,<br/>preserve NaN values xarray-->>plot_field_monitor_data: field_data with zeros replaced plot_field_monitor_data->>numpy: db_factor * np.log10(field_data) Note over numpy: No divide-by-zero warnings<br/>because zeros were replaced numpy-->>plot_field_monitor_data: dB values end plot_field_monitor_data-->>User: plot with dB scale