Package: isimip-qc
ISIMIP quality controlA command line tool for the quality control of climate impact data of the ISIMIP project. It mainly covers tests of:the file name against the protocol schemas and patternsvariables, dimensions and global attributesdata model and typessome consistency checks on the NetCDF time axis andif the data is within a valid value range (when defined in the ISIMIP protocol)This is still work in progress.SetupThe application is written in Python (> 3.6) uses only dependencies, which can be installed without administrator priviledges. The installation of Python (and its developing packages), however differs from operating system to operating system. Optional Git is needed if the application is installed directly from GitHub. The installation of Python 3 and Git for different plattforms is documentedhere.The tool itself can be installed via pip. Usually you want to create avirtual environmentfirst, but this is optional.# setup venv on Linux/macOS/Windows WSLpython3-mvenvenvsourceenv/bin/activate# setup venv on Windows cmdpython-mvenvenv
callenv\Scripts\activate.bat# install from the Python Package Index (PyPI), recommendedpipinstallisimip-qc# update from PyPIpipinstall--upgradeisimip-qc# install directly from GitHubpipinstallgit+https://github.com/ISI-MIP/isimip-qc# update from Githubpipinstall--upgradegit+https://github.com/ISI-MIP/isimip-qcUsageThe tool has several options which can be inspected using the help option-h, --help:usage: isimip-qc [-h] [--config-file CONFIG_FILE] [-c] [-m] [-O]
                 [--unchecked-path UNCHECKED_PATH] [--checked-path CHECKED_PATH]
                 [--protocol-location PROTOCOL_LOCATIONS] [--log-level LOG_LEVEL]
                 [--log-path LOG_PATH] [--log-path-level LOG_PATH_LEVEL] [--include INCLUDE_LIST]
                 [--exclude EXCLUDE_LIST] [-f] [-w] [-e] [-r [MINMAX]] [-nt] [--fix]
                 [--fix-datamodel [FIX_DATAMODEL]] [--check CHECK] [--force-copy-move] [-V]
                 schema_path

Check ISIMIP files for matching protocol definitions

positional arguments:
  schema_path           ISIMIP schema_path, e.g. ISIMIP3a/OutputData/water_global

optional arguments:
  -h, --help            show this help message and exit
  -c, --copy            copy checked files to CHECKED_PATH if no warnings or errors were found
  -m, --move            move checked files to CHECKED_PATH if no warnings or errors were found
  -O, --overwrite       overwrite files in CHECKED_PATH if present. Default is False.
  --unchecked-path UNCHECKED_PATH
                        base path of the unchecked files
  --checked-path CHECKED_PATH
                        base path for the checked files
  --protocol-location PROTOCOL_LOCATIONS
                        URL or file path to the protocol when different from official repository
  --log-level LOG_LEVEL
                        log level (CRITICAL, ERROR, WARN, VRDETAIL, CHECKING, SUMMARY, INFO, or
                        DEBUG) [default: CHECKING]
  --log-path LOG_PATH   base path for the individual log files
  --log-path-level LOG_PATH_LEVEL
                        log level for the individual log files [default: WARN]
  --include INCLUDE_LIST
                        patterns of files to include. Exclude those that don't match any.
  --exclude EXCLUDE_LIST
                        patterns of files to exclude. Include only those that don't match any.
  -f, --first-file      only process first file found in UNCHECKED_PATH
  -w, --stop-on-warnings
                        stop execution on warnings
  -e, --stop-on-errors  stop execution on errors
  --ignore-critical     allow fixing and copy/move files with critical issues found
  -r [MINMAX], --minmax [MINMAX]
                        test values for valid range (slow, argument MINMAX defaults to show the
                        top 10 values)
  -nt, --skip-time-span-check
                        skip check for simulated time period
  --fix                 try to fix warnings detected on the original files
  --fix-datamodel [FIX_DATAMODEL]
                        also fix warnings on data model found using NCCOPY or CDO (slow). Choose
                        preferred tool per lower case argument.
  --check CHECK         perform only one particular check
  --force-copy-move     copy or move files despite errors
  -V, --version         show program's version number and exitThe only mandatory argument is theschema_path, which specifies the pattern and schema to use. Theschema_pathconsitst of thesimulation_round, theproduct, and thesectorseperated by slashes, e.g.ISIMIP3a/OutputData/water_global. If the only argument used isschema_path, the current user path when calling the tool should be same as the directory of the files to be checked.The options in detail--config-file: Default values for the optional arguments are set in the code, but can also be provided via:a config file given by--config-file, or located atisimip-qc.conf,~/.isimip-qc.conf, or/etc/isimip-qc.conf. The config file needs to have a sectionisimip-qcand uses lower case variables and underscores, e.g.:[isimip-qc]
