Skip to content

Commit 54d78d6

Browse files
committed
Add environment variable to disable netCDF file validation.
1 parent d47566b commit 54d78d6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Diff for: docs/source/configuring.rst

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ This page provides an overview of available variables.
2929
you can use :external:py:meth:`logging.getLogger("imaspy").setLevel(...)
3030
<logging.Logger.setLevel>` to change the log level programmatically.
3131

32+
33+
``IMASPY_DISABLE_NC_VALIDATE``
34+
Disables validation of netCDF files when loading an IDS from an IMAS netCDF file.
35+
36+
.. caution::
37+
Disabling the validation may lead to errors when reading data from an IMAS netCDF file.
38+
3239
``IMAS_VERSION``
3340
Sets :ref:`The default Data Dictionary version` to use.
3441

Diff for: imaspy/backends/netcdf/nc2ids.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
from typing import Iterator, List, Optional, Tuple
34

45
import netCDF4
@@ -163,6 +164,14 @@ def run(self) -> None:
163164

164165
def _validate_variables(self) -> None:
165166
"""Validate that all variables in the netCDF Group exist and match the DD."""
167+
disable_validate = os.environ.get("IMASPY_DISABLE_NC_VALIDATE")
168+
if disable_validate and disable_validate != "0":
169+
logger.info(
170+
"NetCDF file validation disabled: "
171+
"This may lead to errors when reading data!"
172+
)
173+
return # validation checks are disabled
174+
166175
for var_name in self.variables:
167176
if var_name.endswith(":shape"):
168177
# Check that there is a corresponding variable

0 commit comments

Comments
 (0)