improver.utilities.compare module¶
Compare netcdf files using python-netCDF4 library.
This comparison is done using netCDF4 rather than iris so that it is not coupled to changes in netCDF representation across iris versions. It is also able to compare non-CF conventions compliant netCDF files that iris has difficulty loading.
Many functions in this module take an argument called ‘reporter’ which is a function to be called to report comparison differences. This provides flexibility regarding what action should be taken when differences are found. For example, the action to take could be to print the message, log the message, or raise an appropriate exception.
-
improver.utilities.compare.compare_attributes(name, actual_ds, desired_ds, reporter)[source]¶ Compare attributes in a netCDF dataset/group.
-
improver.utilities.compare.compare_data(name, actual_var, desired_var, rtol, atol, reporter)[source]¶ Compare attributes in a netCDF variable.
-
improver.utilities.compare.compare_datasets(name, actual_ds, desired_ds, rtol, atol, exclude_vars, reporter)[source]¶ Compare netCDF datasets. This function can call itself recursively to handle nested groups in netCDF4 files which are represented using the same Dataset class by python-netCDF4.
- Parameters
- Returns
None
-
improver.utilities.compare.compare_dims(name, actual_ds, desired_ds, exclude_vars, reporter)[source]¶ Compare dimensions in a netCDF dataset/group.
-
improver.utilities.compare.compare_netcdfs(actual_path, desired_path, rtol, atol, exclude_vars=None, reporter=None)[source]¶ Compare two netCDF files.
- Parameters
actual_path (os.Pathlike) – data file produced by test run
desired_path (os.Pathlike) – data file considered good eg. KGO
rtol (float) – relative tolerance
atol (float) – absolute tolerance
exclude_vars (Iterable[str]) – variable names to exclude from comparison
reporter (Callable[[str], None]) – callback function for reporting differences
- Returns
None