epygram.util — Utilities

Some useful utilities...


epygram.util.find_re_in_list(regexp, a_list)[source]

Finds all elements from a list that match a regular expression. The regexp and the different elements of the list must be of the same type:

  • strings
  • tuples with the same length
  • dictionnaries: all regexp keys must be keys of the list
epygram.util.degrees_nearest_mod(d, ref)[source]

Returns the angle(s) d in the modulo nearest to ref.

epygram.util.positive_longitude(lon, unit='degrees')

Returns lon shifted in [0;360[ or [0;2pi[ (depending on unit).


Creates a custom Colormap from a set of RGB colors in a file with the following formating:





each value being comprised between 0 and 255 e.g. coming from http://colormap.org.


Reads and registers the epygram-or-user-colormap called cmap, which must be either in config.epygram_colormaps or config.usercolormaps.

epygram.util.printstatus(step, end, refresh_freq=1)

Print percentage of the loop it is in, with ‘step’ being the current loopstep, ‘end’ the final loopstep and ‘refresh_freq’ the frequency in % at which reprinting status.


Reads a .csv file as a list of dict, with the assumption: - on first line is described the delimiter - on second line is described the ‘priority’ of the dict.

epygram.util.gfl2R(q, ql=0.0, qi=0.0, qr=0.0, qs=0.0, qg=0.0)

Computes air specific gas constant R according to specific humidity, and hydrometeors if present.

epygram.util.write_formatted(dest, label, value, align='<', firstcolumn_width=50, secondcolumn_width=16)
epygram.util.write_formatted_fields(dest, label, value=None, compression=None, firstcolumn_width=50, secondcolumn_width=16)
epygram.util.write_formatted_dict(dest, fid)
epygram.util.write_formatted_table(dest, table, alignments=['<', '^'], precision=6, float_type='E')

A table is meant to be : <str> <str> <str> ... <str> <num> <num> ...

... ... ... ...
epygram.util.linearize(s, quotes=False)

Returns string s linearized, i.e. without special characters that may be forbidden in filenames. - quotes: must we also remove quotes?

epygram.util.linearize2str(o, quotes=False)

Returns str(o) linearized (cf. util.linearized).


Creates a datetime.datetime from a string or int YYYYMMDDHHMMSS...

epygram.util.add_meridians_and_parallels_to(bm, meridians='auto', parallels='auto')

Adds meridians and parallels to a basemap instance bm.

meridians and parallels enable to fine-tune the choice of lines to plot, with either:

  • ‘auto’: automatic scaling to the basemap extents
  • ‘default’: range(0,360,10) and range(-90,90,10)
  • a list of values
  • a grid step, e.g. 5 to plot each 5 degree.
  • None: no one is plot
  • meridian == ‘greenwich’ // ‘datechange’ // ‘greenwich+datechange’ parallel == ‘equator’ // ‘polarcircles’ // ‘tropics’ or any combination (+) will plot only these.
epygram.util.nearlyEqual(a, b, epsilon=2.220446049250313e-16)

Function to compare floats http://floating-point-gui.de/errors/comparison/ Float.MIN_NORMAL was replaced by sys.float_info.min Float.MAX_VALUE was replaced by sys.float_info.max

epygram.util.nearlyEqualArray(pyfunc, otypes='', doc=None, excluded=None, cache=False)

Function to compare floats http://floating-point-gui.de/errors/comparison/ Float.MIN_NORMAL was replaced by sys.float_info.min Float.MAX_VALUE was replaced by sys.float_info.max

epygram.util.parse_str2dict(string, try_convert=None)

Parse a string (of syntax ‘key1:value1,key2=value2’) to a dict. If try_convert is not None, try to convert values as type try_convert.


Return array.flatten() or compressed(), whether the array is masked or not.


class epygram.util.RecursiveObject[source]

Bases: object

Generic abstract class implementing useful recursive properties:

  • display of object: the __str__ method returns str(attr) for each of the object’s attributes, with automatical indentation for readability.
  • test of (in)equality: the a == b test will be true if a and b have the same attributes and a.attr == b.attr for each attribute.

Returns a copy of the object.


Returns a deepcopy of the object.

class epygram.util.Angle(value, unit)[source]

Bases: epygram.util.RecursiveObject

This class handles an angle. It enables conversions of units, while saving the original unit and value of the angle at its construction.

Available units: ‘degrees’, ‘radians’, ‘cos_sin’ (cos, sin),
‘DMS’ (Degree, Minutes, Seconds).

Returns the angle in the requested unit. If no unit is supplied, the origin unit is used.

Table Of Contents

Previous topic

epygram.config — Configuration: parameters, options

Next topic

epygram.base — Basic, non-specific classes

This Page