GalSim-developers / GalSim

The modular galaxy image simulation toolkit. Documentation:
http://galsim-developers.github.io/GalSim/
Other
223 stars 105 forks source link

Construct images without sanity checks in `_convertMask` function in the HSM module #1264

Closed arunkannawadi closed 5 months ago

arunkannawadi commented 9 months ago

When measuring the moments using FindAdaptiveMom, I find that a significant chunk of time is taken by the _convertMask function, which arises from various Image instantiations. Given that this is an internal function, I expect that the inputs provided to create an Image instance would always pass these checks and can directly use the _Image.

For reference, 38 out of 186 seconds is spend in _convertMask when calling FindAdaptiveMom.

rmjarvis commented 9 months ago

I think the main thing is probably that there are a couple of checks currently that the mask is sane (no negative values and not all zero). So probably adding an option to skip those will speed this up a lot.

rmjarvis commented 9 months ago

Probably simplest would be to add a leading underscore version of this _FindAdaptiveMom that skips all the sanity checks and requires that object_image and weight are already the right dtype and everything.

arunkannawadi commented 9 months ago

That sounds like the least disruptive approach to me (not saying that modifying _convertMask would have been), but I could see a user potentially calling FindAdaptiveMom with inconsistent inputs. I'm happy to code this up, quantify the performance improvements and raise a PR here.

erykoff commented 9 months ago

An additional public interface to observed_e1 and observed_e2 would also be nice. And the current return for observed_shape should probably use the optimized _Shape rather than Shape.

arunkannawadi commented 5 months ago

Closing this issue as completed.