Source code for epygram

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Enhanced Python for Graphics and Analysis of Meteorological fields
------------------------------------------------------------------

**epygram** is a package of classes, designed to handle Meteorological Fields,
and various resource Formats from which the Fields can be extracted.

It is distributed along with a series of applicative tools using the package,
that can be used 'as is', or can be taken as templates for building more complex
applications with the **epygram** package.

The package uses extensively the **footprints** package (included in epygram distributions),
designed by the VORTEX team in order (basically) to tackle once-for-all with Factories
for families of similar classes.
The basic idea behind this concept is that similar classes have a similar set of attributes,
but with behavioral differences (values or name/number of attributes), viewed as their "footprint".

For the needs of the FA & LFI formats and spectral transforms of fields from ARPEGE/ALADIN/AROME models,
the **arpifs4py** library is needed. It is also therein included, 
already compiled for Mageia4 platforms, and with necessary stuff for recompiling it on other platforms.
Be aware to be recompiled, this library needs an 'arpifs' pack pre-compiled with 'gmkpack', and 'gribex' library.
For the needs of the LFA format, the **LFA4py.so** library is needed and herein included, again
already compiled for Mageia4 platforms and Python 2.7, and with necessary stuff for recompiling it on other platforms.

The package also uses classical packages, especially **numpy**.
Some applications or special methods may use **scipy** and **matplotlib**.
The support of GRIB format requires the **gribapi** package.

- A. Mary - Météo France, CNRM/GMAP/COOPE - alexandre.mary@meteo.fr
- S. Riette - Météo France, CNRM/GMME/MESO-NH - sebastien.riette@meteo.fr

2014 --- 2015
"""

import logging
import imp
import importlib

import footprints

__all__ = []

__version__ = '0.4.2'

[docs]class epygramError(Exception): """ Errors class for the package. """ pass #: Log for epygram
epylog = footprints.loggers.getLogger('epylog') # config import config if config.noninteractive_backend: try: import matplotlib matplotlib.use(config.noninteractive_backend) except ImportError: pass ### COMPONENTS (modules) ### import util import base import profiles import myproj import formats_factory import container import args_catalog # Modules that contains only a class : shortcut from H2DGeometry import H2DGeometry from V2DGeometry import V2DGeometry from V1DGeometry import V1DGeometry from PointGeometry import PointGeometry from SpectralGeometry import SpectralGeometry from MiscField import MiscField from H2DField import H2DField from V2DField import V2DField from V1DField import V1DField from PointField import PointField from H2DVectorField import H2DVectorField, make_vector # Formats for f in config.implemented_formats: importlib.import_module('.'+f, __name__) # User modules if len(config.usermodules) > 0: for m in config.usermodules: imp.load_source(m['name'], m['abspath']) ### OTHER TOOLS ###
[docs]def showconfig(): """ Print current config. """ import copy cfg = copy.copy(config.__dict__) header = "### "+cfg['__name__']+" ###" print "#" * len(header) print header print "#" * len(header) toberemoved = ['os', 'sys', 'imp', 'tempfile', 'epygramError', '__name__', '__doc__', '__package__', '__file__', '__builtins__'] for p in toberemoved: cfg.pop(p) for k in sorted(cfg.keys()): print '- '+k+' = '+str(cfg[k])
[docs]def SpecialEnvironment(omp_num_threads=1, no_mpi=True, unlimited_stack=True): """ A function to modify execution environment (to be called early in execution). Currently,\n - environments variables:\n - if *no_mpi*, DR_HOOK_NOT_MPI set to 1 - OMP_NUM_THREADS set to *omp_num_threads* - stack size unlimited on Bull. """ import os import resource # because arpifs library is compiled with MPI & openMP os.putenv('OMP_NUM_THREADS', str(omp_num_threads)) if no_mpi: os.putenv('DR_HOOK_NOT_MPI', '1') if unlimited_stack and ('beaufix' in os.getenv('HOSTNAME') or \ 'prolix' in os.getenv('HOSTNAME')): resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))