sciapp / python-gr Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for the GR framework
Home Page: https://gr-framework.org
License: Other
Python wrapper for the GR framework
Home Page: https://gr-framework.org
License: Other
Hello. Thank you for the great project.
This is a minor issue.
import gr
gr.setlinetype(3)
print(gr.inqlinetype())
3
import gr
gr.inqlinetype()
import gr
gr.inqlinewidth()
Segmentation fault (core dumped)
When installing with pip, you get the following error:
urlopen error Failed to download file from: https://github.com/sciapp/gr/releases/download/v0.55.0/gr-0.55.0-Windows-x86_64-mvsc.tar.gz, http://gr-framework.org/downloads/gr-0.55.0-Windows-x86_64-mvsc.tar.gz```
hi,
i'm sure this is something silly, but i'm getting this error in the examples:
GKS: dlopen(/Users/spencerw/miniconda3/envs/motor/lib/python3.7/site-packages/gr/lib/qt5plugin.so, 1): Library not loaded: @rpath/QtWidgets.framework/Versions/5/QtWidgets Referenced from: /Users/spencerw/miniconda3/envs/motor/lib/python3.7/site-packages/gr/lib/qt5plugin.so Reason: image not found
i'm running python 3.7.3 in a conda environment. in the lib
folder I see qtplugin.so
but not qt5plugin.so
...
I'd like to try GR as I've been using PyQtGraph and I'm looking for better performance with live plotting of data coming in at 2kHZ on 64 channels.
thanks!
Running on macOS Mojave 10.14.5, I'm running the anim example provided here on gr-framework.org.
According that page, the expected results are:
fps (mpl): 29
fps (GR): 1002
speedup: 34.6
However, I'm observing (in Python 2.7.10, using GR module 1.10.0):
fps (mpl): 34
fps (GR): 118
speedup: 3.5
In contrast, when running the the figure output performance example figanim on my machine, it shows something on the order of the expected speedup:
.................................................fps (mpl): 12
.................................................fps (GR): 1865
speedup: 155.4
I apologize if the information here is lacking. I'm not sure what the next steps would be to diagnose or continue profiling.
Hi.
matplotlib.mplot3d
has a function plot_trisurf
that can plot a 3D triangular mesh using vertex coordinates and triangle connectivity information. This is similar to gr3.createindexedmesh()
.
Is there any way to do this using the mlab
interface? My use case is to make a figure with two subplots -- one a 2D line plot and another a 3D plot containing surface mesh of a closed shell.
Thanks
I just installed gr 1.13.0 via
pip install gr
with
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Also, in
https://github.com/sciapp/python-gr/blob/master/examples/wx_ex.py
I had to change for Python 3.8 map()
z = map(lambda x: x & 0xff, d)
to
z = list(map(lambda x: x & 0xff, d))
as init expects a list, and the first call to z on line 73 empties the generator.
I now just get
GKS: Wx support not compiled in
So, how to go about the wx build?
Our goal is to start a drop-in replacement for wx.lib.plot(), which is terribly slow for samples>~100k
Replaced my username with [User].
Running on Windows 10 build 18363.900
As you can see I'm using pyenv to manage my python installation. Not sure if that's causing the problem or not.
How to reproduce:
import grm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\[User]\.pyenv\pyenv-win\versions\3.7.5-amd64\lib\site-packages\grm\__init__.py", line 10, in <module>
_grm = load_runtime(lib_name="libGRM")
File "C:\Users\[User]\.pyenv\pyenv-win\versions\3.7.5-amd64\lib\site-packages\gr\runtime_helper.py", line 69, in load_runtime
library.gr_version.argtypes = []
File "C:\Users\[User]\.pyenv\pyenv-win\versions\3.7.5-amd64\lib\ctypes\__init__.py", line 377, in __getattr__
func = self.__getitem__(name)
File "C:\Users\[User]\.pyenv\pyenv-win\versions\3.7.5-amd64\lib\ctypes\__init__.py", line 382, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'gr_version' not found
I updated from 1.17.3 to 1.18.0 using pip and encountered this error. This prevents me from using qtgr as well since qtgr imports gr3. I uninstalled and downloaded 1.17.3 and sure enough importing gr3 works.
Here's the traceback
>>> import gr3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/emdash00/.pyenv/versions/3.8.12/lib/python3.8/site-packages/gr3/__init__.py", line 145, in <module>
_gr3 = load_runtime()
File "/home/emdash00/.pyenv/versions/3.8.12/lib/python3.8/site-packages/gr3/__init__.py", line 124, in load_runtime
return CDLL(library_filename)
File "/home/emdash00/.pyenv/versions/3.8.12/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/emdash00/.pyenv/versions/3.8.12/lib/python3.8/site-packages/gr/lib/libGR3.so: undefined symbol: gr_inqorthographicprojection
My system specs are:
OS: Ubuntu 20.04.3 LTS
Kernel: Linux 5.4.0-84-generic
CPU: Intel i7-8550U W 4.000 GHz
GPU: Intel UHD Graphics 620
Let me know if you need anything else.
the python bindings currently pass
red green green
instead of
red green blue
to the library function.
A patch to fix this is attached.
patch_inqcolorfromrgb_python_gr.txt
hi, it seems that here the font size at which labels are drawn is set to a fixed multiple of the height of the plot window in normalized device coordinates.
it should be made possible somehow to adjust that.
concrete example: i am trying to produce a non 1:1, landscape-format plot. the only way i found to achieve that was the cumbersome method:
window_cm = np.array([0., 20, 0, 10])
gr.setwsviewport(*(1e-2*window_cm)) # screen window size in meters
gr.setwswindow(0, 1, 0, 0.5) # rect in NDC coords to be scaled to the workspace window
p = Plot(viewport=(.1, .95, 0.05, .45)) # padding of plot into that rect
p.xlabel = 't'
p.ylabel = 'mol number' # it seems currently impossible to change label size.
this means the NDC height is now only 0.5 instead of 1, so that my axis labels now come out as half the font size of the usual case with 1:1 aspect plots, with apparently no way to change that.
edit:
After upgrading the OS to MacOS 10.15 (catalina) apps using qtgr crash. I could track the problem down to the call to _axeslbl_callback
from gr/__init.py__::axeslbl
.
python 3.8.12
Qt 5.15.2
PyQt 5.15.2
python-gr is the latest form master
Following my initial inquiry at sciapp/gr#30 (comment), I am looking for a way to wrap a GR FigureCanvas
object in a way that can be added to an existing PyQt layout. Below is a very simplified code of the way I'm currently doing things with the Qt5Agg FigureCanvas
:
import sys
from PyQt5 import QtCore, QtWidgets
import numpy
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle("QT5 matplotlib example")
self.main_widget = QtWidgets.QWidget(self)
fig = Figure(tight_layout=True)
fig_canvas = FigureCanvas(fig)
v_layout = QtWidgets.QVBoxLayout(self.main_widget)
v_layout.addWidget(fig_canvas)
x = numpy.arange(0, 2 * numpy.pi, numpy.pi / 100)
y = numpy.sin(x)
ax = fig.add_subplot(111)
ax.plot(x, y)
self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)
qApp = QtWidgets.QApplication(sys.argv)
app = ApplicationWindow()
app.show()
sys.exit(qApp.exec_())
Currently, my attempts to integrate the FigureCanvas
from the GR matplotlib backend raises an error as Qt doesn't recognize the FigureCanvasGR
type. Perhaps I am missing an existing capability, but essentially I am looking for a way (using QtGR or other) to wrap the GR FigureCanvas
in an object that Qt will understand.
Julia
function quiver(x, y, u, v, color::Bool=false)
https://github.com/jheinen/GR.jl/blob/d774077076d8250117db356711df776590e348ab/src/GR.jl#L3569
python-gr
Line 315 in 9ef456a
I have noticed that gr.inline('mov')
fails to load the animation to jupyter notebook (ffmpeg is installed in my computer).
For instance, running the following code give "invalid source" displayed at the output of the cell
import math
import gr
import gr3
# plot gr output inline
gr.inline('mov')
gr.setviewport(0, 1, 0, 1)
gr3.setbackgroundcolor(1, 1, 1, 1)
for t in range(200):
f = 0.0375 * (math.cos(t*0.2) * 0.995**t + 1.3)
n = 90
points = [(math.sin(i*math.pi/8), n*0.035-i*f, math.cos(i*math.pi/8)) for i in range(n-5)]
points.append((0, points[-1][1], 0))
points.append((0, points[-1][1]-0.5, 0))
points.append((0, points[-1][1]-1, 0))
points.insert(0, (0, points[0][1], 0))
points.insert(0, (0, points[0][1]+2, 0))
colors = [(1, 1, 1)]*n
radii = [0.1]*n
gr3.clear()
gr3.drawtubemesh(n, points, colors, radii)
gr3.drawspheremesh(1, points[-1], colors, 0.75)
gr.clearws()
gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
gr.updatews()
gr.show()
I was able to fix this by following:
in line 2323 of python-gr/gr/__init__.py
content = HTML(data='<video controls autoplay type="video/mp4" src="data:video/mp4;base64,{0}">'.format(b64encode(open('gks.mov', 'rb').read()).decode('ascii')))
This seems to have arised from change in IPython.display.HTML
Best,
Eunjong
Basically the question above. There's not an exposed method in qtgr and I'm rather confused about the whole concept of gr workstations and how one might use them for multiple qt windows.
I was playing around a bit with qtgrdemo example.The pick button which sets the pick mode of the interactive plot (plot 1) picks point coordinates properly but doesn't draw the crosshair on the right location. I've attached a photo of the behavior. Ignore the absent 2nd widget. I removed it on accident while removing the linear plot.
This is a repost of https://stackoverflow.com/questions/70563646/gr-examples-in-python-dont-open-a-window-with-visualization.
I installed GR and its dependencies on Ubuntu 20.04 with Python 3.8.10 following instructions on https://gr-framework.org/python.html#installation. The first example:
from gr.pygr import mlab
mlab.plot(range(100), lambda x: x**2)
creates a plot in Jupyter as expected. What is a way to get a plot when run from the terminal?
Using Qt5 the use of the mouse wheel creates an error:
'QWheelEvent' object has no attribute 'delta'
The corresponding member is angleDelta in Qt5
I've been toying around with getting graphs to work in a tab view so I can easily add, remove, and view many graphs simultaneously.
Here's my code below. I try to do the example live plotter in a QTabWidget.
import sys
from gr.pygr import Plot, PlotAxes, PlotCurve
from qtgr.backend import QtCore, QtGui, QtWidgets
from qtgr import InteractiveGRWidget
from numpy import arange, sin, pi
class ScaledPlotAxes(PlotAxes):
def doAutoScale(self, curvechanged=None):
xmin, xmax, ymin, ymax = PlotAxes.doAutoScale(self, curvechanged)
bxmin, _bxmax, _bymin, _bymax = self.getBoundingBox()
if xmin < bxmin:
xmin = bxmin
self.setWindow(xmin, xmax, ymin, ymax)
return self.getWindow()
class GRTab(QtWidgets.QTabWidget):
def __init__(self, *args, **kwargs):
QtWidgets.QTabWidget.__init__(self)
self._tabDict = {"Tab 1": InteractiveGRWidget()}
viewport = [0.1, 0.88, 0.1, 0.88]
x = arange(0, 2 * pi, 0.01)
y = sin(x)
self.curve = PlotCurve(x, y)
axes = ScaledPlotAxes(viewport)
axes.addCurves(self.curve)
plot = Plot(viewport).addAxes(axes)
plot.title = "QtGR Timer example"
plot.subTitle = "Plotting Live-Data"
plot.xlabel = "t"
plot.ylabel = "sin(t)"
self._tabDict["Tab 1"].addPlot(plot)
self.addTab(self._tabDict["Tab 1"], "Tab 1")
def updateData(self):
self.curve.x += 0.05
self.curve.y = sin(self.curve.x)
self.update()
class TabWindow(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
layout = QtWidgets.QGridLayout()
self._grtab = GRTab()
layout.addWidget(self._grtab, 0, 0)
self.setLayout(layout)
def main():
app = QtWidgets.QApplication(sys.argv)
mainWindow = TabWindow()
mainWindow.show()
sys.exit(app.exec_())
if (__name__ == '__main__'):
main()
And here is the error:
Traceback (most recent call last):
File "/home/emdash00/.local/lib/python3.7/site-packages/qtgr/__init__.py", line 93, in resizeEvent
self._sizex = self._mwidth / self._mheight
ZeroDivisionError: float division by zero
[1] 19857 abort (core dumped) python3 grtabview.py
I'm not entirely sure what to make this being new to Qt and GR still.
My OS is Ubuntu 19.04 and I'm running this on an Intel Core i7.
The wheel does include platform-specific files, but is not marked as such ( gr-...-any.whl).
See https://stackoverflow.com/questions/45150304/how-to-force-a-python-wheel-to-be-platform-specific-when-building-it how make setup.py aware of this to get platfrm-specific wheels.
https://gr-framework.org/examples/spectrum3
spectrum3.zip
.html
returns
C:\Python38\Tools\scripts\GR\gr2.py:17: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves s
urprisingly on unicode inputs. Use frombuffer instead
amplitudes = np.fromstring(mic.read(SAMPLES), dtype=np.short)
Traceback (most recent call last):
File "C:\Python38\Tools\scripts\GR\gr2.py", line 29, in
power = get_spectrum()
File "C:\Python38\Tools\scripts\GR\gr2.py", line 18, in get_spectrum
return abs(np.fft.fft(amplitudes / 32768.0))[:SAMPLES/2]
TypeError: slice indices must be integers or None or have an index method
Using Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
numpy. version = '1.18.1'
after fixing lines 17 & 18
amplitudes = np.frombuffer(mic.read(SAMPLES), dtype=np.short)
return abs(np.fft.fft(amplitudes / 32768.0))[:int(SAMPLES/2)]
there are no errors, but no gl window. print() does show data in.
Versions:
Runtime: 0.41.0
Python: 1.11.0
The following script illustrates the issue. You will see double drawings in the second subplot.
import gr
from gr.pygr import mlab
import numpy as np
x = np.linspace(-4, 4, 100)
mlab.figure()
mlab.subplot(2,1,1)
mlab.plot(x, np.sin(x))
mlab.ylim(-2, 2)
mlab.subplot(2,1,2)
mlab.plot(x, np.cos(x) + 1)
mlab.ylim(-4, 4)
The example is using the Python wrapper, but I guess this is more an issue of the underlying framework.
Well, by looking at the Python wrapper code I got aware that I could also pass ylim=(...) to the plot command directly. That solves my issue, so no high urgency on this one.
Regards
Guido
Hello there,
I'm trying the matplotlib backend example with the latest matplotlib (3.3.3): https://gr-framework.org/tutorials/matplotlib.html
I'm taking this code:
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
plt.plot(t,s)
plt.title(r'$\alpha_i > \beta_i$', fontsize=20)
plt.text(1, -0.6, r'$\sum_{i=0}^\infty x_i$', fontsize=20)
plt.text(0.6, 0.6, r'$\mathcal{A}\mathrm{sin}(2 \omega t)$',
fontsize=20)
plt.xlabel('time (s)')
plt.ylabel('volts (mV)')
plt.show()
Then setting the backend through the environment variable: export MPLBACKEND="module://gr.matplotlib.backend_gr"
, and running the example script, simply does not produce any window.
Anything I'm missing here?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.