xlens.wcs

WCS conversion utilities between LSST and GalSim coordinate systems.

Coordinate conventions

Both LSST and GalSim use tangent-plane (intermediate world) coordinates, Near the tangent point at (RA_0, Dec_0):

u’ ≈ (RA - RA_0) * cos(Dec_0) (East, LSST/FITS) v’ ≈ Dec - Dec_0 (North, LSST/FITS)

u ≈ -(RA - RA_0) * cos(Dec_0) (West, GalSim) v ≈ Dec - Dec_0 (North, GalSim)

So u = -u’ and v = v’. The cos(Dec_0) factor is absorbed into the projection; the CD matrix entries do NOT scale with 1/cos(Dec).

LSST/FITS CD matrix (getCdMatrix, makeSkyWcs cdMatrix, base_LocalWcs_CDMatrix):

[[du’/dx, du’/dy], [dv’/dx, dv’/dy]] Units: degrees/pixel (getCdMatrix) or radians/pixel (linearizePixelToSky with radians).

GalSim Jacobian (dudx, dudy, dvdx, dvdy in AffineTransform / JacobianWCS):

[[du/dx, du/dy], [dv/dx, dv/dy]] Units: arcsec/pixel (when units=galsim.arcsec).

GalSim FITS CD matrix (TanWCS.cd property):

Same as LSST/FITS convention in degrees/pixel. GalSim converts internally between this and its (u, v) Jacobian.

Conversion rule

To go from LSST/FITS CD matrix to GalSim Jacobian:

Negate the first row (u’ East -> u West) and convert units. du/dx = -du’/dx, du/dy = -du’/dy dv/dx = dv’/dx, dv/dy = dv’/dy

To go from GalSim to LSST:

Use TanWCS.cd (already in FITS convention), pass directly to makeSkyWcs.

Attributes

RAD2ASEC

Functions

jacobian_reconstruction(pixel_scale, g1, g2, rho[, kappa])

Reconstruct a 2x2 Jacobian matrix from shear, rotation, and convergence.

jacobian_decomposition(jac, pixel_scale)

Decompose a 2x2 Jacobian matrix into shear, rotation, and convergence.

make_jwcs(pixel_scale, g1, g2, rho)

Build a GalSim JacobianWCS with shear and rotation.

extract_perturbation_jwcs(wcs, pixel_scale)

Extract (g1, g2, rho, kappa) from a GalSim JacobianWCS.

extract_perturbation_galsim_wcs(wcs_gs, pixel_point, ...)

Extract (g1, g2, rho, kappa) from a GalSim TanWCS at a pixel position.

extract_perturbation_dm_wcs(wcs_dm, pixel_point, ...)

Extract (g1, g2, rho, kappa) from an LSST SkyWcs.

tanwcs_dm2galsim(wcs)

Build a GalSim TanWCS from an LSST SkyWcs.

tanwcs_galsim2dm(wcs_gs)

Convert a GalSim TanWCS to an LSST SkyWcs.

make_tanwcs_galsim(pixel_scale, g1, g2, rho, ra_deg, ...)

Build a GalSim TanWCS with shear (g1, g2) and rotation (rho).

make_tanwcs_dm(pixel_scale, g1, g2, rho, ra_deg, ...)

Build an LSST SkyWcs with shear (g1, g2) and rotation (rho).

correct_fpfs_spin2_wcs(data, g1, g2, rho[, prefix])

Correct FPFS linear shapelet moments for WCS shear and rotation.

Module Contents

RAD2ASEC = 206264.80624709636[source]
jacobian_reconstruction(pixel_scale, g1, g2, rho, kappa=0.0)[source]

Reconstruct a 2x2 Jacobian matrix from shear, rotation, and convergence.

Inverse of jacobian_decomposition. The Jacobian is in the GalSim convention: [[du/dx, du/dy], [dv/dx, dv/dy]] where (u, v) are tangent-plane coordinates with u=West and v=North, in arcsec/pixel. Note: u ≈ -(RA - RA_0) * cos(Dec_0), NOT raw RA.

The Jacobian is factored as:

J = pixel_scale * (1-kappa) * R(rho) @ S(g1, g2)

where R is a rotation matrix and S is the lensing shear matrix:

R(rho) = [[cos(rho), sin(rho)], [-sin(rho), cos(rho)]] S(g1, g2) = [[1-g1, -g2], [-g2, 1+g1]]

Positive rho corresponds to a clockwise rotation in the (u, v) tangent-plane (u=West, v=North). At small rho this reduces to:

J ≈ pixel_scale * (1-kappa) * [[1-g1, -g2+rho], [-g2-rho, 1+g1]]

