vergauwenthomas / PyFa

Python wrapper on Rfa using xarray
MIT License
0 stars 0 forks source link

netCDF4 permission bug #32

Closed vergauwenthomas closed 6 months ago

vergauwenthomas commented 6 months ago

For some reason, there is a bug when writing to a NC file if the same file exists:


Traceback (most recent call last):

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/file_manager.py:211 in _acquire_with_cache_info
    file = self._cache[self._key]

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/lru_cache.py:56 in __getitem__
    value = self._cache[key]

KeyError: [<class 'netCDF4._netCDF4.Dataset'>, ('/home/thoverga/Documents/github/PyFa-tool/development/fa_files/dummy.nc',), 'a', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False)), '1fe337f6-6e29-44a1-b74b-7be960b4fc46']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File ~/Documents/github/PyFa-tool/development/testscript.py:37
    pyfa.save_as_nc(xrdata=data,

  File ~/Documents/github/PyFa-tool/pyfa_tool/modules/to_xarray.py:53 in save_as_nc
    xrdata.to_netcdf(path=target_file,

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/core/dataarray.py:4090 in to_netcdf
    return to_netcdf(  # type: ignore  # mypy cannot resolve the overloads:(

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/api.py:1298 in to_netcdf
    store = store_open(target, mode, format, group, **kwargs)

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/netCDF4_.py:400 in open
    return cls(manager, group=group, mode=mode, lock=lock, autoclose=autoclose)

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/netCDF4_.py:347 in __init__
    self.format = self.ds.data_model

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/netCDF4_.py:409 in ds
    return self._acquire()

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/netCDF4_.py:403 in _acquire
    with self._manager.acquire_context(needs_lock) as root:

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/contextlib.py:119 in __enter__
    return next(self.gen)

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/file_manager.py:199 in acquire_context
    file, cached = self._acquire_with_cache_info(needs_lock)

  File ~/anaconda3/envs/pyfa_env/lib/python3.9/site-packages/xarray/backends/file_manager.py:217 in _acquire_with_cache_info
    file = self._opener(*self._args, **kwargs)

  File src/netCDF4/_netCDF4.pyx:2469 in netCDF4._netCDF4.Dataset.__init__

  File src/netCDF4/_netCDF4.pyx:2028 in netCDF4._netCDF4._ensure_nc_success

PermissionError: [Errno 13] Permission denied: '/home/thoverga/Documents/github/PyFa-tool/development/fa_files/dummy.nc'