Support fetching ionosonde data for FoF2 and MUF display on the Conditions page

This commit is contained in:
Ian Renton
2026-05-15 18:25:54 +01:00
parent 2026b46113
commit 64a7b27887
17 changed files with 473 additions and 28 deletions

View File

@@ -183,6 +183,10 @@ solar-condition-providers:
class: "NOAA3dayForecast"
name: "NOAA 3-day Forecast"
enabled: true
-
class: "GIROIonosonde"
name: "GIRO Ionosonde Data"
enabled: true
# Port to open the local web server on
web-server-port: 8080

View File

@@ -161,6 +161,8 @@ class SolarConditions:
blackout_forecast_r1r2: dict = None
# NOAA Radio Blackout (R3 or greater) probability forecast, keyed by UNIX timestamp of start of day UTC
blackout_forecast_r3_or_greater: dict = None
# Ionosonde measurements from LGDC, list of dicts with keys: ursi, name, fof2, muf
ionosonde_data: list = None
# Derived values (populated by infer_descriptions())
# HF radio blackout risk description, derived from xray

View File

@@ -0,0 +1,42 @@
AA343,"Almaty, Kazakhstan"
AL945,"Alpena, United States"
AT138,"Athens, Greece"
AU930,"Austin, United States"
BR52P,"Brisbane, Australia"
BVJ03,"Boa Vista, Brazil"
CAJ2M,"Cachoeira Paulista, Brazil"
CB53N,"Canberra, Australia"
CGK21,"Campo Grande, Brazil"
DB049,"Dourbes, Belgium"
DW41K,"Darwin, Australia"
EA036,"El Arenosillo, Spain"
EB040,"Roquetes, Spain"
EG931,"Eglin Air Force Base, United States"
FF051,"Fairford, United Kingdom"
GA762,"Gakona, United States"
GM037,"Gibilmanna, Italy"
GR13L,"Grahamstown, South Africa"
HE13N,"Hermanus, South Africa"
HO54K,"Hobart, Australia"
IC437,"I-Cheon, South Korea"
IF843,"Idaho National Laboratory, United States"
JI91J,"Jicamarca, Peru"
JR055,"Juliusruh, Germany"
LAA38,"Lajes Terceira Island, Portugal"
LL721,"Lualualei, United States"
LM42B,"Learmonth, Australia"
LV12P,"Louisvale, South Africa"
MHJ45,"Millstone Hill, United States"
ML10L,"Malindi, Kenya"
NI135,"Nicosia, Cyprus"
NI63_,"Norfolk, Australia"
PA836,"Portt Arguello, United States"
PE43K,"Perth, Australia"
PF765,"Poker Flat, United States"
PQ052,"Pruhonice, Czechia"
RO041,"Rome, Italy"
SAA0K,"Saoluis, Brazil"
SO148,"Sopron, Hungary"
TR169,"Tromso, Norway"
TV51R,"Townsville, Australia"
VT139,"San Vito, Italy"
1 AA343 Almaty, Kazakhstan
2 AL945 Alpena, United States
3 AT138 Athens, Greece
4 AU930 Austin, United States
5 BR52P Brisbane, Australia
6 BVJ03 Boa Vista, Brazil
7 CAJ2M Cachoeira Paulista, Brazil
8 CB53N Canberra, Australia
9 CGK21 Campo Grande, Brazil
10 DB049 Dourbes, Belgium
11 DW41K Darwin, Australia
12 EA036 El Arenosillo, Spain
13 EB040 Roquetes, Spain
14 EG931 Eglin Air Force Base, United States
15 FF051 Fairford, United Kingdom
16 GA762 Gakona, United States
17 GM037 Gibilmanna, Italy
18 GR13L Grahamstown, South Africa
19 HE13N Hermanus, South Africa
20 HO54K Hobart, Australia
21 IC437 I-Cheon, South Korea
22 IF843 Idaho National Laboratory, United States
23 JI91J Jicamarca, Peru
24 JR055 Juliusruh, Germany
25 LAA38 Lajes Terceira Island, Portugal
26 LL721 Lualualei, United States
27 LM42B Learmonth, Australia
28 LV12P Louisvale, South Africa
29 MHJ45 Millstone Hill, United States
30 ML10L Malindi, Kenya
31 NI135 Nicosia, Cyprus
32 NI63_ Norfolk, Australia
33 PA836 Portt Arguello, United States
34 PE43K Perth, Australia
35 PF765 Poker Flat, United States
36 PQ052 Pruhonice, Czechia
37 RO041 Rome, Italy
38 SAA0K Saoluis, Brazil
39 SO148 Sopron, Hungary
40 TR169 Tromso, Norway
41 TV51R Townsville, Australia
42 VT139 San Vito, Italy

