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

Fix multiresolution metrics #174

Merged
merged 16 commits into from
Jul 8, 2021
Merged

Fix multiresolution metrics #174

merged 16 commits into from
Jul 8, 2021

Conversation

thuiop
Copy link
Collaborator

@thuiop thuiop commented Jun 23, 2021

Measure and metrics are currently not compatible with multiresolution, which I try to fix in this PR (closes #160 and #166).

To do this, measure functions should return ra and dec coordinates instead of pixels which is easy to do since we have the WCS. The deblended images and segmentations should also be returned as a dictionnary indexed by the survey names. Then, in the metrics generator, the compute_metrics function is called for each survey (we recover pixel coordinates at this stage using the WCS).

@thuiop thuiop added the WiP Work in Progress label Jun 23, 2021
@thuiop thuiop self-assigned this Jun 23, 2021
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@thuiop thuiop removed the WiP Work in Progress label Jun 29, 2021
@thuiop
Copy link
Collaborator Author

thuiop commented Jun 29, 2021

It should work right now, though it isn't very pretty yet ; you can see the results in the SCARLET notebooks. @ismael-mendoza you are free to take a look ; I will try to make it more maintainable.

@ismael-mendoza ismael-mendoza mentioned this pull request Jun 29, 2021
Copy link
Collaborator

@ismael-mendoza ismael-mendoza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @thuiop , thanks for your work on this issue! I added a few minor comments, please feel free to ignore any are solely because this might still be partially in WiP.

It might also be good if you gave us a walkthrough in the next meeting because I'm not sure I understand all the changes.

Quick question, scarlet has a MR feature for deblending right? Did you leverage that in the notebook or did you just run it separately for each survey (anyway is fine I was just curious)

btk/measure.py Show resolved Hide resolved
btk/measure.py Show resolved Hide resolved
btk/measure.py Outdated Show resolved Hide resolved
btk/measure.py Outdated Show resolved Hide resolved
btk/measure.py Show resolved Hide resolved
btk/plot_utils.py Show resolved Hide resolved
btk/metrics.py Outdated Show resolved Hide resolved
btk/measure.py Outdated Show resolved Hide resolved
@thuiop
Copy link
Collaborator Author

thuiop commented Jul 3, 2021

Quick question, scarlet has a MR feature for deblending right? Did you leverage that in the notebook or did you just run it separately for each survey (anyway is fine I was just curious)

Yes, I used the multiresolution feature here.

@thuiop
Copy link
Collaborator Author

thuiop commented Jul 7, 2021

This should be somewhat mergeable now.

@thuiop thuiop added the Ready for review For PR which should be reviewed label Jul 7, 2021
@codecov
Copy link

codecov bot commented Jul 7, 2021

Codecov Report

Merging #174 (ba2f5d0) into main (560aa65) will increase coverage by 2.21%.
The diff coverage is 86.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #174      +/-   ##
==========================================
+ Coverage   84.12%   86.34%   +2.21%     
==========================================
  Files          13       13              
  Lines        1424     1509      +85     
==========================================
+ Hits         1198     1303     +105     
+ Misses        226      206      -20     
Flag Coverage Δ
unittests 86.34% <86.45%> (+2.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
btk/measure.py 86.95% <75.75%> (-3.29%) ⬇️
btk/utils.py 90.19% <83.33%> (-1.30%) ⬇️
btk/plot_utils.py 82.46% <94.11%> (+9.83%) ⬆️
btk/metrics.py 95.16% <96.87%> (+0.91%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 560aa65...ba2f5d0. Read the comment docs.

@thuiop
Copy link
Collaborator Author

thuiop commented Jul 7, 2021

@ismael-mendoza To give a clearer overview of what happens on the user side :

  • As before, all entries of the blend_results become dictionaries indexed by the surveys
  • In the measure part, the user is expected to return as an output of the measure function :
    • a single catalog, with ra and dec entries for each object
    • segmentations as a dictionary indexed by surveys containing arrays as in the single resolution case
    • same as segmentations for deblended_images
      The catalog will be duplicated automatically by the measure_generator which will add for each survey the x_peak and y_peak columns using the WCS. The measure_results are, much like the blend_results, transformed into dictionaries indexed by the surveys (to be exact, they were already indexed by measure function, so now you have measure_results["sep_measure"]["Rubin"] for instance)
  • In the metrics part, the compute_metrics function is run for each survey, so a dictionary "layer" is added once again to the output.

ismael-mendoza
ismael-mendoza previously approved these changes Jul 8, 2021
Copy link
Collaborator

@ismael-mendoza ismael-mendoza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @thuiop , looks great! Thanks a lot for your work on this. Feel free to merge after resolving my small comments below.

btk/measure.py Outdated Show resolved Hide resolved

# set detection threshold to 5 times std of image
threshold = 5 * np.std(coadd)
coordinates = peak_local_max(coadd, min_distance=2, threshold_abs=threshold)

# construct catalog from measurement.
catalog = astropy.table.Table()
catalog["x_peak"] = coordinates[:, 1]
catalog["y_peak"] = coordinates[:, 0]
catalog["ra"], catalog["dec"] = wcs.pixel_to_world_values(coordinates[:, 1], coordinates[:, 0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you now assume that 'ra', 'dec' are always returned (even if MR feature is not used). That makes sense, since these requires an additional step from the user maybe we should mention this somewhere in the documentation (how to access wcs and use it to convert your pixel coordinates)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this will be done in the following PR.

btk/measure.py Outdated Show resolved Hide resolved
btk/measure.py Outdated Show resolved Hide resolved
f"{out[key].shape[-3:]} vs {batch['blend_images'].shape[-3:]}"
if len(surveys) == 1:
if not isinstance(out[key], np.ndarray):
raise TypeError(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the error cases are not covered by tests (see below for codecov messages). Do you mind updating the tests for coverage? If you prefer to do it later (or for me to do it) feel free to just open an issue about it so we don't forget.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is not an urgent issue as long as we keep the coverage up, so I will open an issue for the time being.

btk/metrics.py Outdated Show resolved Hide resolved
tests/test_measure.py Outdated Show resolved Hide resolved
@thuiop thuiop merged commit f40e042 into main Jul 8, 2021
@thuiop thuiop deleted the fix-multiresolution-metrics branch July 8, 2021 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review For PR which should be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend multiresolution feature to metrics
2 participants