Skip to content

Commit

Permalink
Got temporal focusing example working better. Added save_plot method …
Browse files Browse the repository at this point in the history
…to intensity_image view object.
  • Loading branch information
bryancole committed May 19, 2021
1 parent d2db292 commit 05976d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
13 changes: 11 additions & 2 deletions examples/temporal_focusing_microscopy_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@
# E_vector=(0,0,1)
# )

grating = RectangularGrating(centre=(80.0,0.,0.),
grating = RectangularGrating(centre=(220.0,0.,0.),
direction=(-1,1,0.),
length=15.,
width=20.0,
thickness=3.0,
lines_per_mm=1400.0)
grating.orientation = 45.5

lens1 = PlanoConvexLens(centre=(40.0,0.0,0.0),
direction=(-1,0,0),
diameter=25.0,
CT=6.0,
n_inside=1.6,
curvature=25.0)
curvature=100.0)

lens2 = PlanoConvexLens(centre=(10.0,-30.0,0.0),
direction=(0,1,0),
Expand Down Expand Up @@ -91,6 +92,14 @@ class MyConstraint(Constraint):
@observe("time, time_offset")
def on_time_change(self, evt):
field.time_ps = self.time + self.time_offset


def animate(self, dt, count):
for i in range(count):
field.time_ps = self.time + self.time_offset + i*dt
U = field.intensity
print("Calc:", i)
image.save_plot(f"/home/bryan/tmp/range_{i:03d}.png")

cst = MyConstraint()

Expand Down
1 change: 0 additions & 1 deletion raypier/gausslet_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from raypier.tracer import normaliseVector
from raypier.editors import NumEditor
from raypier.decompositions import decompose_angle, make_hexagonal_grid
from virtualenv.create.via_global_ref.builtin import via_global_self_do


class BaseGaussletSource(BaseRaySource):
Expand Down
14 changes: 11 additions & 3 deletions raypier/intensity_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from chaco.default_colormaps import Spectral

from enable.api import ComponentEditor, KeySpec
from chaco.tools.api import PanTool, ZoomTool
from chaco.tools.api import PanTool, ZoomTool, SaveTool

from .results import Result
from .fields import EFieldPlane
Expand Down Expand Up @@ -158,6 +158,8 @@ def _hbox_default(self):
hbox.add(self.plot)
hbox.add(self.cbar)
#hbox.bgcolor = 'sys_window'
save_tool = SaveTool(component=hbox, filename="/home/bryan/saved_plot.png")
hbox.tools.append(save_tool)
return hbox

def _cbar_default(self):
Expand Down Expand Up @@ -202,12 +204,18 @@ def _plot_default(self):
plot.x_axis.title = "Width /mm"
plot.y_axis.title = "Height /mm"
a = probe.centre
plot.title = f"Intensity @ ({a[0]:0.3f}, {a[1]:0.3f}, {a[2]:0.3f})"
#plot.title = f"Intensity @ ({a[0]:0.3f}, {a[1]:0.3f}, {a[2]:0.3f})"

pantool = PanTool(plot) #self.pan_tool
pantool = self.pan_tool
pantool.component = self.image_plot
self.pan_tool = pantool
plot.tools.append(pantool)

return plot

def save_plot(self, filename):
from chaco.api import PlotGraphicsContext
component = self.hbox
gc = PlotGraphicsContext((int(component.outer_width), int(component.outer_height)))
component.draw(gc, mode="normal")
gc.save(filename)

2 comments on commit 05976d8

@chessybo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am receiving this error.

`runfile('/home/cchester/.config/spyder-py3/temp.py', wdir='/home/cchester/.config/spyder-py3')
Traceback (most recent call last):

  File "/home/cchester/.config/spyder-py3/temp.py", line 12, in <module>
    from raypier.beamsplitters import UnpolarisingBeamsplitterCube

  File "/home/cchester/anaconda3/lib/python3.8/site-packages/raypier/beamsplitters.py", line 6, in <module>
    from .bases import Traceable

  File "/home/cchester/anaconda3/lib/python3.8/site-packages/raypier/bases.py", line 41, in <module>
    from raypier.core import ctracer, cmaterials

  File "raypier/core/ctracer.pyx", line 1, in init raypier.core.ctracer

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject`

@bryancole
Copy link
Owner

@bryancole bryancole commented on 05976d8 May 21, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.