Skip to content

Commit

Permalink
Update input_output.py
Browse files Browse the repository at this point in the history
Added a backup source for the SAM in a GH repository
  • Loading branch information
SeaCelo committed Aug 29, 2024
1 parent 6e576ae commit 0a58d9e
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.")

Check warning on line 23 in ogzaf/input_output.py

View check run for this annotation

Codecov / codecov/patch

ogzaf/input_output.py#L23

Added line #L23 was not covered by tests
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

Check warning on line 38 in ogzaf/input_output.py

View check run for this annotation

Codecov / codecov/patch

ogzaf/input_output.py#L36-L38

Added lines #L36 - L38 were not covered by tests
# If both attempts fail, SAM will be None
if SAM is None:
print("Failed to read SAM from both sources.")

Check warning on line 41 in ogzaf/input_output.py

View check run for this annotation

Codecov / codecov/patch

ogzaf/input_output.py#L41

Added line #L41 was not covered by tests
else:
SAM = None
print("No internet connection. SAM cannot be read.")

Check warning on line 44 in ogzaf/input_output.py

View check run for this annotation

Codecov / codecov/patch

ogzaf/input_output.py#L44

Added line #L44 was not covered by tests


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

0 comments on commit 0a58d9e

Please sign in to comment.