python-oceanoptics icon indicating copy to clipboard operation
python-oceanoptics copied to clipboard

Nonlinearity Correction

Open sdickreuter opened this issue 11 years ago • 5 comments

I could'nt open a second pull request, so here is a patch for the implementation of the nonlinearity correction:

--- ../python-oceanoptics_upstream/oceanoptics/base.py  2015-01-14 10:22:10.573384769 +0100
+++ oceanoptics/base.py 2015-01-16 09:40:37.732968993 +0100
@@ -168,7 +170,7 @@
         only_valid_pixels : bool, optional
             only optical active pixels are returned.
         correct_nonlinearity : bool, optional
-            does nothing yet.
+            corrects for nonlinearity of CCD-Chip
         correct_darkcounts : bool, optional
             does nothing yet.
         correct_saturation : bool, optional
@@ -183,8 +185,14 @@
             data = np.array(self._request_spectrum()[self._valid_pixels], dtype=np.float64)
         else:
             data = np.array(self._request_spectrum(), dtype=np.float64)
+        if correct_nonlinearity:
+            data = data/self._calc_nonlinearity(data)
         return data

+    def _calc_nonlinearity(self, counts):
+        return sum( self._nl_factors[i] * counts**i for i in range(8) )
+
+
     def spectrum(self, raw=False, only_valid_pixels=True,
             correct_nonlinearity=True, correct_darkcounts=True,
             correct_saturation=True):
@@ -197,7 +205,7 @@
         only_valid_pixels : bool, optional
             only optical active pixels are returned.
         correct_nonlinearity : bool, optional
-            does nothing yet.
+            corrects for nonlinearity of CCD-Chip
         correct_darkcounts : bool, optional
             does nothing yet.
         correct_saturation : bool, optional

sdickreuter avatar Jan 16 '15 13:01 sdickreuter

While your implementation of the nonlinearity correction is correct, you must not apply this correction to a spectrum that was not dark-count-corrected!

So before this can be merged into master, the dark-count-correction needs to be implemented and in the code we need to be sure, that if the non-linearity-correction is enabled that the dark-count-correction is enabled too.

ap-- avatar Jan 16 '15 15:01 ap--

Do you mean that the a dark spectrum has to be substracted before the nonlinearity correction ? That would mean that for using the nonlinearity one would have to inlcude a framework for saving the spectra into the oceanoptics-module, that could get ugly ...

By the way, I got the formula for the correction from this site: http://www.manualsdir.com/manuals/292553/ocean-optics-ooinlcorrect.html

sdickreuter avatar Jan 16 '15 15:01 sdickreuter

"Do you mean that the a dark spectrum has to be substracted before the nonlinearity correction ?" No. The counts of the dark pixels (the ones that are physically blocked on the CCD) need to be subtracted from the spectrum.

This is because otherwise the assumption that doubling the integration time = doubling the intensity which should be doubling the counts is wrong.

I guess in spectra suite if you only enable the non-linearity correction but not the dark count correction, the dark counts are added again, after the nonlinearity correction.

ap-- avatar Jan 16 '15 15:01 ap--

Ah ok I understand, I'll have a look into this next week, should'nt be too hard to implement I guess.

sdickreuter avatar Jan 16 '15 16:01 sdickreuter

Will be resolved when PR #19 gets merged.

ap-- avatar Jan 23 '15 12:01 ap--