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

Implement number of islands #801

Merged

Conversation

LukasNickel
Copy link
Member

  • added number_of_islands to image/cleaning.py
    (Calculates the number of connected clusters on a pixel mask)
  • added unit test with LSTCam geometry

* added number_of_islands to image/cleaning.py
(Calculates the number of connected clusters on a pixel mask)
* added unit test with LSTCam geometry
@codecov
Copy link

codecov bot commented Oct 12, 2018

Codecov Report

Merging #801 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #801      +/-   ##
==========================================
+ Coverage    71.9%   71.96%   +0.05%     
==========================================
  Files         204      204              
  Lines       11023    11046      +23     
==========================================
+ Hits         7926     7949      +23     
  Misses       3097     3097
Impacted Files Coverage Δ
ctapipe/image/tests/test_cleaning.py 100% <100%> (ø) ⬆️
ctapipe/image/cleaning.py 100% <100%> (ø) ⬆️

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 31f9397...f4bacd8. Read the comment docs.

"""
hits = np.where(mask)[0]
# store information about marked pixels to avoid double counting
marked = np.ones(hits.shape[0]) * -1
Copy link
Member

Choose a reason for hiding this comment

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

this could be a python set or a boolean mask of length n_pixels. I don't think an integer array with the indices is the best choice here.

ctapipe/image/cleaning.py Show resolved Hide resolved
ctapipe/image/tests/test_cleaning.py Show resolved Hide resolved
i = 0
count = 0

for hit in hits:
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this works for cluster with a radius > 2. You need to treat the neighbors of the neighbors recursively for that.

@LukasNickel
Copy link
Member Author

When I worked on this bigger clusters were counted correctly. In hindsight this might need the pixels to follow a specific camera geometry tho.
I will check on this once I find the time. If we also want to know which pixels connect to a cluster, it might be best to just rework it completely.

@LukasNickel LukasNickel force-pushed the implement_number_of_islands branch 3 times, most recently from 65c4f44 to 36e298b Compare October 19, 2018 07:37
@kosack
Copy link
Contributor

kosack commented Oct 19, 2018

This is written in a very non-pythonic way, so it likely quite inefficient, though perhaps it could be sped up quite a bit with a numba @jit decorator?

I suspect there is already code to count islands somewhere in the scientific python stack, since we use this technique already. @jjlk do you use a better method for this?

@maxnoe
Copy link
Member

maxnoe commented Oct 19, 2018

Yes, this works perfectly.

@LukasNickel can you change the code to use the scipy function?

@LukasNickel
Copy link
Member Author

I think https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.connected_components.html#scipy.sparse.csgraph.connected_components is what we need

That looks pretty good. I didn't expect a scipy function for an arbitrary geometry, but sparse graphs seems to be the keyword here. I'll play around with that function and upload a cleaner scipy version later

- returns integer array of size mask.n_pixels now aswell
-> allows seperating the clusters
- cluster sizes > 2 should be counted correctly now
- unit test contains a bigger cluster for LSTCam geometry
@maxnoe
Copy link
Member

maxnoe commented Oct 19, 2018

Looks good!

@kosack
Copy link
Contributor

kosack commented Oct 23, 2018

@maxnoe do you still want changes? If not, you can accept your review and I'll merge this,

@kosack kosack merged commit 742f27e into cta-observatory:master Oct 24, 2018
watsonjj added a commit to watsonjj/ctapipe that referenced this pull request Nov 9, 2018
* master: (60 commits)
  Add test that shows slicing breaks cam geom and fix it (cta-observatory#782)
  fix ctapipe build failure (cta-observatory#811)
  fix package name for yaml (should be pyyaml) (cta-observatory#810)
  Implement number of islands (cta-observatory#801)
  fixed ranges of cam-display so they correspond to fixed toymodel sims (cta-observatory#808)
  Fix unknown section example warning (cta-observatory#800)
  Fix timing parameters for case when there are negative values in image (cta-observatory#804)
  Update Timing Parameters (cta-observatory#799)
  speed up unit tests that use test_event fixture (cta-observatory#798)
  Add unit to h_max in HillasReconstructor (cta-observatory#797)
  Codacy code style improvements (cta-observatory#796)
  Minor changes: mostly deprecationwarning fixes (cta-observatory#787)
  Array plotting (cta-observatory#784)
  added a config file for github change-drafter plugin (cta-observatory#795)
  Simple HESS adaptations (cta-observatory#794)
  add test for sliced geometries for hillas calculation (cta-observatory#781)
  Impact intersection (cta-observatory#778)
  updated main documentation page (cta-observatory#792)
  Implement concentration image features (cta-observatory#791)
  Fix bad builds by changing channel name (missing pyqt package) (cta-observatory#793)
  ...

# Conflicts:
#	ctapipe/calib/camera/dl1.py
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

Successfully merging this pull request may close these issues.

None yet

3 participants