There are a few functions for managing CliMAF results
Provide the filename for a CliMAF object, or copy this file to target. Launch computation if needed.
Parameters: |
|
---|---|
Returns: |
|
Create a single file for an ensemble of CliMAF objects (launch computation if needed).
This is a convenience function. Such files are not handled in CliMAF cache
Parameters: |
|
---|
Provide the Masked Array value for a CliMAF object. Launch computation if needed.
Parameters: |
|
---|---|
Returns: | a Masked Array containing the object’s value |
Return the value of the array for an object, after MV flattening, at a given index
Example
>>> data=ds(project='mine',variable='tas', ...)
>>> data1=time_average(data)
>>> data2=space_average(data1)
>>> v=cvalue(data2)
Does use the file representation of the object
Builds a CliMAF cpage object, which represents an array of figures (output: ‘png’ or ‘pdf’ figure)
Parameters: |
|
---|
If title is activated:
- x, y (int, optional): annotate the page with text. x is the offset towards the right from the upper left corner of the page, while y is the offset upward or the bottom according to the optional argument ‘gravity’ (i.e. ‘South’ or ‘North’ respectively); CLiMAF default: x=0, y=26. For more details, see: http://www.imagemagick.org/script/command-line-options.php?#annotate ; where x and y correspond respectively to tx and ty in -annotate {+-}tx{+-}ty text
- ybox (int, optional): width of the assigned box for title; CLiMAF default: 50. For more details, see: http://www.imagemagick.org/script/command-line-options.php?#splice
- pt (int, optional): font size of the title; CLiMAF default: 24
- font (str, optional): set the font to use when creating title; CLiMAF default: ‘Times-New-Roman’. To print a complete list of fonts, use: ‘convert -list font’
- gravity (str, optional): the choosen direction specifies where to position title; CLiMAF default: ‘North’. For more details, see: http://www.imagemagick.org/script/command-line-options.php?#gravity
- background (str, optional): background color of the assigned box for title; default: ‘white’. To print a complete list of color names, use: ‘convert -list color’
Example
Using no default value, to create a page with 2 columns and 3 lines:
>>> tas_ds=ds(project='example',simulation='AMIPV6ALB2G', variable='tas', period='1980-1981')
>>> tas_avg=time_average(tas_ds)
>>> fig=plot(tas_avg,title='title')
>>> my_page=cpage([[None, fig],[fig, fig],[fig,fig]], widths=[0.2,0.8],
... heights=[0.33,0.33,0.33], fig_trim=False, page_trim=False,
... format='pdf', title='Page title', x=10, y=20, ybox=45,
... pt=20, font='Utopia', gravity='South', background='grey90',
... page_width=1600., page_height=2400.)
Builds a CliMAF cpage_pdf object, which represents an array of figures (output: ‘pdf’ figure). Figures are automatically centered in the page using ‘pdfjam’ tool; see http://www2.warwick.ac.uk/fac/sci/statistics/staff/academic-research/firth/software/pdfjam
Parameters: |
|
---|
If title is activated, it is by default horizontally centered:
- x (int, optional): title horizontal shift (in cm).
- y (int, optional): vertical shift from the top of the page (in cm); only positive (down) values have an effect, default=2 cm
- titlebox (logical, optional): set it to True to frame the text in a box, frame color is ‘black’
- pt (str, optional): title font size; CLiMAF default: ‘Huge’ (corresponding to 24 pt). You can set or not a backslash before this argument.
- font (str, optional): font abbreviation among available LaTex fonts; default: ‘\\familydefault’.
- background (str, optional): frame fill background color; among LaTex ‘fcolorbox’ colors; default: ‘white’.
Left and right margins are set to 2cm.
Example
Using no default value, to create a PDF page with 2 columns and 3 lines:
>>> tas_ds=ds(project='example',simulation='AMIPV6ALB2G', variable='tas', period='1980-1981')
>>> tas_avg=time_average(tas_ds)
>>> fig=plot(tas_avg,title='title',format='pdf')
>>> crop_fig=cpdfcrop(fig)
>>> my_pdfpage=cpage_pdf([[crop_fig,crop_fig],[crop_fig, crop_fig],[crop_fig,crop_fig]],
... widths=[0.2,0.8], heights=[0.33,0.33,0.33], page_width=800., page_height=1200.,
... scale=0.95, openright=True, title='Page title', x=-5, y=10, titlebox=True,
... pt='huge', font='ptm', background='yellow') # Font name is 'Times'
CliMAF module html defines functions for building some html index giving acces to figure files, through links bearing a label or through thumbnails. It eases iterating over lines and columns in tables.
See a code example in index_html.py
or a screen dump for a similar code here
Returns text for an html document header, with provided title. If a style filename is not provided, a default style sheet will apply
Returns text for a section header in an html document with given title. Style depends on level value. Arg key is not yet used
Returns header text for an html table. title will go as title for first column. columns should be a list of column titles
Create an html line with labels and links from first args list_of_pairs (and when this is not a pair, only put the label). Put a line title if provided. Replace labels with thumbnail figures if arg thumbnail is set to a size (in pixels) and display figures when you mouse over it if arg hover is set to True or to a size (in pixels); in that case, dic can also be a list of filenames. If ‘dirname’ is not None, creates hardlinks to the filenames, in directory dirname, and named as ‘climaf_atlas’([0-9]+).ext (where ‘ext’ is ‘png’, ‘pdf’ or ‘eps’). This allows to generate a portable atlas in dirname
Creates the provided label, with a link to the provided image filename (if not None) and possibly showing a thumbnail for the image (with the provided thumbnail size) and possibly displaying this image when mouse is over it (with the provided hover size).
Does the same as link() ,but for a link which is sole on its own line
Create a table cell with the provided label, which bears a link to the provided filename and possibly shows a thumbnail for the link with the provided thumbnail size (in pixels) and possibly display it when you mouse over it (with the provided hover size in pixels).
If ‘dirname’ is not None, creates a hard link in directory dirname to file filename. This allow to generate a portable atlas in this directory. Hard links are named after pattern climaf_atlas<digit>.<extension>
‘dirname’ can be a relative or absolute path, as long as filename and dirname paths are coherent
If ‘altdir’ is not None (and ‘dirname is None), the HREF links images in index have the prefix of their absolute path changed from $CLIMAF_CACHE to ‘altdir’ (use case : when the Http server only knows another filesystem). Example:
Create the html text for a line of table cells, by iterating calling a function, once per column, with at least two arguments. Cells have a label and possibly a link
So, there will be one column/cell per item in ‘sargs’; each cell shows a label which can be an active link. Both the label value and the link value can be the result of calling ‘func’ arg with the pair of arguments (‘farg’ and the running element of ‘sargs’); the function can return a single value (either a label or a figure filename) or both
Use cases :
a line showing just numeric values; we assume that function average(var,mask) returns such a numeric value, which is a gloabl average of a variable over a mask:
>>> rep=fline(average, 'tas', ... [ 'global', 'sea', 'land', 'tropics'], 'tas averages')a line showing the same average values, but each value is a link to e.g. a figure of the time series of global average values : same call, but just let function ‘average’ compute the average and the figure, and return a couple : average, figure filename
a line showing pre-defined labels, which here are shortcuts for mask names, and which carry links to same figures as above : let function ‘average’ only return the figure filename, and call :
>>> rep=fline(average, 'tas', ... {'global':'GLB','sea':'SEA','land':'LND'}, 'tas averages')
Advanced arguments :
- common_args : a list of additionnal arguments to pass to ‘func’, whatever the value of its second argument
- other_args : a dictionnary of lists of additionnal arguments to pass to ‘func’; only the entry which key equals running value of second argument is passed to ‘func’ (after common_args)
- thumbnail : if ‘func’ returns a filename, generate a thumbnail image of that size (in pixels)
- hover : if ‘func’ returns a filename, display image of that size (in pixels) when you mouse over it. If hover is True:
- hover width and height are respectively set as 3 times that of thumbnail width and height if thumbnail is not None
- hover is set to ‘200*200’ if thumbnail is None
- dirname : if ‘func’ returns a filename, creates a directory (if doesn’t exist) wich contains filename as a hard link to the target dirname/’climaf_atlas’([0-9]+).ext (‘ext’ is ‘png’, ‘pdf’ or ‘eps’)
See doc for fline() first
Creates a table by iterating calling fline over ‘fargs’ (which can be a list or a dict) with :
It forwards remaining keyword arguments (kwargs) to fline()
Example : assuming that function avg returns the filename for a figure showing the average value of a variable over a mask, create a table of links for average values of two variables over two masks, with thumbnail of images and displaying images when you mouse over it with ‘hover’ argument:
>>> t=table_lines(avg,['tas','tos'],['land','sea'],thumbnail=40,hover='60x80')
Internal function used by its front-ends : cls(), crm(), cdu(), cwc()
List the content of CliMAF cache according to some search criteria and operate possibly an action (usage, count or remove) on this list.
Please consider the cost and benefit of first updating CliMAF cache index (by scanning files on disk) using csync()
Parameters: |
|
---|---|
Returns: |
|
Remove the cache files found by ‘clist()’ when using same arguments. See clist()
Example to remove files using more than 3M of disk space, which status was last changed more than 15 days ago and containing the pattern ‘1980-1981’ either in crs or filename:
>>> crm(size='3M', age='+15', pattern='1980-1981')
Report disk usage, for files matching some criteria, as specified for clist(). With count=True, report only total disk usage.
Example to search files using more than 3M of disk space, which status was last changed more than 15 days ago and containing the pattern ‘1980-1981’ either in crs or filename. For found files, we want to estimate only found files total space usage:
>>> cdu(size='3M', age='+15', pattern= '1980-1981', count=True)
Report number of cache files matching some criteria, as specified for clist(). If CRS is True, also return CRS expression of found files.
Example to return the number and crs associated of files using more than 3M of disk space, which status was last changed more than 15 days ago and containing the pattern ‘1980-1981’ either in crs or filename:
>>> cwc(size='3M', age='+15', pattern= '1980-1981', CRS=True)
Deletes the cached file for a CliMAF object, if it exists
Parameters: |
|
---|---|
Returns: | None if object does not exists, False if failing to delete, True if OK |
Example
>>> dg=ds(project='example', simulation='AMIPV6ALB2G', variable='tas', period='1980-1981')
>>> f=cfile(dg)
>>> os.system('ls -al '+f)
>>> cdrop(dg)