Skip to content

Add det_left mode to projection engine for instrument-centered pointing - #252

Open
chervias wants to merge 1 commit into
masterfrom
chervias/instrument_centered_coordinates
Open

chervias wants to merge 1 commit into
masterfrom
chervias/instrument_centered_coordinates

Conversation

@chervias

Copy link
Copy Markdown
Member

This change was implemented with Claude Code (Opus 5.5).

Motivation

The projection engine always combines boresight and detector quaternions as q_bore[t] * q_det[d]. Instrument-centered coordinates (the position of a source such as the Moon or Sun relative to each detector, on axes fixed to the telescope structure) need

q[d,t] = A[d] * X[t]
A[d]   = q_to_eq * Rz(roll0) * q_det[d]^-1 * Rz(-roll0)
X[t]   = Rz(roll[t]) * q_bore[t]^-1 * q_src[t]

where the per-detector factor sits on the LEFT of the per-sample one, so it cannot be expressed in the existing q_bore * q_det form. Rather than transposing the problem (which would give [nsamp, ndet] outputs and require transposed signal, cuts, threads and responses), this adds an opt-in flag that reverses the order of the product, so everything else (all projections, tiling, bilinear interpolation, HEALPix, threads, cuts, weights, [ndet, nsamp] layout) works unchanged.

C++ (src/Projection.cxx, include/Projection.h)

  • Pointer gets a constructor Pointer(bool det_left=false) and a private generic helper GetQdet(i_time, dofs), which reads the boresight quaternion and returns q_ofs * q_bore if det_left is set, q_bore * q_ofs otherwise.
  • The seven GetCoords specializations that combine quaternions (ProjQuat, ARC, SIN, TAN, ZEA, CEA, CAR) now call GetQdet instead of each duplicating the read-and-multiply block. The decoding of the combined quaternion into projection coordinates is unchanged. ProjFlat is untouched.
  • ProjectionEngine gets a private _det_left member (default false) with get_det_left/set_det_left, and passes it to every Pointer it constructs (coords, pixels, pointing_matrix, pixel_ranges, tile_hits, tile_ranges, from_map, to_map, to_weight_map).
  • EXPORT_ENGINE exposes it as the read/write Python property "det_left" on every ProjEng class, including the HEALPix engines. The default is False, so existing behaviour is unchanged.

Python (python/proj/)

  • Assembly has a det_left attribute: Assembly.attach(sight, fplane, det_left=False).
  • _ProjectionistBase.get_ProjEng(..., det_left=False) sets the property on the engine instance.
  • New _ProjectionistBase._get_pointing(assembly) returns (q_bore, q_det, det_left) and is used by every projection method (get_pixels, get_pointing_matrix, get_coords, get_planar, to_map, to_weights, from_map, assign_threads, assign_threads_from_map, get_active_tiles, and ProjectionistHealpix.get_coords). The celestial-to-native rotation of the map must multiply the leftmost factor: normally it is applied to the boresight (cached q_native as before); with det_left it is applied to the detector quaternions.
  • assign_threads(method='domdir') falls back to 'simple' for a det_left Assembly, since the domdir algorithm assumes the normal ordering.

Tests (test/test_proj_eng.py)

  • test_40_det_left_engine: raw engine output with det_left off/on against numpy q_boreq_ofs and q_ofsq_bore.
  • test_41_det_left_projectionist: a det_left Assembly gives the same pixels, coords, to_map and from_map results as an equivalent normal Assembly built per detector, on tiled and untiled TAN maps, and with the simple/domdir thread assignments.

WARNING

This is intended ONLY for projecting a temperature ("T only") mask into sample space in order to flag samples (e.g. Moon/Sun sidelobe cuts, see the companion sotodlib change). It must NOT be used to make maps in instrument-centered coordinates: the polarization angle is not meaningful in this mode (sotodlib builds the detector quaternions with gamma = 0 and only allows comps='T'), and mapmaking in these coordinates has not been designed or validated. That needs a future implementation.

