|
|
@ -10,37 +10,54 @@ from ._wrffortran import (fomp_enabled, fomp_set_num_threads, |
|
|
|
_local_config = local() |
|
|
|
_local_config = local() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _init_local(): |
|
|
|
def _try_enable_xarray(): |
|
|
|
global _local_config |
|
|
|
global _local_config |
|
|
|
|
|
|
|
|
|
|
|
_local_config.xarray_enabled = True |
|
|
|
_local_config.xarray_enabled = True |
|
|
|
_local_config.cartopy_enabled = True |
|
|
|
|
|
|
|
_local_config.basemap_enabled = True |
|
|
|
|
|
|
|
_local_config.pyngl_enabled = True |
|
|
|
|
|
|
|
_local_config.cache_size = 20 |
|
|
|
|
|
|
|
_local_config.initialized = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
from xarray import DataArray |
|
|
|
from xarray import DataArray |
|
|
|
except ImportError: |
|
|
|
except ImportError: |
|
|
|
_local_config.xarray_enabled = False |
|
|
|
_local_config.xarray_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _try_enable_cartopy(): |
|
|
|
|
|
|
|
global _local_config |
|
|
|
|
|
|
|
_local_config.cartopy_enabled = True |
|
|
|
try: |
|
|
|
try: |
|
|
|
from cartopy import crs |
|
|
|
from cartopy import crs |
|
|
|
except ImportError: |
|
|
|
except ImportError: |
|
|
|
_local_config.cartopy_enabled = False |
|
|
|
_local_config.cartopy_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _try_enable_basemap(): |
|
|
|
|
|
|
|
global _local_config |
|
|
|
|
|
|
|
_local_config.basemap_enabled = True |
|
|
|
try: |
|
|
|
try: |
|
|
|
from mpl_toolkits.basemap import Basemap |
|
|
|
from mpl_toolkits.basemap import Basemap |
|
|
|
except ImportError: |
|
|
|
except ImportError: |
|
|
|
_local_config.basemap_enabled = False |
|
|
|
_local_config.basemap_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _try_enable_pyngl(): |
|
|
|
|
|
|
|
global _local_config |
|
|
|
|
|
|
|
_local_config.pyngl_enabled = True |
|
|
|
try: |
|
|
|
try: |
|
|
|
from Ngl import Resources |
|
|
|
from Ngl import Resources |
|
|
|
except ImportError: |
|
|
|
except ImportError: |
|
|
|
_local_config.pyngl_enabled = False |
|
|
|
_local_config.pyngl_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _init_local(): |
|
|
|
|
|
|
|
global _local_config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_try_enable_xarray() |
|
|
|
|
|
|
|
_try_enable_cartopy() |
|
|
|
|
|
|
|
_try_enable_basemap() |
|
|
|
|
|
|
|
_try_enable_pyngl() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_local_config.cache_size = 20 |
|
|
|
|
|
|
|
_local_config.initialized = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Initialize the main thread's configuration |
|
|
|
# Initialize the main thread's configuration |
|
|
|
_init_local() |
|
|
|
_init_local() |
|
|
|
|
|
|
|
|
|
|
@ -51,11 +68,11 @@ def init_local(): |
|
|
|
def func_wrapper(wrapped, instance, args, kwargs): |
|
|
|
def func_wrapper(wrapped, instance, args, kwargs): |
|
|
|
global _local_config |
|
|
|
global _local_config |
|
|
|
try: |
|
|
|
try: |
|
|
|
init = _local_config.init |
|
|
|
initialized = _local_config.initialized |
|
|
|
except AttributeError: |
|
|
|
except AttributeError: |
|
|
|
_init_local() |
|
|
|
_init_local() |
|
|
|
else: |
|
|
|
else: |
|
|
|
if not init: |
|
|
|
if not initialized: |
|
|
|
_init_local() |
|
|
|
_init_local() |
|
|
|
|
|
|
|
|
|
|
|
return wrapped(*args, **kwargs) |
|
|
|
return wrapped(*args, **kwargs) |
|
|
@ -77,17 +94,16 @@ def xarray_enabled(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|
def disable_xarray(): |
|
|
|
def enable_xarray(): |
|
|
|
"""Disable xarray.""" |
|
|
|
"""Enable xarray if it is installed.""" |
|
|
|
global _local_config |
|
|
|
_try_enable_xarray() |
|
|
|
_local_config.xarray_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|
def enable_xarray(): |
|
|
|
def disable_xarray(): |
|
|
|
"""Enable xarray.""" |
|
|
|
"""Disable xarray.""" |
|
|
|
global _local_config |
|
|
|
global _local_config |
|
|
|
_local_config.xarray_enabled = True |
|
|
|
_local_config.xarray_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
@ -105,16 +121,15 @@ def cartopy_enabled(): |
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|
def enable_cartopy(): |
|
|
|
def enable_cartopy(): |
|
|
|
"""Enable cartopy.""" |
|
|
|
"""Enable cartopy if it is installed.""" |
|
|
|
global _local_config |
|
|
|
_try_enable_cartopy() |
|
|
|
_local_config.cartopy_enabled = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|
def disable_cartopy(): |
|
|
|
def disable_cartopy(): |
|
|
|
"""Disable cartopy.""" |
|
|
|
"""Disable cartopy.""" |
|
|
|
global _local_config |
|
|
|
global _local_config |
|
|
|
_local_config.cartopy_enabled = True |
|
|
|
_local_config.cartopy_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
@ -132,16 +147,15 @@ def basemap_enabled(): |
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|
def enable_basemap(): |
|
|
|
def enable_basemap(): |
|
|
|
"""Enable basemap.""" |
|
|
|
"""Enable basemap if it is installed.""" |
|
|
|
global _local_config |
|
|
|
_try_enable_basemap() |
|
|
|
_local_config.basemap_enabled = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|
def disable_basemap(): |
|
|
|
def disable_basemap(): |
|
|
|
"""Disable basemap.""" |
|
|
|
"""Disable basemap.""" |
|
|
|
global _local_config |
|
|
|
global _local_config |
|
|
|
_local_config.basemap_enabled = True |
|
|
|
_local_config.basemap_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
@ -159,16 +173,15 @@ def pyngl_enabled(): |
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|
def enable_pyngl(): |
|
|
|
def enable_pyngl(): |
|
|
|
"""Enable pyngl.""" |
|
|
|
"""Enable pyngl if it is installed.""" |
|
|
|
global _local_config |
|
|
|
_try_enable_pyngl() |
|
|
|
_local_config.pyngl_enabled = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|
def disable_pyngl(): |
|
|
|
def disable_pyngl(): |
|
|
|
"""Disable pyngl.""" |
|
|
|
"""Disable pyngl.""" |
|
|
|
global _local_config |
|
|
|
global _local_config |
|
|
|
_local_config.pyngl_enabled = True |
|
|
|
_local_config.pyngl_enabled = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@init_local() |
|
|
|
@init_local() |
|
|
|