Skip to content

Commit

Permalink
Merge pull request #73 from SeaCelo/wider-sam-fix
Browse files Browse the repository at this point in the history
Update input_output.py
  • Loading branch information
jdebacker authored Sep 6, 2024
2 parents 6e576ae + 0a58d9e commit f003a14
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions ogzaf/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,39 @@
# 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_path_alt = "https://raw.githubusercontent.com/EAPD-DRB/SAM-files/main/Data/ZAF/SASAM-2015-Data-Resource.xlsx"

if is_connected():
SAM = pd.read_excel(
SAM_path,
sheet_name="Micro SAM 2015",
skiprows=6,
index_col=0,
storage_options=storage_options,
)
try:
SAM = pd.read_excel(
SAM_path,
sheet_name="Micro SAM 2015",
skiprows=6,
index_col=0,
storage_options=storage_options,
)
print("Successfully read SAM from WIDER.")
except Exception as e:
print(f"Failed to read from WIDER: {e}")
try:
# Attempt to read from the GitHub repository
SAM = pd.read_excel(
SAM_path_alt,
sheet_name="Micro SAM 2015",
skiprows=6,
index_col=0,
storage_options=storage_options,
)
print("Successfully read SAM from GitHub repository.")
except Exception as e:
print(f"Failed to read from the GitHub repository: {e}")
SAM = None
# If both attempts fail, SAM will be None
if SAM is None:
print("Failed to read SAM from both sources.")
else:
SAM = None
print("No internet connection. SAM cannot be read.")


def get_alpha_c(sam=SAM, cons_dict=CONS_DICT):
Expand Down

0 comments on commit f003a14

Please sign in to comment.