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

Add CLI for MBC masking #174

Closed
tjgalvin opened this issue Sep 25, 2024 · 5 comments
Closed

Add CLI for MBC masking #174

tjgalvin opened this issue Sep 25, 2024 · 5 comments

Comments

@tjgalvin
Copy link
Owner

Add a cli task to apply the minimum absolute boxcar filter

Requires input options for:
file to mask
inflation factor
optionally output file name
optionally lower limit flood factor
- if provided do flood fill out to this level

@tjgalvin
Copy link
Owner Author

I think a general switch up to this stage might be best now that I look at this. I can also remove some of the older approaches.

Can also add something to erode island shapes based on some arbitrary shape. For instance on based on the shape of the restoring beam above a particular level

# fits_data is a mask file, made up of 1.0s and 0.0s

beam = Beam.from_fits_header(fits_hdr)
k = beam.as_kernel(pixscale=2.5*u.Unit("arcsec"), x_size=fits_data.shape[1], y_size=fits_data.shape[0])

# Cut the shape based on the 60 percent response level
circ = k.array > (np.max(k.array) * 0.6)

invert_f_data = np.fft.fft2(fits_data)
invert_circ = np.fft.fft2(circ)

deconvolved = invert_f_data * invert_circ

forward = np.fft.fftshift(np.fft.ifft2(deconvolved))
forward = np.floor(np.abs(forward) + 0.5)

mask = forward >= np.sum(circ)

The above is almost certainly the same as the binary erosion approaches already in scipy with a particular structure function

@tjgalvin
Copy link
Owner Author

tjgalvin commented Oct 7, 2024

Confirmed that the above code produced a mask with the same shape as using scipy.ndimage.binary_erosion with an appropriate structure argument.

Provided the size of the beam shape kernel is small the scipy erosion is many times faster than the approach above, where the inputs need to have the same set of spatial scales (and hence a lot of padding).

@tjgalvin
Copy link
Owner Author

tjgalvin commented Oct 8, 2024

Working on this in the masking branch

@tjgalvin
Copy link
Owner Author

Pull request in #178

@tjgalvin
Copy link
Owner Author

Merged. Closing.

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

No branches or pull requests

1 participant