Package gavo :: Package base :: Module coords
[frames] | no frames]

Module coords

source code

(Mostly deprecated) code to handle coordinate systems and transform between them.

Basically all of this should be taken over by stc and astropysics.

Classes
  Box
is a 2D box.
  Vector3
is a 3d vector that responds to both .x...
Functions
 
makePyfitsFromDict(d)
returns a pyfits header with the cards of d.items().
source code
 
getBbox(points)
returns a bounding box for the sequence of 2-sequences points.
source code
 
clampAlpha(alpha) source code
 
clampDelta(delta) source code
 
straddlesStitchingLine(minRA, maxRA)
returns true if something bordered by minRA and maxRA presumably straddles the stitching line.
source code
 
getWCS(wcsFields, naxis=(1, 2), relax=True)
returns a WCS instance from wcsFields
source code
 
pix2foc(wcsFields, pixels)
returns the focal plane coordindates for the 2-sequence pixels.
source code
 
pix2sky(wcsFields, pixels)
returns the sky coordindates for the 2-sequence pixels.
source code
 
sky2pix(wcsFields, longLat)
returns the pixel coordindates for the 2-sequence longLad.
source code
 
getPixelSizeDeg(wcsFields)
returns the sizes of a pixel at roughly the center of the image for wcsFields.
source code
 
getWCSTrafo(wcsFields)
returns a callable transforming pixel to physical coordinates.
source code
 
getInvWCSTrafo(wcsFields)
returns a callable transforming physical to pixel coordinates.
source code
 
getBboxFromWCSFields(wcsFields)
returns a bbox and a field center for WCS FITS header fields.
source code
 
getSpolyFromWCSFields(wcsFields)
returns a pgsphere spoly corresponding to wcsFields
source code
 
getCenterFromWCSFields(wcsFields, spatialAxes=(1, 2))
returns RA and Dec of the center of an image described by wcsFields.
source code
 
getCoveringCircle(wcsFields, spatialAxes=(1, 2))
returns a pgsphere.scircle large enough to cover the image described by wcsFields.
source code
 
getSkyWCS(hdr)
returns a pair of a wcs.WCS instance and a sequence of the spatial axes.
source code
 
getPixelLimits(cooPairs, wcsFields)
returns pixel cutout slices for covering cooPairs in an image with wcsFields.
source code
 
sgn(a) source code
 
computeUnitSphereCoords(alpha, delta)
returns the 3d coordinates of the intersection of the direction vector given by the spherical coordinates alpha and delta with the unit sphere.
source code
 
dirVecToCelCoos(dirVec)
returns alpha, delta in degrees for the direction vector dirVec.
source code
 
getTangentialUnits(cPos)
returns the unit vectors for RA and Dec at the unit circle position cPos.
source code
 
movePm(alphaDeg, deltaDeg, pmAlpha, pmDelta, timeDiff, foreshort=0)
returns alpha and delta for an object with pm pmAlpha after timeDiff.
source code
 
getGCDist(pos1, pos2)
returns the distance along a great circle between two points.
source code
Variables
  wcs = <gavo.utils.codetricks.DeferredImport object>
  fitsKwPat = re.compile(r'[A-Z0-9_-]{1,8}$')
  __package__ = 'gavo.base'
Function Details

makePyfitsFromDict(d)

source code 

returns a pyfits header with the cards of d.items().

Only keys "looking like" FITS header keywords are used, i.e. all-uppercase and shorter than 9 characters.

getBbox(points)

source code 

returns a bounding box for the sequence of 2-sequences points.

The thing returned is a coords.Box.

>>> getBbox([(0.25, 1), (-3.75, 1), (-2, 4)])
Box((0.25,4), (-3.75,1))

straddlesStitchingLine(minRA, maxRA)

source code 

returns true if something bordered by minRA and maxRA presumably straddles the stitching line.

This assumes minRA<maxRA, and that "something" is less than 180 degrees in longitude.

Angles are in degrees here.

getWCS(wcsFields, naxis=(1, 2), relax=True)

source code 

returns a WCS instance from wcsFields

wcsFields can be either a dictionary or a pyfits header giving some kind of WCS information, or an wcs.WCS instance that is returned verbatim.

This will return None if no (usable) WCS information is found in the header.

We monkeypatch the resulting WCS structure quite a bit. Among others:

* there's longAxis and latAxis attributes taken from naxis * there's _dachs_header, containing the incoming k-v pairs * there's _monkey_naxis_length, the lengths along the WCS axes.

pix2foc(wcsFields, pixels)

source code 

returns the focal plane coordindates for the 2-sequence pixels.

