Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image gain restoration #73

Open
ysBach opened this issue Dec 13, 2021 · 2 comments
Open

Image gain restoration #73

ysBach opened this issue Dec 13, 2021 · 2 comments

Comments

@ysBach
Copy link

ysBach commented Dec 13, 2021

I remember previously astroscrappy.detect_cosmics returned the cleaned array multiplied by gain factor, but now it does not. (I could not find CHANGELOG.. )

astroscrappy.detect_cosmics(np.ones((100,100)), gain=3)[1]
array([[1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       ...,
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.]], dtype=float32)

It used to be

array([[3., 3., 3., ..., 3., 3., 3.],
       [3., 3., 3., ..., 3., 3., 3.],
       [3., 3., 3., ..., 3., 3., 3.],
       ...,
       [3., 3., 3., ..., 3., 3., 3.],
       [3., 3., 3., ..., 3., 3., 3.],
       [3., 3., 3., ..., 3., 3., 3.]], dtype=float32)

if my memory is correct, and this is why I used my custom function to do nccd.data = cleanarr / gain.

Now I find my processed images have extremely small counts & SNR (as I have gain ~ 10).

How can I write a code which incorporates both versions of astroscrappy within a single function?
(e.g., for inbkg, bkg, pssl stuff, I could use try-except clause)

@ysBach
Copy link
Author

ysBach commented Dec 13, 2021

I found a simple code below may work:

divfactor = detect_cosmics(np.ones((3, 3)), gain=1., niter=0)[1][0, 0]
if divfactor != 1.:
    _ccd.data = cleanarr / divfactor

but any better idea?

A digression:
Interestingly, it takes only ~ 40 us on MBP 15", but this becomes ~30x slower (1.2 ms) on MBP 16".
(tested using %timeit detect_cosmics(np.ones((3, 3)), gain=1., niter=0)[1][0, 0] == 1., timings does not change much w.r.t. gain, shape, etc.).
Maybe because I am running python on Rosetta in the latter machine..? Still factor 30 is strange.

MBP 15": [2018, macOS 11.6, i7-8850H (2.6 GHz; 6-core), RAM 16 GB (2400MHz DDR4), Radeon Pro 560X (4GB)]
MBP 16": [2021, macOS 12.0.1, M1Pro, 8P+2E core, GPU 16-core, RAM 16GB]

@ysBach
Copy link
Author

ysBach commented May 2, 2022

I am still using the above code.

BTW, trying on mini-forge, I found this:

  1. the above test was done on default anaconda (intel, running on Rosetta2, ~ 1200 µs)
  2. the code is still slow in default mini-forge installation (apple arm64):
%timeit divfactor = detect_cosmics(np.ones((3, 3)), gain=1., niter=0)[1][0, 0]
643 µs ± 29 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
  1. but from mini-forge (apple arm64) with veclib (see here; install numpy as conda install numpy "blas=*=*accelerate*"), it is much faster (x40+)
In [4]: %timeit divfactor = detect_cosmics(np.ones((3, 3)), gain=1., niter=0)[1][0, 0]
14.5 µs ± 59 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

I think this speedup is not due to np.ones or [1](0, 0) (they reduced the %timeit by only < 1 µs and < 100 µs order, respectively).

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

No branches or pull requests

1 participant