CIROH-UA / CIROH-UA/data_access_example
Add tools to make the notebook functional on Google Colab
- Dominant language
- Jupyter Notebook
- Stars
- 0
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
Adding something like the following to the notebook cell should allow it to run in Google Colab, which is useful for demonstrations.
``` python
import sys
import os
# Check if we are in a Google Colab environment.
# This is a common heuristic to detect Colab.
IN_COLAB = 'google.colab' in sys.modules
if IN_COLAB:
print("Running in Google Colab environment.")
repo_name = "data_access_example"
repo_url = "https://github.com/slama0077/data_access_example"
branch_name = "Forcing"
# Define the target directory for cloning
# clone_dir = os.path.join(os.getcwd(), repo_name)
clone_dir = os.path.join("/", "content", repo_name)
# install the various dependencies
!pip install nwmurl
!pip install ngiab_data_preprocess
!pip install -r "/content/data_access_example/requirements.txt"
# If the directory already exists, remove it to ensure we get the correct branch
if os.path.exists(clone_dir):
print(f"Removing existing directory: {clone_dir}")
# Use !rm -rf for shell command execution in Colab
!rm -rf {clone_dir}
# Clone the specified branch of the repository
print(f"Cloning the '{branch_name}' branch of '{repo_url}' into '{clone_dir}'")
# Use !git clone for shell command execution in Colab
!git clone -b {branch_name} {repo_url} {clone_dir}
# Add the cloned repository path to sys.path
if clone_dir not in sys.path:
sys.path.insert(0, clone_dir)
print(f"Added '{clone_dir}' to Python path.")
else:
print(f"'{clone_dir}' is already in Python path.")
else:
print("Not running in Google Colab environment. Skipping repository cloning and path setup.")
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.