View File

@@ -11,11 +11,12 @@ from core.prometheus_metrics_handler import page_requests_counter
class PageTemplateHandler(tornado.web.RequestHandler):
"""Handler for all HTML pages generated from templates"""
def initialize(self, template_name, web_server_metrics, has_hamqsl=False, has_noaa_forecast=False):
def initialize(self, template_name, web_server_metrics, has_hamqsl=False, has_noaa_forecast=False, has_giro_ionosonde=False):
self._template_name = template_name
self._web_server_metrics = web_server_metrics
self._has_hamqsl = has_hamqsl
self._has_noaa_forecast = has_noaa_forecast
self._has_giro_ionosonde = has_giro_ionosonde
def get(self):
# Metrics
@@ -27,4 +28,5 @@ class PageTemplateHandler(tornado.web.RequestHandler):
# Load named template, and provide variables used in templates
self.render(self._template_name + ".html", software_version=SOFTWARE_VERSION, allow_spotting=ALLOW_SPOTTING,
web_ui_options=WEB_UI_OPTIONS, baseurl=BASE_URL, current_path=self.request.path,
has_hamqsl=self._has_hamqsl, has_noaa_forecast=self._has_noaa_forecast)
has_hamqsl=self._has_hamqsl, has_noaa_forecast=self._has_noaa_forecast,
has_giro_ionosonde=self._has_giro_ionosonde)

View File

