33
44It also imports a few functions from other modules, and declares a number of 'CliMAF standard operators'
55
6- Main functions are ``dataloc``, ``ds``, ``cdataset``, ``cdef``, ``cscript``, ``cfile``, ``cMA`` :
6+ Main functions are :
7+
8+ - for data definition and access :
9+
10+ - ``cproject``: declare a project and its non-standard attributes/facets
11+
712 - ``dataloc`` : set data locations for a series of experiments
13+
814 - ``cdef`` : define some default values for datasets attributes
9- - ``ds`` : define a dataset object
10- - ``cscript`` : define a new CliMAF operator (this also defines a new Pyhton fucntion)
11- - ``cfile`` : get the file value of a CliMAF object (compute it)
15+
16+ - ``ds`` : define a dataset object (actually a front-end for ``cdataset``)
17+
18+ - ``derive`` : define a variable as computed from other variables
19+
20+ - for processing the data
21+
22+ - ``cscript`` : define a new CliMAF operator (this also defines a new Python function)
23+
1224 - ``cMA`` : get the Masked Array value of a CliMAF object (compute it)
1325
26+ - for managing/viewing results :
27+
28+ - ``cfile`` : get the file value of a CliMAF object (compute it)
29+
30+ - ``cshow`` : display a result of type 'figure'
1431
15- Utility functions are ``clog``, ``cdump``, ``craz``, ``csave``:
16- - ``clog`` : tune verbosity
1732 - ``cdump`` : tell what's in cache
33+
34+ - ``cdrop`` : delete the cached file for an object
35+
1836 - ``craz`` : reset cache
19- - ``csave`` : save cache index to disk
37+
38+ - ``csync`` : save cache index to disk
39+
40+
41+ - utility functions :
42+
43+ - ``clog`` : tune verbosity
44+
45+ - ``clog_file`` : tune verbosity for log file
2046
2147"""
2248# Created : S.Senesi - 2014
2551import os , os .path , shutil , logging
2652
2753import climaf , climaf .cache
28- from climaf .classes import cdefault as cdef ,cdataset ,ds #,cperiod
29- from climaf .driver import ceval ,varOf #,cfile,cobj
54+ from climaf .classes import cdef ,cdataset ,ds , cproject , cprojects
55+ from climaf .driver import ceval ,varOf
3056from climaf .dataloc import dataloc
3157from climaf .operators import cscript , scripts as cscripts , derive
32- from climaf .cache import creset as craz , csync as csave , cdump , cdrop
58+ from climaf .cache import craz , csync as csave , cdump , cdrop
3359from clogging import clogger , clog , clog_file
3460import climaf .standard_operators
61+ import climaf .standard_projects
62+
63+ #########################
64+ # CliMAF init phase
65+ #########################
66+
67+ Climaf_version = "0.5"
3568
36- clog (logging .ERROR )
37- clog_file (logging .ERROR )
3869#: Path for the CliMAF package. From here, can write e.g. ``cpath+"../scripts"``. The value shown in the doc is not meaningful for your own CliMAF install
3970cpath = os .path .abspath (climaf .__path__ [0 ])
40- climaf .cache .setNewUniqueCache ("~/tmp/climaf_cache" )
71+
72+ # Set default logging levels
73+ clog (os .getenv ("CLIMAF_LOG_LEVEL" ,"error" ))
74+ clog_file (os .getenv ("CLIMAF_LOGFILE_LEVEL" ,"info" ))
75+
4176climaf .standard_operators .load_standard_operators ()
77+ climaf .standard_projects .init_standard_projects ()
78+ from climaf .site_settings import onCiclad , atCNRM
79+
80+ # Read user config file
81+ conf_file = os .path .expanduser ("~/.climaf" )
82+ if os .path .isfile (conf_file ) : execfile (conf_file , {"Climaf_version" :Climaf_version })
83+
84+ # Decide for cache location
85+ climaf .cache .setNewUniqueCache (os .getenv ("CLIMAF_CACHE" ,"~/tmp/climaf_cache" ))
86+
4287
88+ #########################
4389# Commodity functions
90+ #########################
91+
4492def cfile (object ,target = None ,ln = None ,deep = None ) :
4593 """
4694 Provide the filename for a CliMAF object, or copy this file to target. Launch computation if needed.
@@ -49,21 +97,28 @@ def cfile(object,target=None,ln=None,deep=None) :
4997 object (CliMAF object) : either a dataset or a 'compound' object (e.g. the result of a CliMAF operator)
5098 target (str, optional) : name of the destination file or link; CliMAF will anyway store the result
5199 in its cache;
100+
52101 ln (logical, optional) : if True, target is created as a symlink to the CLiMAF cache file
53- deep (logical, optional) : governs the use of cached values when computing the object
102+
103+ deep (logical, optional) : governs the use of cached values when computing the object:
54104
55105 - if missing, or None : use cache as much as possible (speed up the computation)
106+
56107 - False : make a shallow computation, i.e. do not use cached values for the
57108 top level operation
109+
58110 - True : make a deep computation, i.e. do not use any cached value
59111
60112 Returns:
61- - if 'target' is provided : returns this filename if computation is successful ('target' contains the result), and None otherwise;
113+
114+ - if 'target' is provided : returns this filename (or linkname) if computation is
115+ successful ('target' contains the result), and None otherwise;
116+
62117 - else : returns the filename in CliMAF cache, which contains the result (and None if failure)
63118
64119
65120 """
66- clogger .debug ("cfile called on" + str (object ))
121+ clogger .debug ("cfile called on " + str (object ))
67122 result = climaf .driver .ceval (object ,format = 'file' ,deep = deep )
68123 if target is None : return result
69124 else :
@@ -81,7 +136,7 @@ def cshow(obj) :
81136 For a figure object, this will lead to display it
82137 ( launch computation if needed. )
83138 """
84- clogger .debug ("cshow called on" + str (obj )) #LV
139+ clogger .debug ("cshow called on " + str (obj ))
85140 return climaf .driver .ceval (obj ,format = 'MaskedArray' )
86141
87142def cMA (obj ,deep = None ) :
@@ -106,7 +161,7 @@ def cexport(*args,**kwargs) :
106161 """ Alias for climaf.driver.ceval. Create synonyms for arg 'format'
107162
108163 """
109- clogger .debug ("cexport called with arguments" + str (args )) #LV
164+ clogger .debug ("cexport called with arguments" + str (args ))
110165 if "format" in kwargs :
111166 if (kwargs ['format' ]== "NetCDF" or kwargs ['format' ]== "netcdf" or kwargs ['format' ]== "nc" ) :
112167 kwargs ['format' ]= "file"
0 commit comments