(this is a thin wrapper intended to abstract for pix2world's funky calling convention; also, we fix on the silly "0 pixel is 1 convention")

pix2sky(wcsFields, pixels)

source code 

returns the sky coordindates for the 2-sequence pixels.

(this is a thin wrapper intended to abstract for pix2world's funky calling convention; also, we fix on the silly "0 pixel is 1 convention")

sky2pix(wcsFields, longLat)

source code 

returns the pixel coordindates for the 2-sequence longLad.

(this is a thin wrapper intended to abstract for world2pix's funky calling convention; also, we fix on the silly "0 pixel is 1 convention")

getPixelSizeDeg(wcsFields)

source code 

returns the sizes of a pixel at roughly the center of the image for wcsFields.

Near the pole, this gets a bit weird; we do some limitation of the width of RA pixels there.

getWCSTrafo(wcsFields)

source code 

returns a callable transforming pixel to physical coordinates.

wcsFields is passed to getWCS, see there for legal types.

getInvWCSTrafo(wcsFields)

source code 

returns a callable transforming physical to pixel coordinates.

wcsFields is passed to getWCS, see there for legal types.

getBboxFromWCSFields(wcsFields)

source code 

returns a bbox and a field center for WCS FITS header fields.

wcsFields is passed to getWCS, see there for legal types.

Warning: this is different from wcs.calcFootprint in that we keep negative angles if the stitching line is crossed; also, no distortions or anything like that are taken into account.

This code is only used for bboxSIAP, and you must not use it for anything else; it's going to disappear with it.

getSpolyFromWCSFields(wcsFields)

source code 

returns a pgsphere spoly corresponding to wcsFields

wcsFields is passed to getWCS, see there for legal types.

The polygon returned is computed by using the four corner points assuming a rectangular image. This typically is only loosely related to a proper spherical polygon describing the shape, as image boundaries in the usual projects are not great circles.

Also, the spoly will be in the coordinate system of the WCS. If that is not ICRS, you'll probably get something incompatible with most of the VO.

getCenterFromWCSFields(wcsFields, spatialAxes=(1, 2))

source code 

returns RA and Dec of the center of an image described by wcsFields.

This will use the 1-based axes given by spatialAxes to figure out the pixel lengths of the axes.

getSkyWCS(hdr)

source code 

returns a pair of a wcs.WCS instance and a sequence of the spatial axes.

This will be None, () if no WCS could be discerned. There's some heuristics involved in the identification of the spatial coordinates that will probably fail for unconventional datasets.

getPixelLimits(cooPairs, wcsFields)

source code 

returns pixel cutout slices for covering cooPairs in an image with wcsFields.

cooPairs is a sequence of (ra, dec) tuples. wcsFields is a DaCHS-enhanced wcs.WCS instance.

Behaviour if cooPairs use a different coordinate system from wcsFields is undefined at this point.

Each cutout slice is a tuple of (FITS axis number, lower limit, upper limit).

If cooPairs is off the wcsFields coverage, a null cutout on the longAxis is returned.

computeUnitSphereCoords(alpha, delta)

source code 

returns the 3d coordinates of the intersection of the direction vector given by the spherical coordinates alpha and delta with the unit sphere.

alpha and delta are given in degrees.

>>> print(computeUnitSphereCoords(0,0))
[1,0,0]
>>> print(computeUnitSphereCoords(0, 90))
[0,0,1]
>>> print(computeUnitSphereCoords(90, 90))
[0,0,1]
>>> print(computeUnitSphereCoords(90, 0))
[0,1,0]
>>> print(computeUnitSphereCoords(180, -45))
[-0.71,0,-0.71]

dirVecToCelCoos(dirVec)

source code 

returns alpha, delta in degrees for the direction vector dirVec.

>>> dirVecToCelCoos(computeUnitSphereCoords(25.25, 12.125))
(25.25, 12.125)
>>> dirVecToCelCoos(computeUnitSphereCoords(25.25, 12.125)*16)
(25.25, 12.125)
>>> "%g,%g"%dirVecToCelCoos(computeUnitSphereCoords(25.25, 12.125)+
...   computeUnitSphereCoords(30.75, 20.0))
'27.9455,16.0801'

getTangentialUnits(cPos)

source code 

returns the unit vectors for RA and Dec at the unit circle position cPos.

We compute them by solving u_1*p_1+u_2*p_2=0 (we already know that u_3=0) simultaneously with u_1^2+u_2^2=1 for RA, and by computing the cross product of the RA unit and the radius vector for dec.

This becomes degenerate at the poles. If we're exactly on a pole, we *define* the unit vectors as (1,0,0) and (0,1,0).

Orientation is a pain -- the convention used here is that unit delta always points to the pole.

>>> cPos = computeUnitSphereCoords(45, -45)
>>> ua, ud = getTangentialUnits(cPos)
>>> print abs(ua), abs(ud), cPos*ua, cPos*ud
1.0 1.0 0.0 0.0
>>> print ua, ud
[-0.71,0.71,0] [-0.5,-0.5,-0.71]
>>> ua, ud = getTangentialUnits(computeUnitSphereCoords(180, 60))
>>> print ua, ud
[0,-1,0] [0.87,0,0.5]
>>> ua, ud = getTangentialUnits(computeUnitSphereCoords(0, 60))
>>> print ua, ud
[0,1,0] [-0.87,0,0.5]
>>> ua, ud = getTangentialUnits(computeUnitSphereCoords(0, -60))
>>> print ua, ud
[0,1,0] [-0.87,0,-0.5]

movePm(alphaDeg, deltaDeg, pmAlpha, pmDelta, timeDiff, foreshort=0)

source code 

returns alpha and delta for an object with pm pmAlpha after timeDiff.

pmAlpha has to have cos(delta) applied, everything is supposed to be in degrees, the time unit is yours to choose.

getGCDist(pos1, pos2)

source code 

returns the distance along a great circle between two points.

The distance is in degrees, the input positions are in degrees.