Skip to content

Commit

Permalink
Use warnings package to issue user warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-rose committed Feb 8, 2019
1 parent 29a7c77 commit b60d8f0
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion climlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
has been documented for a comprehensive understanding and traceability.
'''

__version__ = '0.7.1'
__version__ = '0.7.2.dev0'

# this should ensure that we can still import constants.py as climlab.constants
from .utils import constants, thermo, legendre
Expand Down
3 changes: 2 additions & 1 deletion climlab/convection/emanuel_convection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from __future__ import absolute_import

import numpy as np
import warnings
from climlab.process import TimeDependentProcess
from climlab.utils.thermo import qsat
from climlab import constants as const
try:
from ._emanuel_convection import emanuel_convection as convect
except:
print('Cannot import EmanuelConvection fortran extension, this module will not be functional.')
warnings.warn('Cannot import EmanuelConvection fortran extension, this module will not be functional.')
# The array conversion routines we are borrowing from the RRTMG wrapper
from climlab.radiation.rrtm.utils import _climlab_to_rrtm as _climlab_to_convect
from climlab.radiation.rrtm.utils import _rrtm_to_climlab as _convect_to_climlab
Expand Down
3 changes: 2 additions & 1 deletion climlab/domain/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from builtins import str
from builtins import object
from xarray import Dataset, DataArray
import warnings


def Field_to_xarray(field):
Expand Down Expand Up @@ -55,7 +56,7 @@ def state_to_xarray(state):
except:
pass
else:
print('{} excluded from Dataset because it is not a Field variable.'.format(name))
warnings.warn('{} excluded from Dataset because it is not a Field variable.'.format(name))
return ds

def to_xarray(input):
Expand Down
17 changes: 6 additions & 11 deletions climlab/radiation/cam3/cam3.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@
from climlab import constants as const
from climlab.utils.thermo import vmr_to_mmr
from climlab.radiation.radiation import _Radiation_SW, _Radiation_LW
import os
# Wrapping these imports in try/except to avoid failures during documentation building on readthedocs
try:
from . import _cam3
except:
print('Cannot import compiled Fortran extension, CAM3 module will not be functional.')
try:
import xarray as xr
except:
print('Cannot import xarray. Will not be able to properly initialize the CAM3 module.')
import os, warnings
import xarray as xr


def init_cam3(mod):
Expand All @@ -61,10 +53,13 @@ def init_cam3(mod):
setattr(mod, field, data[field].transpose())
data.close()

# Wrapping these imports in try/except to avoid failures during documentation building on readthedocs
try:
from . import _cam3
init_cam3(_cam3.absems)
except:
print('Cannot initialize the CAM3 module.')
warnings.warn('Cannot import and initialize compiled Fortran extension, CAM3 module will not be functional.')


class CAM3(_Radiation_SW, _Radiation_LW):
'''
Expand Down
5 changes: 3 additions & 2 deletions climlab/radiation/radiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@
import os
from climlab import constants as const
from climlab.domain.field import Field
import warnings
try:
import xarray as xr
except:
print('Cannot import xarray. Will not be able to initialize ozone from data file.')

warnings.warn('Cannot import `xarray`. Will not be able to initialize ozone from data file.',
FutureWarning, stacklevel=2)

def default_specific_humidity(Tatm):
'''Initialize a specific humidity distribution
Expand Down
7 changes: 3 additions & 4 deletions climlab/radiation/rrtm/rrtmg_lw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division, print_function, absolute_import
import numpy as np
import warnings
from climlab import constants as const
from climlab.radiation.radiation import _Radiation_LW
from .utils import _prepare_general_arguments
Expand All @@ -16,7 +15,7 @@
# Initialize absorption data
_rrtmg_lw.climlab_rrtmg_lw_ini(const.cp)
except:
print('Cannot import and initialize compiled Fortran extension, RRTMG_LW module will not be functional.')
warnings.warn('Cannot import and initialize compiled Fortran extension, RRTMG_LW module will not be functional.')


class RRTMG_LW(_Radiation_LW):
Expand Down
3 changes: 2 additions & 1 deletion climlab/radiation/rrtm/rrtmg_sw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division, print_function, absolute_import
import numpy as np
import warnings
from climlab import constants as const
from climlab.radiation.radiation import _Radiation_SW
from .utils import _prepare_general_arguments
Expand All @@ -15,7 +16,7 @@
# Initialize absorption data
_rrtmg_sw.climlab_rrtmg_sw_ini(const.cp)
except:
print('Cannot import and initialize compiled Fortran extension, RRTMG_SW module will not be functional.')
warnings.warn('Cannot import and initialize compiled Fortran extension, RRTMG_SW module will not be functional.')


class RRTMG_SW(_Radiation_SW):
Expand Down
4 changes: 2 additions & 2 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "climlab" %}
{% set version = "0.7.1" %}
{% set version = "0.7.2.dev0" %}

package:
name: {{ name|lower }}
Expand All @@ -10,7 +10,7 @@ source:

build:
skip: True # [win32 or (win and py27)]
number: 3
number: 0

requirements:
build:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os, sys
import textwrap

VERSION = '0.7.1'
VERSION = '0.7.2.dev0'

# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be
# properly updated when the contents of directories change (true for distutils,
Expand Down

0 comments on commit b60d8f0

Please sign in to comment.