Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions boompy/src/boompy/catalog/catalogs/panstarrs_hosts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Stage Pan-STARRS DR2 stack morphology joined to PS1-STRM by objID."""

from __future__ import annotations

import os
from pathlib import Path

from ..base import Chunk

ID = "panstarrs-hosts"


def staged_dir() -> Path:
return (
Path(os.getenv("BOOM_CATALOG_DATA_PATH", "data/catalogs"))
/ "staged"
/ ID
)


def list_chunks() -> list[Chunk]:
directory = staged_dir()
files = sorted(
path.name for path in directory.glob("*.jsonl.gz") if path.is_file()
)
if not files:
raise RuntimeError(
f"Stage panstarrs-hosts .jsonl.gz chunks in {directory}."
)
return [Chunk(id=name, label=name) for name in files]


def fetch_chunk(chunk_id: str, dest: Path) -> list[Path]:
if Path(chunk_id).name != chunk_id or not chunk_id.endswith(".jsonl.gz"):
raise ValueError(f"Invalid panstarrs-hosts chunk name: {chunk_id}")
path = staged_dir() / chunk_id
if not path.is_file():
raise RuntimeError(f"Pan-STARRS host chunk is missing: {path}")
return [path]
27 changes: 27 additions & 0 deletions boompy/tests/catalog/catalogs/test_panstarrs_hosts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import gzip

import pytest

from boompy.catalog.catalogs import panstarrs_hosts


def test_staged_chunks_are_read_in_place(tmp_path, monkeypatch):
monkeypatch.setenv("BOOM_CATALOG_DATA_PATH", str(tmp_path))
with pytest.raises(RuntimeError, match="Stage panstarrs-hosts"):
panstarrs_hosts.list_chunks()

directory = tmp_path / "staged" / "panstarrs-hosts"
directory.mkdir(parents=True)
part = directory / "part-0001.jsonl.gz"
with gzip.open(part, "wt") as stream:
stream.write(
'{"_id":191000742646808255,"ra":74.2654807,"dec":69.17252295,'
'"rKronRad":9.7508,"rExtNSigma":41.55,"strm_class":"GALAXY",'
'"strm_prob_galaxy":0.9994,"strm_z_phot":0.0381,"strm_z_phot_err":0.0086}\n'
)
assert [chunk.id for chunk in panstarrs_hosts.list_chunks()] == [part.name]
assert panstarrs_hosts.fetch_chunk(part.name, tmp_path / "download") == [
part
]
with pytest.raises(ValueError, match="Invalid"):
panstarrs_hosts.fetch_chunk("../part-0001.jsonl.gz", tmp_path)
33 changes: 33 additions & 0 deletions docs/catalogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,46 @@ still resolves to the same catalog definition.
| `galex` | `GALEX` | gzipped CSV | per release | Ultraviolet FUV/NUV photometry from the All-Sky Imaging Survey. |
| `vsx` | `VSX` | fixed-width text | 1 | Variability types, magnitudes, epochs and periods for known and suspected variable stars. |
| `panstarrs` | `PS1_DR2` | parquet | HEALPix partitions | Mean PSF magnitudes in grizy, from the HATS mirror of the DR2 otmo table. Requester-pays S3. Does not include the PS1-STRM `strm_*` columns crossmatch config projects. |
| `panstarrs-hosts` | `PS1_DR2_HOSTS` | gzipped JSONL, **staged** | one per staged file | DR2 stack radii joined to PS1-STRM for the opt-in host fallback. |
| `lsdr9` | `LSDR9` | parquet, from FITS pairs | one per `dr9/north` sweep file | Fluxes, Tractor shapes and photo-z posteriors for the BASS+MzLS reduction, which covers the sky DR10's DECam footprint does not reach. Each chunk is one published sweep file merged with its photo-z counterpart. No i-band: DR9 predates it. |
| `lspsc` | `LSPSC` | gzipped JSONL, **staged** | one per exported chunk | Morphological resolved/unresolved scores for 3.1×10⁹ LS DR10 sources ([Liu et al. 2025](https://arxiv.org/abs/2505.17174)). Upstream is a cone-search API, so BOOM ingests an export of its own copy — see below. |
| `erass1-main` | `eRASS1_Main` | parquet, from FITS in a tarball | 1 | eROSITA-DE DR1 Main, 930,203 X-ray sources detected in 0.2-2.3 keV, with fluxes, band rates, extent and detection likelihood. German half of the sky only (Galactic longitude 180° to 360°). |
| `5xmm-dr15` | `5XMM_DR15` | parquet, from FITS | 1 | XMM-Newton serendipitous source table, 818,656 unique sources, with fluxes, hardness ratios, variability and CLASSX classifications. 2 GB decompressed, so it is read memory-mapped. |
| `2sxps` | `2SXPS` | parquet, from FITS | 1 | Swift-XRT point sources, the 146,768 of the clean subset, with count rates, hardness ratios, fluxes and variability probabilities. |
| `4fgl-dr4` | `4FGL_DR4` | parquet, from FITS | 1 | Fermi-LAT 14-year catalog, 7,195 gamma-ray sources with 95% error ellipses, fluxes, variability and associations. |

### Pan-STARRS host fallback

Prepare a catalog with one row per Pan-STARRS `objID`. Join
[DR2 stack measurements](https://outerspace.stsci.edu/spaces/PANSTARRS/pages/298812430/PS1%2BStackObjectAttributes%2Btable%2Bfields)
to [PS1-STRM](https://stdatu.stsci.edu/hlsp/ps1-strm) by object ID and resolve
duplicate stack detections when preparing the join. Stage the completed
`.jsonl.gz` parts in `<catalog data path>/staged/panstarrs-hosts/`. Each line
uses an integer `_id` for `objID`, stack `ra` and `dec` in degrees,
`rKronRad` in arcseconds, `rExtNSigma`, `strm_class`, and `strm_prob_galaxy`.
The `strm_z_phot` and `strm_z_phot_err` fields are optional.

Ingest `panstarrs-hosts` from the admin page. Then enable the fallback in a
deployment's host association settings. Omitting `ps1_fallback` disables it.
An empty `ps1_fallback: {}` uses these defaults.

```yaml
host_galaxy:
enabled: true
ps1_fallback:
radius_arcsec: 45.0
min_galaxy_score: 0.70
min_extendedness_sigma: 0.0
max_dlr: 3.0
```

The fallback runs when NED-LVS and Legacy leave no accepted host. It uses
the r-band Kron radius as a circular size proxy in the existing DLR ranker.
The resulting host carries the catalog and `objID`. A valid STRM photo-z
carries the `photometric` redshift type, with the usual DESI preference for
an available spectrum. The score remains the host ranker's uncalibrated
posterior. The normal Pan-STARRS alert crossmatch has its own settings.

### Matching within a positional error

X-ray and gamma-ray positions are much less precise than optical ones, and
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/HostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ function hostUrl(host: HostSummary): string | null {
return `https://ned.ipac.caltech.edu/byname?objname=${encodeURIComponent(host.name)}`;
}
if (host.ra == null || host.dec == null) return null;
if (host.catalog === 'PS1_DR2_HOSTS') {
return `https://ps1images.stsci.edu/cgi-bin/ps1cutouts?pos=${host.ra}+${host.dec}&filter=color`;
}
const layer = host.catalog === 'LSDR9' ? 'ls-dr9' : 'ls-dr10';
return `https://www.legacysurvey.org/viewer?ra=${host.ra}&dec=${host.dec}&layer=${layer}&zoom=16&mark=${host.ra},${host.dec}`;
}
Expand All @@ -28,7 +31,10 @@ function hostRows(host: HostSummary): [string, ReactNode][] {
}
if (host.catalog) rows.push(['Catalog', host.catalog]);
if (host.z != null) {
rows.push(['Redshift', host.z_err != null ? `${host.z.toFixed(4)} ± ${host.z_err.toFixed(4)}` : host.z.toFixed(4)]);
const label = host.z_type === 'photometric' ? 'Photometric redshift'
: host.z_type === 'spectroscopic' ? 'Spectroscopic redshift'
: 'Redshift';
rows.push([label, host.z_err != null ? `${host.z.toFixed(4)} ± ${host.z_err.toFixed(4)}` : host.z.toFixed(4)]);
}
if (host.dist_mpc != null) rows.push(['Distance', `${host.dist_mpc.toFixed(1)} Mpc`]);
const sep = `${host.sep_arcsec.toFixed(2)}″`;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ export type HostSummary = {
dec?: number;
z?: number | null;
z_err?: number | null;
z_type?: 'photometric' | 'spectroscopic' | null;
dist_mpc?: number | null;
dist_mpc_method?: string | null;
sep_arcsec: number;
Expand Down
3 changes: 3 additions & 0 deletions src/api/routes/babamul/surveys/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct ObjHost {
dec: f64,
z: Option<f64>,
z_err: Option<f64>,
#[serde(default)]
z_type: Option<String>,
dist_mpc: Option<f64>,
dist_mpc_method: Option<String>,
sep_arcsec: f64,
Expand All @@ -77,6 +79,7 @@ impl From<&StoredHostCandidate> for ObjHost {
dec: host.dec,
z: host.z,
z_err: host.z_err,
z_type: host.z_type.clone(),
dist_mpc: host.dist_mpc,
dist_mpc_method: host.dist_mpc_method.clone(),
sep_arcsec: host.sep_arcsec,
Expand Down
42 changes: 22 additions & 20 deletions src/catalogs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub const STATE_COLLECTION: &str = "catalog_state";

/// The task type whose runs populate these collections.
const TASK_TYPE_CATALOG_INGEST: &str = crate::tasks::catalog_ingest::TASK_TYPE;
pub(crate) const PS1_HOSTS_COLLECTION: &str = "PS1_DR2_HOSTS";

/// Which reader turns this catalog's source files into documents.
///
Expand Down Expand Up @@ -72,6 +73,7 @@ pub enum Reader {
Vsx,
/// Pan-STARRS otmo, parquet partitions.
PanStarrs,
Ps1Hosts,
/// Legacy Survey DR9, parquet merged from the published sweep and photo-z
/// FITS pairs.
LsDr9,
Expand Down Expand Up @@ -242,6 +244,16 @@ pub const CATALOGS: &[CatalogDef] = &[
// Configs named PS1_DR1 until #598, though the only mirror was ever DR2.
aliases: &["PS1_DR1"],
},
CatalogDef {
id: "panstarrs-hosts",
collection: PS1_HOSTS_COLLECTION,
title: "Pan-STARRS DR2 Host Galaxies",
description:
"Staged DR2 stack sizes and PS1-STRM classifications and photo-zs, joined by objID.",
reader: Reader::Ps1Hosts,
source: Source::Staged,
aliases: &[],
},
CatalogDef {
id: "lsdr9",
collection: "LSDR9",
Expand Down Expand Up @@ -377,7 +389,7 @@ pub async fn warn_on_empty_crossmatch_catalogs(
}
}

/// Collection names crossmatch config actually references, across all surveys.
/// Collection names the alert pipeline queries across all surveys.
///
/// Separate from [`declared`] because the two answer different questions now:
/// `declared` is "what did config ask for", this is "what will the alert
Expand All @@ -391,16 +403,17 @@ pub fn crossmatched(config: &crate::conf::AppConfig) -> Vec<String> {
.map(|entry| entry.catalog.clone())
.filter(|name| !name.starts_with(crate::api::catalogs::WATCHLIST_PREFIX))
.collect();
if config.host_galaxy.enabled && config.host_galaxy.ps1_fallback.is_some() {
names.push(PS1_HOSTS_COLLECTION.to_string());
}
names.sort_unstable();
names.dedup();
names
}

/// Which catalogs this deployment should hold.
///
/// Derived from `crossmatch.<survey>[].catalog`, because that is where a
/// catalog is actually put to use -- a deployment that crossmatches against
/// NED needs NED, and having to say so twice is how two lists drift apart.
/// Derived from crossmatch and host-association config.
///
/// Entries are returned as slugs where the name maps to a known catalog, and as
/// the raw collection name where it does not, so an unrecognized name surfaces
Expand All @@ -419,22 +432,10 @@ pub fn declared(config: &crate::conf::AppConfig) -> Vec<String> {
}
};

// Sorted for a stable order regardless of the survey map's iteration order,
// so the admin page does not reshuffle its rows between requests.
let mut from_crossmatch: Vec<&str> = config
.crossmatch
.values()
.flatten()
.map(|entry| entry.catalog.as_str())
.filter(|name| !name.starts_with(crate::api::catalogs::WATCHLIST_PREFIX))
.collect();
from_crossmatch.sort_unstable();
from_crossmatch.dedup();

for name in from_crossmatch {
match find_by_collection(name) {
for name in crossmatched(config) {
match find_by_collection(&name) {
Some(def) => push(def.id.to_string()),
None => push(name.to_string()),
None => push(name),
}
}
declared
Expand Down Expand Up @@ -867,6 +868,7 @@ async fn ingest_file(
Reader::Galex => Ok(csv::ingest_csv::<types::Galex>(inserter, path).await?),
Reader::Vsx => Ok(ascii::ingest_ascii::<types::Vsx>(inserter, path).await?),
Reader::PanStarrs => Ok(arrow::ingest_parquet::<types::PanStarrs>(inserter, path).await?),
Reader::Ps1Hosts => Ok(jsonl::ingest_jsonl::<types::Ps1Host>(inserter, path).await?),
Reader::LsDr9 => Ok(arrow::ingest_parquet::<types::LsDr9>(inserter, path).await?),
Reader::Lspsc => Ok(jsonl::ingest_jsonl::<types::Lspsc>(inserter, path).await?),
Reader::Erass1 => Ok(arrow::ingest_parquet::<types::Erass1>(inserter, path).await?),
Expand Down Expand Up @@ -1683,7 +1685,7 @@ mod source_tests {
.collect();
// lspsc is an export of BOOM's own copy and the DESI DR1 dwarfs are not
// published: neither can be fetched, and their files must not be deleted.
assert_eq!(staged, vec!["desi-dr1-dwarfs", "lspsc"]);
assert_eq!(staged, vec!["desi-dr1-dwarfs", "panstarrs-hosts", "lspsc"]);
}

#[test]
Expand Down
19 changes: 19 additions & 0 deletions src/catalogs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,25 @@ impl super::arrow::FromRecordBatch for PanStarrs {

impl HasCoordinates for PanStarrs {}

/// DR2 stack morphology joined to PS1-STRM by objID.
#[derive(Debug, Serialize, Deserialize)]
pub struct Ps1Host {
#[serde(rename = "_id")]
pub id: i64,
pub ra: f64,
pub dec: f64,
#[serde(rename = "rKronRad")]
pub kron_radius_arcsec: f64,
#[serde(rename = "rExtNSigma")]
pub extendedness_sigma: f64,
pub strm_class: String,
pub strm_prob_galaxy: f64,
pub strm_z_phot: Option<f64>,
pub strm_z_phot_err: Option<f64>,
}

impl HasCoordinates for Ps1Host {}

// ---------------------------------------------------------------------------
// Legacy Survey DR9 -- parquet, merged from the published sweep and photo-z
// FITS pairs by boompy
Expand Down
3 changes: 3 additions & 0 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,9 @@ pub fn load_config(config_path: Option<&str>) -> Result<AppConfig, BoomConfigErr
if let Err(e) = app_config.validate_secrets() {
return Err(BoomConfigError::InvalidSecretError(e));
}
if let Some(fallback) = &app_config.host_galaxy.ps1_fallback {
fallback.validate().map_err(config::ConfigError::Message)?;
}

// A misspelled crossmatch catalog does not fail at query time -- it matches
// nothing, and the alerts come out looking confidently unmatched. Fail
Expand Down
2 changes: 1 addition & 1 deletion src/enrichment/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub const DERIVATIONS: &[(&str, u32)] = &[
("detection_history", 2),
("variability", 1),
// hosted, best_host. Also bump when the DLR scoring parameters change: hosts are rewritten in place.
("host_association", 4),
("host_association", 5),
// applecider_fusion, applecider_outputs and fusion_embedding.
("applecider_postprocess", 1),
// arnett_fit and thermal_fit.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/host/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pub(super) fn nearest_galaxy_spectrum(
nearest_where(spectra, ra, dec, max_arcsec, is_good_galaxy_spectrum)
}

fn add_spectroscopic_redshift(
pub(super) fn add_spectroscopic_redshift(
galaxy: &mut GalaxyCandidate,
spectra: &[Document],
config: &HostGalaxyConfig,
Expand Down
Loading
Loading