State of the GR framework - Scientific IT-Systems - Forschungszentrum ...

25.06.2016 - produce video contents on the fly by adding a single line of code. ➟ no need to import an animation module or write extra code. 3 ...
4MB Größe 219 Downloads 437 Ansichten
Member of the Helmholtz Association

State of the GR framework

June 21st – 25th, 2016 Massachusetts Institute of Technology, Cambridge, Massachusetts | JuliaCon 2016 | Josef Heinen | @josef_heinen

http://goo.gl/9CqX0j

Recap – the main ideas behind GR ✓ procedural graphics backend (completely written in C)
 ➟ presentation of continuous data streams ✓ builtin support for 2D plotting and OpenGL (GR3)
 ➟ coexistent 2D and 3D world ✓ support for different programming languages including those popular in Data Science such as Python and Julia (ready for Julia 0.5.0 development version) ✓ interoperability with GUI toolkits and web applications (Jupyter Noteboook)
 ➟ good user interaction June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

2

Use GR as a backend for Matplotlib ✓ combine the power of PyPlot and GR
 ➟ select GR as a backend by setting the MPLBACKEND environment variable export MPLBACKEND="module://gr.matplotlib.backend_gr"

✓ significantly improve the performance of existing Matplotlib applications ✓ create plots containing both 2D and 3D graphics elements ✓ produce video contents on the fly by adding a single line of code
 ➟ no need to import an animation module or write extra code June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

3

Matplotlib using the GR backend $( $&

Arrow

Line2D

%#"#



%$$)"'

$# *

$%"'

(

$#"#

Ellipse

FancyBoxPatch

&

)"'

%

'"#

!

$!

"!! %! $! #! "!

#!

"!

#

%

& +

