Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytta/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ def waterfall(sigObjs, step=2 ** 9, n=2 ** 13, fmin=None, fmax=None, pmin=None,
# Apply rolling window
sliced = np.asarray(list(more_itertools.windowed(ht, n=n, step=step, fillvalue=0)))
window = np.asarray(
[ss.tukey(n, alpha=winAlpha) for s in sliced]) # Tukey window (alpha=0 is a rectangular window)
[ss.windows.tukey(n, alpha=winAlpha) for s in sliced]) # Tukey window (alpha=0 is a rectangular window)
windowed = sliced * window # Apply window
windowedFFT = abs(2 / n * fft(windowed)) # Apply FFT
windowedFFT = windowedFFT[:, idx_min_FFT - fpad: idx_max_FFT + 1 + fpad] # Crop the FFT
Expand Down
98 changes: 7 additions & 91 deletions pytta/apps/roomir.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from os import getcwd, listdir, mkdir
from os.path import isfile, join, exists
import copy as cp
import traceback
from pytta.classes._instanceinfo import caller_name

# Dict with the measurementKinds
# TO DO FUTURE: add 'inchcalibration', 'outchcalibration'
Expand Down Expand Up @@ -2236,21 +2236,7 @@ def RT(self, roomirsGetDict, decay=20, IREndManualCut=None):
each source-receiver configuration, which is a key;

"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(frame, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

# TR in all positions and averagßes
# TR_avgs = {'S1R1': [Analysis_avg1, An_avg2, ..., An_avgn]}
Expand Down Expand Up @@ -2320,21 +2306,7 @@ def G_Lps(self, recalibirsGetDict):
level;

"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(frame, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

recalibirs = recalibirsGetDict
# Calculating Lps for each recalibir MeasuredThing
Expand Down Expand Up @@ -2401,21 +2373,7 @@ def G_Lpe_inSitu(self, roomirsGetDict, IREndManualCut=None):
key;

"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(frame, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

# Lpe in all positions and averagßes
# Lpe_avgs = {'S1R1': [Analysis_avg1, An_avg2, ..., An_avgn]}
Expand Down Expand Up @@ -2461,21 +2419,7 @@ def G_Lpe_revCh(self, roomirsGetDict, IREndManualCut=None):
all the reverberation chamber's impulsive responses;

"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(frame, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

SigObjs = []
if isinstance(roomirsGetDict, dict):
Expand Down Expand Up @@ -2548,21 +2492,7 @@ def G(self, Lpe_avgs, Lpe_revCh, V_revCh, T_revCh, Lps_revCh, Lps_inSitu):
source-receiver configuration, which is a key;

"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(frame, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

# G (omfg) calculation
# G averages in all positions
Expand Down Expand Up @@ -2627,21 +2557,7 @@ def G_T_revCh(self, roomirsGetDict, IREndManualCut=None, T=20):
all the reverberation chamber's impulsive responses;

"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(frame, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

