Skip to content

Loading TCTracks with from_ibtracs_netcdf does not properly close the filestream #920

@spjuhel

Description

@spjuhel

Describe the bug
When reading the IBTrACS.ALL.v04r00.nc file with from_ibtracs_netcdf() the file is opened with xr.open_dataset(ibtracs_path) which opens a stream to the file that is not closed afterwards. I had problems with this on euler when trying to access the file at later stages with the following error:

OSError: [Errno -101] NetCDF: HDF error: '/cluster/work/climate/sjuhel/climada/data/IBTrACS.ALL.v04r00.nc'

To Reproduce
I haven't been able to reproduce the issue on a local computer. This is possibly related to NetCDF too.

Expected behavior
The file is properly closed once the data is loaded.

See also: pydata/xarray#2887

Climada Version: 4.1.1

System Information (please complete the following information):

  • Operating system and version: Ubuntu 22.04 (euler)
  • Python version: 3.10.13 (Custom venv while climada is not yet installed on the cluster, possibly part of the problems)

Additional context
I don't think this is a critical problem, but the following would probably be a better way to handle the opening of the file:

From:

ibtracs_ds = xr.open_dataset(ibtracs_path)

to:

with xr.open_dataset(ibtracs_path) as ds:
    ibtracks_ds = ds.load()

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions