Skip to content
This repository has been archived by the owner on Aug 30, 2020. It is now read-only.

Nonlinearity Correction #16

Open
sdickreuter opened this issue Jan 16, 2015 · 5 comments
Open

Nonlinearity Correction #16

sdickreuter opened this issue Jan 16, 2015 · 5 comments

Comments

@sdickreuter
Copy link
Contributor

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
@ap--
Copy link
Owner

ap-- commented Jan 16, 2015

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.

@sdickreuter
Copy link
Contributor Author

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

@ap--
Copy link
Owner

ap-- commented Jan 16, 2015

"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.

@sdickreuter
Copy link
Contributor Author

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

@ap--
Copy link
Owner

ap-- commented Jan 23, 2015

Will be resolved when PR #19 gets merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants