Skip to content

Commit

Permalink
Merge pull request #34 from gpilab/develop
Browse files Browse the repository at this point in the history
New Minor Version — Full Windows compatibility, Audio & FFTW node improvements
  • Loading branch information
borupdaniel authored Mar 5, 2020
2 parents ac00262 + db9d814 commit 28a2b96
Show file tree
Hide file tree
Showing 22 changed files with 191 additions and 160 deletions.
2 changes: 1 addition & 1 deletion display/GPI/ImageDisplay_GPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def compute(self):
red = data[:,:,0].astype(np.uint8)
green = data[:,:,1].astype(np.uint8)
blue = data[:,:,2].astype(np.uint8)
if(data.ndim is 3 and data.shape[-1] is 4) :
if(data.ndim == 3 and data.shape[-1] == 4) :
alpha = data[:,:,3].astype(np.uint8)
else:
alpha = 255.*np.ones(blue.shape)
Expand Down
2 changes: 1 addition & 1 deletion display/GPI/Matplotlib_GPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def apply_callback(data):
line.set_linestyle(linestyle)
line.set_linewidth(linewidth)
line.set_color(color)
if marker is not 'none':
if marker != 'none':
line.set_marker(marker)
line.set_markersize(markersize)
line.set_markerfacecolor(markerfacecolor)
Expand Down
50 changes: 37 additions & 13 deletions display/GPI/Audio_GPI.py → fileIO/GPI/Audio_GPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import tempfile
import scipy.io.wavfile as spio
import numpy as np
import os
import time
from gpi import QtMultimedia

import gpi
Expand All @@ -54,7 +56,7 @@ class ExternalNode(gpi.NodeAPI):
WIDGETS:
Sample Rate (samp/sec) - D/A dwell time of waveform
# Loops - enter a number > 1 to play multiple times
Loops - enter a number > 1 to play multiple times
Play - write waveform and play audio
KNOWN ISSUES:
Expand All @@ -65,36 +67,58 @@ def initUI(self):
# Widgets
self.addWidget('TextBox', 'Audio Info')
self.addWidget('SpinBox', 'Sample Rate (samp/sec)', min=1, val=1000)
self.addWidget('SpinBox', '# Loops', min=1, val=1)
self.addWidget('SpinBox', 'Loops', min=1, val=1)
self.addWidget('PushButton', 'Play')

self.addWidget(
'SaveFileBrowser', 'File Browser', button_title='Browse',
caption='Save File (*.wav)', filter='Wav (*.wav)')
self.addWidget('PushButton', 'Write Now', button_title='Write Right Now', toggle=False)


# IO Ports
self.addInPort('wave source', 'NPYarray', ndim=1)

self._tmpfile = tempfile.mkstemp(
prefix='gpi_', suffix='.wav', dir='/tmp/', text=False)[1]
self.URI = gpi.TranslateFileURI

def validate(self):

fname = self.URI(self.getVal('File Browser'))
self.setDetailLabel(fname)

return 0

def compute(self):

arr = self.getData('wave source')
rate = self.getVal('Sample Rate (samp/sec)')
loops = self.getVal('# Loops')

loops = self.getVal('Loops')
# make sure the wave is maximized for int16 dyn-range
arr = (arr.astype(np.float32) / np.abs(arr)
.max() * (pow(2, 15) - 1)).astype(np.int16)

spio.write(self._tmpfile, rate, arr)

s = QtMultimedia.QSound('')
if s.isAvailable():
self.setAttr('Audio Info', val='Sound facilities are available.')
else:
self.setAttr(
'Audio Info', val='Sound facilities are NOT available.')
spio.write(self._tmpfile, rate, np.tile(arr,loops))

for i in range(loops):
try:
s = QtMultimedia.QSound('')
self.setAttr('Audio Info', val='Sound module is available.')
dur = len(arr)*loops / rate
s.play(self._tmpfile)
except:
self.setAttr('Audio Info', val='Sound module failed to load!\n Please visit www.github.com/gpilab/core-nodes/issues for help.')

