marvin
marvin copied to clipboard
Permission Denied for Temp Folder
Bug Description
I am trying to load up cubes I have downloaded but keep getting the following error:
OSError: filename C:\Users\juanp\sas\dr15\manga\spectro\redux\v2_4_3\7957\stack\manga-7957-12703-LOGCUBE.fits.gz cannot be found: [Errno 13] Permission denied: 'C:\\Users\\juanp\\AppData\\Local\\Temp\\tmp4ys03e44'
It says the .fits.gz file cannot be found but I see it in the directory it's pointing at. As for the second directory listed after Errno 13 there is no such file in the Temp folder.
This problem persists even if I move the cube file to another location and call it manually with the directory using the Cube function.
Reproduction of Bug The code I am running is set up as follows:
from marvin.tools.cube import Cube
from marvin import config
config.setRelease('DR15')
config.mode = 'local'
config.download = True
my_cube1=Cube('7957-12703')
Expected behaviour To have the downloaded cube open and be able to read it.
Desktop:
- OS: Windows 10 Build 19042.867
- Version of Marvin: 2.6.0
@juanpabloalfonzo Can you provide the full traceback of the error?
@havok2063 Sure, I have pasted it below:
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
~\anaconda3\lib\site-packages\marvin\tools\cube.py in _load_cube_from_file(self, data)
180 with gunzip(self.filename) as gg:
--> 181 self.data = fits.open(gg.name)
182 except (IOError, OSError) as err:
~\anaconda3\lib\site-packages\astropy\io\fits\hdu\hdulist.py in fitsopen(name, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
163
--> 164 return HDUList.fromfile(name, mode, memmap, save_backup, cache,
165 lazy_load_hdus, **kwargs)
~\anaconda3\lib\site-packages\astropy\io\fits\hdu\hdulist.py in fromfile(cls, fileobj, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
402
--> 403 return cls._readfrom(fileobj=fileobj, mode=mode, memmap=memmap,
404 save_backup=save_backup, cache=cache,
~\anaconda3\lib\site-packages\astropy\io\fits\hdu\hdulist.py in _readfrom(cls, fileobj, data, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
1053 # instantiate a FITS file object (ffo)
-> 1054 fileobj = _File(fileobj, mode=mode, memmap=memmap, cache=cache)
1055 # The Astropy mode is determined by the _File initializer if the
~\anaconda3\lib\site-packages\astropy\utils\decorators.py in wrapper(*args, **kwargs)
534
--> 535 return function(*args, **kwargs)
536
~\anaconda3\lib\site-packages\astropy\io\fits\file.py in __init__(self, fileobj, mode, memmap, overwrite, cache)
193 elif isinstance(fileobj, str):
--> 194 self._open_filename(fileobj, mode, overwrite)
195 else:
~\anaconda3\lib\site-packages\astropy\io\fits\file.py in _open_filename(self, filename, mode, overwrite)
566 if os.path.exists(self.name):
--> 567 with fileobj_open(self.name, 'rb') as f:
568 magic = f.read(4)
~\anaconda3\lib\site-packages\astropy\io\fits\util.py in fileobj_open(filename, mode)
395
--> 396 return open(filename, mode, buffering=0)
397
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\juanp\\AppData\\Local\\Temp\\tmp9nd36nco'
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
~\OneDrive - University of Toronto\Documents\U of T\SURP 2021 Project\GitRepo\SURP-2021\Assigment.py in <module>
86
87
---> 88 my_cube1=Cube('7957-12703')
89 central_spaxel1=my_cube1.getSpaxel(0,0)
90
~\anaconda3\lib\site-packages\marvin\tools\cube.py in __init__(self, input, filename, mangaid, plateifu, mode, data, release, drpall, download, nsa_source)
72
73 if self.data_origin == 'file':
---> 74 self._load_cube_from_file(data=self.data)
75 elif self.data_origin == 'db':
76 self._load_cube_from_db(data=self.data)
~\anaconda3\lib\site-packages\marvin\tools\cube.py in _load_cube_from_file(self, data)
181 self.data = fits.open(gg.name)
182 except (IOError, OSError) as err:
--> 183 raise OSError('filename {0} cannot be found: {1}'.format(self.filename, err))
184
185 self.header = self.data[1].header
OSError: filename C:\Users\juanp\sas\dr15\manga\spectro\redux\v2_4_3\7957\stack\manga-7957-12703-LOGCUBE.fits.gz cannot be found: [Errno 13] Permission denied: 'C:\\Users\\juanp\\AppData\\Local\\Temp\\tmp9nd36nco'
So marvin
unzips each file to temporary directory when opening it to speed up data access. I think what's happening here is that the application running marvin
does not have permissions to access, or perhaps delete, the temporary file on Windows. If you're using an editor like PyCharm
or VS Code
, one thing to try is to right-click, and click "Run as Administrator". Or make sure python itself is run as an administrator.
We currently don't have any options for disabling this and reading the gzipped fits file. I think that's something we can look into. Python's NamedTemporaryFile
might not have permissions to delete the file after it becomes uncompressed (see https://github.com/bravoserver/bravo/issues/111#issuecomment-826990) . So another option we could look into is to implement a manual deletion of the file.