title: Python: Order fits-file pixel by brightness, ignore artefacts
body: <p>I have 4000 fits-files images from SPITZER, each containing the same star over a time period. Each image is a photmetry cube of 32 pixel * 32 pixel * 64 consequent time frames. I need to look through all the single frames and order the pixel by brightness. Not hard to do with Python, but sometimes I have in the frames short-lived events/artefacts which are brighter than the brightest pixel of the star (see below). These artefacts last only over one or two consequent time frames</p>
  
  <p>How can I easily correct for the artefacts? Is there an astropy/pyfits package that does this? Or some kind of bad pixel flagging in SPITZER (I know that Kepler-images have flagging of bad pixel)?</p>
  
  <p>Optional: It would be convenient to have the code in vectorized form, avoiding loops, so that I save computtional time</p>
  
  <hr>
  
  <p>Comparison of two frames, in the left one everything is fine, in the right one you see in the top right corner one of this artefacts, being brighter than any of the star pixel. Note: the artefact doesn't reach the level of saturation.
  <a href="https://i.stack.imgur.com/514R8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/514R8.png" alt="enter image description here"></a></p>