feat(tidy3d): FXC-4260-allow-users-to-swap-custom-cmaps-in-field-visualization #3027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enables the support of custom colormaps in field visualizations.
Usage example:
Greptile Overview
Greptile Summary
Adds support for custom colormaps in field visualization methods across the codebase. Users can now pass a
cmapparameter (either a string colormap name or a matplotlib Colormap object) toplot_fieldmethods, which overrides the default colormap inferred from the field type.Key Changes:
cmapparameter toplot_field,plot_field_monitor_data, andplot_scalar_arraymethods inAbstractYeeGridSimulationDataModeSimulationData,HeatChargeSimulationData,ModeSolver, andRectangularDielectriccmapoverrides default colormap inferred fromcmap_typeIssues Found:
mode_solver.py: import statement appears immediately afterTYPE_CHECKINGblock without proper separationConfidence Score: 4/5
mode_solver.pywhere an import statement is incorrectly placed immediately after aTYPE_CHECKINGblock, which should be fixed before merging.tidy3d/components/mode/mode_solver.py- fix import ordering issue on line 82-84Important Files Changed
File Analysis
cmapparameter to all plot methods with proper handling and fallback to defaultscmapparameter toplot_fieldmethod; import ordering issue detectedcmapparameter with proper fallback to 'coolwarm' default and TYPE_CHECKING importSequence Diagram
sequenceDiagram participant User participant plot_field participant plot_field_monitor_data participant plot_scalar_array participant XarrayPlot User->>plot_field: plot_field(monitor_name, field_name, cmap="viridis") Note over plot_field: Accept cmap parameter<br/>(str or Colormap object) plot_field->>plot_field: load_field_monitor(monitor_name) plot_field->>plot_field_monitor_data: plot_field_monitor_data(..., cmap=cmap) Note over plot_field_monitor_data: Process field data<br/>and infer cmap_type plot_field_monitor_data->>plot_scalar_array: plot_scalar_array(..., cmap_type=cmap_type, cmap=cmap) Note over plot_scalar_array: Determine default_cmap<br/>from cmap_type if cmap is None plot_scalar_array->>plot_scalar_array: cmap_to_use = default_cmap if cmap is None else cmap plot_scalar_array->>XarrayPlot: field_data.plot(..., cmap=cmap_to_use) XarrayPlot-->>User: Returns matplotlib axes with field visualization