Package gavo :: Package rscdef :: Module rmkfuncs
[frames] | no frames]

Module rmkfuncs

source code

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?

Classes
  IgnoreThisRow
can be raised by user code to indicate that a row should be skipped when building a table.
Functions
 
addCartesian(result, alpha, delta)
inserts c_x, c_y, and c_z for the equatorial position alpha, delta into result.
source code
 
combinePMs(result, pma, pmd)
inserts pm_total (in degs/yr) and pm_posang (in degs, east over north) into result.
source code
 
getQueryMeta()
returns a query meta object from somewhere up the stack.
source code
 
parseTime(literal, format='%H:%M:%S')
returns a ``datetime.timedelta`` object for literal parsed according to format.
source code
 
parseDate(literal, format='%Y-%m-%d')
returns a ``datetime.date`` object of literal parsed according to the strptime-similar format.
source code
 
parseTimestamp(literal, format='%Y-%m-%dT%H:%M:%S')
returns a ``datetime.datetime`` object from a literal parsed according to the strptime-similar format.
source code
 
toMJD(literal)
returns a modified julian date made from some datetime representation.
source code
 
makeTimestamp(date, time)
makes a datetime instance from a date and a time.
source code
 
parseAngle(literal, format, sepChar=None)
converts the various forms angles might be encountered to degrees.
source code
 
computeMean(val1, val2)
returns the mean value between two values.
source code
 
killBlanks(literal)
returns the string literal with all blanks removed.
source code
 
lastSourceElements(path, numElements)
returns a path made up from the last ``numElements`` items in ``path``.
source code
 
scale(val, factor, offset=0)
returns val*factor+offset if val is not None, None otherwise.
source code
 
parseWithNull(literal, baseParser, nullLiteral=<Undefined>, default=None, checker=None)
returns default if literal is ``nullLiteral``, else ``baseParser(literal)``.
source code
 
getHTTPPar(inputData, parser, single=False, forceUnique=False, parName='?')
returns a parsed value from inputData.
source code
 
requireValue(val, fieldName)
returns ``val`` unless it is ``None``, in which case a ``ValidationError`` for ``fieldName`` will be raised.
source code
 
genLimitKeys(inputKey)
yields _MAX and _MIN inputKeys from a single input key.
source code
 
getFlatName(accref)
returns a unix-compatible file name for an access reference.
source code
 
addProcDefObject(name, func) source code
 
makeProc(funcName, code, setupCode, parent, **moreNames)
compiles a function in the rmkfunc's namespace.
source code
Variables
  DEG_MAS = 2.77777777778e-07
  DEG_ARCSEC = 0.000277777777778
  __package__ = 'gavo.rscdef'
Function Details

addCartesian(result, alpha, delta)

source code 

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); str(r["c_x"]), str(r["c_y"])
('0.784885567221', '0.365998150771')

combinePMs(result, pma, pmd)

source code 

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.

getQueryMeta()

source code 

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"].

Decorators:
  • @utils.document

parseTime(literal, format='%H:%M:%S')

source code 

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(1, 3530)
>>> parseTime("23.4", "!!decimalHours")
datetime.timedelta(0, 84240)
>>> parseTime("3.4:5", "%H.%M:%S")
datetime.timedelta(0, 11045)
>>> parseTime("20:04", "%H:%M")
datetime.timedelta(0, 72240)
Decorators:
  • @utils.document

parseDate(literal, format='%Y-%m-%d')

source code 

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).

Decorators:
  • @utils.document

parseTimestamp(literal, format='%Y-%m-%dT%H:%M:%S')

source code 

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)

Decorators:
  • @utils.document

toMJD(literal)

source code 

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.

Decorators:
  • @utils.document

makeTimestamp(date, time)

source code 

makes a datetime instance from a date and a time.

Decorators:
  • @utils.document

parseAngle(literal, format, sepChar=None)

source code 

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.

>>> str(parseAngle("23 59 59.95", "hms"))
'359.999791667'
>>> "%10.5f"%parseAngle("-20:31:05.12", "dms", sepChar=":")
' -20.51809'
>>> "%010.6f"%parseAngle("21.0209556", "fracHour")
'315.314334'
Decorators:
  • @utils.document

computeMean(val1, val2)

source code 

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)
Decorators:
  • @utils.document

killBlanks(literal)

source code 

returns the string literal with all blanks removed.

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

Nones are passed through.

Decorators:
  • @utils.document

lastSourceElements(path, numElements)

source code 

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

Decorators:
  • @utils.document

scale(val, factor, offset=0)

source code 

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.

Decorators:
  • @utils.document

parseWithNull(literal, baseParser, nullLiteral=<Undefined>, default=None, checker=None)

source code 

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")
8888.0
>>> print(parseWithNull("8888", float, "8888"))
None
>>> print(parseWithNull("N/A", int, "N/A"))
None
Decorators:
  • @utils.document

getHTTPPar(inputData, parser, single=False, forceUnique=False, parName='?')

source code 

returns a parsed value from inputData.

Deprecated. Should no longer be necessary with 1.0-style input processing where you have guaranteed multiplicities after the contextGrammar, and contextGrammars are reasonably cheap to use.

inputData may be

* None -- the function will return None * an empty list -- the function will return None * a value other than a list -- as if it were a list of length 1 * a list -- the function will return a list of parsed items

This is of conveniently and robustly pulling out data from stuff coming out of inputKeys without multiplicity.

If you pass single=True, you'll get exactly one value (or None). The value will be the first one from a sequence.

If you pass forceUnique=True, a MultiplicityError will be raised if inputData is longer than one.

requireValue(val, fieldName)

source code 

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

Decorators:
  • @utils.document

genLimitKeys(inputKey)

source code 

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.

getFlatName(accref)

source code 

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.

Decorators:
  • @utils.document

makeProc(funcName, code, setupCode, parent, **moreNames)

source code 

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.