-
Notifications
You must be signed in to change notification settings - Fork 629
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
"discrete" option in python/visualization.plot_eps #1867
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1867 +/- ##
==========================================
- Coverage 73.40% 73.08% -0.33%
==========================================
Files 17 17
Lines 4896 4923 +27
==========================================
+ Hits 3594 3598 +4
- Misses 1302 1325 +23
|
Looking back I realize one could probably do all this processing outside of the plot function, and just pass the right |
It should be possible to generate a contour plot (via setting (Note that #1827 revamped |
Ah, I'd missed the switch to geometry-defined permittivity visualization. No intermediate epsilons and just pulling the unique levels from the geometry makes this a lot easier. Now that you mention it I am indeed able to get the
An easy fix would be to force it in the plotting function, e.g.
And then if discrete color levels is still useful it can also pull the epsilons from there. |
Here is a 2d test adapted from the one in #1827 (comment) which consists of various geometric objects with different values of ε. The figure below shows the output from running this script when the import meep as mp
import numpy as np
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
cell_size = mp.Vector3(1.,1.,1.)
design_region_resolution = 500.
design_shape = mp.Vector3(1.,1.,0)
Nx = int(design_region_resolution*design_shape.x) + 1
Ny = int(design_region_resolution*design_shape.y) + 1
x = np.linspace(-0.5*cell_size.x,0.5*cell_size.x,Nx)
y = np.linspace(-0.5*cell_size.y,0.5*cell_size.y,Ny)
xv, yv = np.meshgrid(x,y)
rad = 0.201943
w = 0.104283
design_params = np.where(np.logical_and(np.sqrt(np.square(xv) + np.square(yv)) > rad,
np.sqrt(np.square(xv) + np.square(yv)) < rad+w),
1.,
0.)
matgrid = mp.MaterialGrid(mp.Vector3(Nx,Ny),
mp.air,
mp.Medium(index=3.5),
weights=design_params,
do_averaging=False)
geometry = [mp.Cylinder(center=mp.Vector3(0.35,0.1),
radius=0.1,
height=0.5,
material=mp.Medium(index=1.5)),
mp.Block(center=mp.Vector3(-0.15,-0.2),
size=mp.Vector3(0.2,0.24,0.8),
material=mp.Medium(index=1.5431)),
mp.Block(center=mp.Vector3(-0.2,0.2),
size=mp.Vector3(0.4,0.4,0.3),
material=matgrid),
mp.Prism(vertices=[mp.Vector3(0.05,0.45),
mp.Vector3(0.32,0.22),
mp.Vector3(0.15,0.10)],
height=0.5,
material=mp.Medium(index=1.3135))]
sources = [mp.Source(mp.ContinuousSource(1.0),
center=mp.Vector3(),
size=mp.Vector3(0.2,0.2,0.2),
component=mp.Ez)]
sim = mp.Simulation(resolution=20,
cell_size=cell_size,
geometry=geometry,
sources=sources,
boundary_layers=[mp.PML(thickness=0.1,side=mp.High,direction=mp.Y)])
mon = sim.add_dft_fields([mp.Ez],
1.0,
0,
1,
center=mp.Vector3(0.3,-0.2),
size=mp.Vector3(0.3,0.1))
sim.plot2D(eps_parameters={'contour':True, 'resolution':400},
output_plane=mp.Volume(center=mp.Vector3(),
size=mp.Vector3(1.,1.,0)))
plt.title('contour: True')
plt.gca().set_aspect('equal','box')
plt.savefig('plot2D_test_contour.png',
dpi=150,
bbox_inches='tight') |
Thank you for taking a look. I do get this output when I run this example, and my software is up-to-date. I think my problem is simply that, by default, To avoid overcomplicating the function, discrete colors like I implemented can be done outside by the user, but to improve contour plotting I can do another PR with enforced levels for the contour option. |
Small PR for support for "discrete" plotting options in python/visualization.plot_eps
This is useful if a geometry has both large and small index contrasts. Below, for instance, we have ncore=3.45, nclad=1.44, and nfibercore=1.4467.
sim.plot2D()
with default orcontour
options cannot resolve the fiber core:In this PR, the
eps_parameters
optiondiscrete
(a boolean likecontour
) allows plotting of user-provided permittivity ranges in solid colors:This is controlled by new optional entries of the
eps_parameters
dict:discrete
: if True (andcontour
False), enables this option. Default is Falsediscrete_eps_levels
: an iterable with the permittivities to highlight. The code actually sets the coloring thresholds at the midpoints of the unique, sorted values of this iterable. If left unset, will use the minimum and maximum of permittivity data across the simulation region, and threshold at the average.discrete_eps_colors
: an iterable with the colors to use for each permittivity level (sorted in increasing order). Needs to be larger than the iterable corresponding tounique(discrete_eps_levels)
, otherwise will throw anAssertionError
. If left, unset, will generatelen(discrete_eps_levels)
colors equally distributed from thecmap
item, which by default is thebinary
matplotlib colormap.Examples with all options are below. The effect of subpixel averaging can be seen.
Using another colormap:
Using an iterable of colors: