gavo.rscdef.rmkfuncs module¶
Functions available to rowmaker procs.
Rowmaker procs are compiled in the namespace defined by this module.
- exception gavo.rscdef.rmkfuncs.IgnoreThisRow[source]¶
Bases:
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.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) 2.0 >>> computeMean(datetime.datetime(2000, 10, 13), ... datetime.datetime(2000, 10, 12)) datetime.datetime(2000, 10, 12, 12, 0)
- gavo.rscdef.rmkfuncs.genLimitKeys(inputKey)[source]¶
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.
- gavo.rscdef.rmkfuncs.getFlatName(accref)[source]¶
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.
- gavo.rscdef.rmkfuncs.getQueryMeta()[source]¶
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”].
- gavo.rscdef.rmkfuncs.killBlanks(literal)[source]¶
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 inpath
.
- 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")) '359.99979167' >>> "%10.5f"%parseAngle("-20:31:05.12", "dms", sepChar=":") ' -20.51809' >>> "%010.6f"%parseAngle("21.0209556", "fracHour") '315.314334'
- gavo.rscdef.rmkfuncs.parseDate(literal, format='%Y-%m-%d')[source]¶
returns a
datetime.date
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") datetime.timedelta(seconds=84240) >>> parseTime("3.4:5", "%H.%M:%S") datetime.timedelta(seconds=11045) >>> parseTime("20:04", "%H:%M") datetime.timedelta(seconds=72240)
- 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
, elsebaseParser(literal)
.If
checker
is non-None, it must be a callable returningTrue
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, anullExcs
attribute on a rowmakermap
element is the more elegant way:>>> parseWithNull("8888.0", float, "8888") 8888.0 >>> print(parseWithNull("8888", float, "8888")) None >>> print(parseWithNull("N/A", int, "N/A")) None
- gavo.rscdef.rmkfuncs.requireValue(val, fieldName)[source]¶
returns
val
unless it isNone
, in which case aValidationError
forfieldName
will be raised.