Skip to content

Commit 9483ffb

Browse files
committed
refactor: simplify check_kp_multi.sh to remove unused lat/lon parameters
- Removed TARGET_LAT and TARGET_LON (not needed for YR.no location-based API) - Simplified script parameters: now only min_kp and optional yr_location_id - Updated log structure to use location_id instead of lat/lon coordinates - Updated workflow to call script with simplified parameters - Cleaner API focused on YR.no's location-based system
1 parent 25da293 commit 9483ffb

4 files changed

Lines changed: 11 additions & 79 deletions

File tree

.github/workflows/post.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
id: kp_check
2929
if: steps.darkness.outcome == 'success'
3030
run: |
31-
OUTPUT=$(bash src/check_kp_multi.sh 59.959103 10.4592208 3)
31+
OUTPUT=$(bash src/check_kp_multi.sh 3)
3232
echo "$OUTPUT"
3333
# Extract VALIDATED_KP from output and save to GITHUB_OUTPUT
3434
VALIDATED_KP=$(echo "$OUTPUT" | grep "VALIDATED_KP=" | cut -d'=' -f2)

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,7 @@ Trigger a manual run:
143143

144144
- Tryvann: yr.no public webcams (directional views)
145145
- Sylling: yr.no public webcams
146-
## Resources
147-
148-
- [YR.no Aurora Forecast API](https://www.yr.no/en/content/1-83651/the-api-now-supports-an-auroraforecast-endpoint) - Real-time aurora data used by the bot
149-
- [Space Weather Prediction Center](https://www.swpc.noaa.gov/) - Official NOAA space weather site
150-
- [Aurora forecast for Norway](https://www.aurora-service.eu/aurora-forecast/) - Additional forecast source
151-
- [Bluesky API Documentation](https://docs.bsky.app/) - Bluesky API reference
146+
## Privacy
152147

153148
- Only processes public webcam feeds
154149
- No personal data collected or stored
@@ -166,9 +161,10 @@ Feel free to:
166161

167162
## Resources
168163

169-
- [Space Weather Prediction Center](https://www.swpc.noaa.gov/)
170-
- [Aurora forecast for Norway](https://www.aurora-service.eu/aurora-forecast/)
171-
- [Bluesky API Documentation](https://docs.bsky.app/)
164+
- [YR.no Aurora Forecast API](https://www.yr.no/en/content/1-83651/the-api-now-supports-an-auroraforecast-endpoint) - Real-time aurora data used by the bot
165+
- [Space Weather Prediction Center](https://www.swpc.noaa.gov/) - Space weather information
166+
- [Aurora forecast for Norway](https://www.aurora-service.eu/aurora-forecast/) - Additional forecast source
167+
- [Bluesky API Documentation](https://docs.bsky.app/) - Bluesky API reference
172168

173169
## License
174170

src/check_kp_multi.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
# KP/aurora check using YR.no API.
44
# Returns exit 0 if YR.no indicates aurora activity (kpIndex > threshold), else 1.
55
#
6-
# Usage: check_kp_multi.sh <lat> <lon> <min_kp> [yr_location_id]
6+
# Usage: check_kp_multi.sh <min_kp> [yr_location_id]
77

88
set -euo pipefail
99

1010
# Configuration
11-
YR_LOCATION_ID=${4:-"1-72662"} # Default: Lommedalen
11+
MIN_KP=${1:-3}
12+
YR_LOCATION_ID=${2:-"1-72662"} # Default: Lommedalen
1213
YR_URL="https://www.yr.no/api/v0/locations/${YR_LOCATION_ID}/auroraforecast?language=nb"
13-
14-
TARGET_LAT=${1:-59.959103}
15-
TARGET_LON=${2:-10.4592208}
16-
MIN_KP=${3:-3}
1714
KP_DATA_DIR="kp_data"
1815

1916
# Result trackers
@@ -76,15 +73,13 @@ FILE="${DIR}/${YEAR}_${MONTH}.jsonl"
7673

7774
LOG_LINE=$(jq -n \
7875
--arg ts "$TS" \
79-
--argjson lat "$TARGET_LAT" \
80-
--argjson lon "$TARGET_LON" \
76+
--arg location_id "$YR_LOCATION_ID" \
8177
--argjson yr_kp "${YR_KP_INDEX:-0}" \
8278
--argjson yr_aurora "$YR_AURORA_MAX" \
8379
--arg yr_triggered "$YR_TRIGGERED" \
8480
'{
8581
timestamp: $ts,
86-
target_lat: $lat,
87-
target_lon: $lon,
82+
location_id: $location_id,
8883
yr: {kp_index: $yr_kp, aurora_value: $yr_aurora, triggered: ($yr_triggered == "true")}
8984
}'
9085
)

src/main.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -69,65 +69,6 @@ def get_ai_token() -> Optional[str]:
6969
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
7070
azure_rate_limited = False
7171

72-
# Aurora / Kp data source (Ovation model latest snapshot)
73-
OVATION_URL = "https://services.swpc.noaa.gov/json/ovation_aurora_latest.json"
74-
75-
def fetch_current_kp(lat: float = 59.0, lon: float = 10.0) -> Optional[float]:
76-
"""Fetch a local Kp-like value for given coordinates (default Lommedalen area ~59N,10E) using Ovation model.
77-
78-
The endpoint returns a JSON object containing a list of coordinate triples: [latitude, longitude, value].
79-
Example target triple: [59, 10, 0] -> we interpret the third number as localized activity (proxy for Kp / auroral intensity).
80-
81-
Return:
82-
float value (third element) if exact or nearest coordinate found, else None.
83-
Notes:
84-
- This is a localized intensity proxy, not necessarily the global planetary Kp.
85-
- We perform nearest-neighbor match (within 1 degree) if exact integer lat/lon not present.
86-
"""
87-
try:
88-
resp = requests.get(OVATION_URL, timeout=12)
89-
resp.raise_for_status()
90-
data = resp.json()
91-
except Exception as e:
92-
logging.warning(f"Ovation request failed: {e}")
93-
return None
94-
95-
coords = data.get("coordinates") or data.get("data") or []
96-
if not isinstance(coords, list) or not coords:
97-
logging.debug("Ovation payload missing 'coordinates' list")
98-
return None
99-
100-
target_lat = int(round(lat))
101-
target_lon = int(round(lon))
102-
103-
exact_match_val: Optional[float] = None
104-
nearest_val: Optional[float] = None
105-
nearest_dist: float = 9999.0
106-
107-
for triple in coords:
108-
if not (isinstance(triple, list) and len(triple) >= 3):
109-
continue
110-
c_lat, c_lon, c_val = triple[0], triple[1], triple[2]
111-
# Basic validation of numeric types
112-
if not (isinstance(c_lat, (int, float)) and isinstance(c_lon, (int, float)) and isinstance(c_val, (int, float))):
113-
continue
114-
if int(c_lat) == target_lat and int(c_lon) == target_lon:
115-
exact_match_val = float(c_val)
116-
break
117-
# Track nearest within reasonable range (<=1 degree separation)
118-
dist = abs(c_lat - lat) + abs(c_lon - lon)
119-
if dist < nearest_dist and dist <= 1.0:
120-
nearest_dist = dist
121-
nearest_val = float(c_val)
122-
123-
kp_local = exact_match_val if exact_match_val is not None else nearest_val
124-
if kp_local is None:
125-
logging.debug("No suitable Ovation coordinate match for specified location")
126-
return None
127-
128-
logging.info(f"Local Ovation intensity (proxy Kp) at ~({target_lat},{target_lon}) = {kp_local:.2f}")
129-
return kp_local
130-
13172

13273
def get_validated_kp() -> Optional[float]:
13374
"""Read the most recent KP data from bash script logs (YR.no validation).

0 commit comments

Comments
 (0)