gelsa.photframe#

Classes

PhotFrame(**kwargs)

Represents a photometric frame (observation) in the Gelsa simulation.

class gelsa.photframe.PhotFrame(**kwargs)[source]#

Bases: object

Represents a photometric frame (observation) in the Gelsa simulation.

This class handles the parameters, loading, and coordinate transformations for a specific photometric observation frame (e.g., a NISP imaging exposure). It manages WCS information, allowing conversion between sky (RA, Dec) and detector pixel coordinates. It can load existing FITS frames or be used to define new ones based on pointing and WCS parameters.

load_frame(frame_path=None)[source]#

Load frame data and metadata from a NISP photometric FITS file.

Reads the primary header, extracts basic metadata (RA, Dec, PA, Obs ID, etc.), and loads the WCS information for all detectors from their respective extension headers.

Parameters:

frame_path (str, optional) – Path to the FITS science frame file. Can be .gz compressed. Defaults to None.

static rotate_coord_nir_to_sir(x, y, det, inverse=False)[source]#

Rotate pixel coordinates between NIR default layout and SIR layout.

The SIR pipeline often uses a different detector orientation convention than the raw NIR data. This function applies the necessary rotation and flipping based on the detector index.

Parameters:
  • x (np.ndarray) – Input x pixel coordinates.

  • y (np.ndarray) – Input y pixel coordinates.

  • det (np.ndarray) – Detector indices (0-15) corresponding to coordinates.

  • inverse (bool, optional) – If True, rotate from SIR back to NIR. Defaults to False (NIR to SIR).

Returns:

(x_out, y_out) rotated pixel coordinates.

Return type:

tuple

static rotate_image_nir_to_sir(det, im)[source]#

Rotate a detector image from NIR default layout to SIR layout.

Applies the appropriate 90-degree rotation based on the detector index to match the SIR pipeline’s orientation convention.

Parameters:
  • det_index (int) – Detector index (0-15).

  • im (np.ndarray) – The 2D image array for the detector.

Returns:

The rotated image array.

Return type:

np.ndarray

property hdul#

Access the FITS HDUList object for the frame.

Loads the FITS file on first access if not already loaded.

Returns:

The HDUList object.

Return type:

astropy.io.fits.HDUList

Raises:
  • AttributeError – If the frame was not initialized with a file path.

  • FileNotFoundError – If the FITS file specified by ‘frame_path’ does not exist.

close()[source]#

Close the associated FITS file handle, if it was loaded.

Deletes internal references to the HDUList and header.

get_detector(detector_index)[source]#

Get the pixel data arrays (flux, RMS, DQ) for a specific detector.

Retrieves the data from the corresponding FITS extensions. Applies rotation to match the SIR layout if params[‘sir_layout’] is True.

Parameters:

detector_index (int) – NISP detector index (0-15).

Returns:

(flux, rms, dq)

flux (ndarray): Science image data (e.g., counts or flux). rms (ndarray): RMS noise map. dq (ndarray): Data quality mask (0=good).

Return type:

tuple

Raises:
  • IndexError – If detector_index is out of range (0-15).

  • KeyError – If the required FITS extensions (e.g., DET*.SCI) are not found.

  • AttributeError – If the FITS file has not been loaded.

radec_to_pixel(ra, dec)[source]#

Compute detector pixel coordinates (x, y, det_index) from RA, Dec.

Iterates through the WCS of each detector to find which detector(s) contain the given sky coordinates. Applies rotation to SIR layout if params[‘sir_layout’] is True.

Parameters:
  • ra (float or np.ndarray) – Sky position RA in degrees.

  • dec (float or np.ndarray) – Sky position Dec in degrees.

Returns:

(x, y, detector_index)

x (float or ndarray): Pixel x-coordinate(s). -1 if off all detectors. y (float or ndarray): Pixel y-coordinate(s). -1 if off all detectors. detector_index (int or ndarray): Detector index (0-15). -1 if off all detectors.

Return type:

tuple

Raises:

AttributeError – If WCS list (_wcs_list) has not been loaded.

pixel_to_radec(x, y, det)[source]#

Compute sky position (RA, Dec) from detector pixel coordinates.

Uses the WCS object corresponding to the given detector index (det). Applies inverse rotation from SIR layout if params[‘sir_layout’] is True.

Parameters:
  • x (float or np.ndarray) – Detector pixel x-coordinate(s).

  • y (float or np.ndarray) – Detector pixel y-coordinate(s).

  • det (int or np.ndarray) – NISP detector index/indices (0-15).

Returns:

(RA, Dec)

RA (float or ndarray): Right Ascension coordinate(s) in degrees. NaN if input pixel is off-detector. Dec (float or ndarray): Declination coordinate(s) in degrees. NaN if input pixel is off-detector.

Return type:

tuple

Raises:
  • AttributeError – If WCS list (_wcs_list) has not been loaded.

  • IndexError – If any value in det is out of range (0-15).