Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion seabird/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

try:
import netCDF4
except:
except ImportError:
netCDF4 = None
module_logger.warning("netCDF4 is not available.")


Expand All @@ -33,6 +34,12 @@ def cnv2nc(data, filename):
profile = cnv.fCNV("CTD.cnv")
cnv2nc(profile, "CTD.nc")
"""
if netCDF4 is None:
raise ImportError(
"netCDF4 is required to export CNV data to NetCDF. "
"Install it with `pip install 'seabird[CDF]'` or `pip install netCDF4`."
)

logging.info("Saving netcdf output file: %s" % filename)

nc = netCDF4.Dataset(filename, "w", format="NETCDF4")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_netcdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python

import pytest

from seabird import netcdf


def test_cnv2nc_requires_netcdf4(monkeypatch):
monkeypatch.setattr(netcdf, "netCDF4", None)

with pytest.raises(ImportError, match="pip install 'seabird\\[CDF\\]'"):
netcdf.cnv2nc(object(), "output.nc")