Parameters:
  • pixel_scale (float) – Pixel scale in arcsec/pixel.

  • g1 (float) – Reduced shear components in lensing convention (dimensionless).

  • g2 (float) – Reduced shear components in lensing convention (dimensionless).

  • rho (float) – Rotation angle in radians.

  • kappa (float, optional) – Convergence (dimensionless). Default is 0.

Returns:

jac – Jacobian matrix [[du/dx, du/dy], [dv/dx, dv/dy]] in arcsec/pixel, using GalSim tangent-plane convention (u=West, v=North).

Return type:

2x2 np.ndarray

jacobian_decomposition(jac, pixel_scale)[source]

Decompose a 2x2 Jacobian matrix into shear, rotation, and convergence.

Inverse of jacobian_reconstruction. The input Jacobian should be in GalSim convention: [[du/dx, du/dy], [dv/dx, dv/dy]] where (u, v) are tangent-plane coordinates with u=West and v=North, in arcsec/pixel. Note: u ≈ -(RA - RA_0) * cos(Dec_0), NOT raw RA.

The Jacobian is decomposed as:

J = pixel_scale * (1-kappa) * R(rho) @ S(g1, g2)

where R is a rotation matrix and S is the lensing shear matrix (see jacobian_reconstruction for definitions). Positive rho corresponds to a clockwise rotation in the (u, v) tangent-plane.

Parameters:
  • jac (2x2 array) – Jacobian matrix [[du/dx, du/dy], [dv/dx, dv/dy]] in arcsec/pixel, using GalSim tangent-plane convention (u=West, v=North).

  • pixel_scale (float) – Pixel scale in arcsec/pixel.

Returns:

  • g1, g2 (float) – Reduced shear components in lensing convention (dimensionless).

  • rho (float) – Rotation angle in radians.

  • kappa (float) – Convergence (dimensionless).

make_jwcs(pixel_scale, g1, g2, rho)[source]

Build a GalSim JacobianWCS with shear and rotation.

Constructs a 2x2 Jacobian via jacobian_reconstruction() and wraps it in a galsim.JacobianWCS.

Parameters:
  • pixel_scale (float) – Pixel scale in arcsec/pixel.

  • g1 (float) – Reduced shear components in lensing convention.

  • g2 (float) – Reduced shear components in lensing convention.

  • rho (float) – Rotation angle in radians.

Return type:

galsim.JacobianWCS

extract_perturbation_jwcs(wcs, pixel_scale)[source]

Extract (g1, g2, rho, kappa) from a GalSim JacobianWCS.

Reads the 2x2 matrix from a galsim.JacobianWCS and decomposes it via jacobian_decomposition().

Parameters:
  • wcs (galsim.JacobianWCS) – GalSim Jacobian WCS (u=West, v=North, arcsec/pixel).

  • pixel_scale (float) – Reference pixel scale in arcsec/pixel.

Returns:

g1, g2, rho, kappa – Shear, rotation, and convergence perturbations.

Return type:

float

extract_perturbation_galsim_wcs(wcs_gs, pixel_point, pixel_scale)[source]

Extract (g1, g2, rho, kappa) from a GalSim TanWCS at a pixel position.

Evaluates the local Jacobian of the GalSim TanWCS at the given pixel position and decomposes it into shear, rotation, and convergence.

Parameters:
  • wcs_gs (galsim.TanWCS) – GalSim TAN WCS object.

  • pixel_point (galsim.PositionD) – Pixel position at which to evaluate the local Jacobian.

  • pixel_scale (float) – Pixel scale in arcsec/pixel.

Returns:

  • g1, g2 (float) – Reduced shear components in lensing convention (dimensionless).

  • rho (float) – Rotation angle in radians.

  • kappa (float) – Convergence (dimensionless).

extract_perturbation_dm_wcs(wcs_dm, pixel_point, pixel_scale)[source]

Extract (g1, g2, rho, kappa) from an LSST SkyWcs.

Linearizes the LSST SkyWcs at the given pixel position and decomposes the local Jacobian into shear, rotation, and convergence.

Convention difference from GalSim

Both LSST and GalSim use tangent-plane (intermediate world) coordinates, The cos(Dec_0) factor is absorbed in the projection, so the CD matrix entries do NOT scale with 1/cos(Dec).

LSST CDMatrix (from linearizePixelToSky or base_LocalWcs_CDMatrix):

[[du’/dx, du’/dy], [dv’/dx, dv’/dy]] u’ ≈ (RA - RA_0) * cos(Dec_0) (East), v’ ≈ Dec - Dec_0 (North). Units: radians/pixel.

GalSim Jacobian:

[[du/dx, du/dy], [dv/dx, dv/dy]] u ≈ -(RA - RA_0) * cos(Dec_0) (West), v ≈ Dec - Dec_0 (North). Units: arcsec/pixel.

