radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
95 stars 61 forks source link

Writting in place on a large StokesSpectralCube #872

Closed mb010 closed 1 year ago

mb010 commented 1 year ago

I'm trying to write statistical properties on a pixelwise level on a large stokes spectral cube. I would like to do this by simplying writting over the data in a write mode opened file. However, I cannot seem to find any option for this in the StokesSpectralCube class even though there is one in the SpectralCube class. A simple mode option would be ideal, or is there a reason this was not implemented that I am ignorant to?

keflavich commented 1 year ago

SpectralCubes can be read from a variety of different file types, some of which do not support memory-mapped operations (CASA image, CLASS).

It would technically be possible to do as you ask for FITS files specifically, but I don't think it's advisable - most users don't need that feature and might be surprised by it.

I would recommend just using hdu = fits.open('file.fits', mode='update') and writing the output of SpectralCube operations into that. If there are use cases that aren't well-supported by this approach, let us know.