autowisp.database.photref_selection module

Class Inheritance Diagram

Inheritance diagram of ConditionExpression, DataReductionFile, DiagnosticType, Image, ImageDiagnostics, ImageMasterSelection, ImageProcessingManager, MasterFile, MasterType, SkyCoord, Step

Photometric-reference selection helpers shared by the BUI and tests.

This module hosts the non-Django half of what the BUI’s select_photref_views does:

  • compute_photref_candidates() walks processing.pending for fit_magnitudes and groups the per-condition batches that still need a single photometric reference.

  • bind_images_to_photref() writes the ImageMasterSelection rows for every batch image within max_photref_separation of the chosen photref.

The view module calls these to populate the Django session / handle form submissions; the integration test calls them directly to mimic “user picks a photref” without going through HTTP.

autowisp.database.photref_selection.bind_images_to_photref(dr_fname, batch)[source]

Write ImageMasterSelection rows for batch images near the photref.

Reads the fit_magnitudes config to get max_photref_separation (which may be conditional), then for each image in batch computes the angular separation between the image center and the photref center. Images whose separation is within max_photref_separation * photref_diagonal_fov are bound to the photref via an upsert into ImageMasterSelection.

Parameters:
  • dr_fname – Path to the photref DR file that was just registered as a single_photref master via ImageProcessingManager.add_masters().

  • batch – List of (calibrated_fname, dr_fname, image_id, channel) tuples – the candidate images from the same condition group. Only image_id and channel are consumed here; the first two slots exist for parity with compute_photref_candidates’s return shape.

autowisp.database.photref_selection.compute_photref_candidates(processing, db_session)[source]

Return the per-condition batches of images missing a photref.

Holds the data-gathering half of what select_photref_views._get_missing_photref does. The BUI calls this (and then writes the result into the Django session); the integration test calls it directly.

Builds processing.pending for the fit_magnitudes step (optionally falling back to “demo” mode where every candidate is treated as pending), strips images whose solve_astrometry prerequisite failed, groups the survivors by master-condition values, and for each non-empty group produces a (master_values, calculate_photref_merit_config, batch) tuple where batch is the list of (calibrated_fname, dr_fname, image_id, channel) entries bind_images_to_photref() expects.

Parameters:
  • processing – A fresh ImageProcessingManager. Its pending attribute is populated as a side effect.

  • db_session – Open SQLAlchemy session.

Returns:

"demo" (bool)

True iff no images were actually pending fit_magnitudes – the caller may then surface every candidate for inspection rather than only the unbound ones.

"candidates" (list[dict])

One entry per (step_id, image_type_id) in processing.pending. Each entry has:

  • "step_id" (int)

  • "image_type_id" (int)

  • "master_expressions" (list[str]) – the condition expressions defining a photref’s identity.

  • "groups" (list[tuple]) – a tuple of (list(master_values), config, batch) per group of images sharing the same master-condition values.

Return type:

dict with keys