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

Support selecting a percent of total flux given a clean mask file #54

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

sjperkins
Copy link
Collaborator

@sjperkins sjperkins commented Apr 5, 2023

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 then flake8
    to fix the remaining issues.

    $ pip install -U autopep8 flake8
    $ autopep8 -r -i .
    $ flake8 .
    

@sjperkins sjperkins marked this pull request as draft April 7, 2023 09:05
@sjperkins sjperkins marked this pull request as ready for review April 24, 2023 15:01
@sjperkins sjperkins requested a review from paoloserra April 24, 2023 15:17
@sjperkins sjperkins self-assigned this Apr 24, 2023
@@ -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")
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 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}")
Copy link
Collaborator Author

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"
Copy link
Collaborator Author

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")
Copy link
Collaborator Author

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]
Copy link
Collaborator Author

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)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Model 3 sources

  1. 3 components
  2. 2 components
  3. 1 component



def test_clean_mask(wsclean_model_and_clean_mask):
# 3 sources
Copy link
Collaborator Author

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)):
Copy link
Collaborator Author

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.

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.

2 participants