-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support selecting a percent of total flux given a clean mask file #54
base: master
Are you sure you want to change the base?
Conversation
4a8d79e
to
4bb2803
Compare
@@ -66,6 +66,8 @@ def create_parser(): | |||
help="Fraction of system RAM that can be used. " | |||
"Used when setting automatically the " | |||
"chunk size. Default in 0.1.") | |||
p.add_argument("--clean-mask-file", required=False, default="", | |||
help="Clean Mask File. If supplied") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should update the help description
if m := re.match("^SoFiA (?P<version>\\d+\\.\\d+\\.\\d+)$", origin): | ||
major, _, _ = map(int, m.group("version").split(".")) | ||
if major < 2: | ||
raise ValueError(f"SoFiA major version is less than 2: {origin}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that the Clean Mask file is produce by SoFiA 2.
try: | ||
assert header["CTYPE1"].strip() == "RA---SIN" | ||
assert header["CTYPE2"].strip() == "DEC--SIN" | ||
assert header["CTYPE3"].strip() == "VRAD" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume radio velocity quantity, but potentially other types could be supported.
|
||
freq = SpectralQuantity(wsclean_comps["ReferenceFrequency"] * u.Hz, | ||
doppler_rest=wcs.wcs.restfrq * u.Hz, | ||
doppler_convention="radio") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to find some better way to do this conversion as a Radio doppler convention os assumed here. The restfreq is on the wcs attribute for example. I intuit that the wcs.spectral
atttribute (which is a wcs object for the Spectral coordinate axis) should be used, but a simple wcs.spectral.world_to_pixel
didn't work for me..
integrated_fluxes = np.array([flux[sid == source_ids].sum() for sid in source_id_range]) | ||
broadcast_fluxes = integrated_fluxes[source_ids - 1] | ||
|
||
comp_sort_idx = np.lexsort((flux, broadcast_fluxes))[::-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broadcast the total flux for each source over the number of a components and lexically sort. This allows us to partially select components of a source.
(2, 4, 5, 100), | ||
(2, 3, 4, -100), | ||
(2, 3, 2, -100), | ||
(3, 0, 1, -25)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Model 3 sources
- 3 components
- 2 components
- 1 component
|
||
|
||
def test_clean_mask(wsclean_model_and_clean_mask): | ||
# 3 sources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test that the appropriate components are chosen given the percentage flux. I should change this to check that the appropriate sources are selected.
|
||
source_ids = clean_mask[z, y, x] | ||
|
||
if(np.any(source_ids == 0)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that the wsclean components could register to the edge of a clean mask pixel, in which case coordinates could map to the wrong source_id
.
I suspect this won't be a problem in practice, but I guess the only way to find out is to try this PR with real data.
Given a clean mask file produced by Sofia 2, [registers] and groups (https://en.wikipedia.org/wiki/Image_registration) a wsclean component list by source ID's in a SoFiA2 Clean Mask file. Components are lexicographically sorted by
(total source flux, component flux)
and a percentage of components contributing to total flux are selected.Tests added / passed
$ py.test --flake8 -v -s .
If the flake8 tests fail, the quickest way to correct
this is to run
autopep8
and thenflake8
to fix the remaining issues.