From 41d507c3cad74b0c666e0dfc95d3d0c6e47ec9c2 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Sat, 3 Aug 2024 19:21:57 -0400 Subject: [PATCH] check if cnnected --- examples/run_og_zaf.py | 8 +++++--- ogzaf/input_output.py | 18 +++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/run_og_zaf.py b/examples/run_og_zaf.py index 14eae4d..a4c8a6f 100644 --- a/examples/run_og_zaf.py +++ b/examples/run_og_zaf.py @@ -14,6 +14,7 @@ from ogcore import output_plots as op from ogcore.execute import runner from ogcore.utils import safe_read_pickle +from ogzaf.utils import is_connected # Use a custom matplotlib style file for plots plt.style.use("ogcore.OGcorePlots") @@ -50,9 +51,10 @@ def main(): defaults = json.load(file) p.update_specifications(defaults) # Update parameters from calibrate.py Calibration class - c = Calibration(p) - updated_params = c.get_dict() - p.update_specifications(updated_params) + if is_connected(): # only update if connected to internet + c = Calibration(p) + updated_params = c.get_dict() + p.update_specifications(updated_params) # Run model start_time = time.time() diff --git a/ogzaf/input_output.py b/ogzaf/input_output.py index e6d2bee..6db9288 100644 --- a/ogzaf/input_output.py +++ b/ogzaf/input_output.py @@ -1,5 +1,6 @@ import pandas as pd import numpy as np +from ogzaf.utils import is_connected from ogzaf.constants import CONS_DICT, PROD_DICT """ @@ -8,13 +9,16 @@ # Read in SAM file storage_options = {"User-Agent": "Mozilla/5.0"} SAM_path = "https://www.wider.unu.edu/sites/default/files/Data/SASAM-2015-Data-Resource.xlsx" -SAM = pd.read_excel( - SAM_path, - sheet_name="Micro SAM 2015", - skiprows=6, - index_col=0, - storage_options=storage_options, -) +if is_connected(): + SAM = pd.read_excel( + SAM_path, + sheet_name="Micro SAM 2015", + skiprows=6, + index_col=0, + storage_options=storage_options, + ) +else: + SAM = None def get_alpha_c(sam=SAM, cons_dict=CONS_DICT):