gavo.rscdef.rmkfuncs module

Functions available to rowmaker procs.

Rowmaker procs are compiled in the namespace defined by this module.

Maybe we should allow additional modules to be specified in gavorc?

exception gavo.rscdef.rmkfuncs.IgnoreThisRow[source]

Bases: gavo.utils.excs.ExecutiveAction

can be raised by user code to indicate that a row should be skipped when building a table.

Note: To skip an entire source, raise SkipThis (usually in a rowfilter or so).

Also note that the non-code way to skip things, `Triggers`_, is preferred when you don’t already use code.

gavo.rscdef.rmkfuncs.addCartesian(result, alpha, delta)[source]

inserts c_x, c_y, and c_z for the equatorial position alpha, delta into result.

c_x, c_y, and c_z are the cartesian coordinates of the intersection point of the radius vector of alpha, delta with the unit sphere.

alpha and delta already have to be floats, so you probably want to use variables here.

>>> r = {}; addCartesian(r, 25, 30); "%.7f %.7f"%(r["c_x"], r["c_y"])
'0.7848856 0.3659982'
gavo.rscdef.rmkfuncs.addProcDefObject(name, func)[source]
gavo.rscdef.rmkfuncs.combinePMs(result, pma, pmd)[source]

inserts pm_total (in degs/yr) and pm_posang (in degs, east over north) into result.

pma and pmd have to be in degs/yr, with cos(delta) applied to pma.

gavo.rscdef.rmkfuncs.computeMean(val1, val2)[source]

returns the mean value between two values.

Beware: Integer division done here for the benefit of datetime calculations.

>>> computeMean(1.,3)
>>> computeMean(datetime.datetime(2000, 10, 13), 
...   datetime.datetime(2000, 10, 12))
datetime.datetime(2000, 10, 12, 12, 0)

yields _MAX and _MIN inputKeys from a single input key.

This also tries to sensibly fix descriptions and ucds. This is mainly for datalink metaMakers; condDescs may use a similar thing, but that’s not exposed to RDs.

Don’t use this function any more. It will go away soon.


returns a unix-compatible file name for an access reference.

The file name will not contain terrible characters, let alone slashes. This is used to, e.g., keep all previews in one directory.


returns a query meta object from somewhere up the stack.

This is for row makers running within a service. This can be used to, e.g., enforce match limits by writing getQueryMeta()[“dbLimit”].


returns the string literal with all blanks removed.

This is useful when numbers are formatted with blanks thrown in.

Nones are passed through.

gavo.rscdef.rmkfuncs.lastSourceElements(path, numElements)[source]

returns a path made up from the last numElements items in path.

gavo.rscdef.rmkfuncs.makeProc(funcName, code, setupCode, parent, **moreNames)[source]

compiles a function in the rmkfunc’s namespace.

code is a complete function source. setupCode is executed right away in this namespace to add globals.

gavo.rscdef.rmkfuncs.makeTimestamp(date, time)[source]

makes a datetime instance from a date and a time.

gavo.rscdef.rmkfuncs.parseAngle(literal, format, sepChar=None)[source]

converts the various forms angles might be encountered to degrees.

format is one of hms, dms, fracHour. For sexagesimal/time angles, you can pass a sepChar (default: split at blanks) that lets you specify what separates hours/degrees, minutes, and seconds.

>>> "%.8f"%(parseAngle("23 59 59.95", "hms"))
>>> "%10.5f"%parseAngle("-20:31:05.12", "dms", sepChar=":")
' -20.51809'
>>> "%010.6f"%parseAngle("21.0209556", "fracHour")
gavo.rscdef.rmkfuncs.parseDate(literal, format='%Y-%m-%d')[source]

returns a object of literal parsed according to the strptime-similar format.

The function understands the special dateFormat !!jYear (stuff like 1980.89).

gavo.rscdef.rmkfuncs.parseTime(literal, format='%H:%M:%S')[source]

returns a datetime.timedelta object for literal parsed according to format.

For format, you can the magic values !!secondsSinceMidnight, !!decimalHours or a strptime-like spec using the H, M, and S codes.

>>> parseTime("89930", "!!secondsSinceMidnight")
datetime.timedelta(days=1, seconds=3530)
>>> parseTime("23.4", "!!decimalHours")
>>> parseTime("3.4:5", "%H.%M:%S")
>>> parseTime("20:04", "%H:%M")
gavo.rscdef.rmkfuncs.parseTimestamp(literal, format='%Y-%m-%dT%H:%M:%S')[source]

returns a datetime.datetime object from a literal parsed according to the strptime-similar format.

A ValueError is raised if literal doesn’t match format (actually, a parse with essentially DALI-standard ISO representation is always tried)

gavo.rscdef.rmkfuncs.parseWithNull(literal, baseParser, nullLiteral=<Undefined>, default=None, checker=None)[source]

returns default if literal is nullLiteral, else baseParser(literal).

If checker is non-None, it must be a callable returning True if its argument is a null value.

nullLiteral is compared against the unprocessed literal (usually, a string). The intended use is like this (but note that often, a nullExcs attribute on a rowmaker map element is the more elegant way:

>>> parseWithNull("8888.0", float, "8888")
>>> print(parseWithNull("8888", float, "8888"))
>>> print(parseWithNull("N/A", int, "N/A"))
gavo.rscdef.rmkfuncs.requireValue(val, fieldName)[source]

returns val unless it is None, in which case a ValidationError for fieldName will be raised.

gavo.rscdef.rmkfuncs.scale(val, factor, offset=0)[source]

returns val*factor+offset if val is not None, None otherwise.

This is when you want to manipulate a numeric value that may be NULL. It is a somewhat safer alternative to using nullExcs with scaled values.


returns a modified julian date made from some datetime representation.

Valid representations include:

  • MJD (a float smaller than 1e6)

  • JD (a float larger than 1e6)

  • datetime.datetime instances

  • ISO time strings.