Source code for epygram.config

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

"""
This config holds the standard default parameters.

They can be overwritten by the user in the User config file *userconfigfile*.
"""

import os
import sys
import imp
import tempfile

import footprints

from epygram import epygramError



### INSTALL ###
#: Directory of epygram package install
installdir = __file__[:-(len(os.path.basename(__file__))+1)]
home = os.getenv('HOME')
#: User customization directory
usercustomizationdir = home + '/.epygram'
#: User config (overwrites standard config)
userconfigfile = usercustomizationdir + '/userconfig.py'
#: Temporary workdir
tempdir = home + '/tmp/epygram' # root for temporary files (must not exceed 70 characters) !!!
#: epygram Colormaps
epygram_colormaps = {'aspect':installdir+'/data/aspect.cmap',
                     'gaspect':installdir+'/data/gaspect.cmap'}



### PARAMETERS ###
#: gravity constant
g0 = 9.80665
#: Cp dry air
Cpd = 1004.709
#: Specific gas constant, dry air
Rd = 287.059
#: Specific gas constant, water vapor
Rv = 461.524
#: Ptop: pressure @ summit of atmosphere. For vertical coordinates conversions.
default_Ptop = 0.
#: Epsilon
epsilon = sys.float_info.epsilon
#: Maximum number of truncations handled (setup spectral transforms)
KNUMMAXRESOL = 10
#: Plots sizes (in inches)
plotsizes = (16., 12.)
#: Interactive graphical backend
noninteractive_backend = False
#: Default output for apptools
default_graphical_output = False
if os.getenv('DISPLAY') == '' or \
   'beaufix' in os.getenv('HOSTNAME') or \
   'prolix' in os.getenv('HOSTNAME'):
    noninteractive_backend = 'Agg'
    default_graphical_output = 'png'



### FORMATS ###
#: List of formats 
# for the formats_factory, the list is ordered by specificity for those of the
# same family (e.g. FA before LFI, DDHLFA before LFA...) 
# FA is ordered before LFA because the LFA library does not enable to catch 
# errors while opening.
# Removing one of these (in userconfig file) may allow an incomplete install
# of epygram, disabling one format.
implemented_formats = ['GRIB', 'GeoPoints', 'FA', 'DDHLFA', 'LFA']

#: FA default compression parameters
FA_default_compression = {'KNGRIB': 2, 'KDMOPL': 0, 'KPUILA': 0, 'KSTRON': 0, 'KNBPDG': 16, 'KNBCSP': 16}
#: default reference pressure coefficient for converting hybrid A coefficients in FA
FA_default_reference_pressure = 101325.
#: geoid of FA files in pyproj syntax
FA_geoid_for_pyproj = {'a':6371229., 'b':6371229.}
#: FA field dictionaries
CSV_field_dictionaries_FA = {'default':installdir + '/data/Field_Dict_FA.csv',
                             'user':usercustomizationdir + '/Field_Dict_FA.csv'}
#: FA (write) date & time precision: use FANDAR (minute) or FANDAX (second, cy40t1 onwards) 
FA_fandax = True
#: To avoid re-computing lons/lats of Gauss Grids from FA each time needed : makes ARPEGE profiles and section extraction times acceptable (less than 1min).
FA_buffered_gauss_grid = True
#: LFA maximum number of fields
LFA_max_num_fields = 1000
#: LFA default character separator; f2py workaround; shall not be in character strings of LFA fields
LFA_default_char_separator = ','
# GeoPoints write precision for lon/lat 
GeoPoints_lonlat_precision = 4
# GeoPoints write precision for other floats
GeoPoints_precision = 6
# GeoPoints write width of columns
GeoPoints_col_width = 12
# GRIB read whole message when accessing one attribute
GRIB_read_whole_message = False



### OPTIONS ###
#: Use home-made projection formulas (:mod:`epygram.myproj`) instead of *pyproj*.
default_projtool = 'pyproj'
#: arpifs geoid for :mod:`epygram.myproj`
myproj_default_geoid = {'geoidshape':'sphere', 'geoidradius':6371229.}
#: A classical default geoid for *pyproj*
pyproj_default_geoid = {'ellps':'WGS84'}
#: Protect unhappy writes: ask before opening a new file on an existing path
protect_unhappy_writes = False
#: Threshold on field absolute values to mask meaningless field values
mask_outside = 1e19
#: To hide footprints warnings...
hide_footprints_warnings = True
#: To raise an error if the memory needed for Legendre transforms exceeds 
#: this percentage of the available memory.
prevent_swapping_legendre = 0.75



### USER CUSTOMIZATION ###
# user modules: actually should remain empty here !
#: In userconfig, this should be a list of dict containing two keys:
#: the module name and the source absolute path;
#: e.g. {'name':'mymodule', 'abspath':'/home/.../mymodule.py'}.
#:
#: The import is done in epygram *__init__.py*.
usermodules = []
# usercolormaps should also remain empty here
#: In userconfig, this should be a dict whose keys are the colormap name and
#: values the source absolute path of the colormap definition;
#: e.g. {'aspect', '/home/mary/.epygram/aspect.cmap'}.
usercolormaps = {}



### OVERWRITE WITH USER CONFIG ###
if os.path.exists(userconfigfile):
    userconfig = imp.load_source('userconfig', userconfigfile)
    from userconfig import *
    del userconfig
#: colormaps gathers epygram and user colormaps
colormaps = epygram_colormaps.copy()
colormaps.update(usercolormaps)



### FURTHER INITIALIZATIONS ###
if hide_footprints_warnings:
    footprints.logger.setLevel(footprints.loggers.logging.ERROR)
# epygram workdir
if len(tempdir) > 70:
    raise epygramError("'tempdir' must not exceed 70 characters, because of FA/LFI constraints on filenames.") 
tempfile.tempdir = tempdir
if not os.path.exists(tempdir):
    os.mkdir(tempdir)
    
if default_projtool == 'pyproj':
    #: Default geoid (case *pyproj*)
    default_geoid = pyproj_default_geoid
    #: FA default geoid (case *pyproj*)
    FA_default_geoid = FA_geoid_for_pyproj
elif default_projtool == 'myproj':
    #: Default geoid (case *myproj*)
    default_geoid = myproj_default_geoid
    #: FA default geoid (case *myproj*)
    FA_default_geoid = myproj_default_geoid