Ptrskay3 / PySprint

Spectrally resolved interferometry for Python
https://pysprint.readthedocs.io/en/latest/
MIT License
5 stars 2 forks source link

GD_lookup does not work on second call #4

Closed Ptrskay3 closed 4 years ago

Ptrskay3 commented 4 years ago
for ifg in ifgs:
    ifg.chdomain()
    ifg.slice(2, 4.2)
    ifg.GD_lookup(2.355, engine='cwt')

running twice throws:

IndexError                                Traceback (most recent call last)
<ipython-input-21-06dfdcdd2b40> in <module>
      2     ifg.chdomain()
      3     ifg.slice(2, 4.2)
----> 4     ifg.GD_lookup(2.355, engine='cwt')

c:\program files\python37\lib\site-packages\pysprint\api\dataset.py in GD_lookup(self, reference_point, engine, silent, **kwargs)
    112                         width = kwargs.pop('width', 35)
    113                         floor_thres = kwargs.pop('floor_thres', 0.05)
--> 114                         x_min, _, x_max, _ = self.detect_peak_cwt(width=width, floor_thres=floor_thres)
    115 
    116                         #just validation

c:\program files\python37\lib\site-packages\pysprint\api\dataset.py in detect_peak_cwt(self, width, floor_thres)
    295         def detect_peak_cwt(self, width, floor_thres=0.05):
    296                 x, y, ref, sam = self._safe_cast()
--> 297                 xmax, ymax, xmin, ymin = cwt(x, y, ref, sam, width=width, floor_thres=floor_thres)
    298                 return xmax, ymax, xmin, ymin
    299 

c:\program files\python37\lib\site-packages\pysprint\core\dataedits.py in cwt(x, y, ref, sam, width, floor_thres)
     18         idx2 = find_peaks_cwt(1/Ydata, np.arange(1, width))
     19 
---> 20         return Xdata[idx], Ydata[idx]-2, Xdata[idx2], Ydata[idx2]-2
     21 
     22 def savgol(

IndexError: arrays used as indices must be of integer (or boolean) type
Ptrskay3 commented 4 years ago

This is happening because the for will change domain every time it is executed. The solution is to separate it in a different cell, and run it only once.