@@ -57,8 +57,9 @@ class WebServer:
provider_classes = [type(p).__name__ for p in self._solar_condition_providers if p.enabled]
has_hamqsl = "HamQSL" in provider_classes
has_noaa_forecast = "NOAA3dayForecast" in provider_classes
has_giro_ionosonde = "GIROIonosonde" in provider_classes
page_opts = {"web_server_metrics": self.web_server_metrics, "has_hamqsl": has_hamqsl,
"has_noaa_forecast": has_noaa_forecast}
"has_noaa_forecast": has_noaa_forecast, "has_giro_ionosonde": has_giro_ionosonde}
app = tornado.web.Application([
# Routes for API calls

View File

@@ -0,0 +1,122 @@
import csv
import logging
from datetime import datetime, timezone, timedelta
from threading import Thread, Event
import pytz
import requests
from core.constants import HTTP_HEADERS
from solarconditionsproviders.solar_conditions_provider import SolarConditionsProvider
POLL_INTERVAL = 3600 # 1 hour
STATIONS_INDEX = "datafiles/didbase-stations.csv"
LGDC_URL = "https://lgdc.uml.edu/common/DIDBGetValues"
HISTORY_HOURS = 24
class GIROIonosonde(SolarConditionsProvider):
"""Solar conditions provider using ionosonde data from the GIRO Data Center.
Queries foF2 and MUF measurements for all stations in datafiles/didbase-stations.csv."""
def __init__(self, provider_config):
super().__init__(provider_config)
self._stations = self._load_stations()
self._thread = None
self._stop_event = Event()
def _load_stations(self):
"""Load the CSV file containing the list of URSIs and Station Names for currently active ionosondes."""
stations = []
with open(STATIONS_INDEX, newline='') as f:
for row in csv.reader(f):
if len(row) >= 2:
stations.append({"ursi": row[0].strip(), "name": row[1].strip()})
return stations
def start(self):
logging.info(f"Set up query of GIRO ionosonde data API every {POLL_INTERVAL} seconds.")
self._thread = Thread(target=self._run, daemon=True)
self._thread.start()
def stop(self):
self._stop_event.set()
def _run(self):
while True:
self._poll()
if self._stop_event.wait(timeout=POLL_INTERVAL):
break
def _poll(self):
try:
logging.debug(f"Polling {self.name} ionosonde data...")
now = datetime.now(timezone.utc)
from_time = now - timedelta(hours=HISTORY_HOURS)
results = []
for station in self._stations:
if self._stop_event.is_set():
break
ursi = station["ursi"]
name = station["name"]
entry = {"ursi": ursi, "name": name, "fof2": None, "muf": None}
try:
fof2, muf = self._fetch_station_data(ursi, from_time, now)
entry["fof2"] = fof2
entry["muf"] = muf
if fof2 and muf:
results.append(entry)
except Exception:
logging.debug(f"Could not fetch ionosonde data for {ursi} ({name})")
self.update_data({"ionosonde_data": results})
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
logging.debug(f"Received ionosonde data for {len(results)} stations from {self.name}.")
except Exception:
self.status = "Error"
logging.exception(f"Exception in GIRO Ionosonde data provider ({self.name})")
self._stop_event.wait(timeout=1)
def _fetch_station_data(self, ursi, from_time, to_time):
"""Fetch foF2 and MUF readings for a station. Returns (fof2_dict, muf_dict) keyed by UNIX timestamp."""
from_str = from_time.strftime("%Y.%m.%d+%H:%M:%S")
to_str = to_time.strftime("%Y.%m.%d+%H:%M:%S")
url = (
f"{LGDC_URL}?ursiCode={ursi}&charName=foF2,MUFD&DMUF=3000&fromDate={from_str}&toDate={to_str}"
)
response = requests.get(url, headers=HTTP_HEADERS, timeout=(5, 15))
if response.status_code != 200:
return None, None
return self._parse_all(response.text)
@staticmethod
def _parse_all(text):
"""Parse web server response and return (fof2_dict, muf_dict) keyed by UNIX timestamp."""
fof2_data = {}
muf_data = {}
for line in text.splitlines():
line = line.strip()
if not line or line.startswith('#'):
continue
# Data rows: timestamp CS foF2 QD MUFD QD
parts = line.split()
if len(parts) >= 5:
try:
ts = datetime.fromisoformat(parts[0].replace('Z', '+00:00')).timestamp()
except ValueError:
continue
try:
fof2_data[ts] = float(parts[2])
except ValueError:
pass
try:
muf_data[ts] = float(parts[4])
except ValueError:
pass
return fof2_data, muf_data

View File

@@ -27,7 +27,7 @@
<h4 class="mt-4">What data sources are supported?</h4>
<p>Spothole can retrieve spots from: <a href="https://www.dxcluster.info/telnet/">Telnet-based DX clusters</a>, the <a href="https://www.reversebeacon.net/">Reverse Beacon Network (RBN)</a>, the <a href="https://www.aprs-is.net/">APRS Internet Service (APRS-IS)</a>, <a href="https://pota.app">POTA</a>, <a href="https://www.sota.org.uk/">SOTA</a>, <a href="https://wwff.co/">WWFF</a>, <a href="https://www.cqgma.org/">GMA</a>, <a href="https://wwbota.net/">WWBOTA</a>, <a href="http://www.hema.org.uk/">HEMA</a>, <a href="https://www.parksnpeaks.org/">Parks 'n' Peaks</a>, <a href="https://ontheair.nz">ZLOTA</a>, <a href="https://www.wota.org.uk/">WOTA</a>, <a href="https://llota.app">LLOTA</a>, <a href="https://wwtota.com">WWTOTA</a>, <a href="https://tilesontheair.com/">Tiles on the Air</a>, the <a href="https://ukpacketradio.network/">UK Packet Repeater Network</a>, and any site based on the <a href="https://github.com/nischu/xOTA">xOTA software by nischu</a>.</p>
<p>Spothole can retrieve alerts from: <a href="https://www.ng3k.com/">NG3K</a>, <a href="https://pota.app">POTA</a>, <a href="https://www.sota.org.uk/">SOTA</a>, <a href="https://wwff.co/">WWFF</a>, <a href="https://www.parksnpeaks.org/">Parks 'n' Peaks</a>, <a href="https://www.wota.org.uk/">WOTA</a> and <a href="https://www.beachesontheair.com/">BOTA</a>.</p>
<p>Spothole can retrieve solar and propagation condition data from <a href="https://www.hamqsl.com">HamQSL</a>.</p>
<p>Spothole can retrieve solar and propagation condition data from <a href="https://www.hamqsl.com">HamQSL</a>, the <a href="https://www.swpc.noaa.gov/">NOAA Space Weather Prediction Center</a> and the <a href="https://giro.uml.edu/">Lowell GIRO Data Center</a>.</p>
<p>Spothole can also perform lookups for callsign data on behalf of the user from <a href="https://qrz.com">QRZ.com</a> and <a href="https://hamqth.com">HamQTH</a>.</p>
<p>Note that the server owner has not necessarily enabled all these data sources. In particular it is common to disable RBN, to avoid the server being swamped with FT8 traffic, and to disable APRS-IS and UK Packet Net so that the server only displays stations where there is likely to be an operator physically present for a QSO.</p>
<p>Between the various data sources, the following Special Interest Groups (SIGs) are supported: Parks on the Air (POTA), Summits on the Air (SOTA), Worldwide Flora & Fauna (WWFF), Global Mountain Activity (GMA), Worldwide Bunkers on the Air (WWBOTA), HuMPs Excluding Marilyns Award (HEMA), Islands on the Air (IOTA), Mills on the Air (MOTA), the Amateur Radio Lighthouse Socirty (ARLHS), International Lighthouse Lightship Weekend (ILLW), Silos on the Air (SIOTA), World Castles Award (WCA), New Zealand on the Air (ZLOTA), Keith Roget Memorial National Parks Award (KRMNPA), Wainwrights on the Air (WOTA), Beaches on the Air (BOTA), Lagos y Lagunas On the Air (LLOTA), Towers on the Air (WWTOTA), Tiles on the Air, Worked All Britain (WAB), Worked All Ireland (WAI), and Toilets on the Air (TOTA).</p>
@@ -69,7 +69,7 @@
<p>This software is dedicated to the memory of Tom G1PJB, SK, a friend and colleague who sadly passed away around the time I started writing it in Autumn 2025. I was looking forward to showing it to you when it was done.</p>
</div>
<script src="/js/common.js?v=1778853559"></script>
<script src="/js/common.js?v=1778865954"></script>
<script>$(document).ready(function() { $("#nav-link-about").addClass("active"); }); <!-- highlight active page in nav --></script>
{% end %}

View File

@@ -69,8 +69,8 @@
</div>
<script src="/js/common.js?v=1778853559"></script>
<script src="/js/add-spot.js?v=1778853559"></script>
<script src="/js/common.js?v=1778865954"></script>
<script src="/js/add-spot.js?v=1778865954"></script>
<script>$(document).ready(function() { $("#nav-link-add-spot").addClass("active"); }); <!-- highlight active page in nav --></script>
{% end %}

View File

@@ -70,8 +70,8 @@
</div>
<script src="/js/common.js?v=1778853559"></script>
<script src="/js/alerts.js?v=1778853559"></script>
<script src="/js/common.js?v=1778865955"></script>
<script src="/js/alerts.js?v=1778865955"></script>
<script>$(document).ready(function() { $("#nav-link-alerts").addClass("active"); }); <!-- highlight active page in nav --></script>
{% end %}

View File

@@ -76,9 +76,9 @@
<script>
let spotProvidersEnabledByDefault = {% raw json_encode(web_ui_options["spot-providers-enabled-by-default"]) %};
</script>
<script src="/js/common.js?v=1778853559"></script>
<script src="/js/spotsbandsandmap.js?v=1778853559"></script>
<script src="/js/bands.js?v=1778853559"></script>
<script src="/js/common.js?v=1778865954"></script>
<script src="/js/spotsbandsandmap.js?v=1778865954"></script>
<script src="/js/bands.js?v=1778865954"></script>
<script>$(document).ready(function() { $("#nav-link-bands").addClass("active"); }); <!-- highlight active page in nav --></script>
{% end %}

View File

@@ -24,7 +24,7 @@
<title>Spothole</title>
<link rel="stylesheet" href="/css/style.css?v=1778853559" type="text/css">
<link rel="stylesheet" href="/css/style.css?v=1778865954" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
<link href="/fa/css/fontawesome.min.css" rel="stylesheet" />
@@ -52,9 +52,9 @@
integrity="sha384-L1eE4eD41kpBIWe2I0eHy+GnEUC4RIpcvibVW2JCminuPlTl+2Bc528iPdVMg5Dn"
crossorigin="anonymous"></script>
<script src="https://misc.ianrenton.com/jsutils/utils.js?v=1778853559"></script>
<script src="https://misc.ianrenton.com/jsutils/ui-ham.js?v=1778853559"></script>
<script src="https://misc.ianrenton.com/jsutils/geo.js?v=1778853559"></script>
<script src="https://misc.ianrenton.com/jsutils/utils.js?v=1778865954"></script>
<script src="https://misc.ianrenton.com/jsutils/ui-ham.js?v=1778865954"></script>
<script src="https://misc.ianrenton.com/jsutils/geo.js?v=1778865954"></script>
</head>
<body>

View File

@@ -137,7 +137,7 @@
{% if has_noaa_forecast %}
<div class="card mt-5">
<div class="card-header">
Forecast
Solar Weather Forecast
</div>
<div class="card-body">
<div class="row mb-4">
@@ -173,6 +173,25 @@
</div>
{% end %}
{% if has_giro_ionosonde %}
<div class="card mt-5">
<div class="card-header">
Critical Frequency and Maximum Usable Frequency
</div>
<div class="card-body">
<div class="mb-3">
<label for="ionosonde-station" class="form-label">Ionosonde station:</label>
<select id="ionosonde-station" class="form-select storeable-select d-inline-block ms-2"
style="width: auto;" oninput="ionosondeStationChanged();">
</select>
</div>
<div id="ionosonde-latest" class="mb-3"></div>
<canvas id="ionosonde-chart" class="mt-3 mb-3 d-none d-md-block"></canvas>
<div class="form-text mt-2">Data from the <a href="https://lgdc.uml.edu/">Lowell GIRO Data Center</a>.</div>
</div>
</div>
{% end %}
<div class="card mt-5">
<div class="card-header">
DX Opportunities
@@ -230,8 +249,8 @@
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.9/dist/chart.umd.min.js"></script>
<script src="/js/common.js?v=1778853559"></script>
<script src="/js/conditions.js?v=1778853559"></script>
<script src="/js/common.js?v=1778865954"></script>
<script src="/js/conditions.js?v=1778865954"></script>
<script>$(document).ready(function () {
$("#nav-link-conditions").addClass("active");
}); <!-- highlight active page in nav --></script>

View File

@@ -94,9 +94,9 @@
<script>
let spotProvidersEnabledByDefault = {% raw json_encode(web_ui_options["spot-providers-enabled-by-default"]) %};
</script>
<script src="/js/common.js?v=1778853559"></script>
<script src="/js/spotsbandsandmap.js?v=1778853559"></script>
<script src="/js/map.js?v=1778853559"></script>
<script src="/js/common.js?v=1778865955"></script>
<script src="/js/spotsbandsandmap.js?v=1778865955"></script>
<script src="/js/map.js?v=1778865955"></script>
<script>$(document).ready(function() { $("#nav-link-map").addClass("active"); }); <!-- highlight active page in nav --></script>
{% end %}

View File

@@ -104,9 +104,9 @@
<script>
let spotProvidersEnabledByDefault = {% raw json_encode(web_ui_options["spot-providers-enabled-by-default"]) %};
</script>
<script src="/js/common.js?v=1778853559"></script>
<script src="/js/spotsbandsandmap.js?v=1778853559"></script>
<script src="/js/spots.js?v=1778853559"></script>
<script src="/js/common.js?v=1778865954"></script>
<script src="/js/spotsbandsandmap.js?v=1778865954"></script>
<script src="/js/spots.js?v=1778865954"></script>
<script>$(document).ready(function() { $("#nav-link-spots").addClass("active"); }); <!-- highlight active page in nav --></script>
{% end %}

View File

@@ -59,8 +59,8 @@
</div>
</div>
<script src="/js/common.js?v=1778853559"></script>
<script src="/js/status.js?v=1778853559"></script>
<script src="/js/common.js?v=1778865954"></script>
<script src="/js/status.js?v=1778865954"></script>
<script>
$(document).ready(function() { $("#nav-link-status").addClass("active"); }); <!-- highlight active page in nav -->
</script>

View File

@@ -13,6 +13,10 @@ info:
## Changelog
### 1.4
* `/solar` response now includes `ionosonde_data`, a list of ionosonde station measurements (foF2 and MUF) sourced from the GIRO Data Center.
### 1.3
* `/spots`, `/spots/stream`, `/alerts`, `/alerts/stream`, and `/lookup/call` now accept optional QRZ.com and HamQTH credentials as query parameters. When supplied, returned data is enriched with operator name, home location etc. from those services.
@@ -1683,6 +1687,46 @@ components:
type: string
description: Electron flux impact description, derived from electron flux level.
example: "No impact"
ionosonde_data:
type: array
nullable: true
description: >
Ionosonde measurements from the GIRO Data Center, covering active stations listed in the
system. Only stations for which data was successfully retrieved are included. Null if the
GIROIonosonde provider has not yet completed its first poll.
items:
$ref: '#/components/schemas/IonosondeStation'
IonosondeStation:
type: object
description: Ionosonde measurement data for a single station, covering approximately the last 24 hours.
properties:
ursi:
type: string
description: URSI code identifying the ionosonde station.
example: DB049
name:
type: string
description: Human-readable name of the ionosonde station.
example: Dourbes
fof2:
type: object
nullable: true
description: F2 layer critical frequency (foF2) measurements in MHz, keyed by UNIX timestamp (UTC seconds since epoch) of each measurement.
additionalProperties:
type: number
example:
"1747267201.0": 7.45
"1747267501.0": 7.50
muf:
type: object
nullable: true
description: Maximum Usable Frequency (MUF) for a 3000 km path in MHz, keyed by UNIX timestamp (UTC seconds since epoch) of each measurement.
additionalProperties:
type: number
example:
"1747267201.0": 21.66
"1747267501.0": 21.80
SolarConditionsProviderStatus:
type: object

View File

@@ -1,8 +1,12 @@
// Cache for the full dxstats API response, so we can reload on the fly if the user changes the value of their continent
// in the select box
let dxStatsData = null;
// Forecast chart
// Kp forecast chart
let kpChart = null;
// Cache for ionosonde data from the API
let ionosondeData = null;
// Ionosonde foF2/MUF chart
let ionosondeChart = null;
// Load solar conditions
function loadSolarConditions() {
@@ -109,6 +113,14 @@ function loadSolarConditions() {
electronFlux <= 100 ? 'bg-success-subtle' : electronFlux <= 1000 ? 'bg-warning-subtle' : 'bg-danger-subtle');
}
// Ionosonde
if (jsonData.ionosonde_data && jsonData.ionosonde_data.length > 0) {
ionosondeData = jsonData.ionosonde_data;
populateIonosondeDropdown(ionosondeData);
renderIonosondeData();
}
// Forecast
renderKIndexForecast(jsonData.k_index_forecast);
@@ -348,6 +360,203 @@ function renderBlackoutForecast(r1r2Data, r3Data) {
.append(makeRow('R3 or greater', e => e.r3));
}
// Populate the ionosonde station dropdown and restore any saved selection
function populateIonosondeDropdown(data) {
const select = $('#ionosonde-station');
const savedUrsi = localStorage.getItem('#ionosonde-station:value');
const savedValue = savedUrsi ? JSON.parse(savedUrsi) : null;
select.empty();
data.forEach(function (station) {
select.append($('<option>', {value: station.ursi, text: station.name}));
});
if (savedValue && select.find('option[value="' + savedValue + '"]').length) {
select.val(savedValue);
}
}
// Render the foF2/MUF data and line chart for the currently selected station
function renderIonosondeData() {
if (!ionosondeData) return;
const ursi = $('#ionosonde-station').val();
if (!ursi) return;
const station = ionosondeData.find(function (s) {
return s.ursi === ursi;
});
if (!station) return;
const style = getComputedStyle(document.documentElement);
const fof2Color = style.getPropertyValue('--bs-primary').trim();
const mufColor = style.getPropertyValue('--bs-danger').trim();
const textColor = style.getPropertyValue('--bs-body-color').trim() || '#666';
const gridColor = style.getPropertyValue('--bs-border-color').trim() || 'rgba(128,128,128,0.3)';
function toSeries(dict) {
if (!dict) return [];
return Object.entries(dict)
.map(([tsStr, val]) => ({ts: parseFloat(tsStr), val}))
.sort((a, b) => a.ts - b.ts);
}
const fof2Entries = toSeries(station.fof2);
const mufEntries = toSeries(station.muf);
const allTs = [...fof2Entries, ...mufEntries].map(e => e.ts);
if (allTs.length === 0) return;
// Populate latest values summary (visible on all screen sizes)
const latestFof2 = fof2Entries.length ? fof2Entries[fof2Entries.length - 1].val : null;
const latestMuf = mufEntries.length ? mufEntries[mufEntries.length - 1].val : null;
const latestTs = allTs.length ? Math.max(...allTs) : null;
var latestTimeStr = '';
if (latestTs != null) {
const latestDate = moment.utc(latestTs * 1000);
latestTimeStr = latestDate.format('DD MMM YYYY HH:mm [UTC]') + ' (' + latestDate.fromNow() + ')';
}
$('#ionosonde-latest').html(
'<div class="row border-bottom align-items-center me-0">' +
'<div class="col-12 col-md-6 py-2 text-muted">Latest values as of ' + latestTimeStr + '</div>' +
'<div class="col-12 col-md-6 py-2">' +
'<span class="me-5">foF2: <strong>' + (latestFof2 !== null ? latestFof2.toFixed(2) + ' MHz' : 'N/A') + '</strong></span>' +
'<span>MUF (3000 km): <strong>' + (latestMuf !== null ? latestMuf.toFixed(2) + ' MHz' : 'N/A') + '</strong></span>' +
'</div>' +
'</div>'
);
if (ionosondeChart) {
ionosondeChart.destroy();
}
const minTs = Math.min(...allTs);
const maxTs = Math.max(...allTs);
// Compute tick positions at 3-hour UTC boundaries so midnight always lands on a tick, which triggers the date being
// printed, and in general looks nicer than arbitrary ticks based on min & max timestamp
const tickStep = 3 * 3600;
const tickValues = [];
for (let t = Math.ceil(minTs / tickStep) * tickStep; t <= maxTs; t += tickStep) {
tickValues.push(t);
}
tickValues.push(maxTs);
const timeAxis = {
type: 'linear',
min: minTs,
max: maxTs,
title: {display: true, text: 'Time (UTC)', color: textColor},
afterBuildTicks(axis) {
axis.ticks = tickValues.map(v => ({value: v}));
},
ticks: {
color: textColor,
maxRotation: 45,
minRotation: 0,
callback(value) {
const dt = new Date(value * 1000);
const h = dt.getUTCHours();
const m = dt.getUTCMinutes();
const timeStr = String(h).padStart(2, '0') + ':' + String(m).padStart(2, '0');
if (h === 0 && m === 0) {
return [timeStr, dt.toLocaleDateString('en-GB', {day: '2-digit', month: 'short', timeZone: 'UTC'})];
}
return timeStr;
},
},
grid: {color: gridColor},
};
const freqAxis = {
min: 0,
title: {display: true, text: 'Frequency (MHz)', color: textColor},
ticks: {color: textColor},
grid: {display: false},
};
const AMATEUR_BANDS = [
{label: '160m', freq: 1.8},
{label: '80m', freq: 3.5},
{label: '60m', freq: 5.3515},
{label: '40m', freq: 7.0},
{label: '30m', freq: 10.1},
{label: '20m', freq: 14.0},
{label: '17m', freq: 18.068},
{label: '15m', freq: 21.0},
{label: '12m', freq: 24.89},
{label: '10m', freq: 28.0},
];
const bandLinesPlugin = {
id: 'bandLines',
beforeDatasetsDraw(chart) {
const {ctx, chartArea, scales} = chart;
if (!scales.y) return;
ctx.save();
ctx.strokeStyle = gridColor;
ctx.lineWidth = 1;
ctx.setLineDash([]);
const y30 = scales.y.getPixelForValue(30);
if (y30 >= chartArea.top && y30 <= chartArea.bottom) {
ctx.beginPath();
ctx.moveTo(chartArea.left, y30);
ctx.lineTo(chartArea.right, y30);
ctx.stroke();
}
ctx.font = '10px sans-serif';
ctx.fillStyle = textColor;
AMATEUR_BANDS.forEach(({label, freq}) => {
const y = scales.y.getPixelForValue(freq);
if (y < chartArea.top || y > chartArea.bottom) return;
ctx.beginPath();
ctx.moveTo(chartArea.left, y);
ctx.lineTo(chartArea.right, y);
ctx.stroke();
ctx.textAlign = 'right';
ctx.textBaseline = 'bottom';
ctx.fillText(label, chartArea.right - 4, y - 2);
});
ctx.restore();
}
};
ionosondeChart = new Chart(document.getElementById('ionosonde-chart'), {
type: 'line',
data: {
datasets: [
{
label: 'foF2',
data: fof2Entries.map(e => ({x: e.ts, y: e.val})),
borderColor: fof2Color,
backgroundColor: 'transparent',
pointRadius: 0,
tension: 0.2,
},
{
label: 'MUF (3000 km)',
data: mufEntries.map(e => ({x: e.ts, y: e.val})),
borderColor: mufColor,
backgroundColor: 'transparent',
pointRadius: 0,
tension: 0.2,
}
]
},
options: {
responsive: true,
aspectRatio: 3,
plugins: {
legend: {display: true, labels: {color: textColor, usePointStyle: true, pointStyle: 'line'}},
tooltip: {enabled: false}
},
scales: {x: timeAxis, y: freqAxis},
},
plugins: [bandLinesPlugin],
});
}
// Called when the ionosonde station select changes
function ionosondeStationChanged() {
saveSettings();
renderIonosondeData();
}
// Render the DX stats table for the currently selected DE continent
function renderDxStats() {
if (!dxStatsData) {