cutana_source
anomaly_match.datasets.cutana_source
¶
Cutana catalogue data source for training from streaming cutouts.
DIRECT_CUTOUT_MAX_SOURCES = 5000
module-attribute
¶
Threshold below which :func:extract_cutouts_direct is preferred over
StreamingOrchestrator for catalogue-based cutout extraction. Values above
this hit diminishing returns — the orchestrator's worker-pool parallelism
starts outweighing the subprocess/IPC setup cost.
CutanaSource(cfg, *, lazy=False)
¶
Bases: TrainingDataSource
Load training data from one or more Cutana source catalogues.
Supports both single catalogue files and directories containing multiple CSV/parquet catalogues. Catalogues are not merged into memory; only per-file row counts are stored for lightweight indexing.
Creates cutouts on demand using Cutana's streaming orchestrator. For labeled images, sub-catalogues are filtered to just the labeled source IDs. For unlabeled images, random source IDs are sampled across files using cumulative offset logic.
When lazy=True, the O(N) shuffled-index permutation is skipped.
Unlabeled sampling uses random index generation instead. Labeled images
must come from a LabeledDataCache, not from this source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DotMap
|
Configuration; |
required |
lazy
|
bool
|
If True, skip O(N) permutation for billion-scale catalogues. |
False
|
Source code in anomaly_match/datasets/cutana_source.py
get_last_unlabeled_population_sizes()
¶
Return candidate-population diameters of the last batch's tiles.
Returns:
| Type | Description |
|---|---|
ndarray | None
|
Finite diameters of every source in the tiles the last unlabeled |
ndarray | None
|
batch was drawn from, or |
ndarray | None
|
the catalogue has no size column. |
Source code in anomaly_match/datasets/cutana_source.py
get_last_unlabeled_sizes()
¶
Return finite source diameters from the most recent unlabeled batch.
Returns:
| Type | Description |
|---|---|
ndarray | None
|
Array of diameters, or |
ndarray | None
|
the catalogue has no size column. |
Source code in anomaly_match/datasets/cutana_source.py
get_last_unlabeled_size_unit()
¶
Return the unit of the recorded sizes ("pixel" or "arcsec").
Returns:
| Type | Description |
|---|---|
str | None
|
|
str | None
|
|
Source code in anomaly_match/datasets/cutana_source.py
get_labeled_images(label_df)
¶
Load cutouts for labeled source IDs across all catalogue files.
Not available in lazy mode -- use a LabeledDataCache instead.
Returns:
| Type | Description |
|---|---|
list[tuple[str, ndarray]]
|
List of (source_id, image_array) tuples. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called in lazy mode. |
Source code in anomaly_match/datasets/cutana_source.py
get_unlabeled_batch(n, exclude=None)
¶
Load up to n random unlabeled cutouts across all catalogue files.
Samples tile-aware across catalogues, dropping exclude (the labelled
source IDs) from every tile before sampling in both eager and lazy mode —
_sample_by_tiles loads each catalogue in full, so filtering by
SourceID is free and keeps labelled sources out of the unlabelled
pool. Unlike the image/Zarr sources, Cutana sampling is tile-aware
rather than position-indexed, so it takes no exclude_positions.
The RNG is seeded from cfg.seed mixed with the labelled set, so each
active-learning cycle (which adds labels) draws a fresh unlabelled pool
instead of the identical one a fixed seed would reproduce — while staying
deterministic for a given label set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Maximum number of cutouts to return. |
required |
exclude
|
set[str] | None
|
Source IDs to skip, also the per-cycle freshness key. |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, ndarray]]
|
List of (source_id, image_array) tuples. |
Source code in anomaly_match/datasets/cutana_source.py
get_total_count()
¶
Return total number of sources across all catalogue files.
Returns:
| Type | Description |
|---|---|
int
|
Source count. |
detect_num_channels()
¶
Return configured output channel count.
Cutana channel count depends on the normalisation configuration, not the raw data, so we return the configured value.
Returns:
| Type | Description |
|---|---|
int | None
|
Number of output channels from config. |
Source code in anomaly_match/datasets/cutana_source.py
build_cutana_orchestrator_config(catalogue_path, cfg, *, sub_catalogue_df=None, do_only_cutout_extraction=False, prune_unused_bands=False)
¶
Build a Cutana orchestrator config from AnomalyMatch config.
The orchestrator is configured with identity channel weights — one
entry per resolved extension, each a 1.0-weighted one-hot vector of
length n_extensions. This turns Cutana's internal
combine_channels step into a no-op, so the orchestrator output is
per-band normalised data with n_extensions channels. The user's
channel_combination matrix is then applied post-orchestrator via
:func:apply_channel_combination_to_cutana_image, which keeps
combination logic in one place shared with the read-from-cache and
prediction-subprocess paths.
This is the single source of truth for orchestrator config building.
CutanaSource, LabeledDataCache, and prediction_process_cutana
all delegate here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalogue_path
|
str
|
Path to the sub-catalogue file. Used for filter-name
resolution (reads the first row's |
required |
cfg
|
DotMap
|
AnomalyMatch configuration. |
required |
sub_catalogue_df
|
DataFrame | None
|
Optional in-memory catalogue override. When given, filter names are read from its first row instead of hitting disk — the path to parquet roundtrip that the direct-cutout caller would otherwise need. |
None
|
do_only_cutout_extraction
|
bool
|
When |
False
|
prune_unused_bands
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
DotMap
|
Cutana configuration object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If the installed Cutana release does not expose the
|
Source code in anomaly_match/datasets/cutana_source.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 | |
extract_cutouts_direct(sub_catalogue_df, cfg, *, do_only_cutout_extraction=False)
¶
Run Cutana's in-process create_cutouts_direct on a filtered catalogue.
Intended for small batches (< :data:DIRECT_CUTOUT_MAX_SOURCES rows).
Avoids the subprocess spawn + IPC overhead of
StreamingOrchestrator.next_batch so label-cache builds and UI previews
return in seconds instead of tens of seconds.
Passes sub_catalogue_df directly into
:func:build_cutana_orchestrator_config so filter-name resolution stays
in-memory; create_cutouts_direct itself ignores
cutana_cfg.source_catalogue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_catalogue_df
|
DataFrame
|
Filtered catalogue with Cutana columns. |
required |
cfg
|
DotMap
|
AnomalyMatch configuration. |
required |
do_only_cutout_extraction
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of Cutana batch result dicts (one per FITS file set), each with |
list[dict]
|
|
list[dict]
|
The list matches the contract of iterating |
list[dict]
|
|
Source code in anomaly_match/datasets/cutana_source.py
resolve_catalogue_filter_names(catalogue_path)
¶
Resolve filter/band names from a single Cutana catalogue file or folder.
Reads fits_file_paths from the first source and extracts filter
names using Cutana's naming conventions. When names are unrecognised,
falls back to positional Band_0, Band_1, ... labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalogue_path
|
str
|
Path to a catalogue file or directory containing catalogues. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of filter name strings, e.g. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If catalogue_path is a directory with no catalogue files. |
Source code in anomaly_match/datasets/cutana_source.py
first_cutana_catalogue(folder)
¶
Return the path of the first validated Cutana catalogue in folder.
Reading the first .csv/.parquet blindly would trip over a stray
non-catalogue file that sorts first (e.g. a labeled_data.csv label file
living next to the catalogues).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str
|
Directory to search. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Path to the first file that passes |
str | None
|
when folder isn't a readable directory or holds no catalogue. |
Source code in anomaly_match/datasets/cutana_source.py
detect_cutana_filter_names(folder, cfg)
¶
Return the bands a Cutana source in folder will be extracted with.
Resolves through :func:_resolve_extension_names, the resolver the
orchestrator config and the labeled cache use, so the channel-combination
editor is sized to exactly the bands extraction delivers. A separate
catalogue-only parse used to ignore an explicit fits_extension and
returned nothing on a parse error, leaving the editor at its old width while
extraction produced a different band count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str
|
Directory containing Cutana catalogue files. |
required |
cfg
|
DotMap
|
Configuration whose |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Ordered band names, or an empty list when folder holds no Cutana |
list[str]
|
catalogue. |