ESMValGroup / ESMValCore

ESMValCore: A community tool for pre-processing data from Earth system models in CMIP and running analysis scripts.
https://www.esmvaltool.org
Apache License 2.0
42 stars 38 forks source link

API messages don't respect `log_level` setting #1977

Open Peter9192 opened 1 year ago

Peter9192 commented 1 year ago

When using esmvalcore through the API in a jupyter notebook, iris warnings show up in the output despite setting log-level to error in config-user. For example:

from esmvalcore.dataset import Dataset
from esmvalcore.preprocessor import area_statistics

dataset = Dataset(
    short_name='tos',
    mip='Omon',
    project='CMIP6',
    exp= 'historical',
    dataset='MPI-ESM1-2-LR', 
    ensemble='r4i1p1f1',
    grid='gn',
)

dataset.add_supplementary(short_name='areacello', mip='Ofx', exp='historical')
dataset.augment_facets()
cube = dataset.load()
cube = area_statistics(cube, operator='mean')

spits

/home/peter/mambaforge/envs/core5/lib/python3.9/site-packages/iris/coords.py:2226: UserWarning: Cannot check if coordinate is contiguous: Invalid operation for 'cell index along second dimension', with 0 bound(s). Contiguous bounds are only defined for 1D coordinates with 2 bounds. Metadata may not be fully descriptive for 'cell index along second dimension'. Ignoring bounds.
  warnings.warn(msg.format(str(exc), self.name()))
/home/peter/mambaforge/envs/core5/lib/python3.9/site-packages/iris/coords.py:2226: UserWarning: Cannot check if coordinate is contiguous: Invalid operation for 'cell index along first dimension', with 0 bound(s). Contiguous bounds are only defined for 1D coordinates with 2 bounds. Metadata may not be fully descriptive for 'cell index along first dimension'. Ignoring bounds.
  warnings.warn(msg.format(str(exc), self.name()))
/home/peter/mambaforge/envs/core5/lib/python3.9/site-packages/iris/coords.py:2216: UserWarning: Collapsing a multi-dimensional coordinate. Metadata may not be fully descriptive for 'latitude'.
  warnings.warn(msg.format(self.name()))
/home/peter/mambaforge/envs/core5/lib/python3.9/site-packages/iris/coords.py:2216: UserWarning: Collapsing a multi-dimensional coordinate. Metadata may not be fully descriptive for 'longitude'.
  warnings.warn(msg.format(self.name()))

Another one I keep getting is

/home/peter/mambaforge/envs/core5/lib/python3.9/site-packages/iris/fileformats/netcdf/_thread_safe_nc.py:324: UserWarning: WARNING: missing_value not used since it
cannot be safely cast to variable data type
  var = variable[keys]

The amount and non-prosaic nature of these messages very much clutter my notebooks, to the extent that I'd prefer to suppress them. I had expected that the user configuration setting log_level would apply to iris' messages as well, but apparently, it does not.

Peter9192 commented 1 year ago

~related: https://github.com/SciTools/iris/issues/3413~

never mind, happens for esmvalcore's own messages as well

Peter9192 commented 1 year ago

On closer inspection, the problem applies to esmvalcore's own messages as well:

from esmvalcore.dataset import Dataset

dataset = Dataset(
    short_name='tos',
    mip='Omon',
    project='CMIP6',
    exp= 'historical',
    dataset='IPSL-CM6A-LR',
    ensemble='r4i1p1f1',
    grid='gn',
)

dataset.add_supplementary(short_name='areacello', mip='Ofx', exp='historical')
dataset.augment_facets()

cube = dataset.load()
WARNING:esmvalcore.cmor.check:There were warnings in variable areacello:
 Long name for areacello changed from Grid-Cell Area to Grid-Cell Area for Ocean Variables
loaded from file /home/peter/climate_data/CMIP6/CMIP/IPSL/IPSL-CM6A-LR/historical/r4i1p1f1/Ofx/areacello/gn/v20180803/areacello_Ofx_IPSL-CM6A-LR_historical_r4i1p1f1_gn.nc

again, log_level has been set to error (not interactively, but already in config-user.yaml`)