A source is a mission-specific plugin that tells Fornax Cutouts how to find the FITS files that cover a given sky position. The framework handles everything else: job queuing, worker dispatch, cutout generation, and result storage.
The Registry¶
The CutoutRegistry is a singleton that holds all registered sources. It is created once at import time and shared across the API and all worker processes.
from fornax_cutouts.sources import cutout_registryDiscovery¶
At startup, the API and each worker call discover_sources(). This method globs all *.py files under CUTOUTS__SOURCE_PATH and executes each one. Any file that uses the @cutout_registry.register_source() decorator will register its source class automatically.
No imports or explicit registration calls are needed in your application code — just place your source file under the configured path.
Registry Methods¶
| Method | Description |
|---|---|
register_source() | Decorator that registers a source class under the given mission name. |
discover_sources() | Scans CUTOUTS__SOURCE_PATH and executes all .py files. Called at startup. |
get_source_names() | Returns a sorted list of all registered mission keys. |
get_mission(mission) | Returns the AbstractMissionSource instance for a given key. Raises ValueError if not found. |
get_mission_metadata() | Returns a dict mapping mission names to their MissionMetadata. |
validate_mission_params(mission_params, size) | Validates request parameters against each mission’s constraints. Returns a dict of {mission: bool}. |
get_target_filenames(position, mission_params, size) | Calls get_filenames() on each requested mission and returns the combined list of FilenameLookupResponse objects. |
infer_mission(source_file) | Returns the unique registered mission whose source_file_patterns match the filename, or None. |
Source Lifecycle¶
AbstractMissionSource¶
Every source must subclass AbstractMissionSource and provide:
A class-level
metadataattribute of typeMissionMetadataAn implementation of
get_filenames()
get_count() has a default implementation that calls get_filenames() and sums the filename lists. Override it with a cheaper query (for example COUNT(*)) when the UI needs a file count without the full list.
Optional source_file_patterns to allow sync cutouts to infer mission for logs and source resolution. The default is no patterns, which leaves mission as "sync" and color_preview. Override matches_source_file() if globbing behavior needs customization. Async jobs pass mission explicitly and are not inferred.
resolve_source_file(source_file) defaults to returning source_file unchanged. Override it when the worker needs to translate a stored identifier or basename into an openable path or short-lived URL (such as a presigned URL) immediately before creating the cutout.
from fornax_cutouts.sources.base import AbstractMissionSource, MissionMetadata
from fornax_cutouts.models.cutouts import FilenameLookupResponse
from fornax_cutouts.models.base import Positions, TargetPosition
class MySource(AbstractMissionSource):
metadata = MissionMetadata(
name="my_mission",
pixel_size=0.25, # arcseconds per pixel
max_cutout_size=3000, # maximum allowed size in pixels
filter=["g", "r", "i"], # valid filter values
survey=["main"], # valid survey values
)
def get_filenames(
self,
position: TargetPosition | Positions,
filter: str | list[str] = ["g", "r", "i"],
**kwargs,
) -> list[FilenameLookupResponse]: ...MissionMetadata Fields¶
| Field | Type | Description |
|---|---|---|
name | str | Unique mission identifier. Must match the key used in register_source(). |
pixel_size | float | Pixel scale in arcseconds per pixel. |
max_cutout_size | int | Maximum allowed cutout size in pixels per axis. See Built-in Validation. |
filter | list[str] | Valid filter names for this mission. |
survey | list[str] | Valid survey names for this mission. |
MissionMetadata uses extra = "allow", so you can add mission-specific fields beyond the standard ones.
Built-in Validation¶
AbstractMissionSource.validate_request() is called by the registry before dispatching any job. size is an (x, y) tuple in pixels. Angular sizes are converted using metadata.pixel_size. It checks:
each axis of
sizeis> 0each axis of
sizeis<= metadata.max_cutout_sizefiltervalue(s) are inmetadata.filtersurveyvalue(s) are inmetadata.survey
In async jobs, a mission that fails validation is skipped and the rest of the job still runs; the skip is logged by the worker but not reported in the job’s results. Sync requests return 422 when the size exceeds the max_cutout_size of a mission inferred from the source file.
You can override validate_request() to add custom validation logic.
FilenameLookupResponse¶
get_filenames() must return a list of FilenameLookupResponse objects. Each object describes a single FITS file that should be cut:
from fornax_cutouts.models.cutouts import FilenameLookupResponse, FilenameWithMetadata
FilenameLookupResponse(
mission="my_mission",
target=(12.345, 67.89),
metadata=FilenameWithMetadata(
filename="s3://my-bucket/data/file.fits",
metadata={
"filter": "r",
"survey": "main",
"ra": 83.8221,
"dec": -5.3911,
},
),
)The filename field can be a local path or an s3:// URI. The worker uses fsspec to open both.
Next Steps¶
See Building a Source for a complete step-by-step tutorial.