pmelchior / scarlet

hyperspectral galaxy modeling and deblending
MIT License
50 stars 22 forks source link

detection image added to obs[0] #270

Closed pmelchior closed 2 years ago

pmelchior commented 2 years ago

This PR reimplements a single function, build_initialization_image, with one main change. The resulting data structures are attached to the first observation in the list and not put on the cache. This change should fix #256 because Observation goes out of scope.

There are two other changes:

  1. The stored structures allow a quick computation of the detection image in both cases (with and without spectra).
  2. The spectrum-SNR weighted version for detection of a specifically colored object now uses the full variance information (line 315) instead of the mean (averaged over all pixels) RMS per band. This means we now have an optimal detection image considering the variances of every single pixels in every band.

Because of the last change, the result of this method is not identical to the previous method, but I doubt that the differences are large.

pmelchior commented 2 years ago

Just to make sure that I'm following everything: it looks like you're creating the detection image once, caching it in the first observation, then weighting by the spectra only if the spectra is given, right?

Exactly.

That seems fine to me given the current architecture. In the long run it might be better to make a MultiObservation class that contains observations and the mappings between them and the model space, to make sure that things are always consistent. Just attaching the _detect image to the first observation seems problematic for a general use code, but the scarlet users might be specialized enough that a "buyer beware" type of attitude for changing the list of observations later on may be sufficient.

I agree. I'd be more worried if we had use cases where one would want to re-use one observation together with a different one, in which case the detection image would be inconsistent. But I don't see this to be a problem now.