…strument-centered pointing

This change was implemented with Claude Code (Opus 5.5).

Motivation
----------
The projection engine always combines boresight and detector
quaternions as q_bore[t] * q_det[d]. Instrument-centered coordinates
(the position of a source such as the Moon or Sun relative to each
detector, on axes fixed to the telescope structure) need

    q[d,t] = A[d] * X[t]
    A[d]   = q_to_eq * Rz(roll0) * q_det[d]^-1 * Rz(-roll0)
    X[t]   = Rz(roll[t]) * q_bore[t]^-1 * q_src[t]

where the per-detector factor sits on the LEFT of the per-sample one,
so it cannot be expressed in the existing q_bore * q_det form. Rather
than transposing the problem (which would give [nsamp, ndet] outputs
and require transposed signal, cuts, threads and responses), this adds
an opt-in flag that reverses the order of the product, so everything
else (all projections, tiling, bilinear interpolation, HEALPix,
threads, cuts, weights, [ndet, nsamp] layout) works unchanged.

C++ (src/Projection.cxx, include/Projection.h)
----------------------------------------------
- Pointer<CoordSys> gets a constructor Pointer(bool det_left=false)
  and a private generic helper GetQdet(i_time, dofs), which reads the
  boresight quaternion and returns q_ofs * q_bore if det_left is set,
  q_bore * q_ofs otherwise.
- The seven GetCoords specializations that combine quaternions
  (ProjQuat, ARC, SIN, TAN, ZEA, CEA, CAR) now call GetQdet instead of
  each duplicating the read-and-multiply block. The decoding of the
  combined quaternion into projection coordinates is unchanged.
  ProjFlat is untouched.
- ProjectionEngine gets a private _det_left member (default false)
  with get_det_left/set_det_left, and passes it to every Pointer it
  constructs (coords, pixels, pointing_matrix, pixel_ranges, tile_hits,
  tile_ranges, from_map, to_map, to_weight_map).
- EXPORT_ENGINE exposes it as the read/write Python property
  "det_left" on every ProjEng class, including the HEALPix engines.
  The default is False, so existing behaviour is unchanged.

Python (python/proj/)
---------------------
- Assembly has a det_left attribute:
  Assembly.attach(sight, fplane, det_left=False).
- _ProjectionistBase.get_ProjEng(..., det_left=False) sets the
  property on the engine instance.
- New _ProjectionistBase._get_pointing(assembly) returns
  (q_bore, q_det, det_left) and is used by every projection method
  (get_pixels, get_pointing_matrix, get_coords, get_planar, to_map,
  to_weights, from_map, assign_threads, assign_threads_from_map,
  get_active_tiles, and ProjectionistHealpix.get_coords). The
  celestial-to-native rotation of the map must multiply the leftmost
  factor: normally it is applied to the boresight (cached q_native as
  before); with det_left it is applied to the detector quaternions.
- assign_threads(method='domdir') falls back to 'simple' for a
  det_left Assembly, since the domdir algorithm assumes the normal
  ordering.

Tests (test/test_proj_eng.py)
-----------------------------
- test_40_det_left_engine: raw engine output with det_left off/on
  against numpy q_bore*q_ofs and q_ofs*q_bore.
- test_41_det_left_projectionist: a det_left Assembly gives the same
  pixels, coords, to_map and from_map results as an equivalent normal
  Assembly built per detector, on tiled and untiled TAN maps, and
  with the simple/domdir thread assignments.

WARNING
-------
This is intended ONLY for projecting a temperature ("T only") mask
into sample space in order to flag samples (e.g. Moon/Sun sidelobe
cuts, see the companion sotodlib change). It must NOT be used to make
maps in instrument-centered coordinates: the polarization angle is
not meaningful in this mode (sotodlib builds the detector quaternions
with gamma = 0 and only allows comps='T'), and mapmaking in these
coordinates has not been designed or validated. That needs a future
implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chervias

Copy link
Copy Markdown
Member Author

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant