paudetseis / RfPy

Teleseismic receiver function calculation and post-processing
https://paudetseis.github.io/RfPy/
MIT License
39 stars 28 forks source link

Initialization of Meta variables as np.nan, instead of None #26

Closed wasjabloch closed 2 years ago

wasjabloch commented 2 years ago

In rfpy.Meta.__init__(), snr, snrh, cc, ttime, slow and inc get initialized as None. However, when making quality checks such as:

if meta.snr > snr_threshold:
    continue

undetermined values raise a TypeError

It would be better to initialize them as np.nan. Then, the above tests would evaluate as False, as expected. The internal tests for availability of the values could be re-written as:

if self.meta.snr:  # False if None (for backward compatibility)
    if np.isfinite(self.meta.snr):  # False if nan (None throws error)
        print("SNR already calculated - continuing")
        return

I have already implemented this, but did not push it into the future branch, as it may break backward compatibility for scripts that rely on the implicit evaluation of if self.meta.snr as False.