Skip to content

Commit afb1f92

Browse files
committed
Improve comet photometry extraction and add robust SBDB fallback
Improve reliability of comet photometry discovery and persistence by enhancing aerith scraping logic, adding a focused JPL SBDB fallback, and persisting discovered photometry to the model. - Make aerith year-page discovery and parsing more tolerant and selective so pages with real photometry are prioritized. - Add a focused CLI option to process a single target and perform an aggressive SBDB lookup path for fast updates. - Implement a robust SBDB fallback: generate multiple query variants, retry transient errors, parse diverse phys_par formats, and return H, slope (n), and phase when available. - Persist discovered photometry (H, n, phase_coeff and related slope fields) to the orbital-elements model and expose those fields for mass assignment. - Add a small helper script to exercise SBDB queries locally. - Overall effect: fewer missed photometry values, quicker targeted updates, and safer, more reliable external-catalog lookups.
1 parent 9520ca7 commit afb1f92

4 files changed

Lines changed: 793 additions & 64 deletions

File tree

changelog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to `laravel-astronomy-library` will be documented in this file.
44

5+
## Version 6.7.5
6+
7+
Changed:
8+
9+
- Improved aerith/SBDB fallback behavior and photometry persistence (already introduced earlier, documented here for visibility):
10+
- The command still attempts aerith.net year-specific pages and directory candidates, and falls back to JPL SBDB when aerith scraping yields no photometry.
11+
- Photometry values discovered (absolute magnitude `H`, slope `n`, and phase coefficient/G when available) are persisted to the `comets_orbital_elements` model.
12+
13+
Changed (Model):
14+
15+
- `CometsOrbitalElements` (`src/deepskylog/AstronomyLibrary/Models/CometsOrbitalElements.php`):
16+
- Exposes photometry fields in `$fillable`: `H`, `n`, `phase_coeff`, `n_pre`, `n_post` so the `astronomy:updateCometPhotometry` command can persist discovered values.
17+
- Uses `name` as the primary key and disables timestamps (no behavior change, documented for clarity).
18+
519
## Version 6.7.4
620

721
Changed:

