Open apmtowner opened 2 years ago
This should be pretty easy to implement; we can add it.
The way to do this (what we'll implement under the hood, I expect) is:
cube = <your cube>
spectral_inclusion = np.any(cube.mask.include(), axis=(1,2))
start_zpix = np.argmax(spectral_inclusion)
end_zpix = spectral_inclusion.size - np.argmax(spectral_inclusion[::-1])
cube = cube[start_zpix:end_zpix,:,:]
Thanks!
Short version: For https://spectral-cube.readthedocs.io/en/latest/api/spectral_cube.SpectralCube.html#spectral_cube.SpectralCube.minimal_subcube, there is a
spatial_only=True
boolean option. It would be extremely useful to my (admittedly weird) use case to have aspectral_only=True
option as well, i.e. find the minimal subcube in the spectral dimension only and ignore the two spatial dimensions. This is not currently an option but would be very nice to have.Longer context: I'm using SpectralCube masking to create subcubes where the frequencies that are cut out vary depending on the pixel. In my case, I want to cut out the central 5-10 km/s of the cube, but the vlsr varies by up to 5 km/s across the field of view. This is annoying for my science. I'm using masking to tie the central velocity of each pixel to the actual vlsr of that pixel instead of using the same (mostly wrong) vlsr for the whole field. The basic code looks like this:
I had previously been using
mycutout = mycube.with_mask(combinedmask).minimal_subcube()
instead, because hey, why keep 400 channels in memory if you only need 80? But unfortunately minimal_subcube() was also cutting off exactly one column in my n_x axis as well. I don't know why and I can't make it stop. One good (but currently nonexistent) workaround that doesn't torture the RAM on my machine would be to letminimal_subcube
have aspectral_only=True
option just as it does forspatial_only
.I freely admit I might be tormenting SpectralCube with purposes it wasn't designed for, but I do think having a
spectral_only
option would be very helpful in general.