From 10b962fdbfb10d44f2cc0a163ad751d9e70ef677 Mon Sep 17 00:00:00 2001 From: johan12345 Date: Fri, 9 Jul 2021 13:35:21 +0200 Subject: [PATCH] fall back to mirror if helioviewer.org is offline (fixes #5) --- gcs/gui.py | 6 +++--- gcs/utils/helioviewer.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 gcs/utils/helioviewer.py diff --git a/gcs/gui.py b/gcs/gui.py index 39ff17e..6012bf3 100644 --- a/gcs/gui.py +++ b/gcs/gui.py @@ -18,16 +18,16 @@ from matplotlib.gridspec import GridSpec from sunpy import log from sunpy.coordinates import get_horizons_coord -from sunpy.io import read_file from sunpy.map import Map -from sunpy.net import helioviewer from gcs.geometry import gcs_mesh_sunpy, apex_radius +from gcs.utils.helioviewer import get_helioviewer_client from gcs.utils.widgets import SliderAndTextbox matplotlib.use('Qt5Agg') -hv = helioviewer.HelioviewerClient() +hv = get_helioviewer_client() + straight_vertices, front_vertices, circle_vertices = 10, 10, 20 filename = 'gcs_params.json' draw_modes = ['off', 'point cloud', 'grid'] diff --git a/gcs/utils/helioviewer.py b/gcs/utils/helioviewer.py new file mode 100644 index 0000000..2d6e953 --- /dev/null +++ b/gcs/utils/helioviewer.py @@ -0,0 +1,18 @@ +from sunpy.net.helioviewer import HelioviewerClient + + +def get_helioviewer_client(): + hv = HelioviewerClient() + if not _is_online(hv): + # fall back to mirror server + print("https://www.helioviewer.org/ seems to be offline," + "switching to mirror at https://helioviewer.ias.u-psud.fr/") + hv = HelioviewerClient("https://helioviewer-api.ias.u-psud.fr/") + return hv + + +def _is_online(hv: HelioviewerClient): + try: + return hv.is_online() + except: + return False \ No newline at end of file