0

I have an array of data that, when plotted, plateaus at the maximum values. I would like to generate a gaussian fit for this data so I can have a rough approximation of what the data would be without a plateau.

This is what the data looks like:

Saturated Data

I am trying to use scipy.optimize.curve_fit - but I do not know how to achieve the end result as I want to fit a gaussian when ignoring the saturated data in the plateau.

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
SamB
  • 23
  • 3

1 Answers1

1

Without more details on your own solution it's a bit grasping in the dark, but I think numpy.ma might be what you're after. With it you can mask parts of your data, and the documentation even has this to say:

In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.

Apply a mask that hides the saturated parts and run your fitting against that. For example:

In [4]: data = np.arange(10)

In [5]: np.ma.masked_greater_equal(data, 6)
Out[5]: 
masked_array(data = [0 1 2 3 4 5 -- -- -- --],
             mask = [False False False False False False  True  True  True  True],
       fill_value = 999999)

where obviously you'd use your saturation level as the threshold.

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127