time.sleep(.01)
os.remove(self._tmpfile)
if self.getVal('Write Now') or ('File Browser' in self.widgetEvents()):

fname = self.URI(self.getVal('File Browser'))
if not fname.endswith('.wav'):
fname += '.wav'

spio.write(fname,rate,arr)

return 0

Expand Down
6 changes: 3 additions & 3 deletions gridding/dft_PyMOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "PyFI/PyFI.h"
using namespace PyFI;

#include "gpi_core/gridding/dft_core.cpp"
#include "dft_core.cpp"

PYFI_FUNC(dftgrid)
{
Expand All @@ -58,7 +58,7 @@ PYFI_FUNC(dftgrid)
PYFI_POSARG(Array<double>, crds);
PYFI_POSARG(Array<double>, time);
PYFI_POSARG(Array<int64_t>, outdim);
PYFI_POSARG(long, effmtx);
PYFI_POSARG(int64_t, effmtx);

PYFI_SETOUTPUT_ALLOC(Array<complex<double> >, outdata, DA(*outdim));

Expand All @@ -76,7 +76,7 @@ PYFI_FUNC(dft_grid)
PYFI_POSARG(Array<complex<double> >, data);
PYFI_POSARG(Array<double>, crds);
PYFI_POSARG(Array<int64_t>, outdim);
PYFI_POSARG(long, effmtx);
PYFI_POSARG(int64_t, effmtx);
PYFI_POSARG(Array<double>, wghts);

PYFI_SETOUTPUT_ALLOC(Array<complex<double> >, outdata, DA(*outdim));
Expand Down
4 changes: 2 additions & 2 deletions gridding/dft_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// To Non-Cartesian (Degrid) with off-resonance
//========================================================================

int do_dft(Array<complex<double> > &image, Array<double> &offres, Array<double> &crds, Array<double> &time, Array<complex<double> > &data, long effmtx)
int do_dft(Array<complex<double> > &image, Array<double> &offres, Array<double> &crds, Array<double> &time, Array<complex<double> > &data, int64_t effmtx)
{
int i,j,k;
int i2, j2;
Expand Down Expand Up @@ -72,7 +72,7 @@ int do_dft(Array<complex<double> > &image, Array<double> &offres, Array<double>

/* To Cartesian (Grid)
*/
void do_dft_grid(Array<complex<double> > &data, Array<double> &crds, Array<complex<double> > &image, long effmtx, Array<double> &wghts)
void do_dft_grid(Array<complex<double> > &data, Array<double> &crds, Array<complex<double> > &image, int64_t effmtx, Array<double> &wghts)
{
int i,j,k;
int i2, j2;
Expand Down
2 changes: 1 addition & 1 deletion gridding/grid_123d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int griddat(Array<float> &crds, Array<complex<float> > &data, Array<float> &wate
// ROLLOFFDAT
//========================================================================

int rolloffdat(Array<complex<float> > &data, Array<complex<float> > &outdata, long isofov)
int rolloffdat(Array<complex<float> > &data, Array<complex<float> > &outdata, int64_t isofov)
{
int i, i0, i1, i2;
int dmtx0, dmtx1, dmtx2, omtx0, omtx1, omtx2;
Expand Down
5 changes: 2 additions & 3 deletions gridding/grid_PyMOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ using namespace PyFI;

#include <iostream>
using namespace std;
#include <math.h> // for sqrt(), log(), and sin(), pow()
#include "gpi_core/gridding/grid_123d.cpp"
#include "grid_123d.cpp"

PYFI_FUNC(grid)
{
Expand Down Expand Up @@ -79,7 +78,7 @@ PYFI_FUNC(rolloff)
/* input */
PYFI_POSARG(Array<complex<float> >, data);
PYFI_POSARG(Array<int64_t>, outdim);
PYFI_POSARG(long, isofov);
PYFI_POSARG(int64_t, isofov);

PYFI_SETOUTPUT_ALLOC_DIMS(Array<complex<float> >, outdata, outdim->size(), outdim->as_ULONG());

Expand Down
64 changes: 32 additions & 32 deletions gridding/sdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@
/* 1D SDC */
/*******************************/
int onedsdc(Array<double> &crds_in, Array<double> &wates, Array<double> &sdc,
Array<double> &cmtx, long numiter, double taper0)
Array<double> &cmtx, int64_t numiter, double taper0)
{
long i;
int64_t i;
double c0,c1,c2,c3,c4,c5;
double x, x2,x3,x4,x5;
long ii0,ii1,ii,ki;
int64_t ii0,ii1,ii,ki;

long npts = wates.size(0);
int64_t npts = wates.size(0);
Array<double> taper(npts);
Array<double> crds(crds_in); // make a copy

/////////////////
// 1. make kernel
/////////////////

long kernmax = 1000;
int64_t kernmax = 1000;
Array<double> kernel(kernmax+1);

// the kernel, convolved with itself, should be equivalent to FT of a circle convolved with itself
Expand Down Expand Up @@ -124,7 +124,7 @@ int onedsdc(Array<double> &crds_in, Array<double> &wates, Array<double> &sdc,
double knorm = kernmax/krad;
double sdcdenom;
double dx;
long count;
int64_t count;

// Initialize weights by input relative weights
for (i = 0; i < npts; i++) {
Expand Down Expand Up @@ -171,20 +171,20 @@ int onedsdc(Array<double> &crds_in, Array<double> &wates, Array<double> &sdc,
/* 2D SDC */
/*******************************/
int twodsdc(Array<double> &crds, Array<double> &wates, Array<double> &sdc,
Array<double> &cmtx, long numiter, double taper0)
Array<double> &cmtx, int64_t numiter, double taper0)
{
long i;
int64_t i;
double c0,c1,c2,c3,c4,c5;
double x, x2,x3,x4,x5;
long ii0,ii1,jj0,jj1,ii,jj,ki;
int64_t ii0,ii1,jj0,jj1,ii,jj,ki;

long npts = wates.size(0);
int64_t npts = wates.size(0);
Array<double> taper(npts);

/////////////////
// 1. make kernel
/////////////////
long kernmax = 1000;
int64_t kernmax = 1000;
Array<double> kernel(kernmax+1);

// the kernel, convolved with itself, should be equivalent to FT of a circle convolved with itself
Expand Down Expand Up @@ -254,7 +254,7 @@ int twodsdc(Array<double> &crds, Array<double> &wates, Array<double> &sdc,
double knorm = kernmax/krad;
double sdcdenom;
double dx,dx2,dy,rad2;
long count;
int64_t count;

// Initialize weights by input relative weights
for (i = 0; i < npts; i++) {
Expand Down Expand Up @@ -315,21 +315,21 @@ int twodsdc(Array<double> &crds, Array<double> &wates, Array<double> &sdc,
/* 3D SDC */
/*******************************/
int threedsdc(Array<double> &crds, Array<double> &wates, Array<double> &sdc,
Array<double> &cmtx, long numiter, double taper0, double kradscale)
Array<double> &cmtx, int64_t numiter, double taper0, double kradscale)
{
long i;
int64_t i;
double c0,c1,c2,c3,c4,c5;
double x, x2,x3,x4,x5;
long ii0,ii1,jj0,jj1,kk0,kk1,ii,jj,kk,ki;
int64_t ii0,ii1,jj0,jj1,kk0,kk1,ii,jj,kk,ki;

long npts = wates.size(0);
int64_t npts = wates.size(0);
Array<double> taper(npts);

/////////////////
// 1. make kernel
/////////////////

long kernmax = 1000;
int64_t kernmax = 1000;
Array<double> kernel(kernmax+1);

// the kernel, convolved with itself, should be equivalent to FT of a sphere convolved with itself
Expand Down Expand Up @@ -413,7 +413,7 @@ int threedsdc(Array<double> &crds, Array<double> &wates, Array<double> &sdc,
double knorm = kernmax/krad;
double sdcdenom;
double dx,dy,dz,dxy2,rad2;
long count;
int64_t count;
double dx2,dy2[20],dz2[20];

// Initialize weights by input relative weights
Expand Down Expand Up @@ -514,9 +514,9 @@ int threedsdc(Array<double> &crds, Array<double> &wates, Array<double> &sdc,
/* 2D SDC SPIRAL */
/*******************************/
int twodsdcsp(Array<double> &crds, Array<double> &sdc,
long numiter, double taper0, double mtxxy)
int64_t numiter, double taper0, double mtxxy)
{
long i,j,ii,jj,i0,i1;
int64_t i,j,ii,jj,i0,i1;
double c0,c1,c2,c3,c4,c5;
double x, x2,x3,x4,x5;

Expand All @@ -526,14 +526,14 @@ int twodsdcsp(Array<double> &crds, Array<double> &sdc,
Array<double> sdcden(crds.size(1));
Array<double> xcrd(crds.size(1),crds.size(2));
Array<double> ycrd(crds.size(1),crds.size(2));
Array<long> is(crds.size(1));
Array<long> ie(crds.size(1));
Array<int64_t> is(crds.size(1));
Array<int64_t> ie(crds.size(1));

/////////////////
// 1. make kernel
/////////////////

long kernmax = 1000;
int64_t kernmax = 1000;
Array<double> kernel(kernmax+1);

// If you take a circle with diameter = FOV and convolve with itself, this represents the error contribution
Expand Down Expand Up @@ -615,7 +615,7 @@ int twodsdcsp(Array<double> &crds, Array<double> &sdc,

double knorm = kernmax/krad;
double dx,dy,dk;
long count;
int64_t count;

// Initialize weights as ones (no pre-weighting for this scheme, it wouldn't work)
sdcnum = 1.;
Expand Down Expand Up @@ -660,9 +660,9 @@ int twodsdcsp(Array<double> &crds, Array<double> &sdc,
/* 3D SDC SPIRAL */
/*******************************/
int threedsdcsp(Array<double> &crds, Array<double> &sdc,
long numiter, double taper0, double mtxxy, double mtxz)
int64_t numiter, double taper0, double mtxxy, double mtxz)
{
long i,j,ii,jj,i0,i1,j0,j1,jmid;
int64_t i,j,ii,jj,i0,i1,j0,j1,jmid;
double c0,c1,c2,c3,c4,c5;
double x, x2,x3,x4,x5;
double mtxz_sign;
Expand All @@ -674,16 +674,16 @@ int threedsdcsp(Array<double> &crds, Array<double> &sdc,
Array<double> xcrd(crds.size(1),crds.size(2));
Array<double> ycrd(crds.size(1),crds.size(2));
Array<double> zcrd(crds.size(1),crds.size(2));
Array<long> is(crds.size(1));
Array<long> ie(crds.size(1));
Array<long> js(crds.size(1));
Array<long> je(crds.size(1));
Array<int64_t> is(crds.size(1));
Array<int64_t> ie(crds.size(1));
Array<int64_t> js(crds.size(1));
Array<int64_t> je(crds.size(1));

/////////////////
// 1. make kernel
/////////////////

long kernmax = 1000;
int64_t kernmax = 1000;
Array<double> kernel(kernmax+1);

// If you take a sphere with diameter = FOV and convolve with itself, this represents the error contribution
Expand Down Expand Up @@ -785,7 +785,7 @@ int threedsdcsp(Array<double> &crds, Array<double> &sdc,

double knorm = kernmax/krad;
double dx,dy,dz,dk;
long count;
int64_t count;

// Initialize weights as ones (no pre-weighting for this scheme, it wouldn't work)
sdcnum = 1.;
Expand Down
Loading

0 comments on commit 28a2b96

Please sign in to comment.