Since u = -u’, conversion requires negating the first row and scaling from radians to arcsec.

param wcs_dm:

LSST sky WCS object.

type wcs_dm:

lsst.afw.geom.SkyWcs

param pixel_point:

Pixel position at which to linearize the WCS.

type pixel_point:

lsst.geom.Point2D

param pixel_scale:

Pixel scale in arcsec/pixel.

type pixel_scale:

float

returns:
  • g1, g2 (float) – Shear distortion components (dimensionless).

  • rho (float) – Rotation component in radians (dimensionless).

  • kappa (float) – Convergence (dimensionless).

Note

The returned perturbations follow GalSim’s (u=West, v=North) convention. The LSST CDMatrix is first converted to GalSim’s tangent-plane convention before decomposition.

tanwcs_dm2galsim(wcs)[source]

Build a GalSim TanWCS from an LSST SkyWcs.

Converts the LSST CD matrix (u’=East, degrees/pixel) to GalSim’s Jacobian (u=West, arcsec/pixel) by negating the first row and scaling by 3600. See module docstring for coordinate conventions.

Parameters:

wcs (lsst.afw.geom.SkyWcs) – LSST sky WCS object.

Return type:

galsim.TanWCS

tanwcs_galsim2dm(wcs_gs)[source]

Convert a GalSim TanWCS to an LSST SkyWcs.

Uses GalSim’s .cd property, which returns the FITS CD matrix (u’=East, degrees/pixel) — the same convention as LSST’s makeSkyWcs cdMatrix parameter. No sign flip is needed. See module docstring for coordinate conventions.

Parameters:

wcs_gs (galsim.TanWCS) – GalSim TAN WCS object.

Return type:

lsst.afw.geom.SkyWcs

make_tanwcs_galsim(pixel_scale, g1, g2, rho, ra_deg, dec_deg, x_pix, y_pix)[source]

Build a GalSim TanWCS with shear (g1, g2) and rotation (rho).

Parameters:
  • pixel_scale (float) – Pixel scale in arcsec/pixel.

  • g1 (float) – Reduced shear components in lensing convention.

  • g2 (float) – Reduced shear components in lensing convention.

  • rho (float) – Rotation angle in radians.

  • ra_deg (float) – Right ascension of the tangent point in degrees.

  • dec_deg (float) – Declination of the tangent point in degrees.

  • x_pix (float) – Pixel coordinates of the tangent point.

  • y_pix (float) – Pixel coordinates of the tangent point.

Return type:

galsim.TanWCS

make_tanwcs_dm(pixel_scale, g1, g2, rho, ra_deg, dec_deg, x_pix, y_pix)[source]

Build an LSST SkyWcs with shear (g1, g2) and rotation (rho).

Constructs a GalSim TanWCS via make_tanwcs_galsim and converts it to an LSST SkyWcs using tanwcs_galsim2dm.

Parameters:
  • pixel_scale (float) – Pixel scale in arcsec/pixel.

  • g1 (float) – Reduced shear components in lensing convention.

  • g2 (float) – Reduced shear components in lensing convention.

  • rho (float) – Rotation angle in radians.

  • ra_deg (float) – Right ascension of the tangent point in degrees.

  • dec_deg (float) – Declination of the tangent point in degrees.

  • x_pix (float) – Pixel coordinates of the tangent point.

  • y_pix (float) – Pixel coordinates of the tangent point.

Return type:

lsst.afw.geom.SkyWcs

correct_fpfs_spin2_wcs(data, g1, g2, rho, prefix='')[source]

Correct FPFS linear shapelet moments for WCS shear and rotation.

Transforms the spin-2 shapelet moments measured in pixel coordinates to sky coordinates by undoing the WCS-induced shear and rotation.

The correction is applied in two steps: 1. Undo shear: subtract the first-order shear response from each

moment using the relations from the shapelet shear algebra (see notes/shapelets.tex).

  1. Undo rotation: rotate spin-s moments by -s*rho.

Parameters:
  • data (np.ndarray) – Structured array of FPFS shapelet moments with fields m00, m20, m22c, m22s, m40, m42c, m42s, m44c, m44s, m60, m64c, m64s (dtype FpfsShapelets), optionally with a common prefix (e.g. "fpfs1_").

  • g1 (float) – WCS shear components in lensing convention.

  • g2 (float) – WCS shear components in lensing convention.

  • rho (float) – WCS rotation angle in radians.

  • prefix (str, optional) – Column name prefix (e.g. "fpfs1_"). Default is "".

Returns:

Corrected shapelet moments (same dtype as input).

Return type:

np.ndarray