tjgalvin / flint

BSD 3-Clause "New" or "Revised" License
7 stars 2 forks source link

Add CLI for MBC masking #174

Closed tjgalvin closed 1 month ago

tjgalvin commented 1 month ago

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

tjgalvin commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

Working on this in the masking branch

tjgalvin commented 1 month ago

Pull request in #178

tjgalvin commented 1 month ago

Merged. Closing.