pattern_locations = /path/to/isimip-protocol-3/output/pattern/
schema_locations = path/to/isimip-protocol-3/output/schema/environment variables (in caps and with underscores, e.g.UNCHECKED_PATH).-c, --copyand-m, --move: Copy or move files that have successfully passed the checks to a final destination. Effective only when no warnings have been found on the file.'-O, --overwrite`: Allow overwriting of existing files in CHECKED_PATH. Default is to skip copy or move in case the target file is already present.--unchecked-path UNCHECKED_PATH: Any files in this folderandits subfolders will be included into the list of files to test.--checked-path CHECKED_PATH: Target folder for the--copyor--moveoperation. The subfolder structure below CHECKED_PATH will be created and filled according to the sub-structure found in UNCHECKED_PATH--protocol-location PROTOCOL_LOCATIONS: For working with local copies of the ISIMIP protocol (append/outputto the cloned repositories folder). Omit option for using the online GitHub protocol versions forISIMIP2orISIMIP3. An internet connection is required for reading the online protocols.--log-level LOG_LEVEL: Set the detail level of log output. Default isCHECKING. Log levels fromCRITICALtoVRDETAILwill not show the file currently checked in the terminal but write all of them to the data file specific log file.CRITICAL: only very severe errorsERROR: all errorsWARN: warnings and all errorsVRDETAIL: same as CHECKING but with details on time and location of valid ranges violations when invoked with--minmaxoption. Very slow when violations are detected.CHECKING: includes warnings and errorsSUMMARY: includes warnings, errors and the summary shown at the endINFO: includesSUMMARYand details for successful checksDEBUG: all the above plus details for some debugging cases.--log-path LOG_PATH: Also write the logs to a file where the folder structure below LOG_PATH is taken from UNCHECKED_PATH.--log-path-level LOG_PATH_LEVEL: The log level used for the file specific logs belowLOG_PATH. The default isWARNand should suffice for most cases.--include INCLUDE_LIST: Provide a comma-separated list of strings to include for the checks if any of them matches the file path or name, e.g. 'daily,dis' will only check*daily*or*discharge*files while skipping others.--exclude EXCLUDE_LIST: Provide a comma-separated list of strings to exclude from the checks if any of them matches the file path or name, e.g. 'monthly,histsoc' will skip any*monthly*or*histsoc*files.-f, --first-file: Only test the first file found in UNCHECKED_PATH. Useful for revealing issues that may occur on all your files.-w, --stop-on-warnings: The tool will stop after the first file where WARNINGs have been identified.-e, --stop-on-errors: The tool will stop after the first file where ERRORs have been identified.--ignore-critical: allow fixing and copy/move files although critical issues were found. Caution, this might lead to unexpected behaviour.-r [MINMAX], --minmax [MINMAX]: Test the data for valid ranges when defined in the protocol. Per default and when violations are detected the top 20 minimum and maximum values along with their time and geographic location will be logged as well. MINMAX is optional and defines how many values should be reported instead of 20. This test drastically slows down the run time of the tool.-nt, --skip-time-span-check: Skip checking non-dialy data for proper coverage of simulation periods.--fix: Activates a number of fixes for WARNINGs by taking the default values from the protocol, e.g. variable attributes and units. In additions an unique identifier (UUID), the version of this tool and the protocol version (by a git hash) are being written to the global attributes section of the NetCDF file.Attention: Fixes and are going to be applied onyour original filesin UNCHECKED_PATH.--fix-datamodel [FIX_DATAMODEL]: Fixes to the data model and compression level of the NetCDF file can't be made on-the-fly with the libraries used by the tool. We here rely on the external toolscdoor nccopy (from theNetCDF library) to rewrite the entire file. Default isnccopy. Please try to create the files with the proper data model (compressed NETCDF4_CLASSIC) in your postprocessing chain before submitting them to the data server.--check CHECK: Perform only one particular check. The list of CHECKs can be taken from the funtions defined in theisimip_qc/checks/*.pyfiles.--force-copy-move: Copy or move files despite errors found during checks.Scripts/NotebooksThe different functions of the tool can also be used in Python scripts or Jupyter Notebooks. Before any functions are called, the global settings object needs to be initialized using theinit_settingsfunction, e.g.:fromisimip_qc.checksimportchecksfromisimip_qc.mainimportinit_settingsfromisimip_qc.modelsimportFilesettings=init_settings(schema_path='ISIMIP3b/OutputData/water_global',config_file='~/data/isimip/isimip.conf')file_path='~/data/isimip/qc/unchecked/h08_ipsl-cm6a-lr_w5e5_ssp585_2015soc_default_dis_global_monthly_2015_2100.nc'file=File(file_path)file.open_log()file.match()file.open_dataset()forcheckinchecks:check(file)file.close_dataset()