cositools / cosipy

The COSI high-level data analysis tools
Apache License 2.0
3 stars 16 forks source link

Image deconvolution with spacecraft attitude binning method #112

Closed hiyoneda closed 7 months ago

hiyoneda commented 7 months ago

I updated the image deconvolution code using the spacecraft attitude (scatt) binning method.

There are two new classes.

I also uploaded two notebooks demonstrating the image deconvolution with the Crab data in DC2. First, you can run through Crab-DC2-ScAtt-DataReduction.ipynb in docs/tutorials/image_deconvolution/Crab/ScAttBinning. This notebook explains how to produce the binned data using the scatt binning method. Then, the image deconvolution with the produced datasets is presented on Crab-DC2-ScAtt-ImageDeconvolution.ipynb in the same directory.

hiyoneda commented 7 months ago

I added notebooks for 511 keV analysis. And the notebook named ***-DC2-ScAtt-Upsampling.ipynb shows the image deconvolution by better pixel resolution in the model space.

hiyoneda commented 7 months ago

I modified the code sometimes after I had opened this PR. Now it is ready to be reviewed.

ckierans commented 7 months ago

I ran through the Crab data reduction and imaging notebooks with my 16 GB memory computer and had no issues! The Crab image deconvolution took just over an hour. The results that I got were not identical to yours, especially noticeable in the spectrum and also in the likelihood ratio - see attached photos. loglikelihood_Crab_CK spectrum_Crab_CK

Not sure where the difference comes from, or if it's unexpected, but I did notice my response name was slightly different: SMEXv12.Continuum.HEALPixO3_10bins_log_flat.binnedimaging.imagingresponse.nonsparse_nside8.area.good_chunks_unzip.h5 (can't remember what the good_chunks was all about).

Working my way through the 511 data reduction now.

KeigoOkuma commented 7 months ago

I ran the 511 keV image deconvolution and had no issues. There is a typo or something in the part of data reduction that downloads files from wasabi. Which is correct, 511_thin_disk_3months.fits.gz or 511keV_3months_unbinned_data.fits.gz?. Calculating the coordinate conversion matrix in Upsampling took 2 hours and 40 mins with my 32 GB memory M1Mac.

KeigoOkuma commented 7 months ago

I also ran GRB image deconvolution and had no issues.

israelmcmc commented 7 months ago

I haven't run this yet, but I just wanted to clarify that "good_chunks" refers to choosing optimal HDF5 chunks. Depending on how the code is accessing the response matrix, it could make the code run faster, but it shouldn't change the results.

hiyoneda commented 7 months ago

@ckierans Thank you for pointing this out. It may be caused by small changes in my code, e.g., very small but finite constant value to be added in the expected count calculation, a parameter in boosting EM algorithm. Actually, the responses in the old and new formats have a tiny difference between them (though it seems negligible). I run through the notebook again with the update code and the new response file, and the results are consistent with yours. I will update the figures.

hiyoneda commented 7 months ago

I updated the figures on the Grab notebooks and modified the types on the 511 keV notebooks.

fieldrog commented 7 months ago

I've been working through the the notebooks in docs/tutorials/image_deconvolution/511keV/ScAttBinning. All run in my environment.

Here are a few comments:

I have 16GB memory on my M1 mac.

hiyoneda commented 7 months ago

@fieldrog Thanks! I think the second one is already fixed. So, I will work on the first and third comments. Can I ask about the point of the third point? Even in the current code, the tqdm bar appears when running spacecraft_attitude_binning_ccm. Do you think it is better to add an option not to show it?

fieldrog commented 7 months ago

With the %%time magic option, i just get the following output after the cell is running:

CPU times: user 5.2 s, sys: 562 ms, total: 5.76 s Wall time: 6.3 s

I don't get any time bar as the code is running, it just says something like this:

0%| | 0/7979955 [00:00<?, ?it/s]

until the block finishes running.

Whereas with a tqdm option in the loop in the function, it could give an optional progress bar, in a notebook or in a script.

Unless something is wrong with my time magic!

hiyoneda commented 7 months ago

I see, but I already used tqdm in the loop in this function. In my case, the progress bar appears as normal, so it sounds strange. Did the bar appear when removing %%time?