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

Overwrite=True option for cube.write? #831

Closed apmtowner closed 2 years ago

apmtowner commented 2 years ago

Is there a way to write out a spectralcube to a file with mycube.write() such that it will overwrite an existing file with the same name? I.e. something that replicates the overwrite=True or clobber=True keywords in most CASA tasks? This would be very useful for cases where I'm creating large numbers of files at once and find that my script breaks in the middle. I've looked but can't find anything in the documentation that suggests this is currently possible with cube.write().

(I know I can solve this problem by adding an if os.path.exists('myfilename.fits'): os.system('rm -rf myfilename.fits') to the script, and this is what I'm currently doing, but I'd rather not have to do this every time - a built-in "yes, please overwrite the file for me, thank you" would be a nice improvement.)

keflavich commented 2 years ago

It's just the standard overwrite=True, but indeed this is not referenced anywhere in the documentation!

apmtowner commented 2 years ago

Thanks!