gavo.utils.pgsphere module¶
Bindings for the pgsphere library and psycopg2.
Basically, once per program run, you need to call preparePgSphere(connection), and you’re done.
All native representation is in rad.

class
gavo.utils.pgsphere.
PgSAdapter
[source]¶ Bases:
object
A base class for objects adapting pgSphere objects.
The all need a pgType attribute and two static methods
_adaptToPgSphere(obj)
and_castFromPgSphere(value, cursor)
.You must also define a sequence checkedAttributes; all attributes mentioned there must be equal for two adapted values to be equal (equality testing here really is mainly for unit tests with handcrafted values).
Also, all subclasses you should provide an asPoly returning a spherical polygon. This is used when uploading VOTables with REGION columns.
In practice, you also want:
 FromDALI(cls, daliSeq)
a classmethod turning the DALI votable representation (typically, float arrays in degrees) into a corresponding object.
 AsDALI(self)
the inverse of fromDALI
 AsSODA(self)
returns a representation of the geometry as used in SODA parameters.

asSODA
()[source]¶ returns the “SODAform” for this circle.
This is a string containing blankseparated float literals; the floats are what asDALI returns, and hence this is built on top of asDALI. We don’t worry about the fact that the coordinates just might be nonICRS.

pgType
= None¶

class
gavo.utils.pgsphere.
SBox
(corner1, corner2)[source]¶ Bases:
gavo.utils.pgsphere.PgSAdapter
A spherical box from pgSphere.
The constructor accepts the two corner points.

checkedAttributes
= ['corner1', 'corner2']¶

classmethod
fromSIAPPars
(ra, dec, raSize, decSize)[source]¶ returns an SBox corresponding to what SIAP passes in.
In particular, all values are in degrees, and a cartesian projection is assumed.
This is for use with SIAP and tries to partially implement that silly prescription of “folding” over at the poles. If that happens, a TwoSBoxes exception is raised. It contains two SBoxes that should be ORed. I agree that sucks. Let’s fix SIAP.

pattern
= re.compile('\\([^()]+\\)')¶

pgType
= 'sbox'¶


class
gavo.utils.pgsphere.
SCircle
(center, radius)[source]¶ Bases:
gavo.utils.pgsphere.PgSAdapter
A spherical circle from pgSphere.
The constructor accepts an SPoint center and a radius in rad.

asDALI
()[source]¶ returns the “DALIform” for this circle.
This is an array containing the center coordinates and the radius in degrees.

asSMoc
(order=6, inclusive=False)[source]¶ returns an SMoc instance for this circle.
order is the maximum order of the moc returned.

checkedAttributes
= ['center', 'radius']¶

classmethod
fromDALI
(daliSeq)[source]¶ returns a circle from its DALI float sequence.
Any None in daliSeq makes this a None to help with VOTable null value handling.

classmethod
fromPointSet
(points)[source]¶ returns an SCircle covering all the SPoints in points.
(max radius: pi/2).

pattern
= re.compile('<(\\([^)]*\\))\\s*,\\s*([09.e]+)>')¶

pgType
= 'scircle'¶


class
gavo.utils.pgsphere.
SMoc
(moc)[source]¶ Bases:
gavo.utils.pgsphere.PgSAdapter
a MOC with a pgsphere interface.
The default constructor accepts a pymoc.MOC instance, which is accessible as the moc attribute. The database interface uses the ASCII serialisation, for which there’s the fromASCII constructor.

asDALI
()[source]¶ returns the string representation of this MOC.
This isn’t what DALI actually says at this point, but we suspect it will say that at some point.

checkedAttributes
= ['moc']¶

classmethod
fromCells
(order, pixels, maxOrder=None)[source]¶ returns a SMoc instance from a collection of pixels at order.
Pass maxOrder to set an explicit max order for the resulting MOC.

classmethod
fromFITS
(literal)[source]¶ returns an SMoc from a string containing a FITSserialised MOC.

property
maxOrder
¶

pgType
= 'smoc'¶


class
gavo.utils.pgsphere.
SPoint
(x, y)[source]¶ Bases:
gavo.utils.pgsphere.PgSAdapter
A point on a sphere from pgSphere.
>>> SPoint(1, 1).asSTCS("ICRS") 'Position ICRS 57.2957795131 57.2957795131' >>> SPoint.fromDegrees(1, 1).asSTCS("ICRS") 'Position ICRS 1. 1.'

checkedAttributes
= ['x', 'y']¶

pattern
= re.compile('\\s*\\(\\s*([09.eNa]+)\\s*,\\s*([09.eNa]+)\\s*\\)')¶

pgType
= 'spoint'¶


class
gavo.utils.pgsphere.
SPoly
(points)[source]¶ Bases:
gavo.utils.pgsphere.PgSAdapter
A spherical polygon from pgSphere.
The constructor accepts a list points of SPoints.

asCooPairs
()[source]¶ returns the vertices as a sequence of (long, lat) pairs in degrees.
This form is required by some functions from base.coords.

asDALI
()[source]¶ returns the DALI form of this polygon.
This is a sequence of floats of the vertex coordinates in degrees.

asSMoc
(order=6, inclusive=False)[source]¶ returns an SMoc instance for this polygon.
order is the maximum order of the moc returned.

checkedAttributes
= ['points']¶

classmethod
fromDALI
(daliSeq)[source]¶ returns a polygon from a DALI floatsequence
This returns None for empty daliSeqs to help with VOTable NULL value handling.

getCenter
()[source]¶ returns an estimate for some sort of center of this polygon.
This is computed as the mean of the vertices (in unit sphere representation), which, depending on the polygon, may be very far from the polygon’s center of mass. Also, you can kill this by having all points sit on a great circle, etc.
So: handle with care. Doing this properly is hard.

pattern
= re.compile('\\([^)]+\\)')¶

pgType
= 'spoly'¶


exception
gavo.utils.pgsphere.
TwoSBoxes
(box1, box2)[source]¶ Bases:
gavo.utils.excs.ExecutiveAction
is raised when an SBox is constructed from center and size such that it overlaps the pole.