Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update input_output.py #73

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading