slf-dot-ch / snowmicropyn

A python package to read, export and post process data (*.pnt files) recorded by SnowMicroPen, a snow penetration probe for scientific applications developed at SLF.
https://www.slf.ch/en/services-and-products/research-instruments/snowmicropen-r-smp4-version.html
GNU General Public License v3.0
10 stars 12 forks source link

Pyngui failure/crash with some *.pnt files #9

Closed mj9000 closed 2 years ago

mj9000 commented 3 years ago

Hi there,

sometimes my pyngui just closes/crashes while trying to open PNT files.

That's the failure report from the terminal:

Read 24782 raw samples from file /Users/Documents/06_EQUIPMENT/SMP/test_data/S44M0295.pnt

Timestamp of profile as reported by pnt header is 2020-10-20 06:49:37+00:00

/Users/anaconda3/lib/python3.6/site-packages/snowmicropyn/loewe2012.py:58: RuntimeWarning: invalid value encountered in double_scalars

delta = -(3. / 2) c_f[n - 1] / (c_f[n] - c_f[n - 1]) spatial_res

Traceback (most recent call last):

File "/Users/anaconda3/lib/python3.6/site-packages/snowmicropyn/pyngui/main_window.py", line 354, in _open_triggered

self.open_pnts(files)

File "/Users/anaconda3/lib/python3.6/site-packages/snowmicropyn/pyngui/main_window.py", line 366, in open_pnts

doc.recalc_derivatives(self.preferences.window_size, self.preferences.overlap)

File "/Users/anaconda3/lib/python3.6/site-packages/snowmicropyn/pyngui/document.py", line 31, in recalc_derivatives

self._derivatives = proksch2015.calc(samples, window_size, overlap_factor)

File "/Users/anaconda3/lib/python3.6/site-packages/snowmicropyn/proksch2015.py", line 76, in calc

sn = snowmicropyn.loewe2012.calc(samples, window, overlap)

File "/Users/anaconda3/lib/python3.6/site-packages/snowmicropyn/loewe2012.py", line 89, in calc

sn = calc_step(spatial_res, chunk.force)

File "/Users/anaconda3/lib/python3.6/site-packages/snowmicropyn/loewe2012.py", line 61, in calc_step

lambda_ = (4. / 3) * (k1 ** 2) / k2 / delta  # Intensity

ZeroDivisionError: float division by zero

Abort trap: 6

Just checked in the pnt files where it happens and in the files where it does not happen. If there are more than 900 entries of the same value in the end of the file, pyngui crashes. If there are only something like 300 entries of the same value in the end of the file, than it still works.

reisecker commented 2 years ago

Thanks for reporting, fixed with commit 65c70c4. Beware though that there was a good numerical reason for this crash and if you now merely get a warning instead you should still check your data integrity.