From 165f3facaa6cc7c91c0f609d9c6daca5be28629c Mon Sep 17 00:00:00 2001
From: Valentin Bruch <valentin.bruch@rwth-aachen.de>
Date: Wed, 10 May 2023 12:32:55 +0200
Subject: [PATCH] creating 3d animation in plot_pyqtgraph.py

---
 plot_pyqtgraph.py | 65 +++++++++++++++++++++++++++++------------------
 1 file changed, 40 insertions(+), 25 deletions(-)

diff --git a/plot_pyqtgraph.py b/plot_pyqtgraph.py
index 9fd52da..0114c53 100644
--- a/plot_pyqtgraph.py
+++ b/plot_pyqtgraph.py
@@ -12,12 +12,13 @@ from pyqtgraph.Qt import QtGui
 from pyqtgraph.Qt.QtWidgets import QApplication
 from pyqtgraph import makeQImage
 import pyqtgraph.opengl as gl
-from matplotlib.pyplot import cm
+from matplotlib import colormaps as cm
 import pandas as pd
 from scipy.optimize import curve_fit
 import settings
 from data_management import DataManager
 from final_plots import photon_assisted_tunneling
+from pyqtgraph_utils import *
 
 #from OpenGL import GL
 #GL.glEnable(GL.GL_DEPTH_TEST)
@@ -270,8 +271,8 @@ def plot_interpolated(
         mirror_vdc = True,
         mirror_vac = False,
         cmap = "viridis",
+        order = "o3a",
         method = "mu",
-        truncation_order = 3,
         include_Ga = False,
         integral_method = -15,
         **parameters):
@@ -283,7 +284,7 @@ def plot_interpolated(
     data = np.load("figdata/omega5_interp.npz")
     app = QApplication([])
     w = gl.GLViewWidget()
-    w.show()
+    add3DAxes(w, size=(70,70,60), fontColor=(0,0,0,255), xlabel="Vosc", ylabel="Vavg", zlabel="log(G)", r=4, h=9, shift=(0,-135,-95))
     #pos = np.array([*np.meshgrid(data["vdc"], data["vac"]), 50*data["gdc_g"]]).reshape((3,-1)).T
     #sp = gl.GLScatterPlotItem(pos=pos, size=0.2, color=cm.viridis(data["gdc_g"].flatten()), pxMode=False)
     #sp.setGLOptions("additive")
@@ -292,14 +293,8 @@ def plot_interpolated(
     #sp = gl.GLScatterPlotItem(pos=pos_diff, size=0.2, color=cm.viridis(pos_diff[:,2]/10), pxMode=False)
     #sp.setGLOptions("additive")
     #w.addItem(sp)
-    vdc = data["vdc"]
-    order = f"o{truncation_order}"
-    if include_Ga:
-        order += "p"
-        assert integral_method is None or integral_method == -1
-    else:
-        assert integral_method is None or integral_method == -15
-    vac = data["vac"]
+    vdc = data["vdc"][0]
+    vac = data["vac"][:,0]
     gdc = np.pi*data[f"gdc_{method}_{order}"]
     if mirror_vdc:
         vdc = np.concatenate((-vdc[:0:-1], vdc))
@@ -314,34 +309,54 @@ def plot_interpolated(
             y=vdc,
             z=50*np.log(gdc),
             colors=cmap_light(gdc),
-            drawEdges=False)
-    sp.translate(1e-3, -1e-3, -1e-3)
+            drawEdges=False,
+            smooth=True)
+    sp.translate(0, 0, -1e-3)
     #sp.translate(-1e-2, -1e-2, -1e-2)
     w.addItem(sp)
     for i in range(0, vac.size, 10):
         line = gl.GLLinePlotItem(
                 pos=np.array([vac[i]*np.ones_like(vdc), vdc, 50*np.log(gdc[i])]).T,
                 color=cmap_dark(gdc[i]),
-                width=10)
-        line.setGLOptions("translucent")
+                width=10,
+                antialias=True,
+                mode="line_strip")
+        line.setGLOptions("opaque")
+        line.setDepthValue(10)
         w.addItem(line)
     for i in range(0, vdc.size, 10):
         line = gl.GLLinePlotItem(
                 pos=np.array([vac, vdc[i]*np.ones_like(vac), 50*np.log(gdc[:,i])]).T,
                 color=cmap_dark(gdc[:,i]),
-                width=10)
-        line.setGLOptions("translucent")
+                width=10,
+                antialias=True,
+                mode="line_strip")
+        line.setGLOptions("opaque")
+        line.setDepthValue(10)
         w.addItem(line)
-    w.opts["bgcolor"] = (1.,1.,1.,0.)
-    w.opts["azimuth"] = -30
-    w.opts["elevation"] = 30
+    w.show()
+    w.opts["bgcolor"] = (1.,1.,1.,1.)
     #w.opts["fov"] = 100
-    w.opts["distance"] = 450
-    w.opts["center"] = QtGui.QVector3D(0,40,-150)
-    arr = w.renderToArray((1000,800)).transpose((1,0,2))
-    makeQImage(arr).save(f"/tmp/Goverview_{method}_{order}.png")
+
+    w.setGeometry(0, 0, 2000, 1360)
+
+    for frame, progress in enumerate(np.linspace(0, 2*np.pi, 800, endpoint=False)):
+        settings.logger.info(f"progress: {progress*50/np.pi:.1f}%")
+        #w.opts["center"] = QtGui.QVector3D(0,24+18*np.cos(progress+0.3),-180-20*np.sin(progress-0.1))
+        #w.opts["distance"] = 475 - 15*np.cos(progress+0.2)
+        #w.opts["azimuth"] = -22*np.cos(progress+0.3) - 21
+        #w.opts["elevation"] = 12*np.sin(progress-0.1) + 30
+        w.opts["center"] = QtGui.QVector3D(0,24+12*np.cos(progress+0.3),-162-14*np.sin(progress-0.1))
+        w.opts["distance"] = 460 - 10*np.cos(progress+0.2)
+        w.opts["azimuth"] = -16*np.cos(progress+0.3) - 21
+        w.opts["elevation"] = 8*np.sin(progress-0.1) + 30
+
+        #arr = w.renderToArray((2000,1500)).transpose((1,0,2))
+        #makeQImage(arr).save(f"/tmp/frames/img_{frame:04d}.png")
+        w.grabFramebuffer().save(f"/tmp/frames/img_{frame:04d}.png")
+        # ffmpeg -framerate 50 -i /tmp/frames/img_%04d.png -c:v libsvtav1 -b:v 4M -movflags +faststart output.webm
+
     app.exec()
-    #w.grabFrameBuffer().save('/tmp/test.png')
 
 
 def convergence_grid_data(dm,
-- 
GitLab