Spaces:
Running
Running
Deploy SPHEREx Data Explorer (Static)
Browse files- index.html +129 -18
index.html
CHANGED
|
@@ -24,6 +24,13 @@
|
|
| 24 |
(function () {
|
| 25 |
function rewriteSkyUrl(rawUrl) {
|
| 26 |
if (typeof rawUrl !== "string") return rawUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
if (rawUrl.indexOf("MocServer/query") >= 0) {
|
| 28 |
const qIdx = rawUrl.indexOf("?");
|
| 29 |
return qIdx >= 0 ? "/mocserver?" + rawUrl.slice(qIdx + 1) : "/mocserver";
|
|
@@ -1867,12 +1874,27 @@
|
|
| 1867 |
|
| 1868 |
let activeRegimeFilter = "all";
|
| 1869 |
const DEFAULT_SKY = "dss2-color";
|
| 1870 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1871 |
let currentSky = DEFAULT_SKY;
|
| 1872 |
let allCdsSurveys = [];
|
| 1873 |
let activeSurveyUrl = null;
|
| 1874 |
|
| 1875 |
-
function skyUrl(key) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1876 |
|
| 1877 |
function renderSkyOptions() {
|
| 1878 |
skySelect.innerHTML = "";
|
|
@@ -1918,11 +1940,15 @@
|
|
| 1918 |
|
| 1919 |
async function initSky() {
|
| 1920 |
try {
|
| 1921 |
-
const
|
| 1922 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1923 |
} catch (err) {
|
| 1924 |
-
|
| 1925 |
-
return;
|
| 1926 |
}
|
| 1927 |
renderSkyOptions();
|
| 1928 |
|
|
@@ -2254,20 +2280,43 @@
|
|
| 2254 |
if (surveyLoading.dataset.loading === "true") return;
|
| 2255 |
surveyLoading.dataset.loading = "true";
|
| 2256 |
try {
|
| 2257 |
-
|
| 2258 |
-
|
| 2259 |
-
|
| 2260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2261 |
surveyLoading.style.display = "none";
|
| 2262 |
surveyBrowserDirty = true;
|
| 2263 |
-
|
| 2264 |
if (surveyPanel && surveyPanel.classList.contains("open")) {
|
| 2265 |
renderSurveyBrowser(surveySearchInput.value || "");
|
| 2266 |
surveyBrowserDirty = false;
|
| 2267 |
}
|
| 2268 |
} catch (err) {
|
| 2269 |
-
|
| 2270 |
-
|
| 2271 |
} finally {
|
| 2272 |
delete surveyLoading.dataset.loading;
|
| 2273 |
}
|
|
@@ -3371,6 +3420,61 @@
|
|
| 3371 |
return new Date((v - 40587) * 86400000).toISOString().slice(0, 10);
|
| 3372 |
}
|
| 3373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3374 |
const searchClientCache = new Map();
|
| 3375 |
|
| 3376 |
window.runSearch = runSearch;
|
|
@@ -3404,14 +3508,21 @@
|
|
| 3404 |
try {
|
| 3405 |
const coll = (sColl && sColl.value) ? sColl.value : "spherex_qr2";
|
| 3406 |
const cacheKey = `${ra.toFixed(4)}_${dec.toFixed(4)}_${radius.toFixed(3)}_${coll}`;
|
| 3407 |
-
let data;
|
| 3408 |
if (searchClientCache.has(cacheKey)) {
|
| 3409 |
data = searchClientCache.get(cacheKey);
|
| 3410 |
} else {
|
| 3411 |
-
|
| 3412 |
-
|
| 3413 |
-
|
| 3414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3415 |
searchClientCache.set(cacheKey, data);
|
| 3416 |
}
|
| 3417 |
lastSearch = { ra, dec, rows: data.rows };
|
|
|
|
| 24 |
(function () {
|
| 25 |
function rewriteSkyUrl(rawUrl) {
|
| 26 |
if (typeof rawUrl !== "string") return rawUrl;
|
| 27 |
+
const isLocal = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
|
| 28 |
+
if (!isLocal) {
|
| 29 |
+
if (rawUrl.indexOf("alasky.unistra.fr") >= 0 && rawUrl.indexOf("alasky.cds.unistra.fr") === -1) {
|
| 30 |
+
return rawUrl.replace("alasky.unistra.fr", "alasky.cds.unistra.fr");
|
| 31 |
+
}
|
| 32 |
+
return rawUrl;
|
| 33 |
+
}
|
| 34 |
if (rawUrl.indexOf("MocServer/query") >= 0) {
|
| 35 |
const qIdx = rawUrl.indexOf("?");
|
| 36 |
return qIdx >= 0 ? "/mocserver?" + rawUrl.slice(qIdx + 1) : "/mocserver";
|
|
|
|
| 1874 |
|
| 1875 |
let activeRegimeFilter = "all";
|
| 1876 |
const DEFAULT_SKY = "dss2-color";
|
| 1877 |
+
const DEFAULT_SKY_SURVEYS = [
|
| 1878 |
+
{ key: "dss2-color", label: "DSS2 color", id: "P/DSS2/color", url: "https://alasky.cds.unistra.fr/DSS/DSSColor" },
|
| 1879 |
+
{ key: "dss2-red", label: "DSS2 red", id: "P/DSS2/red", url: "https://alasky.cds.unistra.fr/DSS/DSS2Merged" },
|
| 1880 |
+
{ key: "2mass-color", label: "2MASS color", id: "P/2MASS/color", url: "https://alasky.cds.unistra.fr/2MASS/Color" },
|
| 1881 |
+
{ key: "allwise-color", label: "AllWISE color", id: "P/allWISE/color", url: "https://alasky.cds.unistra.fr/AllWISE/RGB-W4-W2-W1" },
|
| 1882 |
+
{ key: "panstarrs", label: "Pan-STARRS DR1 color", id: "P/PanSTARRS/DR1/color-z-zg-g", url: "https://alasky.cds.unistra.fr/Pan-STARRS/DR1/color-z-zg-g" },
|
| 1883 |
+
{ key: "sdss9", label: "SDSS9 color", id: "P/SDSS9/color", url: "https://alasky.cds.unistra.fr/SDSS/DR9/color" },
|
| 1884 |
+
{ key: "mellinger", label: "Mellinger optical", id: "P/DM/color", url: "https://alasky.cds.unistra.fr/MellingerRGB" },
|
| 1885 |
+
];
|
| 1886 |
+
let skySurveys = [...DEFAULT_SKY_SURVEYS];
|
| 1887 |
let currentSky = DEFAULT_SKY;
|
| 1888 |
let allCdsSurveys = [];
|
| 1889 |
let activeSurveyUrl = null;
|
| 1890 |
|
| 1891 |
+
function skyUrl(key) {
|
| 1892 |
+
if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
|
| 1893 |
+
return `${location.origin}/hips/${key}`;
|
| 1894 |
+
}
|
| 1895 |
+
const s = (skySurveys || []).find(x => x.key === key) || DEFAULT_SKY_SURVEYS.find(x => x.key === key);
|
| 1896 |
+
return s ? (s.id || s.url) : "P/DSS2/color";
|
| 1897 |
+
}
|
| 1898 |
|
| 1899 |
function renderSkyOptions() {
|
| 1900 |
skySelect.innerHTML = "";
|
|
|
|
| 1940 |
|
| 1941 |
async function initSky() {
|
| 1942 |
try {
|
| 1943 |
+
const res = await fetch("/api/sky");
|
| 1944 |
+
if (res.ok) {
|
| 1945 |
+
const list = await res.json();
|
| 1946 |
+
if (Array.isArray(list) && list.length > 0) {
|
| 1947 |
+
skySurveys = list.map(s => ({ ...s }));
|
| 1948 |
+
}
|
| 1949 |
+
}
|
| 1950 |
} catch (err) {
|
| 1951 |
+
// Fall back to DEFAULT_SKY_SURVEYS
|
|
|
|
| 1952 |
}
|
| 1953 |
renderSkyOptions();
|
| 1954 |
|
|
|
|
| 2280 |
if (surveyLoading.dataset.loading === "true") return;
|
| 2281 |
surveyLoading.dataset.loading = "true";
|
| 2282 |
try {
|
| 2283 |
+
let surveys = null;
|
| 2284 |
+
try {
|
| 2285 |
+
const res = await fetch("/api/sky/all");
|
| 2286 |
+
if (res.ok) {
|
| 2287 |
+
const data = await res.json();
|
| 2288 |
+
if (data && data.surveys && data.surveys.length > 0) surveys = data.surveys;
|
| 2289 |
+
}
|
| 2290 |
+
} catch (e) {}
|
| 2291 |
+
|
| 2292 |
+
if (!surveys) {
|
| 2293 |
+
try {
|
| 2294 |
+
const cdsRes = await fetch("https://alasky.cds.unistra.fr/MocServer/query?expr=hips_service_url=*&get=record&fmt=json");
|
| 2295 |
+
if (cdsRes.ok) {
|
| 2296 |
+
const cdsList = await cdsRes.json();
|
| 2297 |
+
surveys = cdsList.map(item => ({
|
| 2298 |
+
id: item.ID,
|
| 2299 |
+
title: item.obs_title || item.ID,
|
| 2300 |
+
url: item.hips_service_url,
|
| 2301 |
+
regime: item.obs_regime || "optical",
|
| 2302 |
+
description: item.obs_description || ""
|
| 2303 |
+
}));
|
| 2304 |
+
}
|
| 2305 |
+
} catch (cdsErr) {
|
| 2306 |
+
console.warn("CDS direct query failed, using built-in defaults:", cdsErr);
|
| 2307 |
+
}
|
| 2308 |
+
}
|
| 2309 |
+
|
| 2310 |
+
allCdsSurveys = preindexSurveys(surveys || DEFAULT_SKY_SURVEYS);
|
| 2311 |
surveyLoading.style.display = "none";
|
| 2312 |
surveyBrowserDirty = true;
|
|
|
|
| 2313 |
if (surveyPanel && surveyPanel.classList.contains("open")) {
|
| 2314 |
renderSurveyBrowser(surveySearchInput.value || "");
|
| 2315 |
surveyBrowserDirty = false;
|
| 2316 |
}
|
| 2317 |
} catch (err) {
|
| 2318 |
+
allCdsSurveys = preindexSurveys(DEFAULT_SKY_SURVEYS);
|
| 2319 |
+
surveyLoading.style.display = "none";
|
| 2320 |
} finally {
|
| 2321 |
delete surveyLoading.dataset.loading;
|
| 2322 |
}
|
|
|
|
| 3420 |
return new Date((v - 40587) * 86400000).toISOString().slice(0, 10);
|
| 3421 |
}
|
| 3422 |
|
| 3423 |
+
function searchLocalFootprints(ra, dec, radius) {
|
| 3424 |
+
const d2r = Math.PI / 180;
|
| 3425 |
+
const phi1 = dec * d2r;
|
| 3426 |
+
const waveRanges = {
|
| 3427 |
+
"SPHEREx-D1": [0.75e-6, 1.11e-6],
|
| 3428 |
+
"SPHEREx-D2": [1.11e-6, 1.64e-6],
|
| 3429 |
+
"SPHEREx-D3": [1.64e-6, 2.42e-6],
|
| 3430 |
+
"SPHEREx-D4": [2.42e-6, 3.42e-6],
|
| 3431 |
+
"SPHEREx-D5": [3.42e-6, 4.42e-6],
|
| 3432 |
+
"SPHEREx-D6": [4.42e-6, 5.00e-6],
|
| 3433 |
+
};
|
| 3434 |
+
|
| 3435 |
+
const rows = [];
|
| 3436 |
+
const coordsMap = (serverFileCoordinates && Object.keys(serverFileCoordinates).length > 0)
|
| 3437 |
+
? serverFileCoordinates
|
| 3438 |
+
: {};
|
| 3439 |
+
|
| 3440 |
+
for (const [fname, info] of Object.entries(coordsMap)) {
|
| 3441 |
+
if (!info || typeof info.ra !== "number" || typeof info.dec !== "number") continue;
|
| 3442 |
+
const phi2 = info.dec * d2r;
|
| 3443 |
+
const dphi = (info.dec - dec) * d2r;
|
| 3444 |
+
const dlambda = (info.ra - ra) * d2r;
|
| 3445 |
+
const a = Math.sin(dphi / 2) ** 2 + Math.cos(phi1) * Math.cos(phi2) * Math.sin(dlambda / 2) ** 2;
|
| 3446 |
+
const distDeg = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) * (180 / Math.PI);
|
| 3447 |
+
|
| 3448 |
+
if (distDeg <= (radius + 1.8)) {
|
| 3449 |
+
const bName = info.band || "SPHEREx-D1";
|
| 3450 |
+
const w = waveRanges[bName] || [0.75e-6, 5.0e-6];
|
| 3451 |
+
let polyStr = "";
|
| 3452 |
+
if (Array.isArray(info.polygon) && info.polygon.length >= 3) {
|
| 3453 |
+
polyStr = "Polygon ICRS " + info.polygon.map(pt => `${pt[0]} ${pt[1]}`).join(" ");
|
| 3454 |
+
}
|
| 3455 |
+
rows.push({
|
| 3456 |
+
obs_id: fname,
|
| 3457 |
+
access_url: `/files/${encodeURIComponent(bName)}/${encodeURIComponent(fname)}`,
|
| 3458 |
+
s_region: polyStr,
|
| 3459 |
+
em_min: w[0],
|
| 3460 |
+
em_max: w[1],
|
| 3461 |
+
energy_bandpassname: bName,
|
| 3462 |
+
t_min: 60780.0,
|
| 3463 |
+
s_ra: info.ra,
|
| 3464 |
+
s_dec: info.dec,
|
| 3465 |
+
distance_deg: Math.round(distDeg * 1000) / 1000
|
| 3466 |
+
});
|
| 3467 |
+
}
|
| 3468 |
+
}
|
| 3469 |
+
|
| 3470 |
+
rows.sort((a, b) => a.distance_deg - b.distance_deg);
|
| 3471 |
+
return {
|
| 3472 |
+
count: rows.length,
|
| 3473 |
+
rows: rows,
|
| 3474 |
+
irsa_notice: "Local SPHEREx Footprint Catalog"
|
| 3475 |
+
};
|
| 3476 |
+
}
|
| 3477 |
+
|
| 3478 |
const searchClientCache = new Map();
|
| 3479 |
|
| 3480 |
window.runSearch = runSearch;
|
|
|
|
| 3508 |
try {
|
| 3509 |
const coll = (sColl && sColl.value) ? sColl.value : "spherex_qr2";
|
| 3510 |
const cacheKey = `${ra.toFixed(4)}_${dec.toFixed(4)}_${radius.toFixed(3)}_${coll}`;
|
| 3511 |
+
let data = null;
|
| 3512 |
if (searchClientCache.has(cacheKey)) {
|
| 3513 |
data = searchClientCache.get(cacheKey);
|
| 3514 |
} else {
|
| 3515 |
+
try {
|
| 3516 |
+
const qs = new URLSearchParams({ ra, dec, radius, collection: coll });
|
| 3517 |
+
const res = await fetch(`/api/sia?${qs}`);
|
| 3518 |
+
if (res.ok) {
|
| 3519 |
+
data = await res.json();
|
| 3520 |
+
}
|
| 3521 |
+
} catch (netErr) {}
|
| 3522 |
+
|
| 3523 |
+
if (!data || !data.rows) {
|
| 3524 |
+
data = searchLocalFootprints(ra, dec, radius);
|
| 3525 |
+
}
|
| 3526 |
searchClientCache.set(cacheKey, data);
|
| 3527 |
}
|
| 3528 |
lastSearch = { ra, dec, rows: data.rows };
|