Skip to content

Clarify 0- vs 1-based indexing#22

Open
troyraen wants to merge 1 commit intomainfrom
raen/patch/0-vs-1-base-indexing
Open

Clarify 0- vs 1-based indexing#22
troyraen wants to merge 1 commit intomainfrom
raen/patch/0-vs-1-base-indexing

Conversation

@troyraen
Copy link
Copy Markdown
Collaborator

@troyraen troyraen commented Apr 8, 2026

Closes IRSA-7282

Clarifies 0- vs 1-based indexing by adding the same line as was added to the notebook in Caltech-IPAC/irsa-tutorials#293.

@troyraen troyraen requested a review from jkrick April 11, 2026 00:39
@troyraen troyraen added documentation Improvements or additions to documentation maintenance labels Apr 13, 2026
Copy link
Copy Markdown
Collaborator

@jkrick jkrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thoroughly confused trying to understand this section, so I have suggested more clarification. I understand this probably wasn't what you wanted, but adding a note to the end of something that doesn't make sense doesn't clarify anything. My suggested changes are below.

If this is too difficult to implement, I would suggest just the link to the tutorial and the myst note, and not the 3 items in the enumerated list which, as stated, are only confusing and do not help users with this task.

I do not need to touch this again.

suggestions:

The spatially-varying PSF is represented as an image cube with 121 planes (an 11×11 grid of detector regions).
Each plane is a 101x101 pixel image representing a PSF for a different region of the detector.
Users interested in performing photometry on a cutout will need to select the correct PSF plane for their desired position in the cutout.
The basic steps are described below, and a Python notebook tutorial walks through, in detail, a complete implementation.

 SPHEREx FITS header keywords follow the FITS 1-based pixel convention (first pixel = 1),
 while Python tools such as astropy return 0-based pixel coordinates (first pixel = 0).                                          
 This affects two places in the steps below: the `+1` in step 2 bridges these conventions                                        
 when using `CRPIX1A`/`CRPIX2A`, and in step 3 the PSF cube must be indexed as `i − 1`                                           
 even though the header keyword suffix `i` runs from 1 to 121.                                                                   
  1. Determine the 0-based pixel coordinates of the position of interest in the cutout IMAGE HDU .
    Astropy's world_to_pixel() function returns 0-based coordinates directly and is a natural choice for this.

  2. Convert to 0-based pixel coordinates in the original Spectral Image using the CRPIX1A and CRPIX2A header keywords:

  xpix_orig = 1 + xpix_cutout - CRPIX1A
  ypix_orig = 1 + ypix_cutout - CRPIX2A

CRPIX1A and CRPIX2A are FITS keywords stored in 1-based convention.
The +1 converts xpix_cutout from 0-based to 1-based before subtracting, so that xpix_orig comes out 0-based, which is then consistent with the PSF zone coordinates in step 3.

  1. Identify the PSF cube plane by comparing (xpix_orig, ypix_orig) against the zone centers in the PSF HDU header.
    The PSF HDU header contains keywords XCTR_i and YCTR_i for i = 1 to 121.
    The values of XCTR_i and YCTR_i are 0-based pixel coordinates in the original Spectral Image, so they can be compared directly to xpix_orig and ypix_orig.
    Find the index i whose center is closest to your position (functionality for this is provided in the tutorial linked above).
    The corresponding PSF is in cube plane i − 1 (the keyword index i is 1-based, but the cube array is 0-indexed).

@jkrick
Copy link
Copy Markdown
Collaborator

jkrick commented Apr 14, 2026

suggestions look terrible in the comment above, I was trying to give each sentence its own line, so please read like markdown.

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

Labels

documentation Improvements or additions to documentation maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants