nanophotonics / nplab

Core functions and instrument scripts for the Nanophotonics lab experimental scripts
GNU General Public License v3.0
38 stars 15 forks source link

Seabreeze GUI won't plot if processed spectrum contains NaNs #100

Closed mjh250 closed 4 years ago

mjh250 commented 4 years ago

The "process_spectrum()" method in "instrument.spectrometer" replaces infinities with "NaN" in processed spectra (after subtracting the background and dividing by the reference). This stops the spectrum from being plotted in the GUI when using the latest version of pyqt.

eoinell commented 4 years ago

Just a matter of this before plotting?

def NaNs_to_zeros(array):
        '''converts all NaNs in a multidimensional numpy array to 0'''
        return np.reshape([0 if np.isnan(i) else i for i in np.flatten(array)], np.shape(array))

https://github.com/nanophotonics/nplab/blob/78ba3dd27b931a5b652e7440f404c7ee675a90d4/nplab/instrument/spectrometer/__init__.py#L652 spectrum = np.array([NaNs_to_zeros(s) for s in spectrum]) # in case the spectra are different lengths

wdeacon commented 4 years ago

That will certainly work but I don't know if it's the best approach as it makes it look like there's no light when that is not the case. It means there's no light in the reference (most likely) so I'd suggest it's better to delete the point. wavelengths = wavelengths[~np.isnan(Spectrum)] Spectrum =Spectrum [~np.isnan(Spectrum)]

YagoDel commented 4 years ago

Seems like a bug in pyqtgraph itself https://github.com/pyqtgraph/pyqtgraph/issues/1057

If you can't ignore it for now, I'd say go with an earlier PyQt (thread says 5.13.0 works)

eoinell commented 4 years ago

Still hasn't been tested for multiple spectrometers as I don't have any rigs that use them, but works for 1 spectrometer