(

#"* #")

&"(

#"&

&"#

#"#

%"(

135°

$"( &"#

&"(

'"#

'"(

("# #"* #")

&"(

#"&

&"#

#"#

%"( %"#

! #")

$"(

June 21st – 25th, 2016

&"(

#!"# "!)+ "!'( "!%& "!## "!## "!%& "!'( "!)+ #!"#

6 4 0°

( 225°

315°

! #"* &"#

#!

# &$% # %$') # &$* # %$(+ # '$% # '

%$2

! #"&

%"(

%!

$!

10

180°

'"#

%"#

%!

$"%

'"(

$"(

$!

8

! #"* %"(

#!

# %$&'

# &$*

'"#

'"(

# &

%$# %$*

%

%$%$*

&

%$&$*

'

%$)/07,5/2- * (,0*82*9 1,6. !*440/+*7/32 73 ./-.# 5,63087/32 75/+327385/2-"

45°

! #")

+327385- :/7. 0,9,06

%$%%

&

%$! #"&

%"#

%"#

"!

#"#

$#

*

!

! "! (

$"%

'"#

$"(

%$&'

) %

%$%"'

!% !%

'"(

$"# $"#

%$')

90°

4+30351,6. :/7. 0,9,06

("#

&

%$&!

'

PathPatch

%$(+

# %$*

#

Polygon

&$*

%$*

%!

Circle

%$),

&!

$'"#

-

Rectangle

"!!

+ ,

Wedge

051..-7- 7/67 !'%% 431276"

'

%$%%"'

&

$

"

$ $

&

"

$

&

(

"!'

%$' "!* "!( "!& "!$ "!" "!$ "!& "!( "!*

"!% "!$ "!"

%

%$"!$ "!% "!' #!"

# %$'

"!& #!"

& (

(

270°

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

# &$% # &

%$# %$'

%

%$%$'

&

%$"!&

"!" "!"

"!&

"!& #!"

#!"

4

Use MATLAB–like plot functions using GR figure(figsize=(6,4)) tevent = 1126259462.422 d = readdlm("strain.dat") time, H1_strain, L1_strain = d[:,1], d[:,2], d[:,3] d = readdlm("nr_waveform.dat") NRtime, NR_H1_whitenbp = d[:,1],d[:,2] xlim([-0.1, +0.05]) ylim([-4,+4]) legend("H1 strain", "L1 strain”, "matched NR waveform") xlabel(@sprintf("time (s) since %.3f", tevent)) ylabel("whitented strain") title("Advanced LIGO WHITENED strain data near GW150914") plot(time-tevent, H1_strain, "r", time-tevent, L1_strain, "g", NRtime+0.002, NR_H1_whitenbp, "k")

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

5

… for 2D using LsqFit x = -16:0.5:35 y = 19.4./((x - 7).^2 + 15.8) + randn(size(x))./10;

1.0

model(x, p) = p[1]./((x-p[2]).^2+p[3]) fit = curve_fit(model, x, y, [25.,10.,10.]) p = fit.param f = p[1]./((x-p[2]).^2+p[3])

0.5

using GR plot(x, y, "d", x, f, "-", linewidth=2)

0

- 20

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

0

20

40

6

… for 2D (cont.) 1.0

1.0 J0 J1 J2 J3

0.8

0.5 0.6

0.4 0 0.2

- 0.5

June 21st – 25th, 2016

0

5

10

15

20

0

0

0.2

0.4

0.6

0.8

1.0

using GR

using GR

x = linspace(0,20,200) for order in 0:3 plot(x, besselj(order, x)) hold(true) end legend("J_0", "J_1", "J_2", “J_3")

n = 500 x = rand(n) y = rand(n) area = pi .* (15 .* rand(n)).^2 scatter(x, y, area, 1:n, alpha=0.5)

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

7

… or 3D using GR inline("mov") using GR Ψv = calculate_electronic_density(3, 2, 0) for alpha in 30:210 isosurface(Ψv, isovalue=0.25, rotation=alpha) end

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

8

Mix 2D and 3D scenes and create video content on the fly …

jlgr

GR3

GR

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

9

Use GR with Interact.jl

using Interact using GR inline() z = peaks() @manipulate for θ=20:1:70, Φ=20:1:70 surface(z, rotation=θ, tilt=Φ)

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Use GR with Gtk.jl function paint(w) ctx = Gtk.getgc(w) ENV["GKS_WSTYPE"] = "142" ENV["GKSconid"] = @sprintf("%lu", UInt64(ctx.ptr)) Gtk.show_text(ctx, "Contour Plot using Gtk ...")

end

z = peaks() contourf(z)

win = @Window("Gtk") canvas = @Canvas(600, 450) Gtk.push!(win, canvas) Gtk.draw(paint, canvas) Gtk.showall(win) signal_connect(win, :destroy) do widget Gtk.gtk_quit() end Gtk.gtk_main()

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Use GR as a backend for Plots.jl julia> using Plots julia> gr() Plots.GRBackend()

10

10 250

8

75

250

y1 y2

8 200

200

6

150

100

4

6

150

100

4

50 2

Height

70

65

50 2 60 0

5

10

June 21st – 25th, 2016

15

20

5

10

15

20

2

4

6

8

VoicePart

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

12

Use GR in Atom

✓ powerful IDE ✓ syntax highlighting ✓ command completion ✓ inline graphics

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

Demos

✓ GR / mogli interoperability example ✓ interactive widget demo for a simple surface plot ✓ Visualizing atomic orbitals in a Jupyter notebook ✓ Use GR to visualize instrument data

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

14

Current Activities ✓ near completion of a “fully–featured” GR distribution for Windows based on the MinGW–w64 toolchain ✓ improve the build and deployment process of self–contained GR packages ✓ provide more (MATLAB–like) convenience functions ✓ consolidate the Plots gr() backend ✓ proof–of–concept for an in–browser JavaScript–based GR renderer (transpiled from original C–code) June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

15

What’s next? IPython

QtTerm

C / C++ ... GR3

GR

W IP

off-screen rendering

socket
 communication

direct rendering

JavaScript
 generation

POV-Ray
 generation

QtTerm

✓ plattform–independent

Browser Qt

WebGL

✓ interactive (zoom, pan, 
 pick data, …)

OpenGL (WGL / CGL / GLX)

GKS

POV-Ray

EGS ✓ based on ModernGL

W IP

✓ stand–alone viewer
 (C++, Qt 5.7)

Swift

PyPy

GKS logical device drivers

gksqt

wx

X11

Quartz

GKSTerm

Win32

Cairo

PNG

N ew

Qt

X11

TikZ

LATEX

PDF

MOV

PS

0MQ

SVG

OpenGL

EGS ...

✓ extensibility using plugins ✓ combines 2D and 3D

HTML5

✓ high–performance rendering ✓ GKS driver

June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

16

Why EGS? … because performance matters!

e.g, for the visualization of Micro Swimmers June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

17

Thank you for your attention Questions? Contact: [email protected]
 @josef_heinen

Thanks to: Florian Rhiem, Ingo Heimbach, Christian Felder, David Knodt, Jörg Winkler, Fabian Beule, Philip Klinkhammer, Marvin Goblet, Daniel Kaiser, et al. June 21st – 25th, 2016

Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems

18