Skip to content

Commit 10b962f

Browse files
committed
fall back to mirror if helioviewer.org is offline (fixes #5)
1 parent 33a57b9 commit 10b962f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

gcs/gui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
from matplotlib.gridspec import GridSpec
1919
from sunpy import log
2020
from sunpy.coordinates import get_horizons_coord
21-
from sunpy.io import read_file
2221
from sunpy.map import Map
23-
from sunpy.net import helioviewer
2422

2523
from gcs.geometry import gcs_mesh_sunpy, apex_radius
24+
from gcs.utils.helioviewer import get_helioviewer_client
2625
from gcs.utils.widgets import SliderAndTextbox
2726

2827
matplotlib.use('Qt5Agg')
2928

30-
hv = helioviewer.HelioviewerClient()
29+
hv = get_helioviewer_client()
30+
3131
straight_vertices, front_vertices, circle_vertices = 10, 10, 20
3232
filename = 'gcs_params.json'
3333
draw_modes = ['off', 'point cloud', 'grid']

gcs/utils/helioviewer.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from sunpy.net.helioviewer import HelioviewerClient
2+
3+
4+
def get_helioviewer_client():
5+
hv = HelioviewerClient()
6+
if not _is_online(hv):
7+
# fall back to mirror server
8+
print("https://www.helioviewer.org/ seems to be offline,"
9+
"switching to mirror at https://helioviewer.ias.u-psud.fr/")
10+
hv = HelioviewerClient("https://helioviewer-api.ias.u-psud.fr/")
11+
return hv
12+
13+
14+
def _is_online(hv: HelioviewerClient):
15+
try:
16+
return hv.is_online()
17+
except:
18+
return False

0 commit comments

Comments
 (0)