roomirs = roomirsGetDict
RTs = []
Expand Down
8 changes: 4 additions & 4 deletions pytta/classes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ def point(self, newpoint):
r = (self._point[0]**2+self._point[1]**2+self._point[2]**2)**(1/2)
if r != 0:
elev = np.arccos(self._point[2]/r)
azi = np.arctan(self._point[1] /
self._point[0])
azi = np.arctan2(self._point[1], self._point[0])
else:
elev = 0
azi = 0
Expand Down Expand Up @@ -549,6 +548,7 @@ def _to_dict(self):
out = {'calib': [self.CF, self.calibCheck],
'unit': self.unit,
'name': self.name,
'code': self.code,
'coordinates': self.coordinates._to_dict(),
'orientation': self.orientation._to_dict()}
return out
Expand Down Expand Up @@ -578,11 +578,11 @@ def __init__(self, chList=None):
for memb in chList:
if type(memb) is ChannelObj:
self._channels.append(memb)
elif (type(memb) is int) or (type(memb) is float):
elif isinstance(memb, (int, float, np.number)):
self._channels.append(ChannelObj(int(memb)))
else:
raise TypeError("Could not resolve ChannelsList initialization parameters.")
elif type(chList) is int:
elif isinstance(chList, (int, np.integer)):
self._channels.append(ChannelObj(chList))
elif type(chList) is ChannelObj:
self._channels.append(chList)
Expand Down
14 changes: 14 additions & 0 deletions pytta/classes/_instanceinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,25 @@
"""


import sys
import time
import traceback
import threading


def caller_name():
"""
Name assigned on the module-level line that led to the current call:
'x' for ``x = pytta.generate.sweep()``. The text before '=' (the whole
line if there is none), or '' when the source line is not available.
"""
frame = sys._getframe(2) # the caller of the function asking
while frame.f_code.co_varnames and frame.f_back is not None:
frame = frame.f_back
line = traceback.extract_stack(frame, 1)[0].line or ''
return line.split('=')[0].strip()


class InstanceCreationError(Exception):
pass

Expand Down
64 changes: 12 additions & 52 deletions pytta/classes/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pytta.classes.streaming import Monitor, Streaming
from pytta.classes.signal import SignalObj, ImpulsiveResponse
from pytta import _h5utils as _h5
import traceback
from pytta.classes._instanceinfo import caller_name


# Measurement class
Expand Down Expand Up @@ -92,9 +92,10 @@ def __repr__(self):
f'timeLength={self.timeLength!r}')

def _to_dict(self):
out = {'device': self.device,
'inChannels': self.inChannels._to_dict(),
'outChannels': self.outChannels._to_dict()}
out = super()._to_dict()
out.update({'device': self.device,
'inChannels': self.inChannels._to_dict(),
'outChannels': self.outChannels._to_dict()})
return out

def _h5_save(self, h5group):
Expand Down Expand Up @@ -361,14 +362,15 @@ def __repr__(self):
def _to_dict(self):
sup = super()._to_dict()
sup['fftDegree'] = self.fftDegree
sup['timeLength'] = self.timeLength
return sup

def pytta_save(self, dirname=time.ctime(time.time())):
dic = self._to_dict()
name = dirname + '.pytta'
with zipfile.ZipFile(name, 'w') as zdir:
with open('RecMeasure.json', 'w') as f:
json.dump(dic, f, indent=4)
json.dump(dic, f, indent=4, default=lambda o: o.item())
zdir.write('RecMeasure.json')
return name

Expand Down Expand Up @@ -418,21 +420,7 @@ def run(self):
Run method: starts recording during Tmax seconds
Outputs a signalObj with the recording content
"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(frame, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

# Record
recording = sd.rec(frames=self.numSamples,
Expand Down Expand Up @@ -556,21 +544,7 @@ def run(self):
Starts reproducing the excitation signal and recording at the same time
Outputs a signalObj with the recording content
"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(framenline, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

timeStamp = time.ctime(time.time())
recording = sd.playrec(self.excitation.timeSignal*
Expand Down Expand Up @@ -612,7 +586,7 @@ def pytta_save(self, dirname=time.ctime(time.time())):
zdir.write(excit)
os.remove(excit)
with open('PlayRecMeasure.json', 'w') as f:
json.dump(dic, f, indent=4)
json.dump(dic, f, indent=4, default=lambda o: o.item())
zdir.write('PlayRecMeasure.json')
os.remove('PlayRecMeasure.json')
return name
Expand Down Expand Up @@ -779,7 +753,7 @@ def pytta_save(self, dirname=time.ctime(time.time())):
zdir.write(excit)
os.remove(excit)
with open('FRFMeasure.json', 'w') as f:
json.dump(dic, f, indent=4)
json.dump(dic, f, indent=4, default=lambda o: o.item())
zdir.write('FRFMeasure.json')
os.remove('FRFMeasure.json')
return name
Expand Down Expand Up @@ -807,21 +781,7 @@ def run(self):
Starts reproducing the excitation signal and recording at the same time
Outputs the transferfunction ImpulsiveResponse
"""
# Code snippet to guarantee that generated object name is
# the declared at global scope
# for frame, line in traceback.walk_stack(None):
for framenline in traceback.walk_stack(None):
# varnames = frame.f_code.co_varnames
varnames = framenline[0].f_code.co_varnames
if varnames == ():
break
# creation_file, creation_line, creation_function, \
# creation_text = \
extracted_text = \
traceback.extract_stack(framenline[0], 1)[0]
# traceback.extract_stack(frame, 1)[0]
# creation_name = creation_text.split("=")[0].strip()
creation_name = extracted_text[3].split("=")[0].strip()
creation_name = caller_name()

recording = super().run()
transferfunction = ImpulsiveResponse(self.excitation,
Expand Down
6 changes: 3 additions & 3 deletions pytta/classes/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ def pytta_save(self, dirname=time.ctime(time.time())):
mySigObj['timeSignalAddress'] = filename
filename = 'SignalObj.json'
with open(filename, 'w') as f:
json.dump(mySigObj, f, indent=4)
json.dump(mySigObj, f, indent=4, default=lambda o: o.item())
zdir.write(filename, compress_type=zipfile.ZIP_DEFLATED)
os.remove(filename)
return dirname + '.pytta'
Expand Down Expand Up @@ -1354,7 +1354,7 @@ def pytta_save(self, dirname=time.ctime(time.time())):
out = self._to_dict()
out['SignalAddress'] = {'ir': ir}
with open('ImpulsiveResponse.json', 'w') as f:
json.dump(out, f, indent=4)
json.dump(out, f, indent=4, default=lambda o: o.item())
zdir.write('ImpulsiveResponse.json')
os.remove('ImpulsiveResponse.json')
return dirname + '.pytta'
Expand Down Expand Up @@ -1750,7 +1750,7 @@ def _crossfade_spectruns(self, a, b, freqLims, freqVector):
f1idx = np.where(freqVector <= f1)[0][-1]
totalSamples = a.shape[0]
xsamples = f1idx - f0idx
win = ss.hann(2*xsamples)
win = ss.windows.hann(2*xsamples)

rightWin = win[xsamples-1:-1]
fullRightWin = np.concatenate((np.ones(f0idx),
Expand Down
Loading