scripts/check_sbdb.sh

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env bash
2+
# scripts/check_sbdb.sh
3+
# Quick helper to test SBDB lookups (des= and sstr=) and extract phys_par values (M1/K1/G)
4+
# Usage: ./scripts/check_sbdb.sh "C/1972 E1"
5+
6+
set -euo pipefail
7+
query="$1"
8+
if [ -z "$query" ]; then
9+
echo "Usage: $0 \"designation or name\""
10+
exit 1
11+
fi
12+
13+
# urlencode helper using python3
14+
urlencode() {
15+
python3 -c "import urllib.parse,sys;print(urllib.parse.quote(sys.argv[1]))" "$1"
16+
}
17+
18+
variants=()
19+
variants+=("$query")
20+
# strip parentheses
21+
no_paren=$(echo "$query" | sed -E 's/\s*\(.*\)\s*//')
22+
if [ "$no_paren" != "$query" ]; then
23+
variants+=("$no_paren")
24+
fi
25+
# normalized spacing
26+
norm=$(echo "$no_paren" | tr -s ' /' ' ')
27+
variants+=("$norm")
28+
variants+=("$(echo "$norm" | tr -d ' ')")
29+
# add C/ and P/ prefixes if not already
30+
if [[ ! $no_paren =~ ^[CP]/ ]]; then
31+
variants+=("C/$no_paren")
32+
variants+=("P/$no_paren")
33+
fi
34+
# add name tokens
35+
IFS=' /' read -r -a parts <<< "$query"
36+
if [ ${#parts[@]} -gt 1 ]; then
37+
tail_tokens=()
38+
for p in "${parts[@]}"; do
39+
if [[ $p =~ [A-Za-z] ]]; then
40+
tail_tokens+=("$p")
41+
fi
42+
done
43+
if [ ${#tail_tokens[@]} -gt 0 ]; then
44+
variants+=("${tail_tokens[*]}")
45+
variants+=("$(printf "%s" "${tail_tokens[*]}" | tr -d ' ')")
46+
fi
47+
fi
48+
49+
# deduplicate while preserving order
50+
declare -A seen
51+
cands=()
52+
for v in "${variants[@]}"; do
53+
vtrim=$(echo "$v" | sed -E 's/^\s+|\s+$//g')
54+
if [ -z "$vtrim" ]; then
55+
continue
56+
fi
57+
if [ -z "${seen[$vtrim]:-}" ]; then
58+
seen[$vtrim]=1
59+
cands+=("$vtrim")
60+
fi
61+
done
62+
63+
echo "Testing SBDB lookup variants for: $query"
64+
65+
found_any=0
66+
for cq in "${cands[@]}"; do
67+
enc=$(urlencode "$cq")
68+
for mode in des sstr; do
69+
url="https://ssd-api.jpl.nasa.gov/sbdb.api?${mode}=${enc}&phys-par=1"
70+
echo "\n-> Trying ${mode}=${cq}"
71+
body=$(curl -sS "$url" || true)
72+
if [ -z "$body" ]; then
73+
echo " (no response)"
74+
continue
75+
fi
76+
has_obj=$(echo "$body" | jq 'has("object") or has("orbit")' 2>/dev/null || echo false)
77+
if [ "$has_obj" = "true" ]; then
78+
found_any=1
79+
echo " SBDB record found (mode=${mode})"
80+
else
81+
echo " No object/orbit in response"
82+
fi
83+
84+
# Extract phys_par values: M1, K1, M2, K2, G
85+
m1=$(echo "$body" | jq -r '(.phys_par[]? | select(.name=="M1") | .value) // empty' 2>/dev/null || echo '')
86+
k1=$(echo "$body" | jq -r '(.phys_par[]? | select(.name=="K1") | .value) // empty' 2>/dev/null || echo '')
87+
m2=$(echo "$body" | jq -r '(.phys_par[]? | select(.name=="M2") | .value) // empty' 2>/dev/null || echo '')
88+
k2=$(echo "$body" | jq -r '(.phys_par[]? | select(.name=="K2") | .value) // empty' 2>/dev/null || echo '')
89+
gval=$(echo "$body" | jq -r '(.phys_par[]? | select(.name=="G") | .value) // empty' 2>/dev/null || echo '')
90+
91+
if [ -n "$m1" ] || [ -n "$k1" ] || [ -n "$m2" ] || [ -n "$k2" ] || [ -n "$gval" ]; then
92+
echo " phys_par found:"
93+
[ -n "$m1" ] && echo " M1 (total H) = $m1"
94+
[ -n "$k1" ] && echo " K1 (slope n) = $k1"
95+
[ -n "$m2" ] && echo " M2 (nuclear H) = $m2"
96+
[ -n "$k2" ] && echo " K2 (nuclear slope) = $k2"
97+
[ -n "$gval" ] && echo " G (phase) = $gval"
98+
# print a short object fullname if present
99+
fullname=$(echo "$body" | jq -r '.object.fullname // empty' 2>/dev/null || echo '')
100+
if [ -n "$fullname" ]; then
101+
echo " object fullname: $fullname"
102+
fi
103+
else
104+
echo " No phys_par (M1/K1/etc.) in response"
105+
fi
106+
107+
# If we found an object, stop further queries for brevity
108+
if [ "$has_obj" = "true" ]; then
109+
# break out of inner loop
110+
break 2
111+
fi
112+
done
113+
done
114+
115+
if [ $found_any -eq 0 ]; then
116+
echo "\nNo SBDB record found for any variant of: $query"
117+
exit 2
118+
fi
119+
120+
echo "\nDone."

0 commit comments

Comments
 (0)